tanchiki
changeset 20:ee776b889df7
Improve Game interface.
author | Peter Zotov <whitequark@whitequark.org> |
---|---|
date | Mon, 20 Dec 2010 08:08:18 +0300 |
parents | 31ea2608cc39 |
children | fe5df803d6c2 |
files | tanchiki/game.py |
diffstat | 1 files changed, 26 insertions(+), 26 deletions(-) [+] |
line diff
1.1 --- a/tanchiki/game.py Mon Dec 20 05:27:41 2010 +0300 1.2 +++ b/tanchiki/game.py Mon Dec 20 08:08:18 2010 +0300 1.3 @@ -2,48 +2,48 @@ 1.4 bullets = [] 1.5 1.6 class Game(object): 1.7 - def __init__(self, bodies, users, width, height): 1.8 + def __init__(self, width, height, bodies): 1.9 self.bodies = bodies 1.10 - self.users = users 1.11 self.width = width 1.12 self.height = height 1.13 1.14 - def step(game, delta_t): 1.15 - game.next_positions() 1.16 - game.check_collisions() 1.17 - game.check_walls() 1.18 - game.update_positions() 1.19 - game.invoke_ticks() 1.20 - game.respawn() 1.21 + def step(self, delta_t): 1.22 + self.__calculate_positions(delta_t) 1.23 + self.__check_walls() 1.24 + self.__check_collisions() 1.25 + self.__update_positions() 1.26 + self.__invoke_ticks() 1.27 1.28 - def next_positions(game, delta_t): 1.29 + def __calculate_positions(game, delta_t): 1.30 for i in game.bodies : 1.31 i.next_position = i.position + i.velocity*(delta_t) 1.32 1.33 - def check_collisions(game): 1.34 + def __update_positions(self): 1.35 + for i in self.bodies : 1.36 + i.position = i.next_position 1.37 + 1.38 + def __collides(self, body1, body2): 1.39 pass 1.40 1.41 - def collides(self,body1,body2): 1.42 + def __handle_collision(self, body1, body2): 1.43 pass 1.44 1.45 - def handle_collision(self,body1,body2): 1.46 + def __check_collisions(game): 1.47 pass 1.48 1.49 - def check_walls(game): 1.50 + def __check_walls(game): 1.51 for i in game.bodies : 1.52 - 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) : 1.53 + if ((i.next_position.x - i.radius) <= 0) or 1.54 + ((i.next_position.y - i.radius) <= 0) or 1.55 + ((i.next_position.x + i.radius) >= game.width) or 1.56 + ((i.next_position.y + i.radius) >= game.height) : 1.57 i.on_wall() 1.58 1.59 - def update_positions(game): 1.60 - for i in game.bodies : 1.61 + def __update_positions(self): 1.62 + for i in self.bodies : 1.63 i.position = i.next_position 1.64 1.65 - def invoke_ticks(game): 1.66 - for i in game.users : 1.67 - i.tank.on_tick(other_tanks,bullets) 1.68 - 1.69 - def respawn(game): 1.70 - for i in game.users : 1.71 - if i.tank.strength == 0 : 1.72 - i.tank.on_spawn() 1.73 - i.tank.strength = 1 1.74 + def __invoke_ticks(self): 1.75 + for i in self.bodies : 1.76 + if i.controller 1.77 + i.controller.on_tick(other_tanks, bullets)