Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/tanchiki/annotate/803f8353f38f/game.py
Дата изменения: Unknown
Дата индексирования: Fri Feb 28 23:47:24 2014
Кодировка:
tanchiki: game.py annotate

tanchiki

annotate game.py @ 32:803f8353f38f

Created branch new
author Peter Zotov <whitequark@whitequark.org>
date Mon, 20 Dec 2010 16:05:49 +0300
parents 4f578d001608
children ce43bb4acf82 dfdc1def5d24
rev   line source
whitequark@16 1 other_tanks = []
whitequark@16 2 bullets = []
whitequark@16 3
whitequark@16 4 class Game(object):
whitequark@16 5 def __init__(self, bodies, users, width, height):
whitequark@16 6 self.bodies = bodies
whitequark@16 7 self.users = users
whitequark@16 8 self.width = width
whitequark@16 9 self.height = height
whitequark@16 10
whitequark@16 11 def step(game):
whitequark@16 12 game.next_positions()
whitequark@16 13 game.check_collisions()
whitequark@16 14 game.check_walls()
whitequark@16 15 game.update_positions()
whitequark@16 16 game.invoke_ticks()
whitequark@16 17 game.respawn()
whitequark@16 18
whitequark@16 19 def next_positions(game):
whitequark@16 20 delta_t = 1
whitequark@16 21 for i in game.bodies :
whitequark@16 22 i.next_position = i.position + i.velocity*(delta_t)
whitequark@16 23
whitequark@16 24 def check_collisions(game):
whitequark@16 25 pass
whitequark@16 26
whitequark@16 27 def collides(self,body1,body2):
whitequark@16 28 pass
whitequark@16 29
whitequark@16 30 def handle_collision(self,body1,body2):
whitequark@16 31 pass
whitequark@16 32
whitequark@16 33 def check_walls(game):
whitequark@16 34 for i in game.bodies :
whitequark@16 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) :
whitequark@16 36 i.on_wall()
whitequark@16 37
whitequark@16 38 def update_positions(game):
whitequark@16 39 for i in game.bodies :
whitequark@16 40 i.position = i.next_position
whitequark@16 41
whitequark@16 42 def invoke_ticks(game):
whitequark@16 43 for i in game.users :
whitequark@16 44 i.tank.on_tick(other_tanks,bullets)
whitequark@16 45
whitequark@16 46 def respawn(game):
whitequark@16 47 for i in game.users :
whitequark@16 48 if i.tank.strength == 0 :
whitequark@16 49 i.tank.on_spawn()
whitequark@16 50 i.tank.strength = 1