Esempio n. 1
0
        if e.name == "ninja":
            e.x += dx * 1.5 #TC8
            e.y += dy * 1.5
            tp = random.randint(0, 500)
            if tp % 500 == 0:
                e.x = random.randint(70, 730) #TC8
                e.y = random.randint(70, 525)
                f.write("Ninja teleported \n")
        if e.name == "ranger":
             e.x += dx  #TC8
             e.y += dy
             shoot = random.randint(0, 500)
             if shoot % 500 == 0:
                    enemy_shot = Bullet(e.x, e.y)
                    enemy_shot.x = e.x
                    enemy_shot.y = e.y
                    enemy_shot.direction = e.dirX
                    enemy_bullets.append(enemy_shot)
                    enemy_bullet_group.add(enemy_shot)
                    f.write("Enemy shot\n") #TC5


    for e in boss_group:
        shoot = random.randint(0, 1000)
        if shoot % 20 ==0:
            enemy_up = Bullet(e.x, e.y)
            enemy_up.x = e.x 
            enemy_up.y = e.y 
            enemy_up.direction = "up"
            enemy_bullets.append(enemy_up)
            enemy_bullet_group.add(enemy_up)
Esempio n. 2
0
def player_move(pos, fr, cl, fire, shot_frame, st, jump, js, keys, money):
    pos_0 = 0
    pos_1 = 0
    a25 = player_size[0] / 2
    a55 = player_size[1] - player_size[0] / 2
    ind = int((fr * delay_time) / 100) % 4
    position = [pos[0] - a25, pos[1] - a55]
    rotated_image = player.pic[ind]
    if jump == 0:
        if keys[pygame.K_a] or keys[pygame.K_LEFT]:
            pos_0 -= 1
        if keys[pygame.K_d] or keys[pygame.K_RIGHT]:
            pos_0 += 1
        if keys[pygame.K_w] or keys[pygame.K_UP]:
            pos_1 -= 1
        if keys[pygame.K_s] or keys[pygame.K_DOWN]:
            pos_1 += 1
    else:
        pos[1] += (jump * 5 * player.speed)
        win.blit(
            pygame.transform.scale(
                rotated_image,
                (int(1.2 * player_size[0]), int(1.2 * player_size[1]))),
            (position[0], position[1]))
        if abs(pos[1] - js) >= screen_height / 7:
            jump = 0

    pos_0 *= player.speed
    pos_1 *= player.speed
    if pos_0 != 0 and pos_1 != 0:
        pos_0 /= np.sqrt(2)
        pos_1 /= np.sqrt(2)

    pos_0 = int(pos_0)
    pos_1 = int(pos_1)

    if jump == 0:
        for an in animals:
            if pos[0] - a25 > an.x + an.pic[0].get_width(
            ) or pos[0] + a25 < an.x:
                x = pos[0] + pos_0
                if pos[1] - a25 < an.y + an.pic[0].get_height(
                ) and pos[1] + a25 > an.y:
                    if x - a25 <= an.x + an.pic[0].get_width(
                    ) and x + a25 >= an.x:
                        if x + a25 > an.x + an.pic[0].get_width():
                            pos[0] = an.x + an.pic[0].get_width(
                            ) - pos_0 + a25 + 1
                        else:
                            pos[0] = an.x - a25 - pos_0 - 1
                        break
            else:
                x = pos[1] + pos_1
                if x - a25 < an.y + an.pic[0].get_height() and x + a25 > an.y:
                    if x - a25 > an.y:
                        if screen_height - player_size[1] >= pos[
                                1] + screen_height / 7:
                            jump = 1
                        else:
                            jump = -1
                        js = pos[1]
                        player.hp -= an.damage
                    else:
                        pos[1] -= pos_1
                    break

    pos[0] += pos_0
    pos[1] += pos_1
    if pos[0] >= road_end - player_size[0] / 2:
        pos[0] = road_end - player_size[0] / 2
    elif pos[0] <= road_start + player_size[0] / 2:
        pos[0] = road_start + player_size[0] / 2
    if pos[1] >= screen_height - player_size[0]:
        pos[1] = screen_height - player_size[0] - 1
    elif pos[1] <= a25:
        pos[1] = a25

    if (cl or keys[pygame.K_SPACE]) and time.time() - bullet_reload[sel_bull] >= bullet[sel_bull].reload\
            and bullet[sel_bull].cost <= money:
        money -= bullet[sel_bull].cost
        d = bullet[sel_bull].damage
        r = bullet[sel_bull].reload
        rad = bullet[sel_bull].radius
        l = bullet[sel_bull].lvl
        if sel_bull == 1:
            bull = Bullet(10, 10, 10, BLACK, d,
                          (3 * screen_height) * delay_time / 1000, r, None, l,
                          True, rad)
        elif sel_bull == 2:
            bull = Bullet(1, 5, 10, RED, d,
                          (6 * screen_height) * delay_time / 1000, r, None, l)
        else:
            bull = Bullet(0, 5, 5, BROWN, d,
                          (5 * screen_height) * delay_time / 1000, r, None, l)
        bull.x = pos[0] + int(0.28 * a25)
        bull.y = pos[1] - a55
        bullets.append(bull)
        bullet_reload[sel_bull] = time.time()

    if cl or keys[pygame.K_SPACE]:
        fire = True
    else:
        fire = False

    if not fire:
        if pos_0 > 0:
            if pos_1 > 0:
                rotated_image = pygame.transform.rotate(player.pic[ind], -135)
                position = [pos[0] - a25, pos[1] - a25]
            elif pos_1 < 0:
                rotated_image = pygame.transform.rotate(player.pic[ind], -45)
                position = [pos[0] - a25, pos[1] - a55]
            else:
                rotated_image = pygame.transform.rotate(player.pic[ind], -90)
                position = [pos[0] - a25, pos[1] - a25]
        elif pos_0 < 0:
            if pos_1 > 0:
                rotated_image = pygame.transform.rotate(player.pic[ind], 135)
                position = [pos[0] - a55, pos[1] - a25]
            elif pos_1 < 0:
                rotated_image = pygame.transform.rotate(player.pic[ind], 45)
                position = [pos[0] - a55, pos[1] - a55]
            else:
                rotated_image = pygame.transform.rotate(player.pic[ind], 90)
                position = [pos[0] - a55, pos[1] - a25]
        else:
            if pos_1 > 0:
                rotated_image = pygame.transform.rotate(player.pic[ind], 180)
                position = [pos[0] - a25, pos[1] - a25]

    if not jump:
        win.blit(rotated_image, (position[0], position[1]))
    return pos, fire, shot_frame, st, jump, js, money