Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/tanchiki/annotate/dfdc1def5d24/body.py
Дата изменения: Unknown
Дата индексирования: Fri Feb 28 23:46:32 2014
Кодировка:
tanchiki: body.py annotate

tanchiki

annotate body.py @ 35:dfdc1def5d24

modules changed
author Olga Zolotareva <olya_zol@inbox.ru>
date Mon, 20 Dec 2010 18:42:45 +0300
parents c71c27b09bc7
children 1a0bddee3c54
rev   line source
olya_zol@35 1 import vector
olya_zol@35 2 import math
olya_zol@35 3 import random
olya_zol@35 4
olya_zol@35 5 base_angle = math.pi/32 # deltha phi = math.pi/32
olya_zol@35 6 turret_angle = math.pi/32
olya_zol@35 7 speed_delta = 1
olya_zol@35 8 delta_t = 1
olya_zol@35 9 max_velocity = 4
olya_zol@35 10 max_base_angle = 1
olya_zol@35 11 max_turret_angle = 1
olya_zol@35 12 initial_strength = 1
olya_zol@35 13 bullet_velocity = 10
olya_zol@35 14 width = 100
olya_zol@35 15 height = 100
olya_zol@35 16
olya_zol@35 17 class Body(object):
olya_zol@35 18 def __init__(self, position, velocity = vector.null):
olya_zol@35 19 self.position = position
olya_zol@35 20 self.velocity = velocity
olya_zol@35 21
olya_zol@35 22 class Tank(Body):
olya_zol@35 23 radius = 5
olya_zol@35 24 def __init__(self, position, user, game):
olya_zol@35 25 Body.__init__(self, position)
olya_zol@35 26 self.game = game
olya_zol@35 27 self.turret = vector.i
olya_zol@35 28 self.strength = 0
olya_zol@35 29 self.base_orientation = 1 # 1 or -1
olya_zol@35 30 self.user = user
olya_zol@35 31 user.tank = self
olya_zol@35 32
olya_zol@35 33
olya_zol@35 34 def rotate_base(tank, angle):
olya_zol@35 35 if abs(angle) < max_base_angle:
olya_zol@35 36 self.velocity.phi += angle
olya_zol@35 37 else:
olya_zol@35 38 self.velocity.phi += max_base_angle
olya_zol@35 39
olya_zol@35 40 def rotate_turret(self, angle):
olya_zol@35 41 if abs(angle) < max_base_angle:
olya_zol@35 42 self.turret.phi += angle
olya_zol@35 43 else:
olya_zol@35 44 self.turret.phi += max_turret_angle
olya_zol@35 45
olya_zol@35 46
olya_zol@35 47 def accelerate(self, speed_delta):
olya_zol@35 48 self.velocity += self.velocity.normalize() * speed_delta * delta_t
olya_zol@35 49 print self.velocity.rho
olya_zol@35 50 if self.velocity.rho > max_velocity:
olya_zol@35 51 self.velocity.rho = max_velocity
olya_zol@35 52
olya_zol@35 53 def fire(self):
olya_zol@35 54 bullet_position = self.position + self.turret * (self.radius + 0.1)
olya_zol@35 55 bullet_velocity = self.turret.normalize() * self.game.bullet_speed
olya_zol@35 56 bullet = Bullet(bullet_position, bullet_velocity, self)
olya_zol@35 57 self.game.bodies.append(bullet)
olya_zol@35 58
olya_zol@35 59 def on_tick(self,other_tanks, bullets):
olya_zol@35 60 if self.user.base_left == True:
olya_zol@35 61 self.rotate_base(base_angle)
olya_zol@35 62 if self.user.base_right == True:
olya_zol@35 63 self.rotate_base(-1*base_angle)
olya_zol@35 64 if self.user.accelerate == True:
olya_zol@35 65 self.accelerate(speed_delta)
olya_zol@35 66 if self.user.decelerate == True:
olya_zol@35 67 self.accelerate(-1*speed_delta)
olya_zol@35 68 if self.user.turret_left == True:
olya_zol@35 69 self.rotate_turret(turret_angle)
olya_zol@35 70 if self.user.turret_right == True:
olya_zol@35 71 self.rotate_turret(-1*turret_angle)
olya_zol@35 72 if self.user.fire == True:
olya_zol@35 73 self.fire()
olya_zol@35 74
olya_zol@35 75 def on_spawn(self):
olya_zol@35 76 pass
olya_zol@35 77
olya_zol@35 78 def on_death(self) :
olya_zol@35 79 pass
olya_zol@35 80
olya_zol@35 81 def on_hit(self, bullet):
olya_zol@35 82 pass
olya_zol@35 83
olya_zol@35 84 def on_collision(self, other):
olya_zol@35 85 pass
olya_zol@35 86
olya_zol@35 87 def on_wall(self):
olya_zol@35 88 self.next_position = self.position
olya_zol@35 89
olya_zol@35 90 class Bullet(Body):
olya_zol@35 91 radius = 0.1
olya_zol@35 92 def __init__(self, position, velocity, tank):
olya_zol@35 93 Body.__init__(self, position, velocity = bullet_velocity)
olya_zol@35 94 self.tank = tank