annotate body.py @ 16:c71c27b09bc7
Fixed and updated overall repository format.
Removed CR's. Changed encoding to UTF-8.
Removed trailing whitespace and unified the rest.
Removed test code from vector.py.
author |
Peter Zotov <whitequark@whitequark.org> |
date |
Mon, 20 Dec 2010 04:35:08 +0300 |
parents |
0f8f077a682d |
children |
dfdc1def5d24 |
rev |
line source |
whitequark@16
|
1 import vector |
whitequark@16
|
2 import math |
whitequark@16
|
3 delta_phi = math.pi # deltha phi = math.pi |
whitequark@16
|
4 speed_delta = 1 |
whitequark@16
|
5 delta_t = 1 |
whitequark@16
|
6 max_velocity = 2 |
whitequark@16
|
7 initial_strength = 1 |
whitequark@16
|
8 |
whitequark@16
|
9 class Body(object): |
whitequark@16
|
10 def __init__(self, position, velocity = vector.null): |
whitequark@16
|
11 self.position = position |
whitequark@16
|
12 self.velocity = velocity |
whitequark@16
|
13 self.radius = radius |
whitequark@16
|
14 |
whitequark@16
|
15 class Tank(Body): |
whitequark@16
|
16 radius = 1 |
whitequark@16
|
17 def __init__(self, position, user): |
whitequark@16
|
18 Body.__init__(self, position) |
whitequark@16
|
19 self.strength = 0 |
whitequark@16
|
20 self.turret = vector.i |
whitequark@16
|
21 self.base_orientation = 1 # 1 or -1 |
whitequark@16
|
22 self.user = user |
whitequark@16
|
23 user.tank = self # ?????????????????? ???????? ?? User |
whitequark@16
|
24 |
whitequark@16
|
25 def rotate_base(tank, angle): |
whitequark@16
|
26 self.velocity.phi += angle |
whitequark@16
|
27 |
whitequark@16
|
28 def rotate_turret(self, angle): |
whitequark@16
|
29 self.turret.phi += angle |
whitequark@16
|
30 |
whitequark@16
|
31 def accelerate(self, speed_delta): |
whitequark@16
|
32 self.velocity.rho += speed_delta * delta_t |
whitequark@16
|
33 if self.velocity.rho > max_velocity : |
whitequark@16
|
34 self.velocity.rho = max_velocity |
whitequark@16
|
35 |
whitequark@16
|
36 def fire(self): |
whitequark@16
|
37 pass |
whitequark@16
|
38 |
whitequark@16
|
39 def on_tick(self,other_tanks, bullets): |
whitequark@16
|
40 if self.user.base_left == True : |
whitequark@16
|
41 self.rotate_base(delta_phi) |
whitequark@16
|
42 if self.user.base_right == True : |
whitequark@16
|
43 self.rotate_base(-1*delta_phi) |
whitequark@16
|
44 if self.user.accelerate == True : |
whitequark@16
|
45 self.accelerate(speed_delta) |
whitequark@16
|
46 |
whitequark@16
|
47 def on_spawn(self): |
whitequark@16
|
48 pass |
whitequark@16
|
49 |
whitequark@16
|
50 def on_death(self): |
whitequark@16
|
51 pass |
whitequark@16
|
52 |
whitequark@16
|
53 def on_hit(self,bullet): |
whitequark@16
|
54 pass |
whitequark@16
|
55 |
whitequark@16
|
56 def on_collision(self): |
whitequark@16
|
57 pass |
whitequark@16
|
58 |
whitequark@16
|
59 def on_wall(self): |
whitequark@16
|
60 pass |
whitequark@16
|
61 |
whitequark@16
|
62 class Bullet(Body): |
whitequark@16
|
63 radius = 0.1 |
whitequark@16
|
64 pass |