Äîêóìåíò âçÿò èç êýøà ïîèñêîâîé ìàøèíû. Àäðåñ îðèãèíàëüíîãî äîêóìåíòà : http://kodomo.cmm.msu.ru/trac/tanchiki/browser/body.py?rev=38
Äàòà èçìåíåíèÿ: Unknown
Äàòà èíäåêñèðîâàíèÿ: Mon Apr 11 15:54:49 2016
Êîäèðîâêà: IBM-866
body.py òÀÓ Tanchiki

source: body.py @ 38:cf05c46d014c

Revision 38:cf05c46d014c, 1.8 KB checked in by Daniil Alexeyevsky <me.dendik@òÀæ>, 5 years ago (diff)

Moved UI-related tank stuff into tk_ui.Tank; updated tk_ui to match the current project structure

  • Property exe set to *
Lineˆà
1importˆàvector
2importˆàmath
3importˆàrandom
4
5base_angle =ˆàmath.pi/32ˆà ˆà# deltha phi = math.pi/32
6turret_angle =ˆàmath.pi/32
7speed_delta =ˆà1
8delta_t =ˆà1
9max_velocity =ˆà4
10max_base_angle =ˆà1
11max_turret_angle =ˆà1
12initial_strength =ˆà1
13bullet_velocity =ˆà10
14width =ˆà100
15height =ˆà100
16
17classˆàBody(object):
18ˆà ˆà ˆà ˆà defˆà__init__(self,ˆàposition,ˆàvelocity =ˆàvector.null):
19ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.position =ˆàposition
20ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.velocity =ˆàvelocity
21
22classˆà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
77classˆà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
Note: See TracBrowser for help on using the repository browser.