Esempio n. 1
0
def initSelectionLevel(level):
    """
    Initialise les éléments d'interface du menu de sélection d'un niveau sauvegardé.
    """
    initSaveLevel(level)
    ui.setObject("playButton", {"x":render.WIDTH_WINDOW*0.37})
    ui.addButton(render.WIDTH_WINDOW*0.63, 7*render.HEIGHT_WINDOW/8, width=render.WIDTH_WINDOW/4, height=render.HEIGHT_WINDOW/7, text="Edit", outlineColor="white", textColor="white", action=evenement.setGameEvent, arguments=["edit"])
Esempio n. 2
0
def update(cmap, ID, cutted=False):
    """
    affiche l'ensemble des case de la carte dans data sur le gameCanvas spécifié.

    :param dict data: map actuelle dans un dictionnaire à la clé "map"
    :param string ID: ID dans ui.objects de l'objet de type gameCanvas sur lequel afficher
    """
    ui.setObject(ID, {"squaresMap": cmap[::]}, forceUpdate=True)
Esempio n. 3
0
def saveLevel():
    level=exportEditorLevel()
    if level:
        ui.setObject("saveButton", {"outlineColor":"white","textColor":"white"})
        ui.newPrompt("Nom du niveau:", "Sauvegarder", success=lambda: IO.save(level, ui.objects["prompt_2"]["text"], saveIn="level"), checker=IO.checkSaveName, anyway=lambda: timer.setFactor(1))
    else:
        ui.setObject("saveButton", {"outlineColor":"red","textColor":"red"})
        print("Editor warning: the level can't be exported")
Esempio n. 4
0
def writeMultipleBlocks(canvas, squaresMap, block):
    """
    Ecrit plusieurs blocs sur le canvas donné.
    :param string canvas: ID du canvas cible
    :param list squaresMap: Matrice du niveau
    :param string block: type de bloc à placer
    """
    for p in ui.objects["editorCanvas"]["selected"]:
        squaresMap[p[1]][p[0]]=block
    ui.setObject(canvas, {"selected":None, "squaresMap":squaresMap})
Esempio n. 5
0
def updateCursor(ev, canvas, block=None, onPressed=False):
    """
    Met à jour la position du curseur dans la matrice de l'éditeur de niveau.
    :param tuple ev: Evenement donné par upemtk
    :param string canvas: ID du canvas cible
    :param string block: type de bloc
    :param bool onPressed: condition vraie si le clic de la souris est resté enfoncé
    """
    evType=type_evenement(ev)
    # print(ev)
    # print(ui.objects["editorCanvas"]["selected"])
    if evType in ("Deplacement", "ClicGauche"):
        pos=[clic_x(ev), clic_y(ev)]
        multiSelection=ui.objects["editorCanvas"]["selected"] and len(ui.objects["editorCanvas"]["selected"])>1
        squaresMap=ui.objects[canvas]["squaresMap"]
        if ui.objects[canvas]["ax"] < pos[0] < ui.objects[canvas]["bx"]-1 and ui.objects[canvas]["ay"] < pos[1] < ui.objects[canvas]["by"]-1:
            
            x=int((pos[0]-ui.objects[canvas]["ax"])/ui.objects[canvas]["cellSize"])
            y=int((pos[1]-ui.objects[canvas]["ay"])/ui.objects[canvas]["cellSize"])
            if block:
                # print("inSquare")
                if not onPressed:
                    if multiSelection:
                        writeMultipleBlocks(canvas, squaresMap, block)
                        return
                    else:
                        ui.setObject(canvas, {"selected":[(x,y)]})
                else:
                    if ui.objects["editorCanvas"]["selected"]:
                        ui.setObject(canvas, {"selected":list(set((*ui.objects["editorCanvas"]["selected"],(x,y))))})
                    # ui.setObject(canvas, {"selected":[*ui.objects["editorCanvas"]["selected"],(x,y)]}) # Bad memory usage
            else:
                ui.setObject(canvas, {"selected":[ui.objects["blockCanvas"]["selected"][0], (x,y)]})
            if evType == "ClicGauche":
                if block:
                    squaresMap[y][x]=block
                else:
                    ui.setObject(canvas, {"selected":[(x,y),ui.objects["blockCanvas"]["selected"][1]]})
                render.update(squaresMap, canvas)
        else:
            
            if block:
                # print("notinSquare")
                if multiSelection:
                    writeMultipleBlocks(canvas, squaresMap, block)
                    return
                    # onPressed=False
                    # return onPressed
            else:
                ui.setObject(canvas, {"selected":[ui.objects["blockCanvas"]["selected"][0], None]})
Esempio n. 6
0
def scoresMenu():
    scores = IO.loadScore()
    levels = [key for key in scores["s"]]
    selected = 0
    game.initScores(scores)
    while not evenement.event["game"] == 'return':
        evenement.compute()
        ui.logic(evenement.event["tk"])

        if evenement.event["game"] == "up":
            selected += 1
            for i in range(4):
                ui.setObject(
                    "ltext" + str(i + 1), {
                        "text":
                        levels[(selected + i) % len(levels)] + " - " +
                        str(scores["s"][levels[(selected + i) %
                                               len(levels)]][0]) + "\n\t" +
                        scores["s"][levels[(selected + i) % len(levels)]][1]
                    })
        elif evenement.event["game"] == "down":
            selected -= 1
            for i in range(4):
                ui.setObject(
                    "ltext" + str(i + 1), {
                        "text":
                        levels[(selected + i) % len(levels)] + " - " +
                        str(scores["s"][levels[(selected + i) %
                                               len(levels)]][0]) + "\n\t" +
                        scores["s"][levels[(selected + i) % len(levels)]][1]
                    })

        game.updateTime()
        animation.update()
        ui.render(game.getFps())
        mise_a_jour()
