Changeset 54:5cb3fef573f6
Legend:
- Unmodified
- Added
- Removed
-
body.py
r53 r54 ˆà 53 53 ˆà 54 54 def accelerate(self, speed_delta):ˆà 55 ˆà print 'speed_delta', speed_delta #testˆà56 55 self.velocity += self.base_orientation*speed_delta*delta_tˆà 57 56 if abs(self.velocity) > max_velocity:ˆà òÀæ òÀæ ˆà 78 77 def on_collision(self, other):ˆà 79 78 passˆà ˆà 79 # self.velocity , other.velocity = self.velocity + other.velocity , other.velocity + self.velocityˆà 80 80 ˆà 81 81 def on_wall(self):ˆà -
game.py
r53 r54 ˆà 24 24 self.respawn()ˆà 25 25 self.update_velocities()ˆà 26 ˆà for i in self.bodies :ˆà27 ˆà print iˆà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ˆà32 ˆà if isinstance(i,body.Tank) == True:ˆà33 ˆà print 'base_orientation' , i.base_orientationˆà34 ˆà print '\n'ˆàˆà 26 # for i in self.bodies :ˆà ˆà 27 # print i # testˆà ˆà 28 # print 'next position' , i.next_position # test ˆà ˆà 29 # print 'update_position' , i.position # testˆà ˆà 30 # print 'velocity' , i.velocity # testˆà ˆà 31 # print 'velocity.rho', i.velocity.rho # testˆà ˆà 32 # if isinstance(i,body.Tank) == True: # testˆà ˆà 33 # print 'base_orientation' , i.base_orientation # testˆà ˆà 34 # print '\n'ˆà 35 35 ˆà 36 36 def update_velocities(self):ˆà òÀæ òÀæ ˆà 56 56 if (abs(body1.next_position - body2.next_position) <= (body1.radius + body2.radius)):ˆà 57 57 if (body1 != body2):ˆà 58 ˆà print 'collision'ˆà59 58 return Trueˆà 60 59 else :ˆà òÀæ òÀæ ˆà 68 67 body1.on_collision(body2)ˆà 69 68 else :ˆà 70 ˆà body1.on_hit( )ˆàˆà 69 body1.on_hit(body2)ˆà 71 70 body1.on_death()ˆà ˆà 71 self.bodies.remove(body2)ˆà 72 72 else :ˆà 73 73 if isinstance(body2, body.Tank) == True :ˆà 74 ˆà body2.on_hit( )ˆàˆà 74 body2.on_hit(body2)ˆà 75 75 body2.on_death()ˆà ˆà 76 self.bodies.remove(body1)ˆà 76 77 ˆà 77 78 def check_walls(self):ˆà òÀæ òÀæ ˆà 94 95 if i.tank.strength == 0 :ˆà 95 96 i.tank.on_spawn()ˆà 96 ˆà print 'respawn'ˆà97 ˆà print i.tank.strength , i.tank.positionˆà98 97 i.tank.strength = 1ˆà 99 98 i.tank.velocity = vector.nullˆà òÀæ òÀæ ˆà 101 100 i.tank.position.y = random.randint(i.tank.radius , height - i.tank.radius)ˆà 102 101 i.tank.velocity = vector.null ˆà 103 ˆà print i.tank.strength , i.tank.positionˆà104 102 ˆà 105 103 ˆà -
tk_ui.py
r52 r54 ˆà 9 9 ˆà 10 10 game_size = 500, 500ˆà 11 ˆà keys = {ˆàˆà 11 keys1 = {ˆà 12 12 'ocircumflex': 'base_left', ˆà 13 13 'acircumflex': 'base_right',ˆà òÀæ òÀæ ˆà 18 18 'division': 'fire',ˆà 19 19 }ˆà ˆà 20 ˆà ˆà 21 keys2 = {ˆà ˆà 22 'icircumflex': 'base_left', ˆà ˆà 23 'adiaeresis': 'base_right',ˆà ˆà 24 'atilde': 'turret_left',ˆà ˆà 25 'ugrave': 'turret_right',ˆà ˆà 26 'oslash': 'accelerate',ˆà ˆà 27 'ediaeresis': 'decelerate',ˆà ˆà 28 'udiaeresis': 'fire',ˆà ˆà 29 }ˆà 20 30 ˆà 21 31 welcome = """Press F5 to startˆà 22 32 ˆà 23 33 Keys are:ˆà ˆà 34 ˆà ˆà 35 ˆà ˆà 36 User 1 :ˆà ˆà 37 ˆà 24 38 a, d -- turn tankˆà 25 39 q, e -- turn muzzleˆà 26 40 w, s -- change speedˆà 27 ˆà x -- fire"""ˆà ˆà 41 x -- fireˆà ˆà 42 ˆà ˆà 43 User 2 :ˆà ˆà 44 ˆà ˆà 45 j, l -- turn tankˆà ˆà 46 u, o -- turn muzzleˆà ˆà 47 i, k -- change speedˆà ˆà 48 m -- fire ˆà ˆà 49 """ˆà 28 50 ˆà 29 51 class Tank(BaseTank):ˆà òÀæ òÀæ ˆà 53 75 ˆà 54 76 def init_game(self):ˆà 55 ˆà self.user = User(keys)ˆà ˆà 77 self.user1 = User(keys1)ˆà ˆà 78 self.user2 = User(keys2)ˆà 56 79 w, h = game_size ˆà 57 ˆà game = self.game = Game([], [self.user], w, h)ˆà 58 ˆà tank = Tank(Vector(*game_size) * 0.5, self.user, self.game)ˆà 59 ˆà game.bodies.append(tank)ˆà ˆà 80 game = self.game = Game([], [self.user1, self.user2], w, h)ˆà ˆà 81 tank1 = Tank(Vector(*game_size) * 0.5, self.user1, self.game)ˆà ˆà 82 tank2 = Tank(Vector(*game_size) * 0.5, self.user2, self.game)ˆà ˆà 83 game.bodies.append(tank1)ˆà ˆà 84 game.bodies.append(tank2)ˆà 60 85 ˆà 61 86 def init_ui(self):ˆà òÀæ òÀæ ˆà 79 104 if ev.keysym == "F5":ˆà 80 105 self.step()ˆà 81 ˆà self.user.on_key(ev.keysym, True)ˆà ˆà 106 self.user1.on_key(ev.keysym, True)ˆà ˆà 107 self.user2.on_key(ev.keysym, True)ˆà 82 108 ˆà 83 109 def on_keyrelease(self, ev):ˆà 84 ˆà self.user.on_key(ev.keysym, False)ˆà ˆà 110 self.user1.on_key(ev.keysym, False)ˆà ˆà 111 self.user2.on_key(ev.keysym, False)ˆà 85 112 ˆà 86 113 def step(self):ˆà -
user.py
r52 r54 ˆà 18 18 else:ˆà 19 19 action = self.keyset[key]ˆà 20 ˆà print 'action=', actionˆà21 20 if hasattr(self, action) and action not in ['tank', 'keyset']:ˆà 22 21 setattr(self, action, value)ˆà
Note: See TracChangeset
for help on using the changeset viewer.