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

source: body.py @ 15:43f5b82f3491

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

modules changed

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