コード例 #1
0
ファイル: gameworld.py プロジェクト: MattCCS/PyZ
    def render_GUI(self):
        if self.window_too_small():
            return

        white = colors.get("white")

        layers.add_border(layers.get("main"), color=white)
        layers.get("main").setrange(0,0, "<main>", color=white)

        layers.get("gameworld").setrange(0, 0, "<gameworld>", color=white)

        layers.add_border(layers.get("gameframe"), color=white)
        layers.get("gameframe").setrange(0, 0, "<gameframe>", color=white)

        self.stats.render()
        layers.add_border(layers.get("stats"), color=white)
        layers.get("stats").setrange(0, 0, "<stats>", color=white)

        layers.add_border(layers.get("player"), color=white)
        layers.get("player").setrange(0, 0, "<player>", color=white)
        layers.get("player").setlines(5, 2, BODY, color=white)

        layers.add_border(layers.get("news"), color=white)
        layers.get("news").setrange(0, 0, "<news>", color=white)
        for (y, news) in enumerate(NEWS.latest(3), 1):
            layers.get("news").setrange(1, y, news, color=white)
コード例 #2
0
ファイル: gameworld.py プロジェクト: MattCCS/PyZ
    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))