tanchiki
diff game.py @ 2:e6e7b30ecde0
modules changed
author | Olga Zolotareva <olya_zol@inbox.ru> |
---|---|
date | Sat, 18 Dec 2010 13:23:48 +0300 |
parents | 78df8ab210fe |
children | af02cd410e37 |
line diff
1.1 --- a/game.py Sat Dec 18 06:14:15 2010 +0300 1.2 +++ b/game.py Sat Dec 18 13:23:48 2010 +0300 1.3 @@ -5,13 +5,21 @@ 1.4 self.width = width 1.5 self.height = height 1.6 1.7 - def step(): 1.8 - pass 1.9 + def step(game): 1.10 + game.next_positions() 1.11 + game.check_collisions() 1.12 + game.check_walls() 1.13 + game.update_positions() 1.14 + game.invoke_ticks() 1.15 + game.respawn() 1.16 1.17 - def next_positions(): 1.18 - pass 1.19 + def next_positions(game): 1.20 + delta_t = 1 1.21 + for i in game.bodies: 1.22 + i.next_position = i.position + i.velocity.mul_v(delta_t) 1.23 1.24 - def check_collisions(): 1.25 + 1.26 + def check_collisions(game): 1.27 pass 1.28 1.29 def collides(body1,body2): 1.30 @@ -20,15 +28,23 @@ 1.31 def handle_collision(body1,body2): 1.32 pass 1.33 1.34 - def check_walls(): 1.35 - pass 1.36 + def check_walls(game): 1.37 + for i in game.bodies : 1.38 + if (i.next_position.x <= 0) or (i.next_position.y <= 0) or (i.next_position.x <= width) or (i.next_position.y >= game.height) : 1.39 + i.on_wall() 1.40 + 1.41 1.42 - def update_positions(): 1.43 - pass 1.44 + def update_positions(game): 1.45 + for i in game.bodies: 1.46 + i.position = i.next_position 1.47 1.48 - def invoke_ticks(): 1.49 + def invoke_ticks(game): 1.50 pass 1.51 1.52 - def respawn(): 1.53 - pass 1.54 - 1.55 \ No newline at end of file 1.56 + def respawn(game): 1.57 + for i in game.users : 1.58 + if i.tank.strength == 0 : 1.59 + i.tank.respawn() 1.60 + 1.61 + 1.62 + 1.63 \ No newline at end of file