Exemplo n.º 1
0
def player_escalator(p):
    pion = lvl.selected_pion[p]
    case_pos = lvl.pion_pos[pion]
    case = lvl.level[case_pos[1]][case_pos[0]]
    case_mean = lvl.meanings[case]

    if case_mean == "escalator":
        lvl.pion_pos[pion] = lvl.escalator[lvl.pion_pos[pion]]
        display.display_pion(pion)
Exemplo n.º 2
0
def check_hourglass_case(pos):
    """
    Vérifie si la case indiquée est un sablier^et active l'effet si c'est le cas.
    """
    mean = lvl.meanings[lvl.level[pos[1]][pos[0]]]

    if mean == "flip hourglass" and pos not in lvl.deactive_hourglass:
        lvl.discussing = True
        spell_end_effects()
        lvl.deactive_hourglass.append(pos)
        timer.flip_timer()
        display.display_timer_X(case=pos)
        for i in range(4):
            display.display_pion(i)
        if not check_guard_catch():
            display.display_discuss(x=10, y=130)
Exemplo n.º 3
0
def player_spell(p, spell):
    spell = spell.replace("spell_", "")

    if spell == "balai" and len(lvl.deactive_hourglass) != 0:
        lvl.player_using_spell = p
        lvl.spell_being_used = spell
        lvl.selected_spell_target = lvl.deactive_hourglass[0]
        display.display_selected_target(lvl.selected_spell_target)
    elif spell=="grenouille" \
    and any(filter(lambda name: "garde" in name, lvl.pion_name)): # Vérifie si un garde existe
        lvl.player_using_spell = p
        lvl.spell_being_used = spell
        for i in range(len(lvl.pion_name)):
            if "garde" in lvl.pion_name[i]:
                lvl.selected_spell_target = lvl.pion_pos[i]
                break
        display.display_selected_target(lvl.selected_spell_target)
    elif spell in ("echange", "teleportation"):
        lvl.player_using_spell = p
        lvl.spell_being_used = spell
        lvl.selected_spell_target = lvl.pion_pos[lvl.selected_pion[p]]
        display.display_selected_target(lvl.selected_spell_target)
    elif spell=="appat"\
    and any(filter(lambda name: "garde" in name, lvl.pion_name)) \
    and any(filter(lambda line: lvl.meanings_reverse["McTrollald"] in line, lvl.level)):
        lvl.player_using_spell = p
        lvl.spell_being_used = spell
        for i in range(len(lvl.pion_name)):
            if "garde" in lvl.pion_name[i]:
                lvl.selected_spell_target = lvl.pion_pos[i]
        display.display_selected_target(lvl.selected_spell_target)
    elif spell == "invisibilite":
        lvl.invisible = True
        lvl.spell_being_used = spell
        display.display_pion(lvl.pion_name.index("magicienne"))
        spell_end_use()
    elif spell == "fantome":
        lvl.ghost_mod = True
        lvl.spell_being_used = spell
        display.display_pion(lvl.pion_name.index("magicienne"))
        spell_end_use()

    else:
        print(
            "Le sort utilisé n'est pas assigné ou ne peut pas être utilisé maintenant."
        )
Exemplo n.º 4
0
def player_move(direction, pion):
    """
    Bouge le joueur 1 selon la touche indiquée.
    """
    pion_pos = lvl.pion_pos[
        pion]  # Création d'un raccourci pour appeler la position du personnage

    vec_move_x = (direction == "right") * 2 - (direction == "left") * 2
    vec_move_y = (direction == "down") * 2 - (direction == "up") * 2
    new_pos = (pion_pos[0] + vec_move_x, pion_pos[1] + vec_move_y)

    if check_collision(pion_pos, new_pos, lvl.pion_name[pion]) and check_guard(
            lvl.pion_name[pion], new_pos):
        lvl.pion_pos[pion] = new_pos
        display.display_pion(pion)

        check_hourglass_case(new_pos)
