tanchiki
annotate game.py @ 34:b7a85caedc7f
Re-imported files after merge
| author | Daniil Alexeyevsky <me.dendik@gmail.com> |
|---|---|
| date | Mon, 20 Dec 2010 16:12:55 +0300 |
| parents | |
| children | 1a0bddee3c54 |
| rev | line source |
|---|---|
| me@34 | 1 other_tanks = [] |
| me@34 | 2 bullets = [] |
| me@34 | 3 |
| me@34 | 4 class Game(object): |
| me@34 | 5 def __init__(self, bodies, users, width, height): |
| me@34 | 6 self.bodies = bodies |
| me@34 | 7 self.users = users |
| me@34 | 8 self.width = width |
| me@34 | 9 self.height = height |
| me@34 | 10 |
| me@34 | 11 def step(game): |
| me@34 | 12 game.next_positions() |
| me@34 | 13 game.check_collisions() |
| me@34 | 14 game.check_walls() |
| me@34 | 15 game.update_positions() |
| me@34 | 16 game.invoke_ticks() |
| me@34 | 17 game.respawn() |
| me@34 | 18 |
| me@34 | 19 def next_positions(game): |
| me@34 | 20 delta_t = 1 |
| me@34 | 21 for i in game.bodies : |
| me@34 | 22 i.next_position = i.position + i.velocity*(delta_t) |
| me@34 | 23 |
| me@34 | 24 def check_collisions(game): |
| me@34 | 25 pass |
| me@34 | 26 |
| me@34 | 27 def collides(self,body1,body2): |
| me@34 | 28 pass |
| me@34 | 29 |
| me@34 | 30 def handle_collision(self,body1,body2): |
| me@34 | 31 pass |
| me@34 | 32 |
| me@34 | 33 def check_walls(game): |
| me@34 | 34 for i in game.bodies : |
| me@34 | 35 if ((i.next_position.x - i.radius) <= 0) or ((i.next_position.y - i.radius) <= 0) or ((i.next_position.x + i.radius) >= game.width) or ((i.next_position.y + i.radius) >= game.height) : |
| me@34 | 36 i.on_wall() |
| me@34 | 37 |
| me@34 | 38 def update_positions(game): |
| me@34 | 39 for i in game.bodies : |
| me@34 | 40 i.position = i.next_position |
| me@34 | 41 |
| me@34 | 42 def invoke_ticks(game): |
| me@34 | 43 for i in game.users : |
| me@34 | 44 i.tank.on_tick(other_tanks,bullets) |
| me@34 | 45 |
| me@34 | 46 def respawn(game): |
| me@34 | 47 for i in game.users : |
| me@34 | 48 if i.tank.strength == 0 : |
| me@34 | 49 i.tank.on_spawn() |
| me@34 | 50 i.tank.strength = 1 |
