Äīźóģåķņ āē’ņ čē źżųą ļīčńźīāīé ģąųčķū. Ąäšåń īščćčķąėüķīćī äīźóģåķņą : http://kodomo.cmm.msu.su/trac/tanchiki/changeset/36%3A1a0bddee3c54/
Äąņą čēģåķåķč’: Unknown
Äąņą čķäåźńčšīāąķč’: Sun Apr 10 06:49:26 2016
Źīäčšīāźą: UTF-8
Changeset 36:1a0bddee3c54 ? Tanchiki

Changeset 36:1a0bddee3c54


Ignore:
Timestamp:
12/20/10 18:43:18 (5 years ago)
Author:
Olga Zolotareva <olya_zol@?>
Branch:
new
Parents:
34:b7a85caedc7f (diff), 35:dfdc1def5d24 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Automated merge with ?ssh://kodomo.fbb.msu.ru/tanchiki

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • body.py

    • Property exe set to *
    r34 r36 š
    11import vectorš
    22import mathš
    3šdelta_phi = math.pi   # deltha phi = math.piš
    š3import randomš
    š4š
    š5base_angle = math.pi/32   # deltha phi = math.pi/32š
    š6turret_angle = math.pi/32š
    47speed_delta = 1š
    58delta_t = 1š
    6šmax_velocity = 2š
    š9max_velocity = 4š
    š10max_base_angle = 1š
    š11max_turret_angle = 1š
    712initial_strength = 1š
    š13bullet_velocity = 10š
    š14width = 100š
    š15height = 100š
    816š
    917class Body(object):š
    ? ? š
    1119                self.position = positionš
    1220                self.velocity = velocityš
    13š                self.radius = radiusš
    1421š
    1522class Tank(Body):š
    16š        radius = 1š
    17š        def __init__(self, position, user):š
    š23        radius = 5š
    š24        def __init__(self, position, user, game):š
    1825                Body.__init__(self, position)š
    š26                self.game = gameš
    š27                self.turret = vector.iš
    1928                self.strength = 0š
    20š                self.turret = vector.iš
    2129                self.base_orientation = 1       # 1 or -1š
    2230                self.user = userš
    23š                user.tank = self # äīįąāė’åņ ńåį’ ā Userš
    š31                user.tank = self š
    2432š
    25š        def rotate_base(tank, angle): š
    26š                self.velocity.phi += angleš
    š33š
    š34        def rotate_base(tank, angle):š
    š35                if abs(angle) < max_base_angle:  š
    š36                        self.velocity.phi += angleš
    š37                else:š
    š38                        self.velocity.phi += max_base_angleš
    2739š
    2840        def rotate_turret(self, angle):š
    29š                self.turret.phi += angleš
    š41                if abs(angle) < max_base_angle:  š
    š42                        self.turret.phi += angleš
    š43                else:š
    š44                        self.turret.phi += max_turret_angleš
    š45š
    3046š
    3147        def accelerate(self, speed_delta):š
    32š                self.velocity.rho += speed_delta * delta_tš
    33š                if self.velocity.rho > max_velocity :š
    š48                self.velocity += self.velocity.normalize() * speed_delta * delta_tš
    š49                print self.velocity.rhoš
    š50                if self.velocity.rho > max_velocity:š
    3451                        self.velocity.rho = max_velocityš
    3552š
    3653        def fire(self):š
    37š                passš
    š54                bullet_position = self.position + self.turret * (self.radius + 0.1)š
    š55                bullet_velocity = self.turret.normalize() * self.game.bullet_speedš
    š56                bullet = Bullet(bullet_position, bullet_velocity, self)š
    š57                self.game.bodies.append(bullet)š
    3858š
    3959        def on_tick(self,other_tanks, bullets):š
    40š                if self.user.base_left == True :š
    41š                        self.rotate_base(delta_phi)š
    42š                if self.user.base_right == True :š
    43š                        self.rotate_base(-1*delta_phi)š
    44š                if self.user.accelerate == True :š
    š60                if self.user.base_left == True:š
    š61                        self.rotate_base(base_angle)š
    š62                if self.user.base_right == True:š
    š63                        self.rotate_base(-1*base_angle)š
    š64                if self.user.accelerate == True:š
    4565                        self.accelerate(speed_delta)š
    š66                if self.user.decelerate == True:š
    š67                        self.accelerate(-1*speed_delta)š
    š68                if self.user.turret_left == True:š
    š69                        self.rotate_turret(turret_angle)š
    š70                if self.user.turret_right == True:š
    š71                        self.rotate_turret(-1*turret_angle)š
    š72                if self.user.fire == True:š
    š73                        self.fire()š
    4674š
    4775        def on_spawn(self):š
    4876                passš
    4977š
    50š        def on_death(self):š
    š78        def on_death(self) :š
    š79                passš
    š80        š
    š81        def on_hit(self, bullet):š
    5182                passš
    5283š
    53š        def on_hit(self,bullet):š
    54š                passš
    55šš
    56š        def on_collision(self):š
    š84        def on_collision(self, other):š
    5785                passš
    5886š
    5987        def on_wall(self):š
    60š                passš
    š88                self.next_position = self.positionš
    6189š
    6290class Bullet(Body):š
    6391        radius = 0.1š
    64š        passš
    š92        def __init__(self, position, velocity, tank):š
    š93                Body.__init__(self, position, velocity = bullet_velocity)š
    š94                self.tank = tankš
  • game.py

    • Property exe set to *
    r34 r36 š
    š1import vectorš
    š2import bodyš
    š3import timeš
    š4š
    15other_tanks = []š
    26bullets = []š
    ? ? š
    711                self.users = usersš
    812                self.width = widthš
    9š                self.height = heightš
    š13                self.height = height     š
    1014š
    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()š
    š15        def step(self):š
    š16                for i in self.bodies:           #testš
    š17                        print "begin", i, i.positionš
    š18                self.next_positions()š
    š19                self.check_collisions()š
    š20                self.check_walls()š
    š21                self.update_positions()š
    š22                self.invoke_ticks()š
    š23                self.respawn()š
    1824š
    19š        def next_positions(game):š
    š25                for i in self.bodies:           #testš
    š26                        print "end", i, i.position      #testš
    š27        #       time.sleep(1)                   #testš
    š28        #       self.step()                     #testš
    š29                š
    š30š
    š31        def next_positions(self):š
    2032                delta_t = 1š
    21š                for i in game.bodies :š
    š33                for i in self.bodies:š
    2234                        i.next_position = i.position + i.velocity*(delta_t)š
    š35        š
    2336š
    24š        def check_collisions(game):š
    25š                passš
    š37        def check_collisions(self):š
    š38                for i in self.bodies:š
    š39                        for j in self.bodies:š
    š40                                if self.collides(i,j) == True :š
    š41                                        self.handle_collision(i,j)                      š
    2642š
    2743        def collides(self,body1,body2):š
    28š                passš
    š44                print body1, body2š
    š45                if (abs(body1.next_position - body2.next_position) <= (body1.radius + body2.radius)):š
    š46                        print 'collision'š
    š47                        print body1.position , body2.position š
    š48                        if (body1 != body2):š
    š49                                return Trueš
    š50                        else :š
    š51                                return Falseš
    š52                else :š
    š53                        return Falseš
    2954š
    3055        def handle_collision(self,body1,body2):š
    31š                passš
    š56                if isinstance(body1, body.Tank) == True : š
    š57                        if isinstance(body2, body.Tank) == True :š
    š58                                body1.on_collision(body2)š
    š59                        else :š
    š60                                body1.on_hit()š
    š61                                body1.on_death()š
    š62                else :š
    š63                        if isinstance(body2, body.Tank) == True :š
    š64                                body2.on_hit()š
    š65                                body2.on_death()š
    3266š
    33š        def check_walls(game):š
    34š                for i in game.bodies :š
    35š                        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) :š
    š67        def check_walls(self):š
    š68                for i in self.bodies :š
    š69                        if ((i.next_position.x - i.radius) <= 0) or ((i.next_position.y - i.radius) <= 0) or ((i.next_position.x + i.radius) >= self.width) or ((i.next_position.y + i.radius) >= self.height) :š
    3670                                i.on_wall()š
    š71                                print 'wall'      #testš
    3772š
    38š        def update_positions(game):š
    39š                for i in game.bodies :š
    š73        def update_positions(self):š
    š74                for i in self.bodies:š
    4075                        i.position = i.next_positionš
    4176š
    42š        def invoke_ticks(game):š
    43š                for i in game.users :š
    44š                        i.tank.on_tick(other_tanks,bullets)š
    45š        š
    46š        def respawn(game):š
    47š                for i in game.users :š
    š77        def invoke_ticks(self):š
    š78                for i in self.bodies :š
    š79                        if isinstance(i, body.Tank) :š
    š80                                i.on_tick([], [])š
    š81š
    š82š
    š83        def respawn(self):                     š
    š84                for i in self.users :š
    4885                        if i.tank.strength == 0 :š
    4986                                i.tank.on_spawn()š
    50š                                i.tank.strength = 1 š
    š87                                i.tank.strength = 1š
    š88                                i.tank.velocity = vector.nullš
    š89                                i.tank.position.x = random.randint(self.radius , width - self.radius)š
    š90                                i.tank.position.y = random.randint(self.radius , height - self.radius)š
    š91                                i.tank.velocity = vector.null š
    š92š
    š93 š
  • user.py

    r34 r36 š
    11class User(object):     š
    22š
    3š        def __init__(self, base_left = False, base_right = False,š
    4š                           turret_left = False, turret_right = False,š
    5š                           accelerate = False, decelerate = False,š
    6š                           fire = False, tank = 0):š
    š3        def __init__(self, base_left = False , base_right = False, turret_left = False, turret_right = False, accelerate = False, decelerate = False, fire = False, tank = 0):š
    74                self.base_left = base_leftš
    85                self.base_right = base_rightš
  • vector.py

    • Property exe set to *
    r34 r36 š
    11import mathš
    22š
    3šclass Vector(object):š
    š3class Vector(object):   š
    44š
    5š        def __init__(self, x=0 , y=0):š
    š5        def __init__(self, x=0 , y=0):         š
    66                self.x = xš
    77                self.y = yš
    8šš
    š8        š
    99        def __add__(self, other):š
    1010                result = Vector(0,0)š
    1111                result.x = self.x + other.xš
    1212                result.y = self.y + other.yš
    š13                return resultš
    š14š
    š15        def __sub__(self, other):š
    š16                result = Vector(0,0)š
    š17                result.x = self.x - other.xš
    š18                result.y = self.y - other.yš
    1319                return resultš
    1420š
    ? ? š
    2026š
    2127        def dot_product(self, other):š
    22š                return self.x*other.x + self.y*other.yš
    š28                return  self.x*other.x + self.y*other.y š
    2329š
    2430        def __abs__(self):š
    ? ? š
    3440                        return 0š
    3541š
    š42        def normalize(self):š
    š43                result = Vector()š
    š44                result.x = self.xš
    š45                result.y = self.yš
    š46                result.rho = 1š
    š47                return resultš
    š48š
    3649        def get_rho(self):š
    3750                return abs(self)š
    3851š
    3952        def set_rho(self, new_rho):š
    40š                if self.is_null() == 1 :š
    š53                if self.is_null() == 1:š
    4154                        self.x , self.y = new_rho*math.cos(self.phi) , new_rho*math.sin(self.phi)š
    4255                else :š
    ? ? š
    4962                if self.is_null == 1:š
    5063                        phi = 0š
    51š                return phiš
    š64                return  phiš
    5265š
    5366        def set_phi(self, new_phi):š
    5467                rho = abs(self)š
    55š                self.x, self.y = rho*math.cos(new_phi) , rho*math.sin(new_phi)š
    š68                self.x , self.y = rho*math.cos(new_phi) , rho*math.sin(new_phi)š
    5669š
    5770        phi = property(get_phi, set_phi)š
    š71                š
    š72i = Vector(1,0)š
    š73j = Vector(0,1)š
    š74null = Vector(0,0)š
Note: See TracChangeset for help on using the changeset viewer.