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)
def start(data, keepScore=False): """ Initialise une partie. :param list curMap: map actuelle sous forme de liste >>> start([['150s', '1d'],['B', 'R', 'G'], ['.', 'E', 'D'], ['W', 'W', 'W']]) ([(1, 1), 0], [(0, 1), (2, 2)], True) """ logic.findRockford(data) # refactoring logic.findFallable(data) logic.findEnd(data) timer.new(data["map"][0][0], "game") if not keepScore: data["score"] = 0 data["time"]["remain"] = timer.getTimer("game", int, remain=True) data["debug"] = False data["origin"] = data["map"][:]
import logging import telebot import timer import bot import os logging.basicConfig( level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') logging.info("Begin start server.") tgBot = telebot.TeleBot(os.getenv("BOT_ID", "")) bot.getTracker(tgBot, logging)() timer.getTimer(tgBot, logging)("Timer").start() logging.info("Start polling") def _pull(): try: tgBot.polling(none_stop=True, interval=1) except Exception as e: _pull() _pull()
def updatePhysic(data): # Retirer rockford """ met a jour la physique et return vrai si les fallables peuvent encore tomber :param list fallables: liste de couple de fallable (abscisse, ordonnee) :param bool fall: fallable tombe encore :param list rockford: rockford :param list curMap: map actuel sous forme de liste >>> updatePhysic([(0, 1), (2, 2)], False, \ [(1, 1), 0], [['150s', '1d'],['B', 'R', 'G'], ['.', 'E', 'D'], ['W', 'W', 'W']]) (True, [(1, 1), 0]) >>> updatePhysic([(0, 1), (2, 2), (1, 1)], True, \ [(1, 1), 0], [['150s', '1d'],['B', 'B', 'G'], ['.', 'R', 'D'], ['W', 'W', 'W']]) (True, 'lose') """ global GAME_STATUS if data["fall"]["fallings"] and timer.isOver("fallings"): nbFalling = 0 for i, fa in enumerate(data["fall"]["fallables"]): faX = fa["pos"][0] faY = fa["pos"][1] if fa["falling"] and data["map"][faY + 1][faX] == "R": setCell(data["map"], (faX, faY + 1), data["map"][faY][faX]) setCell(data["map"], (faX, faY), ".") GAME_STATUS = False if data["map"][faY + 1][faX] == ".": setCell(data["map"], (faX, faY + 1), data["map"][faY][faX]) setCell(data["map"], (faX, faY), ".") data["fall"]["fallables"][i] = { "pos": (faX, faY + 1), "falling": True } nbFalling += 1 elif (data["map"][faY][faX + 1] == "." and data["map"][faY + 1][faX + 1] == ".") and (data["map"][faY - 1][faX] != "D" and data["map"][faY - 1][faX] != "B"): setCell(data["map"], (faX + 1, faY), data["map"][faY][faX]) setCell(data["map"], (faX, faY), ".") data["fall"]["fallables"][i] = { "pos": (faX + 1, faY), "falling": True } nbFalling += 1 elif (data["map"][faY][faX - 1] == "." and data["map"][faY + 1][faX - 1] == ".") and (data["map"][faY - 1][faX] != "D" and data["map"][faY - 1][faX] != "B"): setCell(data["map"], (faX - 1, faY), data["map"][faY][faX]) setCell(data["map"], (faX, faY), ".") data["fall"]["fallables"][i] = { "pos": (faX - 1, faY), "falling": True } nbFalling += 1 else: data["fall"]["fallables"][i]["falling"] = False if nbFalling > 0: print("before being restored", timer.getTimer("fallings", remain=True), timer.timers["fallings"]["progression"]) timer.restore("fallings") print("after being restored", timer.getTimer("fallings", remain=True), timer.timers["fallings"]["progression"]) data["fall"]["fallings"] = True else: data["fall"]["fallings"] = False
def play(level=None, mode="r"): """ Lance une partie. :param string level: Nom du niveau à charger :param string mode: Type de partie à jouer ("r": random "s": save "l":level) """ global data ui.reset() ui.setBackground("black") initGameUI() initData() data["level"] = level data["mode"] = mode # data["origin"] = data["map"][1::] if level and mode=="s": IO.loadLevel(data, level) elif level and mode=="l": IO.loadSave(level, data) else: IO.loadLevel(data) start(data) render.update(data["map"][1::], "gameCanvas") while True: evenement.compute(inGame=True) ui.logic(evenement.event["tk"]) #direction = (0, 0) if ui.focus is None: timer.start("game") gameEvenement=evenement.event["game"] if handleEvenement(gameEvenement): if gameEvenement=="return": break continue # if evenement.event["game"] == "reset" or ui.evenement == "reset": # continue # elif evenement.event["game"] == "move": # elif evenement.event["game"] == "save": # #fileName = IO.save(data) # continue # elif evenement.event["game"] == "load": # continue # elif evenement.event["game"] == 'return': # break # if evenement.event["game"] == "debug" or ui.evenement == "debug": # debug = (False if debug else True) # print("DEBUG ACTIVATED" if debug else "DEBUG DEACTIVATED") # ui.evenement = None # continue logic.updatePhysic(data) if data["fall"]["fallings"]: render.update(data["map"][1::], "gameCanvas") updateStats(data["time"]["remain"], (data["diamonds"]["owned"], int(data["map"][0][1])), data["score"]) updateTime() data["time"]["remain"] = timer.getTimer("game", int, remain=True) #print(timer.timers["game"]["progression"]) win = logic.status(data) logic.updateGameStatus() if win and data["mode"] == "s": break elif win: IO.loadLevel(data) start(data, keepScore=True) render.update(data["map"][1::], "gameCanvas") elif win==False: break ui.render(getFps()) mise_a_jour() ui.reset() initMenuUI()
def checkData(): try: f = open("config.txt", "r") for x in f: if x[0:3] == "APG": xSplit = x.split(" ") #global APG APG = int(xSplit[1]) f.close() except: APG = 0 global glAPG glAPG = APG global drogueChute drogueChute = False while continueFM("FM106"): try: #if True: #check for Apogee if altitudeM > glAPG: #new Apogee! glAPG = int(round(altitudeM)) with open('config.txt', 'r') as file: data = file.readlines() for x in range(len(data)): dataSplit = data[x].split(" ") if dataSplit[0] == "APG": data[x] = "APG " + str(glAPG) + " \n" with open('config.txt', 'w') as file: file.writelines(data) break Comm.fnc_CommTransmit("APG " + str(Apogee)) #print("Well") #check if Apogee fits with timer #print("trying") import timer if timer.getTimer() > 25: #print("Timer exceeded 25!") #check if Apogee is above 200 above GLA #print(GLA) if glAPG < (GLA + 250): #print("Altimeter not working") Comm.fnc_CommTransmit("MSG FM106_AltimeterIncorrect") #switch to FM107 changeFM("FM107") #Check for parachute opening if -5 > vSpeed > -15: print("Parachute is open") Comm.fnc_CommTransmit("MSG FM106_DrogueOpen") #Check for Main Chute Deployment Altitude if (GLA + 100) > altitudeM: print("Deploying Main Chute!!") #switch to FM107 changeFM("FM107") time.sleep(0.1) except: pass