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): |
me@38
|
60 pass |
olya_zol@35
|
61 |
olya_zol@35
|
62 def on_spawn(self): |
olya_zol@35
|
63 pass |
olya_zol@35
|
64 |
olya_zol@35
|
65 def on_death(self) : |
olya_zol@35
|
66 pass |
olya_zol@35
|
67 |
olya_zol@35
|
68 def on_hit(self, bullet): |
olya_zol@35
|
69 pass |
olya_zol@35
|
70 |
olya_zol@35
|
71 def on_collision(self, other): |
olya_zol@35
|
72 pass |
olya_zol@35
|
73 |
olya_zol@35
|
74 def on_wall(self): |
me@39
|
75 pass |
olya_zol@35
|
76 |
olya_zol@35
|
77 class Bullet(Body): |
olya_zol@35
|
78 radius = 0.1 |
olya_zol@35
|
79 def __init__(self, position, velocity, tank): |
olya_zol@35
|
80 Body.__init__(self, position, velocity = bullet_velocity) |
me@39
|
81 self.tank = tank |