def selectionItem(state): global isOpen if state == "down": if isActive and isOpen and (usedInterface != None): currentItem = usedInterface.getEntry("currentLine") if (currentItem == 1): # save the game Data.setData("isNewGame", False) Data.setData("lastPosition", playerBehaviour.getPlayer().getPosition()) Data.setData("lastScene", sceneBehaviour.getCurrentScene().getFileName()) Data.saveData() print('Game saved...') usedInterface.delete() Global.setInterfaceOpen(False) playerBehaviour.setControlsEnabled(True) isOpen = False characterBehaviour.stopMouvementForAllCharacters(True) else: os._exit(99)
def appendToRender(self): # adding all the elements to the render k = 0; for e in self.getAssignedElements(): k += 1; Render.set(e); if(k == len(self.getAssignedElements())): Global.setTimeout(self.resetRender, 1000);
def appendToRender(self): # adding all the elements to the render k = 0 for e in self.getAssignedElements(): k += 1 Render.set(e) if k == len(self.getAssignedElements()): Global.setTimeout(self.resetRender, 1000)
def editSky(self): isFlash = randint(1,10); if(isFlash == 2): self.elements['sky'].setVisible(True); self.elements['sky_darker'].setVisible(True); if(self.callOutsider): self.callOutsider(); Global.setTimeout(self.editSky2, 80);
def editSky(self): isFlash = randint(1, 10) if (isFlash == 2): self.elements['sky'].setVisible(True) self.elements['sky_darker'].setVisible(True) if (self.callOutsider): self.callOutsider() Global.setTimeout(self.editSky2, 80)
def shakeCamera(intensity, time): global isCameraShaking global shakeIntensity global savedPositionBeforeShaking if not isCameraShaking: isCameraShaking = True shakeIntensity = intensity camPosition = cameraToUse.getPosition() savedPositionBeforeShaking = [camPosition[0], camPosition[1]] Global.setInterval(camRandomPosition, 100 / intensity) Global.setTimeout(stopShaking, time)
def shakeCamera(intensity, time): global isCameraShaking; global shakeIntensity; global savedPositionBeforeShaking; if not isCameraShaking: isCameraShaking = True; shakeIntensity = intensity; camPosition = cameraToUse.getPosition(); savedPositionBeforeShaking = [camPosition[0], camPosition[1]]; Global.setInterval(camRandomPosition, 100/intensity); Global.setTimeout(stopShaking, time);
def callFunctions(self): for function in self.functionsToCallWhenAction: function(); if self.assignedDialog != None and self.assignedDialog.getStarted() == False: if not Global.isInterfaceOpen(): dialogBehaviour.setDialog(self.assignedDialog); self.assignedDialog.setCharacter(self); self.assignedDialog.setStarted(True); dialogBehaviour.start(); Global.setInterfaceOpen(True); playerBehaviour.enableMouvement(False);
def callFunctions(self): for function in self.functionsToCallWhenAction: function() if self.assignedDialog != None and self.assignedDialog.getStarted( ) == False: if not Global.isInterfaceOpen(): dialogBehaviour.setDialog(self.assignedDialog) self.assignedDialog.setCharacter(self) self.assignedDialog.setStarted(True) dialogBehaviour.start() Global.setInterfaceOpen(True) playerBehaviour.enableMouvement(False)
def startApp(): # get saved data before game start screenSize = Data.getData("screenSize"); Global.setScreenSize(screenSize[0], screenSize[1]); settings = pygame.HWSURFACE; isFullScreen = Data.getData("fullscreen"); if isFullScreen == "True": settings = settings | pygame.FULLSCREEN; Global.setScreenSize(infoObject.current_w, infoObject.current_h); Global.screen = pygame.display.set_mode(Global.screenSize, settings); startMenu(); initGame();
def setSpeed(self, speed): self.speed = speed # update the interval since we edited the speed if not self.timer is None: self.timer.destroy() self.timer = Global.Interval(self.updateFrames, 1000 / self.getSpeed())
def moveElementTo(self, elementName, x, y, time, steps=24): currentElement = self.getElementByName(elementName) if currentElement: if currentElement['element']: currentPosition = currentElement['element'].getPosition() currentElement['isMoving'] = True currentElement['target'] = [x, y] currentElement['vector'] = [(x - currentPosition[0]) / steps, (y - currentPosition[1]) / steps] currentElement['timer'] = Global.Interval( (lambda: self.updatePosition(currentElement, x, y)), time / steps) currentElement['timeout'] = Global.setTimeout( (lambda: self.destroyTimer(currentElement)), time) else: return None
def keyboardOpenPause(state): global isOpen; if(state == "down" and isActive): if isOpen: usedInterface.delete(); Global.setInterfaceOpen(False); playerBehaviour.setControlsEnabled(True); isOpen = False; characterBehaviour.stopMouvementForAllCharacters(True); else: if not Global.isInterfaceOpen(): usedInterface.create(); isOpen = True; Global.setInterfaceOpen(True); playerBehaviour.setControlsEnabled(False); characterBehaviour.stopMouvementForAllCharacters(False);
def keyboardOpenInventory(state): global isOpen; if (state == "down") and isActive and (usedInventory != None) and (usedInterface != None): if isOpen: # close it Global.setInterfaceOpen(False); usedInterface.delete(); isOpen = False; playerBehaviour.setControlsEnabled(True); else: # open it if not Global.isInterfaceOpen(): usedInterface.create(); isOpen = True; Global.setInterfaceOpen(True); playerBehaviour.setControlsEnabled(False);
def keyboardOpenPause(state): global isOpen if (state == "down" and isActive): if isOpen: usedInterface.delete() Global.setInterfaceOpen(False) playerBehaviour.setControlsEnabled(True) isOpen = False characterBehaviour.stopMouvementForAllCharacters(True) else: if not Global.isInterfaceOpen(): usedInterface.create() isOpen = True Global.setInterfaceOpen(True) playerBehaviour.setControlsEnabled(False) characterBehaviour.stopMouvementForAllCharacters(False)
def stop(): global isDialogStarted; global currentDialog; global currentIndex; playerBehaviour.setControlsEnabled(True); playerBehaviour.enableMouvement(True); isDialogStarted = False; currentDialog.setStarted(False); interface = currentDialog.getAssignedInterface(); interface.delete(); characterElement = currentDialog.getCharacter(); characterElement.isWalking(True); currentDialog = None; currentIndex = 1; Global.setInterfaceOpen(False);
def __init__(self): super().__init__() screenSize = Global.getScreenSize() background = Image("assets/cinematics/test.png") background.setSize(screenSize[0], screenSize[1]) background.setDepth(200) character = Image("assets/characterTest.png") character.setPosition(100, 100) character.setSize(100, 100) character.setDepth(201) self.append(character, "character") self.moveElementTo("character", 200, 200, 2000) Global.setTimeout(self.whenArriveToEnd, 2000) self.setBackground(background)
def __init__(self): super().__init__(); screenSize = Global.getScreenSize(); background = Image("assets/cinematics/test.png"); background.setSize(screenSize[0], screenSize[1]); background.setDepth(200); character = Image("assets/characterTest.png"); character.setPosition(100,100); character.setSize(100,100); character.setDepth(201); self.append(character, "character"); self.moveElementTo("character", 200,200, 2000); Global.setTimeout(self.whenArriveToEnd, 2000); self.setBackground(background);
def stop(): global isDialogStarted global currentDialog global currentIndex playerBehaviour.setControlsEnabled(True) playerBehaviour.enableMouvement(True) isDialogStarted = False currentDialog.setStarted(False) interface = currentDialog.getAssignedInterface() interface.delete() characterElement = currentDialog.getCharacter() characterElement.isWalking(True) currentDialog = None currentIndex = 1 Global.setInterfaceOpen(False)
def open(): global isOpen; if isActive and (usedInterface != None): if isOpen: # close it Global.setInterfaceOpen(False); usedInterface.delete(); isOpen = False; playerBehaviour.setControlsEnabled(True); GlobalVars.getVar("sounds")['thunder'].stop(); GlobalVars.getVar("sounds")['creepy'].stop(); else: # open it if not Global.isInterfaceOpen(): usedInterface.create(); isOpen = True; Global.setInterfaceOpen(True); playerBehaviour.setControlsEnabled(False);
def create(self): sX = Global.screenSize[0] sY = Global.screenSize[1] self.currentOpacity = 0 self.fadeDone = False self.fadeDirection = "in" self.fadeInterval = Global.Interval(self.updateOpacity, 100) self.functionToCallWhenDone = None super().create()
def moveElementTo(self, elementName, x, y, time, steps = 24): currentElement = self.getElementByName(elementName); if currentElement: if currentElement['element']: currentPosition = currentElement['element'].getPosition(); currentElement['isMoving'] = True; currentElement['target'] = [x, y]; currentElement['vector'] = [(x - currentPosition[0])/steps, (y - currentPosition[1])/steps]; currentElement['timer'] = Global.Interval((lambda: self.updatePosition(currentElement, x, y)), time / steps); currentElement['timeout'] = Global.setTimeout((lambda: self.destroyTimer(currentElement)), time); else: return None;
def selectionItem(state): global isOpen; if state == "down": if isActive and isOpen and (usedInterface != None): currentItem = usedInterface.getEntry("currentLine"); if(currentItem == 1): # save the game Data.setData("isNewGame", False); Data.setData("lastPosition", playerBehaviour.getPlayer().getPosition()); Data.setData("lastScene", sceneBehaviour.getCurrentScene().getFileName()); Data.saveData(); print('Game saved...'); usedInterface.delete(); Global.setInterfaceOpen(False); playerBehaviour.setControlsEnabled(True); isOpen = False; characterBehaviour.stopMouvementForAllCharacters(True); else: os._exit(99);
def __init__(self): self.backgroundElement = None; self.dynamicElements = []; screenSize = Global.getScreenSize(); self.fade = { "direction" : None, "interval" : None, "running" : False, "element" : Image("assets/dot.png") }; self.fade['element'].setSize(screenSize[0], screenSize[1]); self.fade['element'].setDepth(300); self.fade['element'].setAffectedByCamera(False); self.fade['element'].setOpacity(0);
def __init__(self): self.backgroundElement = None self.dynamicElements = [] screenSize = Global.getScreenSize() self.fade = { "direction": None, "interval": None, "running": False, "element": Image("assets/dot.png") } self.fade['element'].setSize(screenSize[0], screenSize[1]) self.fade['element'].setDepth(300) self.fade['element'].setAffectedByCamera(False) self.fade['element'].setOpacity(0)
def __init__(self, imagePath, frames=None, uniqueLoop=False): super().__init__(imagePath) self.type = "sprite" self.speed = 24 # images per second self.isPaused = False self.currentImage = 0 self.isUniqueLoop = uniqueLoop self.loopFinished = False self.isFlipped = False texture = self.getTexture() textureSize = texture.get_size() if not frames: self.maxImage = textureSize[0] / 64 else: self.maxImage = frames self.frameWidth = textureSize[0] / self.maxImage self.frameHeight = textureSize[1] self.timer = None self.timer = Global.Interval(self.updateFrames, 1000 / self.getSpeed())
def __init__(self, sceneToLoad): super().__init__(); self.setType("scene"); self.assignedElements = []; self.actions = []; self.sceneData = None; self.spawnPoint = None; self.name = ""; self.file = sceneToLoad; # load a scene if sceneToLoad: f = open("assets/scenes/" + sceneToLoad + ".json", "r", encoding='utf-8'); if f: self.sceneData = json.load(f); f.close(); # getting scene size self.setSize(0, 400); # set the position and size of the ground self.groundElement = Ground(); self.groundElement.setSize(self.size[0], self.size[0]); self.groundElement.setPosition(0, self.size[1]); mapSize = 0; self.name = self.sceneData['name']; # generate the map for e in self.sceneData['data']: if e: _type = e[0]; data = e[1] position = [e[2], e[3]]; element = None; if _type == "wall": element = Wall(data, position[0], position[1]); mapSize += 1; elif _type == "pickup": element = Pickup(data, position[0], position[1]); elif _type == "door": element = Door(data, position[0], position[1], e[4]); mapSize += 1; if len(e) == 6: self.actions.append(Teleport(position, e[5], [125, 0])); elif _type == "action": self.actions.append(ActionDispatcher(data, position[0], position[1])); elif _type == "spawn": self.spawnPoint = position; elif _type == "character": element = Character(e[5], e[6], e[1]); position = [e[2], self.getGroundPosition(element)]; if(e[4] != None): dialog = Dialog(e[4]); dialog.assignInterface(GlobalVars.getVar("dialogInterface")); element.assignDialog(dialog); elif _type == "teleport": targetScene = data; targetPosition = [e[4], e[5]]; self.actions.append(Teleport(position, targetScene, targetPosition)); if element: self.append(element, position[0], position[1]); self.setSize(250 * mapSize, 400); # check if the scene have a background if 'background' in self.sceneData: element = Background(self.sceneData['background'], 250 * mapSize); self.append(element, 250 * mapSize,0); backgroundBehaviour.setBackground(element); self.assignedPlayer = None; Global.setTimeout(self.appendToRender, 500);
def whenArriveToEnd2(self): self.moveElementTo("character", 200, 0, 2000) Global.setTimeout(self.stop, 2000)
def changeFade(self): self.fadeDirection = "out" self.fadeInterval = Global.Interval(self.updateOpacity, 100) self.fadeDone = False
def define(self): sX = Global.screenSize[0] sY = Global.screenSize[1] self.elements['background'] = Image("assets/homescreen.png") self.elements['background'].setPosition(0, 0) self.elements['background'].setSize(1 * sX, 1 * sY) self.elements['background'].setDepth(22) self.elements['sky'] = Image("assets/sky.png") self.elements['sky'].setPosition(0, 0) self.elements['sky'].setSize(1 * sX, 1 * sY) self.elements['sky'].setDepth(21) self.elements['sky'].setVisible(False) self.elements['sky_darker'] = Image("assets/sky_darker.png") self.elements['sky_darker'].setPosition(0, 0) self.elements['sky_darker'].setSize(1 * sX, 1 * sY) self.elements['sky_darker'].setDepth(20) self.elements['sky_darker'].setVisible(False) self.elements['menu_background'] = Image("assets/dot.png") self.elements['menu_background'].setPosition(0, 0) self.elements['menu_background'].setSize(0.5 * sX, 1 * sY) self.elements['menu_background'].setDepth(23) self.elements['menu_background'].setOpacity(0.25) self.elements['logo'] = Image("assets/logo_white.png") self.elements['logo'].setPosition( ((0.5 * sX) / 2) - ((0.5 * sX) - 180) / 2, 60) self.elements['logo'].setSize((0.5 * sX) - 180, ((0.5 * sX) - 180) / (649 / 186)) self.elements['logo'].setDepth(24) button_width = (0.5 * sX) - 180 button_height = ((0.5 * sX) - 180) / (269 / 68) # play button self.elements['play_background'] = Image("assets/white.png") self.elements['play_background'].setPosition( ((0.5 * sX) / 2) - ((0.5 * sX) - 180) / 2, 60 + ((0.5 * sX) - 180) / (649 / 186) + 20) self.elements['play_background'].setSize(button_width, button_height) self.elements['play_background'].setDepth(24) self.elements['play_background'].setVisible(False) self.elements['play_text'] = Text("Jouer", "arial") self.elements['play_text'].setFontSize(25) self.elements['play_text'].setColor((43, 56, 66)) self.elements['play_text'].setDepth(25) self.elements['play_text'].setAlign("center") self.elements['play_text'].setPosition( ((0.5 * sX) / 2), 60 + ((0.5 * sX) - 180) / (649 / 186) + 20 + button_height / 2 - 20) # settings button self.elements['settings_background'] = Image("assets/white.png") self.elements['settings_background'].setPosition( ((0.5 * sX) / 2) - ((0.5 * sX) - 180) / 2, self.elements['play_background'].position[1] + 80) self.elements['settings_background'].setSize(button_width, button_height) self.elements['settings_background'].setDepth(24) self.elements['settings_background'].setVisible(False) self.elements['settings_text'] = Text("Paramètres", "arial") self.elements['settings_text'].setFontSize(25) self.elements['settings_text'].setColor((43, 56, 66)) self.elements['settings_text'].setDepth(25) self.elements['settings_text'].setAlign("center") self.elements['settings_text'].setPosition( ((0.5 * sX) / 2), self.elements['play_text'].position[1] + 80) # credits button self.elements['credits_background'] = Image("assets/white.png") self.elements['credits_background'].setPosition( ((0.5 * sX) / 2) - ((0.5 * sX) - 180) / 2, self.elements['settings_background'].position[1] + 80) self.elements['credits_background'].setSize(button_width, button_height) self.elements['credits_background'].setDepth(24) self.elements['credits_background'].setVisible(False) self.elements['credits_text'] = Text("Crédits", "arial") self.elements['credits_text'].setFontSize(25) self.elements['credits_text'].setColor((43, 56, 66)) self.elements['credits_text'].setDepth(25) self.elements['credits_text'].setAlign("center") self.elements['credits_text'].setPosition( ((0.5 * sX) / 2), self.elements['settings_text'].position[1] + 80) # quit button self.elements['quit_background'] = Image("assets/white.png") self.elements['quit_background'].setPosition( ((0.5 * sX) / 2) - ((0.5 * sX) - 180) / 2, self.elements['credits_background'].position[1] + 80) self.elements['quit_background'].setSize(button_width, button_height) self.elements['quit_background'].setDepth(24) self.elements['quit_background'].setVisible(False) self.elements['quit_text'] = Text("Quitter", "arial") self.elements['quit_text'].setFontSize(25) self.elements['quit_text'].setColor((43, 56, 66)) self.elements['quit_text'].setDepth(25) self.elements['quit_text'].setAlign("center") self.elements['quit_text'].setPosition( ((0.5 * sX) / 2), self.elements['credits_text'].position[1] + 80) # game menu self.elements['game_background'] = Image("assets/dot.png") self.elements['game_background'].setPosition( 0.5 * sX + 20, 60 + ((0.5 * sX) - 180) / (649 / 186) + 20) self.elements['game_background'].setSize(0.5 * sX - 40, 160) self.elements['game_background'].setDepth(25) self.elements['game_background'].setOpacity(0.25) self.elements['game_background'].setVisible(False) self.elements['continue_background'] = Image("assets/white.png") self.elements['continue_background'].setPosition( 0.5 * sX + 20, self.elements['game_background'].position[1]) self.elements['continue_background'].setSize(0.5 * sX - 40, button_height) self.elements['continue_background'].setDepth(26) self.elements['continue_background'].setVisible(False) self.elements['continue_text'] = Text("Continuer", "arial") self.elements['continue_text'].setFontSize(25) self.elements['continue_text'].setColor((243, 243, 243)) self.elements['continue_text'].setDepth(27) self.elements['continue_text'].setAlign("center") self.elements['continue_text'].setVisible(False) self.elements['continue_text'].setPosition( ((0.5 * sX) / 2) + 0.5 * sX + 20, self.elements['game_background'].position[1] + 20) self.elements['new_background'] = Image("assets/white.png") self.elements['new_background'].setPosition( 0.5 * sX + 20, self.elements['continue_background'].position[1] + 80) self.elements['new_background'].setSize(0.5 * sX - 40, button_height) self.elements['new_background'].setDepth(26) self.elements['new_background'].setVisible(False) self.elements['new_text'] = Text("Nouvelle partie", "arial") self.elements['new_text'].setFontSize(25) self.elements['new_text'].setColor((243, 243, 243)) self.elements['new_text'].setDepth(27) self.elements['new_text'].setAlign("center") self.elements['new_text'].setVisible(False) self.elements['new_text'].setPosition( ((0.5 * sX) / 2) + 0.5 * sX + 20, self.elements['continue_text'].position[1] + 80) global thunderInterval thunderInterval = Global.Interval(self.editSky, 1000)
def __init__(self, sceneToLoad): super().__init__() self.setType("scene") self.assignedElements = [] self.actions = [] self.sceneData = None self.spawnPoint = None self.name = "" self.file = sceneToLoad # load a scene if sceneToLoad: f = open("assets/scenes/" + sceneToLoad + ".json", "r", encoding="utf-8") if f: self.sceneData = json.load(f) f.close() # getting scene size self.setSize(0, 400) # set the position and size of the ground self.groundElement = Ground() self.groundElement.setSize(self.size[0], self.size[0]) self.groundElement.setPosition(0, self.size[1]) mapSize = 0 self.name = self.sceneData["name"] # generate the map for e in self.sceneData["data"]: if e: _type = e[0] data = e[1] position = [e[2], e[3]] element = None if _type == "wall": element = Wall(data, position[0], position[1]) mapSize += 1 elif _type == "pickup": element = Pickup(data, position[0], position[1]) elif _type == "door": element = Door(data, position[0], position[1], e[4]) mapSize += 1 if len(e) == 6: self.actions.append(Teleport(position, e[5], [125, 0])) elif _type == "action": self.actions.append(ActionDispatcher(data, position[0], position[1])) elif _type == "spawn": self.spawnPoint = position elif _type == "character": element = Character(e[5], e[6], e[1]) position = [e[2], self.getGroundPosition(element)] if e[4] != None: dialog = Dialog(e[4]) dialog.assignInterface(GlobalVars.getVar("dialogInterface")) element.assignDialog(dialog) elif _type == "teleport": targetScene = data targetPosition = [e[4], e[5]] self.actions.append(Teleport(position, targetScene, targetPosition)) if element: self.append(element, position[0], position[1]) self.setSize(250 * mapSize, 400) # check if the scene have a background if "background" in self.sceneData: element = Background(self.sceneData["background"], 250 * mapSize) self.append(element, 250 * mapSize, 0) backgroundBehaviour.setBackground(element) self.assignedPlayer = None Global.setTimeout(self.appendToRender, 500)
def whenArriveToEnd2(self): self.moveElementTo("character", 200,0,2000); Global.setTimeout(self.stop, 2000);