def __init__(self): super().__init__() self.setType("player") self.assignedScene = None self.speed = 10 # assign a drawable for test self.sprites = { "walking": Sprite("assets/characters/william/walking.png"), "static": Sprite("assets/characters/william/static.png", 2) } # sprite settings self.sprites['walking'].setSpeed(12) self.sprites['walking'].setSize(256, 256) self.sprites['static'].setSpeed(1) self.sprites['static'].setSize(256, 256) self.setDepth(2) self.assignDrawable(self.sprites['static']) self.setSize(256, 256) Render.set(self)
def startMenu(): # global vars GlobalVars.setActive(); # world world = World(); # camera cam = Camera(world); Render.setCamera(cam); cameraBehaviour.setCamera(cam); Global.isApplicationRunning = True; # sounds GlobalVars.getVar("sounds")['thunder'].play(); GlobalVars.getVar("sounds")['creepy'].play(); # menu behaviour menuBehaviour.setActive(True); menuBehaviour.open(); menuBehaviour.assign("play", menuBehaviour.playMenu); menuBehaviour.assign("settings", startSettings); menuBehaviour.assign("credits", startCredits); menuBehaviour.assign("quit", doQuit); menuBehaviour.assign("continue", continueGame); menuBehaviour.assign("new", startNewGame); newGame = Data.getData("isNewGame"); menuBehaviour.setNewGame(newGame);
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 updateElements(self): for element in self.dynamicElements: if "element" in element: element['element'].setAffectedByCamera(False) Render.set(element['element']) if self.backgroundElement: self.backgroundElement.setAffectedByCamera(False) Render.set(self.backgroundElement)
def updateElements(self): for element in self.dynamicElements: if "element" in element: element['element'].setAffectedByCamera(False); Render.set(element['element']); if self.backgroundElement: self.backgroundElement.setAffectedByCamera(False); Render.set(self.backgroundElement);
def output(text): global currentLine textElement = Text(text, "arial") textElement.setPosition(20, 20 + currentLine * 20) textElement.setAffectedByCamera(False) Render.set(textElement) lines.append(textElement) currentLine += 1
def output(text): global currentLine; textElement = Text(text, "arial"); textElement.setPosition(20, 20 + currentLine * 20); textElement.setAffectedByCamera(False); Render.set(textElement); lines.append(textElement); currentLine += 1;
def destroy(self): for element in self.getAssignedElements(): element.destroy() Render.delete(element) for action in self.actions: action.destroy() Render.delete(action) self.actions = [] self.assignedElements = []
def destroy(self): for element in self.getAssignedElements(): element.destroy(); Render.delete(element); for action in self.actions: action.destroy(); Render.delete(action); self.actions = []; self.assignedElements = [];
def stop(self, time = 0): # if time != 0: # ## doing fade out # self.fade['element'].setOpacity(1); # Render.set(self.fade['element']); # self.fade['running'] = True; # self.fade['direction'] = "out"; # self.fade['interval'] = Global.Interval(self.updateFade, 50); # else: for element in self.dynamicElements: Render.delete(element['element']); if self.backgroundElement: Render.delete(self.backgroundElement);
def stop(self, time=0): # if time != 0: # ## doing fade out # self.fade['element'].setOpacity(1); # Render.set(self.fade['element']); # self.fade['running'] = True; # self.fade['direction'] = "out"; # self.fade['interval'] = Global.Interval(self.updateFade, 50); # else: for element in self.dynamicElements: Render.delete(element['element']) if self.backgroundElement: Render.delete(self.backgroundElement)
def __init__(self, position, targetScene, targetPosition): super().__init__() self.setType("teleportation") self.uniqid = uuid.uuid4() self.action = ActionDispatcher(self.uniqid, position[0], position[1]) self.receiver = ActionReceiver(self.uniqid) self.receiver.on(self.doTeleport) texture = Image("assets/icons/door.png") texture.setSize(64, 64) texture.setOffsetPosition(93, 300) texture.setDepth(101) self.assignDrawable(texture) self.setPosition(position[0], position[1]) self.targetScene = targetScene self.targetPosition = targetPosition Render.set(texture)
def __init__(self, position, targetScene, targetPosition): super().__init__(); self.setType("teleportation"); self.uniqid = uuid.uuid4(); self.action = ActionDispatcher(self.uniqid, position[0], position[1]); self.receiver = ActionReceiver(self.uniqid); self.receiver.on(self.doTeleport); texture = Image("assets/icons/door.png"); texture.setSize(64,64); texture.setOffsetPosition(93,300); texture.setDepth(101); self.assignDrawable(texture); self.setPosition(position[0], position[1]); self.targetScene = targetScene; self.targetPosition = targetPosition; Render.set(texture);
def fadeOutEnd(self): self.fade['running'] = False; Render.delete(self.fade['element']); self.fade['interval'].destroy(); for element in self.dynamicElements: Render.delete(element['element']); if self.backgroundElement: Render.delete(self.backgroundElement);
def fadeOutEnd(self): self.fade['running'] = False Render.delete(self.fade['element']) self.fade['interval'].destroy() for element in self.dynamicElements: Render.delete(element['element']) if self.backgroundElement: Render.delete(self.backgroundElement)
def clear(): global lines; for line in lines: Render.delete(line); lines = [];
def create(self): for element in self.elements: self.elements[element].setAffectedByCamera(False) Render.set(self.elements[element])
def delete(self): for element in self.elements: Render.delete(self.elements[element])
def fadeInEnd(self): self.fade['running'] = False Render.delete(self.fade['element']) self.fade['interval'].destroy() self.updateElements()
def destroy(self): self.action.destroy(); self.receiver.destroy(); for element in self.getAssignedDrawables(): Render.delete(element);
def clear(): global lines for line in lines: Render.delete(line) lines = []
def delete(self): for element in self.elements: Render.delete(self.elements[element]);
def create(self): for element in self.elements: self.elements[element].setAffectedByCamera(False); Render.set(self.elements[element]);
def fadeInEnd(self): self.fade['running'] = False; Render.delete(self.fade['element']); self.fade['interval'].destroy(); self.updateElements();
def destroy(self): self.action.destroy() self.receiver.destroy() for element in self.getAssignedDrawables(): Render.delete(element)
settings = settings | pygame.FULLSCREEN; Global.setScreenSize(infoObject.current_w, infoObject.current_h); Global.screen = pygame.display.set_mode(Global.screenSize, settings); startMenu(); initGame(); startApp(); # --------------------------------------------------- *\ # Main loop # --------------------------------------------------- */ while Global.isApplicationRunning: Render.onUpdate(); Update.onUpdate(); event = pygame.event.poll(); if(event.type == pygame.QUIT): Global.isApplicationRunning = False; pygame.quit(); os._exit(0); # Keyboard events if not (isGameStarting): if(event.type == pygame.KEYDOWN): k=deepcopy(Input.events); for e in k: for key in Input.events[e]['keys']: