Skip to content

Commit 80731ff

Browse files
committed
Added basic collision tutorial
1 parent 7d38d9c commit 80731ff

File tree

6 files changed

+737
-8
lines changed

6 files changed

+737
-8
lines changed

intermediate/add.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# Imports as usual
2-
import cocos
32
from cocos.sprite import Sprite
43
from cocos.tiles import load
54
from cocos.layer import ScrollingManager, ScrollableLayer
@@ -13,11 +12,12 @@
1312

1413
# The first thing I need to do is initialize the director, because many other objects in this program depend on it
1514
# 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
1717

1818
# Here I set a scroller and a key manager
1919
# 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!
2121
keyboard = key.KeyStateHandler()
2222

2323
# And the scrolling manager like you saw last time
@@ -39,18 +39,19 @@ def step(self, dt):
3939
# Finally, I add it to the rotation of the "target", which would be the sprite we tell to do this action
4040

4141
# 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!
4344

4445
# Next I'm going to make the car stop completely if the space key is held
4546
if keyboard[key.SPACE]:
4647
self.target.speed = 0
4748
# Pretty easy, huh?
4849

4950
# 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
5152
super(CarDriver, self).step(dt)
5253

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
5455
scroller.set_focus(self.target.x, self.target.y)
5556

5657

18.6 KB
Loading

0 commit comments

Comments
 (0)