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

tanchiki

annotate body.py @ 54:5cb3fef573f6

UI for two users
author Olga Zolotareva <olya_zol@inbox.ru>
date Sat, 25 Dec 2010 01:51:31 +0300
parents 5450c97fbc38
children
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@52 7 speed_delta = 2
olya_zol@35 8 delta_t = 1
olya_zol@35 9 max_velocity = 4
olya_zol@52 10 acceleration = 1
olya_zol@35 11 max_base_angle = 1
olya_zol@35 12 max_turret_angle = 1
olya_zol@35 13 initial_strength = 1
olya_zol@35 14 bullet_velocity = 10
olya_zol@52 15 width = 500
olya_zol@52 16 height = 500
olya_zol@52 17 bullet_speed = 10
olya_zol@35 18
olya_zol@35 19 class Body(object):
olya_zol@52 20 def __init__(self, position = vector.null, velocity = vector.null):
olya_zol@35 21 self.position = position
olya_zol@35 22 self.velocity = velocity
olya_zol@35 23
olya_zol@35 24 class Tank(Body):
olya_zol@35 25 radius = 5
olya_zol@35 26 def __init__(self, position, user, game):
olya_zol@35 27 Body.__init__(self, position)
olya_zol@35 28 self.game = game
olya_zol@52 29 self.turret = vector.Vector(0,-1)
olya_zol@35 30 self.strength = 0
olya_zol@52 31 self.base_orientation = vector.Vector(0,-1) # Vector
olya_zol@35 32 self.user = user
olya_zol@35 33 user.tank = self
olya_zol@35 34
olya_zol@35 35
olya_zol@52 36 def rotate_base(self, angle):
olya_zol@35 37 if abs(angle) < max_base_angle:
olya_zol@35 38 self.velocity.phi += angle
olya_zol@52 39 self.base_orientation.phi +=angle
olya_zol@52 40 self.turret.phi += angle
olya_zol@52 41
olya_zol@35 42 else:
olya_zol@35 43 self.velocity.phi += max_base_angle
olya_zol@52 44 self.base_orientation.phi += max_base_angle
olya_zol@52 45 self.turret.phi += max_turret_angle
olya_zol@35 46
olya_zol@35 47 def rotate_turret(self, angle):
olya_zol@35 48 if abs(angle) < max_base_angle:
olya_zol@35 49 self.turret.phi += angle
olya_zol@35 50 else:
olya_zol@35 51 self.turret.phi += max_turret_angle
olya_zol@35 52
olya_zol@35 53
olya_zol@35 54 def accelerate(self, speed_delta):
olya_zol@52 55 self.velocity += self.base_orientation*speed_delta*delta_t
olya_zol@52 56 if abs(self.velocity) > max_velocity:
olya_zol@35 57 self.velocity.rho = max_velocity
olya_zol@35 58
olya_zol@35 59 def fire(self):
olya_zol@35 60 bullet_position = self.position + self.turret * (self.radius + 0.1)
olya_zol@52 61 bullet_velocity = self.turret.normalize() * bullet_speed
olya_zol@35 62 bullet = Bullet(bullet_position, bullet_velocity, self)
olya_zol@35 63 self.game.bodies.append(bullet)
olya_zol@35 64
olya_zol@35 65 def on_tick(self,other_tanks, bullets):
me@38 66 pass
olya_zol@35 67
olya_zol@35 68 def on_spawn(self):
olya_zol@35 69 pass
olya_zol@35 70
olya_zol@35 71 def on_death(self) :
olya_zol@35 72 pass
olya_zol@35 73
olya_zol@35 74 def on_hit(self, bullet):
olya_zol@53 75 self.strength -= 1
olya_zol@35 76
olya_zol@35 77 def on_collision(self, other):
olya_zol@35 78 pass
olya_zol@54 79 # self.velocity , other.velocity = self.velocity + other.velocity , other.velocity + self.velocity
olya_zol@35 80
olya_zol@35 81 def on_wall(self):
olya_zol@53 82 self.velocity = vector.Vector(0,0)
olya_zol@53 83 self.next_position = self.position
olya_zol@35 84
olya_zol@35 85 class Bullet(Body):
olya_zol@35 86 radius = 0.1
olya_zol@35 87 def __init__(self, position, velocity, tank):
me@39 88 self.tank = tank
olya_zol@52 89 Body.__init__(self, position, velocity = self.tank.turret*bullet_velocity)
olya_zol@52 90
olya_zol@52 91 def on_wall(self):
olya_zol@53 92 self.tank.game.bodies.remove(self)