view game.py @ 46:dba440ba9a00
Bugfixed: constant names for tank movement; added the tank to the game
author |
Daniil Alexeyevsky <me.dendik@gmail.com> |
date |
Mon, 20 Dec 2010 20:37:54 +0300 |
parents |
b7a85caedc7f dfdc1def5d24 |
children |
d740eff76e7e |
line source
9 def __init__(self, bodies, users, width, height):
16 for i in self.bodies: #test
17 print "begin", i, i.position
19 self.check_collisions()
21 self.update_positions()
25 for i in self.bodies: #test
26 print "end", i, i.position #test
31 def next_positions(self):
34 i.next_position = i.position + i.velocity*(delta_t)
37 def check_collisions(self):
40 if self.collides(i,j) == True :
41 self.handle_collision(i,j)
43 def collides(self,body1,body2):
45 if (abs(body1.next_position - body2.next_position) <= (body1.radius + body2.radius)):
47 print body1.position , body2.position
55 def handle_collision(self,body1,body2):
56 if isinstance(body1, body.Tank) == True :
57 if isinstance(body2, body.Tank) == True :
58 body1.on_collision(body2)
63 if isinstance(body2, body.Tank) == True :
67 def check_walls(self):
68 for i in self.bodies :
69 if ((i.next_position.x - i.radius) <= 0) or ((i.next_position.y - i.radius) <= 0) or ((i.next_position.x + i.radius) >= self.width) or ((i.next_position.y + i.radius) >= self.height) :
73 def update_positions(self):
75 i.position = i.next_position
77 def invoke_ticks(self):
78 for i in self.bodies :
79 if isinstance(i, body.Tank) :
85 if i.tank.strength == 0 :
88 i.tank.velocity = vector.null
89 i.tank.position.x = random.randint(self.radius , width - self.radius)
90 i.tank.position.y = random.randint(self.radius , height - self.radius)
91 i.tank.velocity = vector.null