Äîêóìåíò âçÿò èç êýøà ïîèñêîâîé ìàøèíû. Àäðåñ îðèãèíàëüíîãî äîêóìåíòà : http://kodomo.cmm.msu.su/trac/tanchiki/changeset/28%3A4ef6336d1707/?old=27%3Ab9856f9de9e2&old_path=
Äàòà èçìåíåíèÿ: Unknown
Äàòà èíäåêñèðîâàíèÿ: Sun Mar 2 20:58:23 2014
Êîäèðîâêà: IBM-866
Diff [b9856f9de9e2f856aebfc09b09933ca9ae1eaafd:4ef6336d1707056e8c9a118a7a31973ed4e5a2f4] for / òÀÓ Tanchiki

Ignore:
Location:
tanchiki
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • tanchiki/body.py

    r25 r28 ˆà
    55ˆà
    66class Body(object):ˆà
    7ˆà        def __init__(self, position, velocity = vector.Vector.null):ˆà
    ˆà7        def __init__(self, game, position, velocity = vector.Vector.null):ˆà
    ˆà8                self.game = gameˆà
    89                self.position = positionˆà
    910                self.velocity = velocityˆà
    òÀæ òÀæ ˆà
    1314        model = "tank"ˆà
    1415ˆà
    15ˆà        def __init__(self, position, controller):ˆà
    16ˆà                Body.__init__(self, position)ˆà
    ˆà16        def __init__(self, game, position, controller):ˆà
    ˆà17                Body.__init__(self, game, position)ˆà
    1718                self.controller = controllerˆà
    1819                self.turret = vector.Vector()ˆà
    òÀæ òÀæ ˆà
    2021ˆà
    2122        def rotate_base(tank, angle): ˆà
    22ˆà                self.velocity.phi += angleˆà
    ˆà23                if abs(angle) < self.game.max_base_delta :ˆà
    ˆà24                        self.velocity.phi += angleˆà
    ˆà25                else :ˆà
    ˆà26                        self.velocity.phi += self.game.max_base_deltaˆà
    2327ˆà
    2428        def rotate_turret(self, angle):ˆà
    25ˆà                self.turret.phi += angleˆà
    ˆà29                if abs(angle) < self.game.max_base_delta :ˆà
    ˆà30                        self.turret.phi += angleˆà
    ˆà31                else :ˆà
    ˆà32                        self.turret.phi += self.game.max_turret_deltaˆà
    2633ˆà
    2734        def accelerate(self, speed_delta):ˆà
    28ˆà                self.velocity.rho += speed_delta * delta_tˆà
    ˆà35                self.velocity += self.velocity.normalize() * speed_deltaˆà
    2936                if self.velocity.rho > max_velocity :ˆà
    3037                        self.velocity.rho = max_velocityˆà
    3138ˆà
    3239        def fire(self):ˆà
    33ˆà                passˆà
    ˆà40                bullet_position = self.position + self.turret * (self.radius + 0.1)ˆà
    ˆà41                bullet_velocity = self.turret.normalize() * self.game.bullet_speedˆà
    ˆà42                bullet = Bullet(bullet_position, bullet_velocity, self)ˆà
    ˆà43                self.game.bodies.append(bullet)ˆà
    3444ˆà
    3545class Bullet(Body):ˆà
    òÀæ òÀæ ˆà
    3747        model = "bullet"ˆà
    3848ˆà
    39ˆà        passˆà
    ˆà49        def __init__(self, position, velocity, tank):ˆà
    ˆà50                Body.__init__(self, position, velocity)ˆà
    ˆà51                self.origin = originˆà
  • tanchiki/game.py

    r22 r28 ˆà
    2424ˆà
    2525        def __collides(self, body1, body2):ˆà
    26ˆà                passˆà
    ˆà26                return (abs(body1.position - body2.position) <= (body1.radius + body2.radius))ˆà
    ˆà27                       and (body1 != body2)ˆà
    2728ˆà
    2829        def __handle_collision(self, body1, body2):ˆà
    29ˆà                passˆà
    ˆà30                if isinstance(body1, body.Tank) == True : ˆà
    ˆà31                        if isinstance(body2, body.Tank) == True :ˆà
    ˆà32                                body1.on_collision(body2)ˆà
    ˆà33                                body2.on_collision(body1)ˆà
    ˆà34                        else :ˆà
    ˆà35                                body1.on_hit()ˆà
    ˆà36                                body1.on_death()ˆà
    ˆà37                else :ˆà
    ˆà38                        if isinstance(body2, body.Tank) == True :ˆà
    ˆà39                                body2.on_hit()ˆà
    ˆà40                                body2.on_death()ˆà
    3041ˆà
    3142        def __check_collisions(game):ˆà
    32ˆà                passˆà
    ˆà43                for i in range(len(self.bodies)) :ˆà
    ˆà44                        for j in range(i, len(self.bodies)) :ˆà
    ˆà45                                a, b = self.bodies[i], self.bodies[j]ˆà
    ˆà46                                if self.collides(a, b) == True :ˆà
    ˆà47                                        self.handle_collision(a, b)ˆà
    3348ˆà
    34ˆà        def __check_walls(game):ˆà
    35ˆà                for i in game.bodies :ˆà
    ˆà49        def __check_walls(self):ˆà
    ˆà50                for i in self.bodies :ˆà
    3651                        if ((i.next_position.x - i.radius) <= -game.width/2) or \ˆà
    3752                           ((i.next_position.y - i.radius) <= -game.width/2) or \ˆà
  • tanchiki/vector.py

    r23 r28 ˆà
    11import mathˆà
    22ˆà
    3ˆàclass Vector(object):ˆà
    4ˆà        def __init__(self, x=0 , y=0):ˆà
    ˆà3class Vector(object):   ˆà
    ˆà4ˆà
    ˆà5        def __init__(self, x=0 , y=0):         ˆà
    56                self.x = xˆà
    67                self.y = yˆà
    7ˆàˆà
    ˆà8        ˆà
    89        def __add__(self, other):ˆà
    910                result = Vector(0,0)ˆà
    òÀæ òÀæ ˆà
    1920ˆà
    2021        def dot_product(self, other):ˆà
    21ˆà                return self.x*other.x + self.y*other.yˆà
    ˆà22                return  self.x*other.x + self.y*other.y ˆà
    2223ˆà
    2324        def __abs__(self):ˆà
    òÀæ òÀæ ˆà
    3334                        return 0ˆà
    3435ˆà
    ˆà36        def normalize(self):ˆà
    ˆà37                result = Vector()ˆà
    ˆà38                result.x = self.xˆà
    ˆà39                result.y = self.yˆà
    ˆà40                result.rho = 1ˆà
    ˆà41                return resultˆà
    ˆà42ˆà
    3543        def get_rho(self):ˆà
    3644                return abs(self)ˆà
    3745ˆà
    3846        def set_rho(self, new_rho):ˆà
    39ˆà                if self.is_null() == 1 :ˆà
    ˆà47                if self.is_null() == 1:ˆà
    4048                        self.x , self.y = new_rho*math.cos(self.phi) , new_rho*math.sin(self.phi)ˆà
    4149                else :ˆà
    òÀæ òÀæ ˆà
    4856                if self.is_null == 1:ˆà
    4957                        phi = 0ˆà
    50ˆà                return phiˆà
    ˆà58                return  phiˆà
    5159ˆà
    5260        def set_phi(self, new_phi):ˆà
    5361                rho = abs(self)ˆà
    54ˆà                self.x, self.y = rho*math.cos(new_phi) , rho*math.sin(new_phi)ˆà
    ˆà62                self.x , self.y = rho*math.cos(new_phi) , rho*math.sin(new_phi)ˆà
    5563ˆà
    5664        phi = property(get_phi, set_phi)ˆà
    57ˆàˆà
    58ˆàVector.null = Vector(0,0)ˆà
Note: See TracChangeset for help on using the changeset viewer.