The slides to accompany the Introduction to Game Programming tutorial I ran at LCA 2010. The tutorial ran over 90 minutes with the participants following along.
38. Shooting ... and Hitting
...
elif a.y + a.height/2 < 0:
a.y += w.height + a.height
for a in asteroids:
if distance(a, ship) < (a.width/2 + ship.width/2):
sys.exit('GAME OVER')
for a in list(asteroids):
if collide(a, ship):
sys.exit('GAME OVER')
for b in list(bullets):
if collide(a, b):
bullets.remove(b)
asteroids.remove(a)
if not asteroids:
sys.exit('YOU WIN')
pyglet.clock.schedule_interval(update, 1./30)
...
40. ...
Chunks
for b in list(bullets):
if collide(a, b):
bullets.remove(b)
asteroids.remove(a)
if a.image is big_asteroid_image.texture:
for i in range(2):
s = pyglet.sprite.Sprite(medium_asteroid_image, a.x, a.y)
s.dx = a.dx + random.randint(-50, 50)
s.dy = a.dy + random.randint(-50, 50)
s.dr = a.dr + random.randint(-50, 50)
asteroids.append(s)
elif a.image is medium_asteroid_image.texture:
for i in range(2):
s = pyglet.sprite.Sprite(small_asteroid_image, a.x, a.y)
s.dx = a.dx + random.randint(-50, 50)
s.dy = a.dy + random.randint(-50, 50)
s.dr = a.dr + random.randint(-50, 50)
asteroids.append(s)
if not asteroids:
sys.exit('YOU WIN')
...