def choose_party(party :list):
    """Let's the player choose their party"""
    walking_left = [pygame.image.load("src/Sprites/stand_left.png")]
    walking_right = [pygame.image.load("src/Sprites/stand_right.png")]
    walking_top = [pygame.image.load("src/Sprites/stand_top.png")]
    walking_down = [pygame.image.load("src/Sprites/stand_bot.png")]

    for _ in range(7):
        walking_left.append(pygame.image.load("src/Sprites/step_left.png"))
        walking_right.append(pygame.image.load("src/Sprites/step_right.png"))
        walking_top.append(pygame.image.load("src/Sprites/step_top.png"))
        walking_down.append(pygame.image.load("src/Sprites/step_bot.png"))
    for _ in range(7):
        walking_left.append(pygame.image.load("src/Sprites/stand_left.png"))
        walking_right.append(pygame.image.load("src/Sprites/stand_right.png"))
        walking_top.append(pygame.image.load("src/Sprites/stand_top.png"))
        walking_down.append(pygame.image.load("src/Sprites/stand_bot.png"))
    for _ in range(7):
        walking_left.append(pygame.image.load("src/Sprites/step_left2.png"))
        walking_right.append(pygame.image.load("src/Sprites/step_right2.png"))
        walking_top.append(pygame.image.load("src/Sprites/step_top2.png"))
        walking_down.append(pygame.image.load("src/Sprites/step_bot2.png"))
    for _ in range(7):
        walking_left.append(pygame.image.load("src/Sprites/stand_left.png"))
        walking_right.append(pygame.image.load("src/Sprites/stand_right.png"))
        walking_top.append(pygame.image.load("src/Sprites/stand_top.png"))
        walking_down.append(pygame.image.load("src/Sprites/stand_bot.png"))

    walking_animation = [walking_left, walking_right, walking_top, walking_down]
    sprite = pygame.image.load("src/Sprites/main_character.png")

    main_character = Character("Leon", sprite, walking_animation)
    give_items(main_character)

    sprite = pygame.image.load("src/Sprites/knight.png")
    knight = Character("Knight", sprite, sprite)

    sprite = pygame.image.load("src/Sprites/archer.png")
    archer = Character("Archer", sprite, sprite)

    sprite = pygame.image.load("src/Sprites/wizard.png")
    wizard = Character("Wizard", sprite, sprite)

    sprite = pygame.image.load("src/Sprites/assassin.png")
    assassin = Character("Assassin", sprite, sprite)

    sprite = pygame.image.load("src/Sprites/monk.png")
    monk = Character("Monk", sprite, sprite)

    main_character.choose_character(party)
    left = [assassin,archer,knight,monk,wizard]
    while len(party) < 4:
        render_character_screen(left)
        while True:
            choice = choose_action("party")
            if choice <= len(left):
                break
        left[choice-1].choose_character(party)
        left.remove(left[choice-1])
Exemple #2
0
def use_item(party, monsters, user):
    """Activates chosen item and returns True if skill was used and False if something went wrong."""
    render_battle(party, monsters, user, "choose_item")
    character = party[0]
    while True:
        choice = choose_action("choose skill")
        if choice == 0:
            return False
        if choice == "d":
            render_info(character.items)
            while True:
                if choose_action("choose skill") == 0:
                    render_battle(party, monsters, user, "choose_item")
                    break
        elif choice <= len(character.items):
            item = character.items[choice - 1]
            if item.amount > 0:
                break
    if item.aoe == 0:
        render_battle(party, monsters, character, "choose_target_ally")
        while True:
            target = choose_action("choose target")
            try:
                if target == 0:
                    return False
                if item.use(party[target - 1]):
                    item.amount -= 1
                    return item
                else:
                    render_action("Does nothing on target", 500)
                    render_battle(party, monsters, character,
                                  "choose_target_ally")
            except IndexError:
                pass
    else:
        for member in party:
            item.use(member)
        item.amount -= 1
        return item
Exemple #3
0
 def __init__(self):
     self.party = []
     self.monsters = []
     render_map_selection()
     while True:
         pick = choose_action("Pick map")
         if pick in (1, 2):
             break
     self.map = generate_map(pick)
     self.start = self.map[0]
     self.boss = self.map[1]
     choose_party(self.party)
     generate_monsters(self.monsters)
     render_start(self.boss.name)
     self.start.activate(self.party, self.monsters, self.boss)
