def animate(dt): # update car rotation & speed r = car.rotation r += (keyboard[key.RIGHT] - keyboard[key.LEFT]) * 200 * dt if r < 0: r += 360 elif r > 360: r -= 360 car.rotation = r car.speed = (keyboard[key.UP] - keyboard[key.DOWN]) * 200 * dt # ... and the rest spryte.update_kinematics(car, dt) # handle balls for i, s in enumerate(balls): # update positions s.x += s.dx * dt s.y += s.dy * dt if s.right > win.width and s.dx > 0: s.dx *= -1 s.right = win.width elif s.left < 0 and s.dx < 0: s.dx *= -1 s.left = 0 if s.top > win.height and s.dy > 0: s.dy *= -1 s.top = win.height elif s.bottom < 0 and s.dy < 0: s.dy *= -1 s.bottom = 0 # handle collisions if not s.intersects(car): continue if s.scale > 2: # pop! explosion = EffectSprite(explosion_animation, 0, 0, batch=explosions) explosion.center = s.center explosion.push_handlers s.delete() spryte.Sprite(ball, win.width * random.random(), win.height * random.random(), batch=balls, dx=-50 + 100 * random.random(), dy=-50 + 100 * random.random()) else: s.scale += .1 n = min(1, max(0, 2 - s.scale)) s.color = (1, 1, 1, .5 + n / 2)
def animate(dt): # update car rotation & speed r = car.rotation r += (keyboard[key.RIGHT] - keyboard[key.LEFT]) * 200 * dt if r < 0: r += 360 elif r > 360: r -= 360 car.rotation = r car.speed = (keyboard[key.UP] - keyboard[key.DOWN]) * 300 * dt # ... and the rest spryte.update_kinematics(car, dt) v.focus = car.position