def update_viewport(self, sound=True): flag = self.window_too_small() self._truex, self._truey = true_terminal_size() # ^ reserved curses.resize_term(self._truey, self._truex) self.resize_layers() if sound: audio.play("weapons/trigger.aif", volume=0.2) if flag != self.window_too_small(): self.render_frame()
def toggle_mode(self): audio.play("weapons/trigger.aif", volume=0.2) self.mode = (self.mode + 1) % len(self.modes) return self.modes[self.mode]
def handle_interaction(self, key): #################################### # updating (oldx, oldy) = self.player.position() (x,y) = self.player.position() if key in ARROW_KEYS: if key == curses.KEY_UP: y = min(y+1, self.y-1) elif key == curses.KEY_DOWN: y = max(y-1, 0) elif key == curses.KEY_LEFT: x = max(x-1, 0) elif key == curses.KEY_RIGHT: x = min(x+1, self.x-1) if (x,y) == self.player.position(): pass # edge of map NEWS.add("You bump into the blocky white abyss.") # TODO: should be edge of AVAILABLE map elif GRID.nodes[(x,y)].is_passable(): audio.play_movement(self.player_stand_state, self.player_sneakwalksprint, GRID.nodes[(x,y)].s_move) # self.player.set_position( (x,y) ) self.player.set_parent(GRID.nodes[(x,y)]) NEWS.add("") else: # it's an obstacle! AKA gameobject if not self.is_visible((x,y)): NEWS.add("You bump into something.") # TODO: material hints! time.sleep(0.2) # TODO: CANNOT INTERACT IF CAN'T SEE ?????? elif self.player.prefs.auto_attack and self.player.weapon: obj = None objs = GRID.nodes[(x,y)].objects if len(objs) == 1: obj = objs[0] else: damageable_objs = [obj for obj in objs if obj.damageable] if len(damageable_objs) == 1: obj = damageable_objs[0] # only auto-attack damageable, impassible objects if obj and obj.damageable and obj.impassible: NEWS.add("You chop the {}!".format(obj.name)) self.player.weapon.attack(obj, self, GRID, layers.get("gameworld")) else: NEWS.add("You bump into the {}.".format(GRID.nodes[(x,y)].name)) elif key in list(map(ord, 'sS')): # toggle sneak/walk/sprint self.player_sneakwalksprint = (self.player_sneakwalksprint + 1) % 3 NEWS.add("You begin {}.".format(SPEED_DICT[self.player_sneakwalksprint])) audio.play('weapons/trigger.aif', volume=0.2) elif key in list(map(ord, 'zZ')): # lower if self.player_stand_state > 0: self.player_stand_state -= 1 if self.player_stand_state == 0: NEWS.add("You go prone.") audio.play('movement/changing/prone.aif') else: NEWS.add("You crouch.") audio.play('movement/changing/nonprone.aif') elif key in list(map(ord, 'xX')): # raise if self.player_stand_state < 2: self.player_stand_state += 1 if self.player_stand_state == 1: NEWS.add("You crouch.") else: NEWS.add("You stand up.") audio.play('movement/changing/nonprone.aif') elif key == ord('l'): if not self.is_visible((x,y)): NEWS.add("It's too dark to see!") else: NEWS.add("You see: {}".format(', '.join(obj.name for obj in GRID.nodes[self.player.position()].objects if obj is not self.player))) elif key == ord('p'): items = [obj for obj in GRID.nodes[(x,y)].objects if isinstance(obj, objects.Item)] n = len(items) if n == 0: NEWS.add("There's nothing to pick up!") elif n == 1: if not self.player.container: NEWS.add("You don't have a container!") else: item = items[0] res = self.player.container.store(item) if res: NEWS.add("Added {}[{}] to your container ({} left).".format(item.name, item.size, self.player.container.remaining)) else: NEWS.add("Not enough room for {}[{}] -- {} left!".format(item.name, item.size, self.player.container.remaining)) else: NEWS.add("[!] Not implemented yet!") elif key == ord('i'): if self.player.container: NEWS.add("You are holding: {}".format(repr([item.name for item in self.player.container.items]))) else: NEWS.add("You don't have a container to check!") elif key == ord('d'): if self.player.container: items = self.player.container.items if len(items) == 0: NEWS.add("No items to drop.") elif len(items) == 1: item = list(items)[0] self.player.container.remove(item) item.set_parent(GRID.nodes[(x,y)]) NEWS.add("Dropped {}.".format(item.name)) else: NEWS.add("[!] Not implemented!") else: NEWS.add("You don't have an inventory!") # TODO: this is incorrect -- e.g. weapons + clothes. elif key == 27: # ESC quit_window.QuitWindow(self.controlmanager) # IMPLICITLY ADDS if hasattr(self.player, 'flashlight'): _layer = layers.get("gameworld") if key == ord('f'): # toggle flashlight on = self.player.flashlight.toggle() NEWS.add("You switch your flashlight {}.".format("on" if on else "off")) time.sleep(0.2) elif key == ord('m'): mode = self.player.flashlight.toggle_mode() NEWS.add("You switch your flashlight to '{}' mode.".format(mode)) elif key == ord('q'): self.player.flashlight.swivel(12, self, GRID, _layer) elif key == ord('Q'): self.player.flashlight.swivel(60, self, GRID, _layer) elif key == ord('e'): self.player.flashlight.swivel(-12, self, GRID, _layer) elif key == ord('E'): self.player.flashlight.swivel(-60, self, GRID, _layer) self.player.flashlight.update_direction(key_to_coord(key))
def toggle(self): audio.play("items/flashlight_toggle.m4a", volume=3.0) self.on = not self.on return self.on