Exemple #4
0
    def activate(self, party: list, monsters: list, boss):
        """Lets the player move around in the area and activates battles."""
        area_monsters = []
        if not self.start and not self.boss:
            for _ in range(randint(0, 6)):
                while True:
                    monster = monsters[randint(0, len(monsters) - 1)]
                    if monster not in area_monsters:
                        area_monsters.append(monster)
                        break
                monster.x = randint(
                    wall,
                    screen_width - wall - monster.over_sprite.get_width())
                monster.y = randint(
                    wall,
                    screen_height - wall - monster.over_sprite.get_height())
        countdown = 0
        while True:
            move(party[0])
            character_width = party[0].over_sprite[
                party[0].direction][countdown].get_width()
            character_height = party[0].over_sprite[
                party[0].direction][countdown].get_height()

            if self.boss:
                if collision(party[0], boss, countdown):
                    battle(party, [boss])
                    render_game_over("victory")
                    while True:
                        choose_action("victory")

            if party[0].left and party[0].x >= wall and party[
                    0].up is False and party[0].down is False:
                party[0].x -= 6
                countdown += 1
                party[0].direction = 0

            if party[0].left and party[0].x >= wall and (party[0].up
                                                         or party[0].down):
                party[0].x -= 4
                countdown += 1
                party[0].direction = 0

            if party[0].right and party[
                    0].x <= screen_width - character_width - wall and party[
                        0].up is False and party[0].down is False:
                party[0].x += 6
                countdown += 1
                party[0].direction = 1

            if party[0].right and party[
                    0].x <= screen_width - character_width - wall and (
                        party[0].up or party[0].down):
                party[0].x += 4
                countdown += 1
                party[0].direction = 1

            if party[0].up and party[0].y >= wall and party[
                    0].right is False and party[0].left is False:
                party[0].y -= 6
                countdown += 1
                party[0].direction = 2

            if party[0].up and party[0].y >= wall and (party[0].right
                                                       or party[0].left):
                party[0].y -= 4
                countdown += 1
                party[0].direction = 2

            if party[0].down and party[
                    0].y <= screen_height - character_height - wall and party[
                        0].right is False and party[0].left is False:
                party[0].y += 6
                countdown += 1
                party[0].direction = 3

            if party[0].down and party[
                    0].y <= screen_height - character_height - wall and (
                        party[0].right or party[0].left):
                party[0].y += 4
                countdown += 1
                party[0].direction = 3

            if countdown > 27:
                countdown = 0

            if party[0].right and party[
                    0].x + 6 > screen_width - character_width - wall and door_tall < party[
                        0].y + character_height / 2 < screen_height - door_tall:
                if self.right is not None:
                    party[0].x = wall
                    self.right.activate(party, monsters, boss)
            if party[0].left and party[0].x - 6 < wall and door_tall < party[
                    0].y + character_height / 2 < screen_height - door_tall:
                if self.left is not None:
                    party[0].x = screen_width - wall - character_width
                    self.left.activate(party, monsters, boss)
            if party[0].up and party[0].y - 6 < wall and door_wide < party[
                    0].x + character_width / 2 < screen_width - door_wide:
                if self.top is not None:
                    party[0].y = screen_height - wall - character_height
                    self.top.activate(party, monsters, boss)
            if party[0].down and party[
                    0].y + 6 > screen_height - character_height - wall and door_wide < party[
                        0].x + character_width / 2 < screen_width - door_wide:
                if self.bottom is not None:
                    party[0].y = wall
                    self.bottom.activate(party, monsters, boss)

            if len(area_monsters) != 0:
                for monster in area_monsters:
                    monster.x += monster.speed_x
                    monster.y += monster.speed_y
                    if monster.x >= screen_width - monster.over_sprite.get_width(
                    ) - wall:
                        monster.change_speed("x")
                    if monster.x <= wall:
                        monster.change_speed("x")
                    if monster.y >= screen_height - monster.over_sprite.get_height(
                    ) - wall:
                        monster.change_speed("y")
                    if monster.y <= wall:
                        monster.change_speed("y")

                    if collision(party[0], monster, countdown):
                        if battle(party, monster.monsters):
                            for character in party:
                                character.give_exp(
                                    monster.monsters[0].level[0] * 50 *
                                    len(monster.monsters))
                        area_monsters.remove(monster)
                        party[0].right = False
                        party[0].left = False
                        party[0].up = False
                        party[0].down = False
            render_area(party, area_monsters, party[0].direction, countdown,
                        self, boss)
            clock.tick(50)
