Changeset 20:ee776b889df7
- Timestamp:
- 12/20/10 08:08:18 (5 years ago)
- Branch:
- default
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tanchiki/game.py
r19 r20 ˆà 3 3 ˆà 4 4 class Game(object):ˆà 5 ˆà def __init__(self, bodies, users, width, height):ˆàˆà 5 def __init__(self, width, height, bodies):ˆà 6 6 self.bodies = bodiesˆà 7 ˆà self.users = usersˆà8 7 self.width = widthˆà 9 8 self.height = heightˆà 10 9 ˆà 11 ˆà def step(game, delta_t):ˆà 12 ˆà game.next_positions()ˆà 13 ˆà game.check_collisions()ˆà 14 ˆà game.check_walls()ˆà 15 ˆà game.update_positions()ˆà 16 ˆà game.invoke_ticks()ˆà 17 ˆà game.respawn()ˆà ˆà 10 def step(self, delta_t):ˆà ˆà 11 self.__calculate_positions(delta_t)ˆà ˆà 12 self.__check_walls()ˆà ˆà 13 self.__check_collisions()ˆà ˆà 14 self.__update_positions()ˆà ˆà 15 self.__invoke_ticks()ˆà 18 16 ˆà 19 ˆà def next_positions(game, delta_t):ˆàˆà 17 def __calculate_positions(game, delta_t):ˆà 20 18 for i in game.bodies :ˆà 21 19 i.next_position = i.position + i.velocity*(delta_t)ˆà 22 20 ˆà 23 ˆà def check_collisions(game):ˆà ˆà 21 def __update_positions(self):ˆà ˆà 22 for i in self.bodies :ˆà ˆà 23 i.position = i.next_positionˆà ˆà 24 ˆà ˆà 25 def __collides(self, body1, body2):ˆà 24 26 passˆà 25 27 ˆà 26 ˆà def collides(self,body1,body2):ˆàˆà 28 def __handle_collision(self, body1, body2):ˆà 27 29 passˆà 28 30 ˆà 29 ˆà def handle_collision(self,body1,body2):ˆàˆà 31 def __check_collisions(game):ˆà 30 32 passˆà 31 33 ˆà 32 ˆà def check_walls(game):ˆàˆà 34 def __check_walls(game):ˆà 33 35 for i in game.bodies :ˆà 34 ˆà 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) :ˆà ˆà 36 if ((i.next_position.x - i.radius) <= 0) orˆà ˆà 37 ((i.next_position.y - i.radius) <= 0) orˆà ˆà 38 ((i.next_position.x + i.radius) >= game.width) orˆà ˆà 39 ((i.next_position.y + i.radius) >= game.height) :ˆà 35 40 i.on_wall()ˆà 36 41 ˆà 37 ˆà def update_positions(game):ˆà38 ˆà for i in game.bodies :ˆàˆà 42 def __update_positions(self):ˆà ˆà 43 for i in self.bodies :ˆà 39 44 i.position = i.next_positionˆà 40 45 ˆà 41 ˆà def invoke_ticks(game):ˆà 42 ˆà for i in game.users :ˆà 43 ˆà i.tank.on_tick(other_tanks,bullets)ˆà 44 ˆà ˆà 45 ˆà def respawn(game):ˆà 46 ˆà for i in game.users :ˆà 47 ˆà if i.tank.strength == 0 :ˆà 48 ˆà i.tank.on_spawn()ˆà 49 ˆà i.tank.strength = 1 ˆà ˆà 46 def __invoke_ticks(self):ˆà ˆà 47 for i in self.bodies :ˆà ˆà 48 if i.controllerˆà ˆà 49 i.controller.on_tick(other_tanks, bullets)ˆà
Note: See TracChangeset
for help on using the changeset viewer.