tanchiki
diff body.py @ 15:43f5b82f3491
modules changed
author | Olga Zolotareva <olya_zol@inbox.ru> |
---|---|
date | Mon, 20 Dec 2010 10:53:47 +0300 |
parents | 0f8f077a682d |
children |
line diff
1.1 --- a/body.py Sun Dec 19 16:04:29 2010 +0300 1.2 +++ b/body.py Mon Dec 20 10:53:47 2010 +0300 1.3 @@ -1,66 +1,95 @@ 1.4 import vector 1.5 import math 1.6 -delta_phi = math.pi # deltha phi = math.pi 1.7 +import random 1.8 + 1.9 +base_angle = math.pi/32 # deltha phi = math.pi/32 1.10 +turret_angle = math.pi/32 1.11 speed_delta = 1 1.12 delta_t = 1 1.13 max_velocity = 2 1.14 +max_base_angle = 1 1.15 +max_turret_angle = 1 1.16 initial_strength = 1 1.17 +bullet_velocity = 5 1.18 +width = 10 1.19 +height = 10 1.20 1.21 class Body(object): 1.22 def __init__(self, position, velocity = vector.null): 1.23 self.position = position 1.24 self.velocity = velocity 1.25 - self.radius = radius 1.26 - 1.27 1.28 class Tank(Body): 1.29 - radius = 1 1.30 + radius = 0.5 1.31 def __init__(self, position, user): 1.32 Body.__init__(self, position) 1.33 + self.turret = vector.i 1.34 self.strength = 0 1.35 - self.turret = vector.i 1.36 self.base_orientation = 1 # 1 or -1 1.37 self.user = user 1.38 - user.tank = self # добавляет себя в User 1.39 + user.tank = self 1.40 1.41 1.42 - def rotate_base(tank, angle): 1.43 - self.velocity.phi += angle 1.44 + def rotate_base(tank, angle): 1.45 + if abs(angle) < max_base_angle: 1.46 + self.velocity.phi += angle 1.47 + else: 1.48 + self.velocity.phi += max_base_angle 1.49 1.50 def rotate_turret(self, angle): 1.51 - self.turret.phi += angle 1.52 + if abs(angle) < max_base_angle: 1.53 + self.turret.phi += angle 1.54 + else: 1.55 + self.turret.phi += max_turret_angle 1.56 + 1.57 1.58 def accelerate(self, speed_delta): 1.59 - self.velocity.rho += speed_delta * delta_t 1.60 + self.velocity += self.velocity.normalize() * speed_delta * delta_t 1.61 + print self.velocity.rho 1.62 if self.velocity.rho > max_velocity: 1.63 self.velocity.rho = max_velocity 1.64 1.65 def fire(self): 1.66 - pass 1.67 + bullet_position = self.position + self.turret*(self.radius + 0.1) 1.68 + bullet = Bullet(bullet_position, bullet_velocity, self) 1.69 + bodies.append(bullet) 1.70 1.71 def on_tick(self,other_tanks, bullets): 1.72 if self.user.base_left == True: 1.73 - self.rotate_base(delta_phi) 1.74 + self.rotate_base(base_angle) 1.75 if self.user.base_right == True: 1.76 - self.rotate_base(-1*delta_phi) 1.77 + self.rotate_base(-1*base_angle) 1.78 if self.user.accelerate == True: 1.79 self.accelerate(speed_delta) 1.80 + if self.user.decelerate == True: 1.81 + self.accelerate(-1*speed_delta) 1.82 + if self.user.turret_left == True: 1.83 + self.rotate_turret(turret_angle) 1.84 + if self.user.turret_right == True: 1.85 + self.rotate_turret(-1*turret_angle) 1.86 + if self.user.fire == True: 1.87 + self.fire() 1.88 1.89 def on_spawn(self): 1.90 pass 1.91 +# self.position.x = random.randint(1,width - 10) 1.92 +# self.position.y = random.randint(1,height - 10) 1.93 +# self.velocity = vector.null 1.94 1.95 def on_death(self) : 1.96 pass 1.97 1.98 - def on_hit(self,bullet): 1.99 + def on_hit(self, bullet): 1.100 pass 1.101 1.102 - def on_collision(self): 1.103 + def on_collision(self, other): 1.104 pass 1.105 1.106 def on_wall(self): 1.107 - pass 1.108 + self.next_position = self.position 1.109 1.110 class Bullet(Body): 1.111 radius = 0.1 1.112 - pass 1.113 \ No newline at end of file 1.114 + def __init__(self, position, velocity, tank): 1.115 + Body.__init__(self, position, velocity) 1.116 + self.tank = tank 1.117 \ No newline at end of file