Exemple #5
0
def battle(party, monsters):
    """The main code for battles. Asks the player what they want to do and leads to the corresponding function. Ends when all monsters are defeated."""
    for monster in monsters:
        for i in range(1, party[0].level[0] + 1):
            monster.level_up(i)
    if monsters[0].boss:
        for i in range(1, party[0].level[0] + 1):
            monsters[0].level_up(min(i + 3, 10))
    active_skills = []
    characters = []
    for character in party:
        characters.append(character)
    for character in monsters:
        characters.append(character)
    while True:
        for skill in active_skills:
            skill.duration -= 1
            if skill.duration == 0:
                skill.deactivate(party)
                active_skills.remove(skill)
        for character in characters:
            if character.alive:
                while True:
                    render_battle(party, monsters, character, "battle")
                    if character.monster is False:
                        while True:
                            action = choose_action("battle")
                            if 1 <= action <= 4:
                                break

                        if action == 1:
                            render_battle(party, monsters, character,
                                          "choose_target_enemy")
                            while True:
                                target = choose_action("choose target")
                                if 0 <= target <= len(monsters):
                                    if monsters[
                                            target -
                                            1].alive is True or target == 0:
                                        break
                            if target != 0:
                                character.attack(monsters[target - 1], 0)
                                break

                        if action == 2:
                            skill = use_skill(party, monsters, character,
                                              active_skills)
                            if skill is not False:
                                render_action(skill.name, 500)
                                break

                        if action == 3:
                            item = use_item(party, monsters, character)
                            if item is not False:
                                render_action(item.name, 500)
                                break

                        if action == 4:
                            if not monsters[0].boss:
                                chance = randint(1, 3)
                                if chance == 1:
                                    render_action("ESCAPE", 1000)
                                    return False
                                render_action("ESCAPE FAILED", 800)
                                break
                            render_action("CAN'T ESCAPE", 800)
                    else:
                        while True:
                            target = randint(0, 3)
                            if party[target].alive:
                                break
                        action = randint(1, len(character.skills) + 8)
                        if character.boss:
                            action += 2
                        if action > 5:
                            if len(character.skills) > 0:
                                skill = character.skills[randint(
                                    0,
                                    len(character.skills) - 1)]
                                if skill.aoe != 1:
                                    skill.activate(character, party[target])
                                else:
                                    for party_member in party:
                                        skill.activate(character, party_member)
                                render_action(skill.name, 1000)
                                break
                        character.attack(party[target], 0)
                        render_action("ATTACK", 500)
                        break

                if character.status[0] == "Poison":
                    render_battle(party, monsters, character, "battle")
                    character.take_dmg(
                        (character.hp + character.taken_dmg) // 4)
                    render_action("POISON DAMAGE", 500)
                    character.status[1] -= 1
                    if character.status[1] <= 0:
                        character.status = ["none", 0]
                        render_battle(party, monsters, character, "battle")
                        render_action("POISON CURED", 800)
                render_battle(party, monsters, character, "battle")
                pygame.time.wait(50)
            alive_characters = 4
            alive_monsters = len(monsters)
            for character in characters:
                if character.alive is False:
                    if character.monster is False:
                        alive_characters -= 1
                    else:
                        alive_monsters -= 1
            if alive_characters == 0:
                render_game_over("defeat")
                while True:
                    choose_action("defeat")

            if alive_monsters == 0:
                for skill in active_skills:
                    skill.deactivate(party)
                render_action("VICTORY", 1000)
                return True
Exemple #6
0
def use_skill(party, monsters, character, active_skills):
    """Activates chosen skill and returns False if something went wrong."""
    render_battle(party, monsters, character, "choose_skill")
    while True:
        choice = choose_action("choose skill")
        if choice == "d":
            render_info(character.skills)
            while True:
                if choose_action("choose skill") == 0:
                    render_battle(party, monsters, character, "choose_skill")
                    break
        elif choice <= len(character.skills):
            if choice == 0:
                return False
            skill = character.skills[choice - 1]
            if character.mp - skill.cost >= 0:
                break
    character.mp -= skill.cost
    character.used_mp += skill.cost

    if skill.aoe != 1:
        if skill.buff == 0 and skill.recover == 0 and skill.resurrect == 0:
            render_battle(party, monsters, character, "choose_target_enemy")
            while True:
                target = choose_action("choose target")
                if 0 <= target <= len(monsters):
                    if target == 0:
                        return False
                    if monsters[target - 1].alive is True:
                        skill.activate(character, monsters[target - 1])
                        break

        elif skill.recover == 1:
            if skill.aoe == -1:
                skill.activate(character, character)
                return skill
            render_battle(party, monsters, character, "choose_target_ally")
            while True:
                target = choose_action("choose target")
                if 0 <= target <= 4:
                    if target == 0:
                        return False
                    if party[target - 1].alive is True:
                        skill.activate(character, party[target - 1])
                        break
                    render_action("Target must be alive", 500)
                    render_battle(party, monsters, character,
                                  "choose_target_ally")

        elif skill.resurrect == 1:
            render_battle(party, monsters, character, "choose_target_ally")
            while True:
                target = choose_action("choose target")
                if 0 <= target <= 4:
                    if target == 0:
                        return False
                    if party[target - 1].alive is False:
                        skill.activate(character, party[target - 1])
                        break
                    render_action("Target must be dead", 500)
                    render_battle(party, monsters, character,
                                  "choose_target_ally")
        else:
            if skill in active_skills:
                skill.deactivate(party)
                active_skills.remove(skill)
            skill.activate(character, character)
            skill.user = character.name
            active_skills.append(skill)

    else:
        if skill.buff == 0 and skill.recover == 0:
            for monster in monsters:
                skill.activate(character, monster)
        elif skill.recover == 1:
            for party_member in party:
                skill.activate(character, party_member)
        else:
            if skill in active_skills:
                skill.deactivate(party)
                active_skills.remove(skill)
            for party_member in party:
                skill.activate(character, party_member)
            active_skills.append(skill)
    return skill