Esempio n. 7
0
def updateStats(remainTime, diamonds, score):
    """
    Met à jour les statistiques de la partie et les textes les affichant.
    :param int remainTime: Temps restant dans la partie
    :param tuple diamonds: Tuple contenant en position 0 le nombre de diamants ramassés et en position 1 le nombre de diamants dans la partie
    :param int score: Score actuel du joueur dans la partie
    """
    # Time left#
    ui.setObject("timeLeftText", {"text":language.get("timeText") + str(remainTime), "textColor":("green" if remainTime > 10 else "red")})
    # Diamonds#
    ui.setObject("diamondsText", {"text":language.get("diamondsText") + str(diamonds[0]) + "/" + str(diamonds[1]), "textColor":("red" if diamonds[0] < diamonds[1] else "green"), "x":ui.objects["timeLeftText"]["x"]+longueur_texte(ui.objects["timeLeftText"]["text"])})
    # Score#
    ui.setObject("scoreText", {"text":language.get("scoreText") + str(score), "x":ui.objects["diamondsText"]["x"]+longueur_texte(ui.objects["diamondsText"]["text"])})
def update():
    """
    Met à jour toutes les animations.
    """
    if enabled:
        global animations
        toDelete = set()
        for anim in animations.keys():
            if animations[anim]["status"] == 1:
                if timer.exists(anim + "timer"):
                    percentage = timer.getTimer(anim + "timer") / timer.timers[
                        anim + "timer"]["size"]
                    ui.setObject(
                        anim, {
                            a[0]: a[1][0] + ((a[1][1] * percentage) *
                                             (1 if a[1][2] else -1))
                            for a in animations[anim]["parameters"][
                                animations[anim]["step"]].items()
                        })
                elif animations[anim]["step"] < len(
                        animations[anim]["time"]) - 1:
                    ui.setObject(
                        anim, {
                            a[0]: a[1][0] + ((a[1][1]) *
                                             (1 if a[1][2] else -1))
                            for a in animations[anim]["parameters"][
                                animations[anim]["step"]].items()
                        })
                    animations[anim]["step"] += 1
                    timer.new(
                        animations[anim]["time"][animations[anim]["step"]],
                        anim + "timer")
                elif not animations[anim]["permanent"]:
                    toDelete.add(anim)
                else:
                    ui.setObject(
                        anim, {
                            a[0]: a[1][0] + ((a[1][1]) *
                                             (1 if a[1][2] else -1))
                            for a in animations[anim]["parameters"][
                                animations[anim]["step"]].items()
                        })
                    animations[anim]["status"] = 0
                    animations[anim]["step"] = 0
        for e in toDelete:
            animations.pop(e)
Esempio n. 9
0
def moveRender(levels, levelSelected, load):
    ui.setObject("levelName", {"text": levels[levelSelected]})
    ui.setObject("levelSelected",
                 {"text": str(levelSelected + 1) + "/" + str(len(levels))})
    render.update(load(level=levels[levelSelected])[1::], "levelSelection")
Esempio n. 10
0
def editor(level=None):
    """
    Lance et fait fonctionner l'éditeur de niveau.
    :param list level: Niveau à charger
    """
    ui.reset()
    ui.setBackground("black")
    initEditorUI()
    blockMap=[
        ["W", "G"],
        [".", "B"],
        ["D", "X"],
        ["R", "E"],
        ]
    editorWidth = 20
    editorHeight = 12
    if level:
        # squaresMap=[]
        level=IO.loadLevel(level=level)
        ui.setObject("timeLeftTextField", {"text": str(level[0][0])})
        level=level[1:]
        ydiff=editorHeight-len(level)
        xdiff=editorWidth-len(level[0])
        for y in range(len(level)):
            level[y].extend(["." for x in range(xdiff)])
        level.extend([["." for y in range(editorWidth)] for y in range(ydiff)])
    else:
        level=[["." for x in range(editorWidth)] for y in range(editorHeight)]
    render.update(level, "editorCanvas")
    render.update(blockMap, "blockCanvas")
    onPressed=False
    while not evenement.event["game"] == 'return':
        evenement.compute()
        ui.logic(evenement.event["tk"])
        tkEvent=evenement.getTkEvent()
        # print(type(ui.objects["blockCanvas"]["selected"]))
        if ui.focus is None:
            if ui.exclusiveLayer is None:
                updateCursor(tkEvent, "editorCanvas", ui.objects["blockCanvas"]["squaresMap"][ui.objects["blockCanvas"]["selected"][0][1]][ui.objects["blockCanvas"]["selected"][0][0]], onPressed)
                updateCursor(tkEvent, "blockCanvas")
            # print(evenement.event["game"])
            if evenement.event["game"] == "reset":
                render.update([["." for x in range(editorWidth)] for y in range(editorHeight)], "editorCanvas")
                # ui.render(game.getFps())
                # continue
            elif evenement.event["game"] == "save":
                timer.factor = 0
                if level:
                    IO.save(ui.objects["editorCanvas"]["squaresMap"], level[1])
                else:
                    ui.newPrompt("Nom de la sauvegarde:", "Sauvegarder", success=lambda: IO.save(game.data, ui.objects["prompt_2"]["text"]), checker=IO.checkSaveName, anyway=lambda: timer.setFactor(1))
            if type_evenement(tkEvent)=="Deplacement":
                if "|" in str(tkEvent):
                    onPressed=True
                else:
                    onPressed=False

        game.updateTime()
        ui.render(game.getFps())
        mise_a_jour()
    ui.reset()