def status(data): """ verifie si la partie de Rockford est gagnée ou perdue :param list rockford: rockford """ global GAME_STATUS if data["time"]["remain"] <= 0: GAME_STATUS = False if GAME_STATUS is not None: if GAME_STATUS: timer.new(1, ID="endScoreUpdate", permanent=True) # shadows the older timer /!\ vector = data["time"]["remain"] * 10 currentTime = data["time"]["remain"] currentScore = data["score"] while not timer.isOver("endScoreUpdate"): currentVector = vector * ( timer.timers["endScoreUpdate"]["progression"] / timer.timers["endScoreUpdate"]["size"]) data["score"] = currentScore + int(currentVector) data["time"]["remain"] = currentTime + int(currentScore / 10) updateStats( data["time"]["remain"], (data["diamonds"]["owned"], int(data["map"][0][1])), data["score"]) updateTime() ui.render(getFps()) mise_a_jour() data["score"] = currentScore + vector data["time"]["remain"] = 0 updateStats(data["time"]["remain"], (data["diamonds"]["owned"], int(data["map"][0][1])), data["score"]) ui.render(getFps()) if data["mode"] == "s": updateScore(data["score"], getPlayer(), level=data["level"]) endGame(True) ui.remObject("endText") ui.render(getFps()) return True else: if data["mode"] == "s": updateScore(data["score"], getPlayer(), level=data["level"]) endGame(False) else: updateScore(data["score"], getPlayer()) endGame(False) ui.remObject("endText") ui.render(getFps()) return False
def levelSaveMenu(): """ Fait fonctionner le menu de sélection d'une sauvegarde. """ goInBlack() levels = IO.getLevels("save") levelSelected = 0 level = IO.loadSave(levels[0]) game.initSaveLevel(level) moveRender(levels, levelSelected, IO.loadSave) while not evenement.event["game"] == 'return': evenement.compute() ui.logic(evenement.event["tk"]) if evenement.event["game"] == "right": levelSelected = move(levelSelected, levels, 1, IO.loadSave) elif evenement.event["game"] == "left": levelSelected = move(levelSelected, levels, -1, IO.loadSave) elif evenement.event["game"] == "play": goInBlack() game.play(levels[levelSelected], "l") backInBlack(game.initSaveLevel, [levels[levelSelected]]) moveRender(levels, levelSelected, IO.loadSave) game.updateTime() animation.update() ui.render(game.getFps()) mise_a_jour() backInBlack(game.initPlayMenu)
def levelSelectionMenu(): """ Fait fonctionner le menu de sélection d'un niveau enregistré. """ goInBlack() levels = IO.getLevels("level") levelSelected = 0 level = IO.loadLevel(level=levels[0]) game.initSelectionLevel(level) moveRender(levels, levelSelected, IO.loadLevel) while not evenement.event["game"] == 'return': evenement.compute() ui.logic(evenement.event["tk"]) if evenement.event["game"] == "right": levelSelected = move(levelSelected, levels, 1, IO.loadLevel) elif evenement.event["game"] == "left": levelSelected = move(levelSelected, levels, -1, IO.loadLevel) elif evenement.event["game"] == "play": goInBlack() game.play(levels[levelSelected], "s") backInBlack(game.initSelectionLevel, [levels[levelSelected]]) moveRender(levels, levelSelected, IO.loadLevel) elif evenement.event["game"] == "edit": goInBlack() editor.editor(levels[levelSelected]) backInBlack(game.initSelectionLevel, [levels[levelSelected]]) moveRender(levels, levelSelected, IO.loadLevel) game.updateTime() animation.update() ui.render(game.getFps()) mise_a_jour() backInBlack(game.initPlayMenu)
def endGame(win): ui.addText(WIDTH_WINDOW / 2, HEIGHT_WINDOW / 2, textSize=48, text=("VOUS AVEZ GAGNE :)" if win else "VOUS AVEZ PERDU :("), textColor=("green" if win else "red"), ID="endText", layer=2) ui.render(getFps()) attente_clic_ou_touche()
def choicePlaystyleMenu(): """ Fait fonctionner le menu de sélection du mode de jeu. """ while not evenement.event["game"] == 'return': evenement.compute() ui.logic(evenement.event["tk"]) # home:play:selection if evenement.event["game"] == 'selection': levelSelectionMenu() # home:play:save if evenement.event["game"] == 'save': levelSaveMenu() # home:play:random if evenement.event["game"] == 'play': goInBlack() game.play(mode="r") backInBlack(game.initPlayMenu) game.updateTime() ui.render(game.getFps()) mise_a_jour()
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()
game.initMenuUI() while not evenement.event["game"] == 'return': # ev=donne_evenement() # if ev[0]!='RAS': # print(ev) evenement.compute() ui.logic(evenement.event["tk"]) # home:play if evenement.event["game"] == 'play': goInBlack(game.initPlayMenu) choicePlaystyleMenu() backInBlack(game.initMenuUI) # home:editor elif evenement.event["game"] == 'editor': goInBlack() editor.editor() backInBlack(game.initMenuUI) elif evenement.event["game"] == 'score': goInBlack() scoresMenu() backInBlack(game.initMenuUI) game.updateTime() animation.update() # /!\ render.updateAnimations before ui.render ui.render(game.getFps()) mise_a_jour() ############################################################################### ###############################################################################
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()