tanchiki
annotate game.py @ 8:4f578d001608
Game.collides and Game.handle_collision are now methods of game, not hidden functions
| author | Daniil Alexeyevsky <me.dendik@gmail.com> |
|---|---|
| date | Sat, 18 Dec 2010 16:09:05 +0300 |
| parents | af02cd410e37 |
| children | 43f5b82f3491 c71c27b09bc7 |
| rev | line source |
|---|---|
| olya_zol@3 | 1 other_tanks = [] |
| olya_zol@3 | 2 bullets = [] |
| olya_zol@3 | 3 |
| olya_zol@1 | 4 class Game(object): |
| olya_zol@1 | 5 def __init__(self, bodies, users, width, height): |
| olya_zol@1 | 6 self.bodies = bodies |
| olya_zol@1 | 7 self.users = users |
| olya_zol@1 | 8 self.width = width |
| olya_zol@1 | 9 self.height = height |
| olya_zol@1 | 10 |
| olya_zol@2 | 11 def step(game): |
| olya_zol@2 | 12 game.next_positions() |
| olya_zol@2 | 13 game.check_collisions() |
| olya_zol@2 | 14 game.check_walls() |
| olya_zol@2 | 15 game.update_positions() |
| olya_zol@2 | 16 game.invoke_ticks() |
| olya_zol@2 | 17 game.respawn() |
| olya_zol@1 | 18 |
| olya_zol@2 | 19 def next_positions(game): |
| olya_zol@2 | 20 delta_t = 1 |
| olya_zol@2 | 21 for i in game.bodies: |
| olya_zol@3 | 22 i.next_position = i.position + i.velocity*(delta_t) |
| olya_zol@1 | 23 |
| olya_zol@2 | 24 |
| olya_zol@2 | 25 def check_collisions(game): |
| olya_zol@1 | 26 pass |
| olya_zol@1 | 27 |
| me@8 | 28 def collides(self,body1,body2): |
| me@8 | 29 pass |
| olya_zol@1 | 30 |
| me@8 | 31 def handle_collision(self,body1,body2): |
| me@8 | 32 pass |
| olya_zol@1 | 33 |
| olya_zol@2 | 34 def check_walls(game): |
| olya_zol@2 | 35 for i in game.bodies : |
| olya_zol@3 | 36 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) : |
| olya_zol@2 | 37 i.on_wall() |
| olya_zol@2 | 38 |
| olya_zol@1 | 39 |
| olya_zol@2 | 40 def update_positions(game): |
| olya_zol@2 | 41 for i in game.bodies: |
| olya_zol@2 | 42 i.position = i.next_position |
| olya_zol@1 | 43 |
| olya_zol@2 | 44 def invoke_ticks(game): |
| olya_zol@3 | 45 for i in game.users: |
| olya_zol@3 | 46 i.tank.on_tick(other_tanks,bullets) |
| olya_zol@1 | 47 |
| olya_zol@2 | 48 def respawn(game): |
| olya_zol@2 | 49 for i in game.users : |
| olya_zol@2 | 50 if i.tank.strength == 0 : |
| olya_zol@3 | 51 i.tank.on_spawn() |
| me@8 | 52 i.tank.strength = 1 |
