Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/tanchiki/file/4f578d001608/game.py
Дата изменения: Unknown
Дата индексирования: Sun Feb 3 10:39:06 2013
Кодировка:
tanchiki: 4f578d001608 game.py

tanchiki

view 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
line source
1 other_tanks = []
2 bullets = []
4 class Game(object):
5 def __init__(self, bodies, users, width, height):
6 self.bodies = bodies
7 self.users = users
8 self.width = width
9 self.height = height
11 def step(game):
12 game.next_positions()
13 game.check_collisions()
14 game.check_walls()
15 game.update_positions()
16 game.invoke_ticks()
17 game.respawn()
19 def next_positions(game):
20 delta_t = 1
21 for i in game.bodies:
22 i.next_position = i.position + i.velocity*(delta_t)
25 def check_collisions(game):
26 pass
28 def collides(self,body1,body2):
29 pass
31 def handle_collision(self,body1,body2):
32 pass
34 def check_walls(game):
35 for i in game.bodies :
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) :
37 i.on_wall()
40 def update_positions(game):
41 for i in game.bodies:
42 i.position = i.next_position
44 def invoke_ticks(game):
45 for i in game.users:
46 i.tank.on_tick(other_tanks,bullets)
48 def respawn(game):
49 for i in game.users :
50 if i.tank.strength == 0 :
51 i.tank.on_spawn()
52 i.tank.strength = 1