Äîêóìåíò âçÿò èç êýøà ïîèñêîâîé ìàøèíû. Àäðåñ îðèãèíàëüíîãî äîêóìåíòà : http://kodomo.fbb.msu.ru/trac/tanchiki/changeset/54
Äàòà èçìåíåíèÿ: Unknown
Äàòà èíäåêñèðîâàíèÿ: Sun Apr 10 04:51:45 2016
Êîäèðîâêà: IBM-866
Changeset 54:5cb3fef573f6 òÀÓ Tanchiki

Changeset 54:5cb3fef573f6


Ignore:
Timestamp:
12/25/10 01:51:31 (5 years ago)
Author:
Olga Zolotareva <olya_zol@òÀæ>
Branch:
new
Tags:
tip
Message:

UI for two users

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • body.py

    r53 r54 ˆà
    5353ˆà
    5454        def accelerate(self, speed_delta):ˆà
    55ˆà                print 'speed_delta', speed_delta        #testˆà
    5655                self.velocity += self.base_orientation*speed_delta*delta_tˆà
    5756                if abs(self.velocity) > max_velocity:ˆà
    òÀæ òÀæ ˆà
    7877        def on_collision(self, other):ˆà
    7978                passˆà
    ˆà79        #       self.velocity , other.velocity =  self.velocity + other.velocity , other.velocity + self.velocityˆà
    8080ˆà
    8181        def on_wall(self):ˆà
  • game.py

    r53 r54 ˆà
    2424                self.respawn()ˆà
    2525                self.update_velocities()ˆà
    26ˆà                for i in self.bodies :ˆà
    27ˆà                        print iˆà
    28ˆà                #       print 'next position' , i.next_position ˆà
    29ˆà                        print 'update_position' ,  i.positionˆà
    30ˆà                        print 'velocity'  , i.velocityˆà
    31ˆà                        print 'velocity.rho', i.velocity.rho    # testˆà
    32ˆà                        if isinstance(i,body.Tank) == True:ˆà
    33ˆà                                print 'base_orientation' , i.base_orientationˆà
    34ˆà                        print '\n'ˆà
    ˆà26        #       for i in self.bodies :ˆà
    ˆà27        #               print i                                                 # testˆà
    ˆà28        #               print 'next position' , i.next_position                 # test ˆà
    ˆà29        #               print 'update_position' ,  i.position                   # testˆà
    ˆà30        #               print 'velocity'  , i.velocity                          # testˆà
    ˆà31        #               print 'velocity.rho', i.velocity.rho                    # testˆà
    ˆà32        #               if isinstance(i,body.Tank) == True:                     # testˆà
    ˆà33        #                       print 'base_orientation' , i.base_orientation   # testˆà
    ˆà34        #               print '\n'ˆà
    3535ˆà
    3636        def update_velocities(self):ˆà
    òÀæ òÀæ ˆà
    5656                if (abs(body1.next_position - body2.next_position) <= (body1.radius + body2.radius)):ˆà
    5757                        if (body1 != body2):ˆà
    58ˆà                                print 'collision' ˆà
    5958                                return Trueˆà
    6059                        else :ˆà
    òÀæ òÀæ ˆà
    6867                                body1.on_collision(body2)ˆà
    6968                        else :ˆà
    70ˆà                                body1.on_hit()ˆà
    ˆà69                                body1.on_hit(body2)ˆà
    7170                                body1.on_death()ˆà
    ˆà71                                self.bodies.remove(body2)ˆà
    7272                else :ˆà
    7373                        if isinstance(body2, body.Tank) == True :ˆà
    74ˆà                                body2.on_hit()ˆà
    ˆà74                                body2.on_hit(body2)ˆà
    7575                                body2.on_death()ˆà
    ˆà76                                self.bodies.remove(body1)ˆà
    7677ˆà
    7778        def check_walls(self):ˆà
    òÀæ òÀæ ˆà
    9495                        if i.tank.strength == 0 :ˆà
    9596                                i.tank.on_spawn()ˆà
    96ˆà                                print 'respawn'ˆà
    97ˆà                                print i.tank.strength , i.tank.positionˆà
    9897                                i.tank.strength = 1ˆà
    9998                                i.tank.velocity = vector.nullˆà
    òÀæ òÀæ ˆà
    101100                                i.tank.position.y = random.randint(i.tank.radius , height - i.tank.radius)ˆà
    102101                                i.tank.velocity = vector.null ˆà
    103ˆà                                print i.tank.strength , i.tank.positionˆà
    104102ˆà
    105103 ˆà
  • tk_ui.py

    r52 r54 ˆà
    99ˆà
    1010game_size = 500, 500ˆà
    11ˆàkeys = {ˆà
    ˆà11keys1 = {ˆà
    1212        'ocircumflex': 'base_left', ˆà
    1313        'acircumflex': 'base_right',ˆà
    òÀæ òÀæ ˆà
    1818        'division': 'fire',ˆà
    1919}ˆà
    ˆà20        ˆà
    ˆà21keys2 = {ˆà
    ˆà22        'icircumflex': 'base_left', ˆà
    ˆà23        'adiaeresis': 'base_right',ˆà
    ˆà24        'atilde': 'turret_left',ˆà
    ˆà25        'ugrave': 'turret_right',ˆà
    ˆà26        'oslash': 'accelerate',ˆà
    ˆà27        'ediaeresis': 'decelerate',ˆà
    ˆà28        'udiaeresis': 'fire',ˆà
    ˆà29}ˆà
    2030ˆà
    2131welcome = """Press F5 to startˆà
    2232ˆà
    2333Keys are:ˆà
    ˆà34ˆà
    ˆà35ˆà
    ˆà36User 1 :ˆà
    ˆà37ˆà
    2438a, d -- turn tankˆà
    2539q, e -- turn muzzleˆà
    2640w, s -- change speedˆà
    27ˆàx -- fire"""ˆà
    ˆà41x -- fireˆà
    ˆà42ˆà
    ˆà43User 2 :ˆà
    ˆà44 ˆà
    ˆà45j, l -- turn tankˆà
    ˆà46u, o -- turn muzzleˆà
    ˆà47i, k -- change speedˆà
    ˆà48m -- fire       ˆà
    ˆà49"""ˆà
    2850ˆà
    2951class Tank(BaseTank):ˆà
    òÀæ òÀæ ˆà
    5375ˆà
    5476        def init_game(self):ˆà
    55ˆà                self.user = User(keys)ˆà
    ˆà77                self.user1 = User(keys1)ˆà
    ˆà78                self.user2 = User(keys2)ˆà
    5679                w, h = game_size ˆà
    57ˆà                game = self.game = Game([], [self.user], w, h)ˆà
    58ˆà                tank = Tank(Vector(*game_size) * 0.5, self.user, self.game)ˆà
    59ˆà                game.bodies.append(tank)ˆà
    ˆà80                game = self.game = Game([], [self.user1, self.user2], w, h)ˆà
    ˆà81                tank1 = Tank(Vector(*game_size) * 0.5,  self.user1, self.game)ˆà
    ˆà82                tank2 = Tank(Vector(*game_size) * 0.5,  self.user2, self.game)ˆà
    ˆà83                game.bodies.append(tank1)ˆà
    ˆà84                game.bodies.append(tank2)ˆà
    6085ˆà
    6186        def init_ui(self):ˆà
    òÀæ òÀæ ˆà
    79104                if ev.keysym == "F5":ˆà
    80105                        self.step()ˆà
    81ˆà                self.user.on_key(ev.keysym, True)ˆà
    ˆà106                self.user1.on_key(ev.keysym, True)ˆà
    ˆà107                self.user2.on_key(ev.keysym, True)ˆà
    82108ˆà
    83109        def on_keyrelease(self, ev):ˆà
    84ˆà                self.user.on_key(ev.keysym, False)ˆà
    ˆà110                self.user1.on_key(ev.keysym, False)ˆà
    ˆà111                self.user2.on_key(ev.keysym, False)ˆà
    85112ˆà
    86113        def step(self):ˆà
  • user.py

    r52 r54 ˆà
    1818                else:ˆà
    1919                        action = self.keyset[key]ˆà
    20ˆà                        print 'action=', actionˆà
    2120                        if hasattr(self, action) and action not in ['tank', 'keyset']:ˆà
    2221                                setattr(self, action, value)ˆà
Note: See TracChangeset for help on using the changeset viewer.