Exemplo n.º 5
0
def vortex_selection(input):
    """
    Gère la sélection et l'utilisation du vortex.
    """
    p = lvl.player_using_vortex
    control = lvl.controller[p]
    vort = lvl.selected_vortex
    pion = lvl.selected_pion[p]
    pion_name = lvl.pion_name[pion]
    pion_pos_others = lvl.pion_pos[0:pion] + lvl.pion_pos[pion +
                                                          1:len(lvl.pion_pos)]

    if input in control.keys():
        if "select" in control[input]:
            select_delta = int(control[input].replace(
                "select player ", "").replace("select action ", ""))

            y_start = vort[1]
            y_end = len(lvl.level) * (select_delta == 1) - (select_delta == -1)
            x_start = vort[0] + select_delta * 2
            x_end = len(lvl.level[0]) * (select_delta == 1) - (select_delta
                                                               == -1)

            for y in range(y_start, y_end, select_delta * 2):
                for x in range(x_start, x_end, select_delta * 2):
                    if lvl.meanings[lvl.level[y][
                            x]] == "vortex " + pion_name and check_guard(
                                pion_name,
                                (x, y)) and (x, y) not in pion_pos_others:
                        lvl.selected_vortex = (x, y)
                        display.display_selected_target(lvl.selected_vortex)
                        return None

                x_start = (len(lvl.level[0]) - 1) * (select_delta
                                                     == -1) + select_delta

        elif control[input] == "do action":
            lvl.player_using_vortex = -1
            lvl.pion_pos[lvl.selected_pion[p]] = vort
            display.efface_selected_target()
            display.display_pion(lvl.selected_pion[p])
Exemplo n.º 6
0
def spell_end_effects():
    """Met fin aux effets temporaires des sorts."""
    # Fin de l'effet grenouille
    for i in range(len(lvl.pion_name)):
        if "grenouille" in lvl.pion_name[i]:
            lvl.pion_name[i] = "garde_" + lvl.pion_name[i].split("_")[1]
            display.display_pion(i)
    # Fin de l'effet McTrollald
    if lvl.eating is not None:
        pion = lvl.pion_name.index(lvl.eating)
        lvl.eating = None
        display.display_pion(pion)
    # Fin des effets fantôme et invisibilité
    lvl.ghost_mod = False
    lvl.invisible = False
    display.display_pion(lvl.pion_name.index("magicienne"))
