Changeset 2:e6e7b30ecde0
Legend:
- Unmodified
- Added
- Removed
-
body.py
r1 r2 ˆà ˆà 1 import vectorˆà ˆà 2 ˆà 1 3 class Body(object):ˆà 2 ˆà def __init__(self, position, velocity, next_position, radius ):ˆàˆà 4 def __init__(self, position, velocity, next_position, radius=1):ˆà 3 5 self.position = positionˆà 4 6 self.velocity = velocityˆà òÀæ òÀæ ˆà 11 13 self.strength = strengthˆà 12 14 self.turret = turretˆà 13 ˆà self.base_orientation = orientationˆàˆà 15 self.base_orientation = base_orientationˆà 14 16 self.game = gameˆà 15 17 self.user = userˆà 16 ˆà def rotate_base( angle):ˆàˆà 18 def rotate_base(tank, angle):ˆà 17 19 passˆà 18 20 ˆà 19 ˆà def rotate_turret( angle):ˆàˆà 21 def rotate_turret(tank, angle):ˆà 20 22 passˆà 21 23 ˆà 22 ˆà def accelerate( speed_delta):ˆàˆà 24 def accelerate(tank, speed_delta):ˆà 23 25 passˆà 24 26 ˆà 25 ˆà def fire( ):ˆàˆà 27 def fire(tank):ˆà 26 28 passˆà 27 29 ˆà 28 ˆà def on_tick( other_tanks, bullets):ˆàˆà 30 def on_tick(tank,other_tanks, bullets):ˆà 29 31 passˆà 30 32 ˆà 31 ˆà def on_spawn( ):ˆàˆà 33 def on_spawn(tank):ˆà 32 34 passˆà 33 35 ˆà 34 ˆà def on_death( ) :ˆàˆà 36 def on_death(tank) :ˆà 35 37 passˆà 36 38 ˆà 37 ˆà def on_hit( bullet):ˆàˆà 39 def on_hit(tank,bullet):ˆà 38 40 passˆà 39 41 ˆà òÀæ òÀæ ˆà 41 43 passˆà 42 44 ˆà 43 ˆà def on_wall( ):ˆàˆà 45 def on_wall(tank):ˆà 44 46 passˆà 45 47 ˆà -
game.py
r1 r2 ˆà 6 6 self.height = heightˆà 7 7 ˆà 8 ˆà def step():ˆà 9 ˆà passˆà ˆà 8 def step(game):ˆà ˆà 9 game.next_positions()ˆà ˆà 10 game.check_collisions()ˆà ˆà 11 game.check_walls()ˆà ˆà 12 game.update_positions()ˆà ˆà 13 game.invoke_ticks()ˆà ˆà 14 game.respawn()ˆà 10 15 ˆà 11 ˆà def next_positions():ˆà 12 ˆà passˆà ˆà 16 def next_positions(game):ˆà ˆà 17 delta_t = 1ˆà ˆà 18 for i in game.bodies:ˆà ˆà 19 i.next_position = i.position + i.velocity.mul_v(delta_t)ˆà 13 20 ˆà 14 ˆà def check_collisions():ˆà ˆà 21 ˆà ˆà 22 def check_collisions(game):ˆà 15 23 passˆà 16 24 ˆà òÀæ òÀæ ˆà 21 29 passˆà 22 30 ˆà 23 ˆà def check_walls():ˆà 24 ˆà passˆà ˆà 31 def check_walls(game):ˆà ˆà 32 for i in game.bodies :ˆà ˆà 33 if (i.next_position.x <= 0) or (i.next_position.y <= 0) or (i.next_position.x <= width) or (i.next_position.y >= game.height) :ˆà ˆà 34 i.on_wall()ˆà ˆà 35 ˆà 25 36 ˆà 26 ˆà def update_positions():ˆà 27 ˆà passˆà ˆà 37 def update_positions(game):ˆà ˆà 38 for i in game.bodies:ˆà ˆà 39 i.position = i.next_positionˆà 28 40 ˆà 29 ˆà def invoke_ticks( ):ˆàˆà 41 def invoke_ticks(game):ˆà 30 42 passˆà 31 43 ˆà 32 ˆà def respawn():ˆà 33 ˆà pass ˆà 34 ˆà ˆà ˆà 44 def respawn(game): ˆà ˆà 45 for i in game.users :ˆà ˆà 46 if i.tank.strength == 0 :ˆà ˆà 47 i.tank.respawn()ˆà ˆà 48 ˆà ˆà 49 ˆà ˆà 50 ˆà -
user.py
r1 r2 ˆà 1 1 class User(object): ˆà 2 2 ˆà 3 ˆà def __init__(self, base_left , base_right, turret_left, turret_right, accelerate, decelerate, fire, tank):ˆàˆà 3 def __init__(self, base_left = False , base_right = False, turret_left = False, turret_right = False, accelerate = False, decelerate = False, fire = False, tank = 0):ˆà 4 4 self.base_left = base_leftˆà 5 5 self.base_right = base_rightˆà
Note: See TracChangeset
for help on using the changeset viewer.