Äîêóìåíò âçÿò èç êýøà ïîèñêîâîé ìàøèíû. Àäðåñ îðèãèíàëüíîãî äîêóìåíòà : http://kodomo.cmm.msu.su/trac/tanchiki/browser/body.py?desc=1
Äàòà èçìåíåíèÿ: Unknown
Äàòà èíäåêñèðîâàíèÿ: Sun Apr 10 20:43:36 2016
Êîäèðîâêà: IBM-866
body.py òÀÓ Tanchiki

source: body.py @ 54:5cb3fef573f6

Revision 54:5cb3fef573f6, 2.3 KB checked in by Olga Zolotareva <olya_zol@òÀæ>, 5 years ago (diff)

UI for two users

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 =ˆà2
8delta_t =ˆà1
9max_velocity =ˆà4
10acceleration =ˆà1
11max_base_angle =ˆà1
12max_turret_angle =ˆà1
13initial_strength =ˆà1
14bullet_velocity =ˆà10
15width =ˆà500
16height =ˆà500
17bullet_speed =ˆà10
18
19classˆàBody(object):
20ˆà ˆà ˆà ˆà defˆà__init__(self,ˆàposition =ˆàvector.null,ˆàvelocity =ˆàvector.null):
21ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.position =ˆàposition
22ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.velocity =ˆàvelocity
23
24classˆàTank(Body):
25ˆà ˆà ˆà ˆà radius =ˆà5
26ˆà ˆà ˆà ˆà defˆà__init__(self,ˆàposition,ˆàuser,ˆàgame):
27ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà Body.__init__(self,ˆàposition)
28ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.game =ˆàgame
29ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.turret =ˆàvector.Vector(0,-1)
30ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.strength =ˆà0
31ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.base_orientation =ˆàvector.Vector(0,-1)ˆà ˆà ˆà# Vector
32ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.user =ˆàuser
33ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà user.tank =ˆàselfˆà
34
35
36ˆà ˆà ˆà ˆà defˆàrotate_base(self,ˆàangle):
37ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ifˆàabs(angle)ˆà<ˆàmax_base_angle:ˆà
38ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.velocity.phi +=ˆàangle
39ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.base_orientation.phi +=angle
40ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.turret.phi +=ˆàangle
41
42ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà else:
43ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.velocity.phi +=ˆàmax_base_angle
44ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.base_orientation.phi +=ˆàmax_base_angle
45ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.turret.phi +=ˆàmax_turret_angle
46
47ˆà ˆà ˆà ˆà defˆàrotate_turret(self,ˆàangle):
48ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ifˆàabs(angle)ˆà<ˆàmax_base_angle:ˆà
49ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.turret.phi +=ˆàangle
50ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà else:
51ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.turret.phi +=ˆàmax_turret_angle
52
53
54ˆà ˆà ˆà ˆà defˆàaccelerate(self,ˆàspeed_delta):
55ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.velocity +=ˆàself.base_orientation*speed_delta*delta_t
56ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ifˆàabs(self.velocity)ˆà>ˆàmax_velocity:
57ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.velocity.rho =ˆàmax_velocity
58
59ˆà ˆà ˆà ˆà defˆàfire(self):
60ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà bullet_position =ˆàself.position +ˆàself.turret *ˆà(self.radius +ˆà0.1)
61ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà bullet_velocity =ˆàself.turret.normalize()ˆà*ˆàbullet_speed
62ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà bullet =ˆàBullet(bullet_position,ˆàbullet_velocity,ˆàself)
63ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.game.bodies.append(bullet)
64
65ˆà ˆà ˆà ˆà defˆàon_tick(self,other_tanks,ˆàbullets):
66ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà pass
67
68ˆà ˆà ˆà ˆà defˆàon_spawn(self):
69ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà pass
70
71ˆà ˆà ˆà ˆà defˆàon_death(self)ˆà:
72ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà pass
73ˆà ˆà ˆà ˆà
74ˆà ˆà ˆà ˆà defˆàon_hit(self,ˆàbullet):
75ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.strength -=ˆà1
76
77ˆà ˆà ˆà ˆà defˆàon_collision(self,ˆàother):
78ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà pass
79ˆà ˆà ˆà ˆà #ˆà ˆà ˆà ˆàself.velocity , other.velocity =ˆà self.velocity + other.velocity , other.velocity + self.velocity
80
81ˆà ˆà ˆà ˆà defˆàon_wall(self):
82ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.velocity =ˆàvector.Vector(0,0)
83ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.next_position =ˆàself.position
84
85classˆàBullet(Body):
86ˆà ˆà ˆà ˆà radius =ˆà0.1
87ˆà ˆà ˆà ˆà defˆà__init__(self,ˆàposition,ˆàvelocity,ˆàtank):
88ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.tank =ˆàtank
89ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà Body.__init__(self,ˆàposition,ˆàvelocity =ˆàself.tank.turret*bullet_velocity)
90
91ˆà ˆà ˆà ˆà defˆàon_wall(self):
92ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.tank.game.bodies.remove(self)
Note: See TracBrowser for help on using the repository browser.