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

source: game.py @ 8:4f578d001608

Revision 8:4f578d001608, 1.2 KB checked in by Daniil Alexeyevsky <me.dendik@òÀæ>, 5 years ago (diff)

Game.collides and Game.handle_collision are now methods of game, not hidden functions

  • Property exe set to *
Lineˆà
1other_tanks =ˆà[]
2bullets =ˆà[]
3
4classˆàGame(object):
5ˆà ˆà ˆà ˆà defˆà__init__(self,ˆàbodies,ˆàusers,ˆàwidth,ˆàheight):
6ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.bodies =ˆàbodies
7ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.users =ˆàusers
8ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.width =ˆàwidth
9ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.height =ˆàheight
10
11ˆà ˆà ˆà ˆà defˆàstep(game):
12ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà game.next_positions()
13ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà game.check_collisions()
14ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà game.check_walls()
15ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà game.update_positions()
16ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà game.invoke_ticks()
17ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà game.respawn()
18
19ˆà ˆà ˆà ˆà defˆànext_positions(game):
20ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà delta_t =ˆà1
21ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà forˆài inˆàgame.bodies:
22ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà i.next_position =ˆài.position +ˆài.velocity*(delta_t)
23ˆà ˆà ˆà ˆà
24
25ˆà ˆà ˆà ˆà defˆàcheck_collisions(game):
26ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà pass
27
28ˆà ˆà ˆà ˆà defˆàcollides(self,body1,body2):
29ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà pass
30
31ˆà ˆà ˆà ˆà defˆàhandle_collision(self,body1,body2):
32ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà pass
33
34ˆà ˆà ˆà ˆà defˆàcheck_walls(game):
35ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà forˆài inˆàgame.bodies :
36ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ifˆà((i.next_position.x -ˆài.radius)ˆà<=ˆà0)ˆàorˆà((i.next_position.y -ˆài.radius)ˆà<=ˆà0)ˆàorˆà((i.next_position.x +ˆài.radius)ˆà>=ˆàgame.width)ˆàorˆà((i.next_position.y +ˆài.radius)ˆà>=ˆàgame.height)ˆà:
37ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà i.on_wall()
38ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà
39
40ˆà ˆà ˆà ˆà defˆàupdate_positions(game):
41ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà forˆài inˆàgame.bodies:
42ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà i.position =ˆài.next_position
43
44ˆà ˆà ˆà ˆà defˆàinvoke_ticks(game):
45ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà forˆài inˆàgame.users:
46ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà i.tank.on_tick(other_tanks,bullets)
47ˆà ˆà ˆà ˆà
48ˆà ˆà ˆà ˆà defˆàrespawn(game):ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà
49ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà forˆài inˆàgame.users :
50ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ifˆài.tank.strength ==ˆà0ˆà:
51ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà i.tank.on_spawn()
52ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà i.tank.strength =ˆà1ˆà
Note: See TracBrowser for help on using the repository browser.