Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.cmm.msu.su/trac/tanchiki/browser/body.py?format=txt
Дата изменения: Sat Dec 25 01:51:31 2010
Дата индексирования: Tue Oct 2 10:50:16 2012
Кодировка:
import vector
import math
import random

base_angle = math.pi/32 # deltha phi = math.pi/32
turret_angle = math.pi/32
speed_delta = 2
delta_t = 1
max_velocity = 4
acceleration = 1
max_base_angle = 1
max_turret_angle = 1
initial_strength = 1
bullet_velocity = 10
width = 500
height = 500
bullet_speed = 10

class Body(object):
def __init__(self, position = vector.null, velocity = vector.null):
self.position = position
self.velocity = velocity

class Tank(Body):
radius = 5
def __init__(self, position, user, game):
Body.__init__(self, position)
self.game = game
self.turret = vector.Vector(0,-1)
self.strength = 0
self.base_orientation = vector.Vector(0,-1) # Vector
self.user = user
user.tank = self


def rotate_base(self, angle):
if abs(angle) < max_base_angle:
self.velocity.phi += angle
self.base_orientation.phi +=angle
self.turret.phi += angle

else:
self.velocity.phi += max_base_angle
self.base_orientation.phi += max_base_angle
self.turret.phi += max_turret_angle

def rotate_turret(self, angle):
if abs(angle) < max_base_angle:
self.turret.phi += angle
else:
self.turret.phi += max_turret_angle


def accelerate(self, speed_delta):
self.velocity += self.base_orientation*speed_delta*delta_t
if abs(self.velocity) > max_velocity:
self.velocity.rho = max_velocity

def fire(self):
bullet_position = self.position + self.turret * (self.radius + 0.1)
bullet_velocity = self.turret.normalize() * bullet_speed
bullet = Bullet(bullet_position, bullet_velocity, self)
self.game.bodies.append(bullet)

def on_tick(self,other_tanks, bullets):
pass

def on_spawn(self):
pass

def on_death(self) :
pass

def on_hit(self, bullet):
self.strength -= 1

def on_collision(self, other):
pass
# self.velocity , other.velocity = self.velocity + other.velocity , other.velocity + self.velocity

def on_wall(self):
self.velocity = vector.Vector(0,0)
self.next_position = self.position

class Bullet(Body):
radius = 0.1
def __init__(self, position, velocity, tank):
self.tank = tank
Body.__init__(self, position, velocity = self.tank.turret*bullet_velocity)

def on_wall(self):
self.tank.game.bodies.remove(self)