| 1 | importˆàvector |
|---|
| 2 | importˆàmath |
|---|
| 3 | importˆàrandom |
|---|
| 4 | |
|---|
| 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 |
|---|
| 16 | |
|---|
| 17 | classˆàBody(object): |
|---|
| 18 | ˆà ˆà ˆà ˆà defˆà__init__(self,ˆàposition,ˆàvelocity =ˆàvector.null): |
|---|
| 19 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.position =ˆàposition |
|---|
| 20 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.velocity =ˆàvelocity |
|---|
| 21 | |
|---|
| 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ˆà |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 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 |
|---|
| 39 | |
|---|
| 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 |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 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 |
|---|
| 52 | |
|---|
| 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) |
|---|
| 58 | |
|---|
| 59 | ˆà ˆà ˆà ˆà defˆàon_tick(self,other_tanks,ˆàbullets): |
|---|
| 60 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà pass |
|---|
| 61 | |
|---|
| 62 | ˆà ˆà ˆà ˆà defˆàon_spawn(self): |
|---|
| 63 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà pass |
|---|
| 64 | |
|---|
| 65 | ˆà ˆà ˆà ˆà defˆàon_death(self)ˆà: |
|---|
| 66 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà pass |
|---|
| 67 | ˆà ˆà ˆà ˆà |
|---|
| 68 | ˆà ˆà ˆà ˆà defˆàon_hit(self,ˆàbullet): |
|---|
| 69 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà pass |
|---|
| 70 | |
|---|
| 71 | ˆà ˆà ˆà ˆà defˆàon_collision(self,ˆàother): |
|---|
| 72 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà pass |
|---|
| 73 | |
|---|
| 74 | ˆà ˆà ˆà ˆà defˆàon_wall(self): |
|---|
| 75 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.next_position =ˆàself.position |
|---|
| 76 | |
|---|
| 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 |
|---|