1 | other_tanks =ˆà[] |
---|
2 | bullets =ˆà[] |
---|
3 | |
---|
4 | classˆàGame(object): |
---|
5 | ˆà ˆà ˆà ˆà defˆà__init__(self,ˆàwidth,ˆàheight,ˆàbodies): |
---|
6 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.bodies =ˆàbodies |
---|
7 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.width =ˆàwidth |
---|
8 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.height =ˆàheight |
---|
9 | |
---|
10 | ˆà ˆà ˆà ˆà defˆàstep(self,ˆàdelta_t): |
---|
11 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.__calculate_positions(delta_t) |
---|
12 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.__check_walls() |
---|
13 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.__check_collisions() |
---|
14 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.__update_positions() |
---|
15 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.__invoke_ticks() |
---|
16 | |
---|
17 | ˆà ˆà ˆà ˆà defˆà__calculate_positions(game,ˆàdelta_t): |
---|
18 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà forˆài inˆàgame.bodies : |
---|
19 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà i.next_position =ˆài.position +ˆài.velocity*(delta_t) |
---|
20 | |
---|
21 | ˆà ˆà ˆà ˆà defˆà__update_positions(self): |
---|
22 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà forˆài inˆàself.bodies : |
---|
23 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà i.position =ˆài.next_position |
---|
24 | |
---|
25 | ˆà ˆà ˆà ˆà defˆà__collides(self,ˆàbody1,ˆàbody2): |
---|
26 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà pass |
---|
27 | |
---|
28 | ˆà ˆà ˆà ˆà defˆà__handle_collision(self,ˆàbody1,ˆàbody2): |
---|
29 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà pass |
---|
30 | |
---|
31 | ˆà ˆà ˆà ˆà defˆà__check_collisions(game): |
---|
32 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà pass |
---|
33 | |
---|
34 | ˆà ˆà ˆà ˆà defˆà__check_walls(game): |
---|
35 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà forˆài inˆàgame.bodies : |
---|
36 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ifˆà((i.next_position.x -ˆài.radius)ˆà<=ˆà-game.width/2)ˆàorˆà\ |
---|
37 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà((i.next_position.y -ˆài.radius)ˆà<=ˆà-game.width/2)ˆàorˆà\ |
---|
38 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà((i.next_position.x +ˆài.radius)ˆà>=ˆàgame.width/2)ˆàorˆà\ |
---|
39 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà((i.next_position.y +ˆài.radius)ˆà>=ˆàgame.height/2)ˆà: |
---|
40 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà i.on_wall() |
---|
41 | |
---|
42 | ˆà ˆà ˆà ˆà defˆà__invoke_ticks(self): |
---|
43 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà forˆài inˆàself.bodies : |
---|
44 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ifˆài.controller : |
---|
45 | ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà i.controller.on_tick(other_tanks,ˆàbullets) |
---|