1 | #coding:utf-8 |
---|
2 | |
---|
3 | importˆàvector |
---|
4 | importˆàmath |
---|
5 | |
---|
6 | classˆàBody(object): |
---|
7 | ˆà ˆà ˆà ˆà defˆà__init__(self,ˆàgame,ˆàposition,ˆàvelocity =ˆàvector.Vector.null): |
---|
8 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.game =ˆàgame |
---|
9 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.position =ˆàposition |
---|
10 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.velocity =ˆàvelocity |
---|
11 | |
---|
12 | classˆàTank(Body): |
---|
13 | ˆà ˆà ˆà ˆà radius =ˆà1 |
---|
14 | ˆà ˆà ˆà ˆà model =ˆà"tank" |
---|
15 | |
---|
16 | ˆà ˆà ˆà ˆà defˆà__init__(self,ˆàgame,ˆàposition,ˆàcontroller): |
---|
17 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà Body.__init__(self,ˆàgame,ˆàposition) |
---|
18 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.controller =ˆàcontroller |
---|
19 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.turret =ˆàvector.Vector() |
---|
20 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.strength =ˆà0 |
---|
21 | |
---|
22 | ˆà ˆà ˆà ˆà defˆàrotate_base(tank,ˆàangle):ˆà |
---|
23 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ifˆàabs(angle)ˆà<ˆàself.game.max_base_delta : |
---|
24 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.velocity.phi +=ˆàangle |
---|
25 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà elseˆà: |
---|
26 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.velocity.phi +=ˆàself.game.max_base_delta |
---|
27 | |
---|
28 | ˆà ˆà ˆà ˆà defˆàrotate_turret(self,ˆàangle): |
---|
29 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ifˆàabs(angle)ˆà<ˆàself.game.max_base_delta : |
---|
30 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.turret.phi +=ˆàangle |
---|
31 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà elseˆà: |
---|
32 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.turret.phi +=ˆàself.game.max_turret_delta |
---|
33 | |
---|
34 | ˆà ˆà ˆà ˆà defˆàaccelerate(self,ˆàspeed_delta): |
---|
35 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.velocity +=ˆàself.velocity.normalize()ˆà*ˆàspeed_delta |
---|
36 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ifˆàself.velocity.rho >ˆàmax_velocity : |
---|
37 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.velocity.rho =ˆàmax_velocity |
---|
38 | |
---|
39 | ˆà ˆà ˆà ˆà defˆàfire(self): |
---|
40 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà bullet_position =ˆàself.position +ˆàself.turret *ˆà(self.radius +ˆà0.1) |
---|
41 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà bullet_velocity =ˆàself.turret.normalize()ˆà*ˆàself.game.bullet_speed |
---|
42 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà bullet =ˆàBullet(bullet_position,ˆàbullet_velocity,ˆàself) |
---|
43 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.game.bodies.append(bullet) |
---|
44 | |
---|
45 | classˆàBullet(Body): |
---|
46 | ˆà ˆà ˆà ˆà radius =ˆà0.1 |
---|
47 | ˆà ˆà ˆà ˆà model =ˆà"bullet" |
---|
48 | |
---|
49 | ˆà ˆà ˆà ˆà defˆà__init__(self,ˆàposition,ˆàvelocity,ˆàtank): |
---|
50 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà Body.__init__(self,ˆàposition,ˆàvelocity) |
---|
51 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.origin =ˆàorigin |
---|