Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/tanchiki/file/21d63c918715/body.py
Дата изменения: Unknown
Дата индексирования: Sun Feb 3 10:39:42 2013
Кодировка:
tanchiki: 21d63c918715 body.py

tanchiki

view body.py @ 50:21d63c918715

Fixed bug: was unable to display bullets.
author Daniil Alexeyevsky <me.dendik@gmail.com>
date Mon, 20 Dec 2010 21:10:48 +0300
parents cf05c46d014c
children d740eff76e7e
line source
1 import vector
2 import math
3 import random
5 base_angle = math.pi/32 # deltha phi = math.pi/32
6 turret_angle = math.pi/32
7 speed_delta = 1
8 delta_t = 1
9 max_velocity = 4
10 max_base_angle = 1
11 max_turret_angle = 1
12 initial_strength = 1
13 bullet_velocity = 10
14 width = 100
15 height = 100
17 class Body(object):
18 def __init__(self, position, velocity = vector.null):
19 self.position = position
20 self.velocity = velocity
22 class Tank(Body):
23 radius = 5
24 def __init__(self, position, user, game):
25 Body.__init__(self, position)
26 self.game = game
27 self.turret = vector.i
28 self.strength = 0
29 self.base_orientation = 1 # 1 or -1
30 self.user = user
31 user.tank = self
34 def rotate_base(tank, angle):
35 if abs(angle) < max_base_angle:
36 self.velocity.phi += angle
37 else:
38 self.velocity.phi += max_base_angle
40 def rotate_turret(self, angle):
41 if abs(angle) < max_base_angle:
42 self.turret.phi += angle
43 else:
44 self.turret.phi += max_turret_angle
47 def accelerate(self, speed_delta):
48 self.velocity += self.velocity.normalize() * speed_delta * delta_t
49 print self.velocity.rho
50 if self.velocity.rho > max_velocity:
51 self.velocity.rho = max_velocity
53 def fire(self):
54 bullet_position = self.position + self.turret * (self.radius + 0.1)
55 bullet_velocity = self.turret.normalize() * self.game.bullet_speed
56 bullet = Bullet(bullet_position, bullet_velocity, self)
57 self.game.bodies.append(bullet)
59 def on_tick(self,other_tanks, bullets):
60 pass
62 def on_spawn(self):
63 pass
65 def on_death(self) :
66 pass
68 def on_hit(self, bullet):
69 pass
71 def on_collision(self, other):
72 pass
74 def on_wall(self):
75 pass
77 class Bullet(Body):
78 radius = 0.1
79 def __init__(self, position, velocity, tank):
80 Body.__init__(self, position, velocity = bullet_velocity)
81 self.tank = tank