def tick(self): """Advance the game one tick""" #if there's no active object, use input to update the main game world if self.foregroundObject is None: for key in self.keysJustPressed: if key == game_input.BT_SAVE: self.writeSave() sound.playEffect(sound.SD_SAVE) elif key == game_input.BT_A: self.player.investigate() elif key == game_input.BT_B: self.player.speed = 2 elif key == game_input.BT_START: self.paused = not self.paused self.foregroundObject = pause_menu.PauseMenu( self.screen, self, os.path.join(settings.path, "data", self.menuPath)) elif key == game_input.BT_DEBUG: pass for key in self.keysJustReleased: if key == game_input.BT_B: self.player.speed = 1 for key in self.keysDown: if key == game_input.BT_UP: self.player.walk(sprite.DIR_UP) elif key == game_input.BT_DOWN: self.player.walk(sprite.DIR_DOWN) elif key == game_input.BT_LEFT: self.player.walk(sprite.DIR_LEFT) elif key == game_input.BT_RIGHT: self.player.walk(sprite.DIR_RIGHT) #if there is an active object, feed keydowns to it #tick it and check whether it's finished or not else: for key in self.keysJustPressed: self.foregroundObject.inputButton(key) self.foregroundObject.tick() if not self.foregroundObject.busy: self.foregroundObject = None self.paused = False #if we're not paused, tick the script engine and map if not self.paused: self.scriptEngine.tick() self.player.map.tick() #we've not been told to exit, so not done yet done = False return done
def tick(self): """Advance the game one tick""" # if there's no active object, use input to update the main game world if self.foregroundObject is None: for key in self.keysJustPressed: if key == game_input.BT_SAVE: self.writeSave() sound.playEffect(sound.SD_SAVE) elif key == game_input.BT_A: self.player.investigate() elif key == game_input.BT_B: self.player.speed = 2 elif key == game_input.BT_START: self.paused = not self.paused self.foregroundObject = pause_menu.PauseMenu( self.screen, self, os.path.join(settings.path, "data", self.menuPath) ) elif key == game_input.BT_DEBUG: pass for key in self.keysJustReleased: if key == game_input.BT_B: self.player.speed = 1 for key in self.keysDown: if key == game_input.BT_UP: self.player.walk(sprite.DIR_UP) elif key == game_input.BT_DOWN: self.player.walk(sprite.DIR_DOWN) elif key == game_input.BT_LEFT: self.player.walk(sprite.DIR_LEFT) elif key == game_input.BT_RIGHT: self.player.walk(sprite.DIR_RIGHT) # if there is an active object, feed keydowns to it # tick it and check whether it's finished or not else: for key in self.keysJustPressed: self.foregroundObject.inputButton(key) self.foregroundObject.tick() if not self.foregroundObject.busy: self.foregroundObject = None self.paused = False # if we're not paused, tick the script engine and map if not self.paused: self.scriptEngine.tick() self.player.map.tick() # we've not been told to exit, so not done yet done = False return done
def inputButton(self, button): """ Process a button press button - the button which has been pressed. """ #if it's the confirm button, and we've finished drawing, then we're done if button == game_input.BT_A: if not self.writing: self.busy = False sound.playEffect(sound.SD_SELECT)
def walk(self, direction, force=False, isPlayer=False): """ Walk (or run etc.) to a new position. direction - the direction to move. force - if True, bypass checks for being locked or busy. isPlayer - True when called by the player. """ #check whether we are able to move if (not (self.busy or self.locked) or force) and self.visible: #set our direction as given, and calculate the destination position self.direction = direction if direction == DIR_UP: self.destination = self.position[0], self.position[1]-1 elif direction == DIR_DOWN: self.destination = self.position[0], self.position[1]+1 elif direction == DIR_LEFT: self.destination = self.position[0]-1, self.position[1] elif direction == DIR_RIGHT: self.destination = self.position[0]+1, self.position[1] #if we can move to the movement permission, and the mpa is empty, then start the step #set ourselves as busy to start moving when next ticked, and play the correct animation #notify the map that we are coming to the destination position col = self.map.getCollisionData(self.destination) if (self.canMoveTo(col) and self.map.emptyAt(self.destination)): self.busy = True self.animation = self.animations[direction] self.animation.play(False) self.hasBumped = False if self.status == S_TERRAIN: action = col%8 if action != TERRAIN: self.setStatus(S_WALK) self.map.walkonto(self, self.destination, isPlayer) #if we can't move to the destination, then if we're the player and we haven't bumped yet, play the sound effect else: if isPlayer and not self.hasBumped: sound.playEffect(sound.SD_BUMP) self.hasBumped = True
def inputButton(self, button): """ Process a button press. button - the button which has been pressed. """ #feed the button to the main dialog to process Dialog.inputButton(self, button) #if it's UP or DOWN, change the selected option as required if button == game_input.BT_DOWN: if self.current < len(self.choices)-1: self.current += 1 sound.playEffect(sound.SD_CHOOSE) elif button == game_input.BT_UP: if self.current > 0: self.current -= 1 sound.playEffect(sound.SD_CHOOSE) #if we're exiting, set the LASTRESULT script engine variable to the current selected choice if self.busy == False: self.scriptEngine.variables["LASTRESULT"] = self.choices[self.current]
def tick(self): """Update the screen one tick - ie process input.""" # use input to update the screen for key in self.keysJustPressed: # if it's we've selected the current option, return True to say we're done if key == game_input.BT_A: sound.playEffect(sound.SD_SELECT) return True # if we've moved up or down, make sure it's possible and then update elif key == game_input.BT_UP: if self.current > 0: self.current -= 1 sound.playEffect(sound.SD_CHOOSE) elif key == game_input.BT_DOWN: if self.current < len(self.boxes) - 1: self.current += 1 sound.playEffect(sound.SD_CHOOSE) # we've not done yet return False
def tick(self): """Update the screen one tick - ie process input.""" #use input to update the screen for key in self.keysJustPressed: #if it's we've selected the current option, return True to say we're done if key == game_input.BT_A: sound.playEffect(sound.SD_SELECT) return True #if we've moved up or down, make sure it's possible and then update elif key == game_input.BT_UP: if self.current > 0: self.current -= 1 sound.playEffect(sound.SD_CHOOSE) elif key == game_input.BT_DOWN: if self.current < len(self.boxes) - 1: self.current += 1 sound.playEffect(sound.SD_CHOOSE) #we've not done yet return False