Äîêóìåíò âçÿò èç êýøà ïîèñêîâîé ìàøèíû. Àäðåñ îðèãèíàëüíîãî äîêóìåíòà : http://kodomo.cmm.msu.su/trac/tanchiki/changeset/3
Äàòà èçìåíåíèÿ: Unknown
Äàòà èíäåêñèðîâàíèÿ: Sun Apr 10 01:54:42 2016
Êîäèðîâêà: IBM-866
Changeset 3:af02cd410e37 òÀÓ Tanchiki

Changeset 3:af02cd410e37


Ignore:
Timestamp:
12/18/10 15:20:51 (5 years ago)
Author:
Olga Zolotareva <olya_zol@òÀæ>
Branch:
default
Children:
4:7313e5a09453, 6:b95121219b90
Message:

modules changed

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • body.py

    • Property exe set to *
    r2 r3 ˆà
    11import vectorˆà
    ˆà2import mathˆà
    ˆà3delta_phi = math.pi   # deltha phi = math.piˆà
    ˆà4speed_delta = 1ˆà
    ˆà5delta_t = 1ˆà
    ˆà6max_velocity = 2ˆà
    27ˆà
    38class Body(object):ˆà
    4ˆà        def __init__(self, position, velocity, next_position, radius=1):ˆà
    ˆà9        def __init__(self, position, velocity, next_position, radius):ˆà
    510                self.position = positionˆà
    611                self.velocity = velocityˆà
    òÀæ òÀæ ˆà
    1318                self.strength = strengthˆà
    1419                self.turret = turretˆà
    15ˆà                self.base_orientation = base_orientationˆà
    ˆà20                self.base_orientation = base_orientation # 1 or -1ˆà
    1621                self.game = gameˆà
    1722                self.user = userˆà
    18ˆà        def rotate_base(tank, angle):ˆà
    19ˆà                passˆà
    ˆà23ˆà
    ˆà24        def rotate_base(tank, angle): ˆà
    ˆà25                tank.base_velocity.phi += angleˆà
    ˆà26                tank.velocity.phi *= tank.base_orientationˆà
    2027ˆà
    2128        def rotate_turret(tank, angle):ˆà
    òÀæ òÀæ ˆà
    2330ˆà
    2431        def accelerate(tank, speed_delta):ˆà
    25ˆà                passˆà
    ˆà32                tank.velocity.rho += speed_delta * delta_tˆà
    ˆà33                if tank.velocity.rho > max_velocity:ˆà
    ˆà34                        tank.velocity.rho = max_velocityˆà
    2635ˆà
    2736        def fire(tank):ˆà
    òÀæ òÀæ ˆà
    2938ˆà
    3039        def on_tick(tank,other_tanks, bullets):ˆà
    31ˆà                passˆà
    ˆà40                if tank.user.base_left == True:ˆà
    ˆà41                        tank.rotate_base(delta_phi)ˆà
    ˆà42                if tank.user.base_right == True:ˆà
    ˆà43                        tank.rotate_base(-1*delta_phi)ˆà
    ˆà44                if tank.user.accelerate == True:ˆà
    ˆà45                        tank.accelerate(speed_delta)ˆà
    3246ˆà
    3347        def on_spawn(tank):ˆà
  • game.py

    • Property exe set to *
    r2 r3 ˆà
    ˆà1other_tanks = []ˆà
    ˆà2bullets = []ˆà
    ˆà3ˆà
    14class Game(object):ˆà
    25        def __init__(self, bodies, users, width, height):ˆà
    òÀæ òÀæ ˆà
    1720                delta_t = 1ˆà
    1821                for i in game.bodies:ˆà
    19ˆà                        i.next_position = i.position + i.velocity.mul_v(delta_t)ˆà
    ˆà22                        i.next_position = i.position + i.velocity*(delta_t)ˆà
    2023        ˆà
    2124ˆà
    òÀæ òÀæ ˆà
    3134        def check_walls(game):ˆà
    3235                for i in game.bodies :ˆà
    33ˆà                        if (i.next_position.x <= 0) or (i.next_position.y <= 0) or (i.next_position.x <= width) or (i.next_position.y >= game.height) :ˆà
    ˆà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) :ˆà
    3437                                i.on_wall()ˆà
    3538                ˆà
    òÀæ òÀæ ˆà
    4043ˆà
    4144        def invoke_ticks(game):ˆà
    42ˆà                passˆà
    ˆà45                for i in game.users:ˆà
    ˆà46                        i.tank.on_tick(other_tanks,bullets)ˆà
    4347        ˆà
    4448        def respawn(game):                     ˆà
    4549                for i in game.users :ˆà
    4650                        if i.tank.strength == 0 :ˆà
    47ˆà                                i.tank.respawn()ˆà
    48ˆàˆà
    49ˆàˆà
    50ˆà ˆà
    ˆà51                                i.tank.on_spawn()ˆà
    ˆà52                                i.tank.strength = 1 ˆà
  • user.py

    • Property exe set to *
  • vector.py

    • Property exe set to *
    r0 r3 ˆà
    1313                return resultˆà
    1414ˆà
    15ˆà        def mul_v(self, alpha):ˆà
    ˆà15        def __mul__(self, alpha):ˆà
    1616                result = Vector()ˆà
    1717                result.x = self.x * alphaˆà
    òÀæ òÀæ ˆà
    2222                return  self.x*other.x + self.y*other.y ˆà
    2323ˆà
    24ˆà        def len_v(self):ˆà
    ˆà24        def __abs__(self):ˆà
    2525                return (self.x**2 + self.y**2)**0.5ˆà
    2626        ˆà
    òÀæ òÀæ ˆà
    2929ˆà
    3030        def is_null(self):ˆà
    31ˆà                if self.len_v()  == 0 :ˆà
    ˆà31                if abs(self)     == 0 :ˆà
    3232                        return 1ˆà
    3333                else :ˆà
    òÀæ òÀæ ˆà
    3636ˆà
    3737        def get_rho(self):ˆà
    38ˆà                return self.len_v()ˆà
    ˆà38                return abs(self)ˆà
    3939ˆà
    4040        def set_rho(self, new_rho):ˆà
    41ˆà                self.x , self.y = self.x*(new_rho/self.len_v()) , self.y*(new_rho/self.len_v())ˆà
    ˆà41                self.x , self.y = self.x*(new_rho/abs(self)) , self.y*(new_rho/abs(self))ˆà
    4242ˆà
    4343        rho = property(get_rho, set_rho) ˆà
    4444        ˆà
    4545        def get_phi(self):ˆà
    46ˆà                cos = self.dot_product(Vector(1,0))/(self.len_v()*1)ˆà
    ˆà46                cos = self.dot_product(Vector(1,0))/(abs(self)*1)ˆà
    4747                if self.y < 0 : ˆà
    4848                        phi = -acos(cos)ˆà
    òÀæ òÀæ ˆà
    5252             ˆà
    5353        def set_phi(self, new_phi):ˆà
    54ˆà                self.x , self.y = self.len_v()*cos(new_phi) , self.len_v()*sin(new_phi)ˆà
    ˆà54                self.x , self.y = abs(self)*cos(new_phi) , abs(self)*sin(new_phi)ˆà
    5555ˆà
    5656        phi = property(get_phi, set_phi)ˆà
Note: See TracChangeset for help on using the changeset viewer.