1
1
# Imports as usual
2
- import cocos
3
2
from cocos .sprite import Sprite
4
3
from cocos .tiles import load
5
4
from cocos .layer import ScrollingManager , ScrollableLayer
13
12
14
13
# The first thing I need to do is initialize the director, because many other objects in this program depend on it
15
14
# This time I'm going to pass in a few more parameters than usual into the initialize function
16
- director .init (width = 800 , height = 600 , autoscale = False , resizable = True ) # I simply set an X and Y for the window, and allow it to be resized
15
+ director .init (width = 800 , height = 600 , autoscale = False , resizable = True )
16
+ # I simply set an X and Y for the window, and allow it to be resized
17
17
18
18
# Here I set a scroller and a key manager
19
19
# The key manager is something new you haven't seen!
20
- # It allows me to get the keys being pressed globally. Pretty neat!
20
+ # It allows me to get the keys being pressed, globally. Pretty neat!
21
21
keyboard = key .KeyStateHandler ()
22
22
23
23
# And the scrolling manager like you saw last time
@@ -39,18 +39,19 @@ def step(self, dt):
39
39
# Finally, I add it to the rotation of the "target", which would be the sprite we tell to do this action
40
40
41
41
# Now I'm going to do something very similar for the sprite's acceleration
42
- self .target .acceleration = (keyboard [key .UP ] - keyboard [key .DOWN ]) * 350 # See if you can figure this out yourself!
42
+ self .target .acceleration = (keyboard [key .UP ] - keyboard [key .DOWN ]) * 350
43
+ # See if you can figure this out yourself!
43
44
44
45
# Next I'm going to make the car stop completely if the space key is held
45
46
if keyboard [key .SPACE ]:
46
47
self .target .speed = 0
47
48
# Pretty easy, huh?
48
49
49
50
# That's basically it!
50
- # Now we just need to call the original step function to let it do its magic and then update the scroller
51
+ # Now we just need to call the original step function to let it do its magic
51
52
super (CarDriver , self ).step (dt )
52
53
53
- # Lastly, this line simply tells the ScrollingManager to set the center to the sprite
54
+ # Lastly, this line simply tells the ScrollingManager to set the center of the screen on the sprite
54
55
scroller .set_focus (self .target .x , self .target .y )
55
56
56
57
0 commit comments