Exemplo n.º 7
0
def spell_target_selection(input):
    spell = lvl.spell_being_used
    p = lvl.player_using_spell
    control = lvl.controller[p]
    target = lvl.selected_spell_target
    target_id = None

    if input in control.keys():
        if "select" in control[input]:
            select_delta = int(control[input].replace(
                "select player ", "").replace("select action ", ""))

            # Sélection pour le sort balai
            if spell == "balai":
                target_id = lvl.deactive_hourglass.index(target)
                target_id += select_delta
                if target_id >= len(lvl.deactive_hourglass):
                    target_id = 0
                lvl.selected_spell_target = lvl.deactive_hourglass[target_id]
                display.display_selected_target(lvl.selected_spell_target)

            # Sélection durant le sort grenouille
            if spell == "grenouille":
                target_id = lvl.pion_pos.index(target)
                while True:
                    target_id += select_delta
                    if target_id >= len(lvl.pion_name):
                        target_id = 0
                    if target_id < 0:
                        target_id = len(lvl.pion_name) - 1
                    if "garde" in lvl.pion_name[target_id]:
                        lvl.selected_spell_target = lvl.pion_pos[target_id]
                        break
                display.display_selected_target(lvl.selected_spell_target)

            # Sélection pour le sort echange
            if spell == "echange":
                target_id = lvl.get_index_pion_pos(target)
                while True:
                    target_id += select_delta
                    if target_id >= len(lvl.pion_name):
                        target_id = 0
                    if target_id < 0:
                        target_id = len(lvl.pion_name) - 1
                    if "grenouille" not in lvl.pion_name[
                            target_id] and target_id not in lvl.move_pion:
                        lvl.selected_spell_target = lvl.pion_pos[target_id]
                        break
                display.display_selected_target(lvl.selected_spell_target)

            # Sélection pour le sort teleportation
            if spell == "teleportation" and len(lvl.move_pion) == 0:
                target_id = lvl.get_index_pion_pos(target)
                while True:
                    target_id += select_delta
                    if target_id >= len(lvl.pion_name):
                        target_id = 0
                    if target_id < 0:
                        target_id = len(lvl.pion_name) - 1
                    if "grenouille" not in lvl.pion_name[
                            target_id] and target_id not in lvl.move_pion:
                        lvl.selected_spell_target = lvl.pion_pos[target_id]
                        break
                display.display_selected_target(lvl.selected_spell_target)

            # Sélection durant le sort grenouille
            if spell == "appat":
                target_id = lvl.get_index_pion_pos(target)
                if len(lvl.move_pion) == 0:
                    while True:
                        target_id += select_delta
                        if target_id >= len(lvl.pion_name):
                            target_id = 0
                        if target_id < 0:
                            target_id = len(lvl.pion_name) - 1
                        if "garde" in lvl.pion_name[target_id]:
                            lvl.selected_spell_target = lvl.pion_pos[target_id]
                            break
                    display.display_selected_target(lvl.selected_spell_target)
                else:
                    y_start = target[1]
                    y_end = len(lvl.level) * (select_delta == 1) - (
                        select_delta == -1)
                    x_start = target[0] + select_delta * 2
                    x_end = len(lvl.level[0]) * (select_delta == 1) - (
                        select_delta == -1)
                    for y in range(y_start, y_end, select_delta * 2):
                        for x in range(x_start, x_end, select_delta * 2):
                            if lvl.meanings[lvl.level[y][x]] == "McTrollald":
                                lvl.selected_spell_target = (x, y)
                                display.display_selected_target(
                                    lvl.selected_spell_target)
                                return None
                        x_start = (len(lvl.level[0]) -
                                   1) * (select_delta == -1) + select_delta

        elif control[input] == "do action":
            # Effet du sort balai
            if spell == "balai":
                lvl.deactive_hourglass.remove(target)
                utk.efface("X_" + str(target[0]) + "_" + str(target[1]))
                display.efface_selected_target()
                spell_end_use()

            # Effet du sort grenouille
            if spell == "grenouille":
                target_id = lvl.pion_pos.index(target)
                lvl.pion_name[target_id] = "grenouille_" + lvl.pion_name[
                    target_id].split("_")[1]
                if lvl.selected_pion[p] == target_id:
                    lvl.selected_pion[p] += 1
                display.display_pion(target_id)
                spell_end_use()

            # Effet du sort echange
            if spell == "echange":
                target_id = lvl.get_index_pion_pos(target)
                if len(lvl.move_pion) == 0:
                    lvl.move_pion.append(target_id)
                    display.display_selected_target_confirmed(target)
                else:
                    lvl.move_pion.append(target_id)
                    lvl.pion_pos[lvl.move_pion[0]], lvl.pion_pos[
                        lvl.move_pion[1]] = lvl.pion_pos[
                            lvl.move_pion[1]], lvl.pion_pos[lvl.move_pion[0]]
                    for pion in lvl.move_pion:
                        display.display_pion(pion)
                    spell_end_use()

            # Effet du sort teleportation
            if spell == "teleportation":
                target_id = lvl.get_index_pion_pos(target)
                if len(lvl.move_pion) == 0:
                    lvl.move_pion.append(target_id)
                    display.display_selected_target_confirmed(target)
                elif check_collision(target, target) and check_guard(
                        lvl.pion_name[lvl.move_pion[0]], target):
                    lvl.pion_pos[lvl.move_pion[0]] = target
                    display.display_pion(lvl.move_pion[0])
                    spell_end_use()

            # Effet du sort appat
            if spell == "appat":
                if len(lvl.move_pion) == 0:
                    target_id = lvl.get_index_pion_pos(target)
                    lvl.move_pion.append(target_id)
                    display.display_selected_target_confirmed(target)
                    for y in range(len(lvl.level)):
                        for x in range(len(lvl.level[y])):
                            if lvl.meanings[lvl.level[y][x]] == "McTrollald":
                                lvl.selected_spell_target = (x, y)
                                display.display_selected_target(
                                    lvl.selected_spell_target)
                                return None
                else:
                    lvl.pion_pos[lvl.move_pion[0]] = target
                    lvl.eating = lvl.pion_name[lvl.move_pion[0]]
                    display.display_pion(lvl.move_pion[0])
                    spell_end_use()

    elif input in ("Up", "Down", "Left", "Right"
                   ) and spell == "teleportation" and len(lvl.move_pion) != 0:
        vec_move_x = (input == "Right") * 2 - (input == "Left") * 2
        vec_move_y = (input == "Down") * 2 - (input == "Up") * 2
        new_pos = (target[0] + vec_move_x, target[1] + vec_move_y)

        if 0 <= new_pos[1] < len(lvl.level) and 0 <= new_pos[0] < len(
                lvl.level[0]):
            lvl.selected_spell_target = new_pos
            display.display_selected_target(lvl.selected_spell_target)