1 | other_tanks =ˆà[] |
---|
2 | bullets =ˆà[] |
---|
3 | |
---|
4 | classˆà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ˆà |
---|