Esempio n. 1
0
def check_collision():
    Labirint.var.number_enemies = 0
    for e in Constants.ENEMIES:
        Labirint.var.number_enemies += 1
    for r in Labirint.var.rooms_parameters:
        if math_functions.check_wall_collision(r.x + Constants.block_size, r.y + Constants.block_size, r.x_size - Constants.block_size, r.y_size - Constants.block_size,
                                               Hero.hero.x, Hero.hero.y, -Hero.hero.radius - 1) == True:
            if Labirint.var.number_enemies == 0:
                if r.can_spawn > 0:
                    for i in range(2, (r.y_size - Constants.block_size) // Constants.block_size):
                        for j in range(2, (r.x_size - Constants.block_size) // Constants.block_size):
                            spawner(j * Constants.block_size + r.x, i * Constants.block_size + r.y, r.can_spawn)
                    r.can_spawn -= 1

    for w in Labirint.var.physics_WALLS:
        if w.can_collision == 1:
            for b in Constants.BULLETS[:]:
                if math_functions.check_wall_collision(w.x, w.y, w.size, w.size, b.x, b.y, b.radius) == True:
                    Constants.BULLETS.remove(b)
    for b in Constants.BULLETS[:]:
        if math_functions.distance_to(b.x, b.y, Hero.hero.x, Hero.hero.y) < b.radius + Hero.hero.radius:
            Hero.hero.hp-=20
            Constants.BULLETS.remove(b)
            if Hero.hero.hp<=0:
                end_game()
            
        if math_functions.inter_arena(b.x, b.y) == False:
            if b in Constants.BULLETS:
                Constants.BULLETS.remove(b)
Esempio n. 2
0
def spawner(x, y, chance):
    '''спавнер мобов'''
    if Labirint.randint(1, 100) < 40 / ((chance + 4) * 4)*(var.Hard)/10:
        if math_functions.distance_to(Hero.hero.x, Hero.hero.y, x, y) > Hero.hero.radius + 2 * Constants.block_size:
            e = Enemies.Enemy()
            rnd = Labirint.randint(1, 3)
            if rnd == 1:
                e.type = "soldier"
                e.range_to_move = 3250
                e.range_to_attack = 250
                e.color = Constants.MAGENTA
            if rnd == 2:
                e.type = "zombie"
                e.range_to_move = Hero.hero.radius * 1.2
                e.range_to_attack = Hero.hero.radius * 1.3
                e.color = Constants.GREEN
            if rnd == 3:
                e.type = "mage"
                e.range_to_move = 400
                e.range_to_attack = 300
                e.color = Constants.BLUE
            e.now_action = "move"
            e.x = x
            e.y = y
            Constants.ENEMIES.append(e)
Esempio n. 3
0
def check_damage():
    '''
    проверка столкновний объектов и
    вылета за границы игрового поля
    '''
    for e in Constants.ENEMIES[:]:
        for h_b in Constants.hero_BULLETS:
            if math_functions.distance_to(h_b.x, h_b.y, e.x, e.y) < e.radius + h_b.radius:
                if h_b.type == "shock":
                    e.hp -= 100
                if h_b.type == "uzi":
                    e.hp -= 20
                if h_b.type == "snipe":
                    e.hp -= 100
                if h_b.type == "gun":
                    e.hp -= 20
                if h_b.type == "ice_sphere":
                    e.hp -= 30
                    e.slow = h_b.ice_slow
                    e.time_end_slow = h_b.time_slow_duration + Labirint.var.TIME
                if h_b.type == "fire_sphere":
                    sf = Hero.fire_floor_surfaces()
                    sf.x = h_b.x
                    sf.y = h_b.y
                    sf.time_for_destroy = Labirint.var.TIME + sf.time_exist
                    Constants.SURFACES.append(sf)
                Constants.hero_BULLETS.remove(h_b)

    for e in Constants.ENEMIES[:]:
        for sf in Constants.SURFACES:
            if max(e.x - sf.x, e.y - sf.y) < sf.radius:
                e.time_end_fire = Labirint.var.TIME + sf.tick_time
                e.fire_damage = sf.damage

    for e in Constants.ENEMIES[:]:
        if e.hp <= 0:
            d = Enemies.Dead()
            d.x = e.x
            d.y = e.y
            d.type = e.type
            d.time_for_destroy = Labirint.var.TIME + d.time_exist
            Constants.Deads.append(d)
            Constants.ENEMIES.remove(e)

    for w in Labirint.var.physics_WALLS:
        if w.can_collision == 1:
            for h_b in Constants.hero_BULLETS[:]:
                if math_functions.check_wall_collision(w.x, w.y, w.size, w.size, h_b.x, h_b.y, h_b.radius) == True:
                    if h_b.type == "fire_sphere":
                        sf = Hero.fire_floor_surfaces()
                        sf.x = h_b.x
                        sf.y = h_b.y
                        sf.time_for_destroy = Labirint.var.TIME + sf.time_exist
                        Constants.SURFACES.append(sf)
                    Constants.hero_BULLETS.remove(h_b)
                    continue
Esempio n. 4
0
    def action(self):
        if self.time_end_fire > Hero.var.TIME:
            if Hero.var.TIME > self.last_fire_tick + self.next_fire_tick:
                self.last_fire_tick = Hero.var.TIME
                self.hp -= self.fire_damage

        if self.slow != 0:
            if Hero.var.TIME > self.time_end_slow:
                self.slow = 0
        if self.now_action == "move":
            self.move()
        if self.now_action == "attack":
            self.SHOOT()
            if self.type == "mage":
                self.SPAWN()

        if math_functions.distance_to(self.x, self.y, Hero.hero.x,
                                      Hero.hero.y) > self.range_to_move:
            self.now_action = "move"
        if math_functions.distance_to(self.x, self.y, Hero.hero.x,
                                      Hero.hero.y) < self.range_to_attack:
            self.now_action = "attack"
Esempio n. 5
0
                if event.key == draw_images.pygame.K_2:
                    if  Hero.hero_weapon1 == Hero.hero_select_weapon:
                        Hero.hero_weapon1 = Hero.hero_select_weapon
                        Hero.hero_select_weapon = Hero.hero_weapon2

                if event.key == draw_images.pygame.K_SPACE:
                    if Labirint.var.TIME > Hero.hero.blink_cd + Hero.hero.last_use_blink:
                        Hero.hero.x = Hero.aim.mx + Hero.my_map.x
                        Hero.hero.y = Hero.aim.my + Hero.my_map.y
                        Hero.hero.last_use_blink = Labirint.var.TIME
                if event.key == draw_images.pygame.K_ESCAPE:
                        if var.game_room=="game":
                            end_game()       
                if event.key == draw_images.pygame.K_e:
                    if math_functions.distance_to(Hero.hero.x, Hero.hero.y, Labirint.my_portal.x, Labirint.my_portal.y) < Labirint.my_portal.radius - Hero.hero.radius:
                        Labirint.my_portal.teleport()
                    else:
                        for c in var.Chests:
                            if math_functions.distance_to(Hero.hero.x,Hero.hero.y,c.x+c.size//2,c.y+c.size//2)<Hero.hero.radius*2:
                                c.drop_item()
                        for item in var.Items[:]:
                            if math_functions.distance_to(Hero.hero.x,Hero.hero.y,item.x,item.y)<Hero.hero.radius*2: 
                                item.take_weapon()
                                var.Items.remove(item)



    if var.game_room=="game": 

        Hero.hero.move()