view game.py @ 52:d740eff76e7e
some bugs corrected
author |
Olga Zolotareva <olya_zol@inbox.ru> |
date |
Fri, 24 Dec 2010 22:10:08 +0300 |
parents |
1a0bddee3c54 |
children |
5450c97fbc38 |
line source
12 def __init__(self, bodies, users, width, height):
20 self.check_collisions()
22 self.update_positions()
25 self.update_velocities()
26 for i in self.bodies :
28 # print 'next position' , i.next_position
29 print 'update_position' , i.position
30 print 'velocity' , i.velocity
31 print 'velocity.rho', i.velocity.rho # test
33 if isinstance(i,body.Tank) == True:
34 print 'base_orientation' , i.base_orientation
36 def update_velocities(self):
38 if isinstance(i, body.Tank):
39 if abs(i.velocity) > 1e-10 :
40 i.velocity = i.velocity - i.velocity.normalize()*body.acceleration
44 def next_positions(self):
47 i.next_position = i.position + i.velocity*body.delta_t
48 if isinstance(i, body.Bullet) == True:
51 def check_collisions(self):
54 if self.collides(i,j) == True :
55 self.handle_collision(i,j)
57 def collides(self,body1,body2):
58 # if (abs(body1.next_position - body2.next_position) <= (body1.radius + body2.radius)): if (body1 != body2):
66 def handle_collision(self,body1,body2):
67 if isinstance(body1, body.Tank) == True :
68 if isinstance(body2, body.Tank) == True :
69 body1.on_collision(body2)
74 if isinstance(body2, body.Tank) == True :
78 def check_walls(self):
79 for i in self.bodies :
80 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) :
84 def update_positions(self):
86 i.position = i.next_position
88 def invoke_ticks(self):
89 for i in self.bodies :
90 if isinstance(i, body.Tank) :
96 if i.tank.strength == 0 :
99 print i.tank.strength , i.tank.position
101 i.tank.velocity = vector.null
102 i.tank.position.x = random.randint(i.tank.radius , width - i.tank.radius)
103 i.tank.position.y = random.randint(i.tank.radius , height - i.tank.radius)
104 i.tank.velocity = vector.null
105 print i.tank.strength , i.tank.position