Äîêóìåíò âçÿò èç êýøà ïîèñêîâîé ìàøèíû. Àäðåñ îðèãèíàëüíîãî äîêóìåíòà : http://kodomo.fbb.msu.ru/trac/tanchiki/changeset/20%3Aee776b889df7
Äàòà èçìåíåíèÿ: Unknown
Äàòà èíäåêñèðîâàíèÿ: Sun Apr 10 09:33:49 2016
Êîäèðîâêà: IBM-866
Changeset 20:ee776b889df7 òÀÓ Tanchiki

Changeset 20:ee776b889df7


Ignore:
Timestamp:
12/20/10 08:08:18 (5 years ago)
Author:
Peter Zotov <whitequark@òÀæ>
Branch:
default
Message:

Improve Game interface.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tanchiki/game.py

    r19 r20 ˆà
    33ˆà
    44class Game(object):ˆà
    5ˆà        def __init__(self, bodies, users, width, height):ˆà
    ˆà5        def __init__(self, width, height, bodies):ˆà
    66                self.bodies = bodiesˆà
    7ˆà                self.users = usersˆà
    87                self.width = widthˆà
    98                self.height = heightˆà
    109ˆà
    11ˆà        def step(game, delta_t):ˆà
    12ˆà                game.next_positions()ˆà
    13ˆà                game.check_collisions()ˆà
    14ˆà                game.check_walls()ˆà
    15ˆà                game.update_positions()ˆà
    16ˆà                game.invoke_ticks()ˆà
    17ˆà                game.respawn()ˆà
    ˆà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()ˆà
    1816ˆà
    19ˆà        def next_positions(game, delta_t):ˆà
    ˆà17        def __calculate_positions(game, delta_t):ˆà
    2018                for i in game.bodies :ˆà
    2119                        i.next_position = i.position + i.velocity*(delta_t)ˆà
    2220ˆà
    23ˆà        def check_collisions(game):ˆà
    ˆà21        def __update_positions(self):ˆà
    ˆà22                for i in self.bodies :ˆà
    ˆà23                        i.position = i.next_positionˆà
    ˆà24ˆà
    ˆà25        def __collides(self, body1, body2):ˆà
    2426                passˆà
    2527ˆà
    26ˆà        def collides(self,body1,body2):ˆà
    ˆà28        def __handle_collision(self, body1, body2):ˆà
    2729                passˆà
    2830ˆà
    29ˆà        def handle_collision(self,body1,body2):ˆà
    ˆà31        def __check_collisions(game):ˆà
    3032                passˆà
    3133ˆà
    32ˆà        def check_walls(game):ˆà
    ˆà34        def __check_walls(game):ˆà
    3335                for i in game.bodies :ˆà
    34ˆà                        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) :ˆà
    ˆà36                        if ((i.next_position.x - i.radius) <= 0) orˆà
    ˆà37                           ((i.next_position.y - i.radius) <= 0) orˆà
    ˆà38                           ((i.next_position.x + i.radius) >= game.width) orˆà
    ˆà39                           ((i.next_position.y + i.radius) >= game.height) :ˆà
    3540                                i.on_wall()ˆà
    3641ˆà
    37ˆà        def update_positions(game):ˆà
    38ˆà                for i in game.bodies :ˆà
    ˆà42        def __update_positions(self):ˆà
    ˆà43                for i in self.bodies :ˆà
    3944                        i.position = i.next_positionˆà
    4045ˆà
    41ˆà        def invoke_ticks(game):ˆà
    42ˆà                for i in game.users :ˆà
    43ˆà                        i.tank.on_tick(other_tanks,bullets)ˆà
    44ˆà        ˆà
    45ˆà        def respawn(game):ˆà
    46ˆà                for i in game.users :ˆà
    47ˆà                        if i.tank.strength == 0 :ˆà
    48ˆà                                i.tank.on_spawn()ˆà
    49ˆà                                i.tank.strength = 1 ˆà
    ˆà46        def __invoke_ticks(self):ˆà
    ˆà47                for i in self.bodies :ˆà
    ˆà48                        if i.controllerˆà
    ˆà49                                i.controller.on_tick(other_tanks, bullets)ˆà
Note: See TracChangeset for help on using the changeset viewer.