コード例 #1
0
ファイル: gamestates.py プロジェクト: raphigaziano/barbar3
    def __init__(self):
        from barbarian.dungeon import Dungeon
        from barbarian.objects.entity import Player

        self.dungeon = Dungeon()

        # Dummy game objects
        # for _ in range(10):
        #     x, y = rng.randrange(0, 80), rng.randrange(0, 40)
        #     while self.dungeon.current_level.is_blocked(x, y):
        #         x, y = rng.randrange(0, 80), rng.randrange(0, 40)
        #     e = Actor(x=x, y=y, char=rng.choice(('#', '!', 'o')), blocks=False)
        #     self.dungeon.current_level.objects.append(e)

        px, py = rng.randrange(0, 80), rng.randrange(0, 40)
        while self.dungeon.current_level.is_blocked(px, py):
            px, py = rng.randrange(0, 80), rng.randrange(0, 40)
        self.player = Player(x=px, y=py, char='@')
        self.dungeon.current_level.compute_fov(self.player.x, self.player.y)

        super(DungeonState, self).__init__()
コード例 #2
0
ファイル: gamestates.py プロジェクト: raphigaziano/barbar3
class DungeonState(GameState):

    """ Dummy Gameplay State """

    def __init__(self):
        from barbarian.dungeon import Dungeon
        from barbarian.objects.entity import Player

        self.dungeon = Dungeon()

        # Dummy game objects
        # for _ in range(10):
        #     x, y = rng.randrange(0, 80), rng.randrange(0, 40)
        #     while self.dungeon.current_level.is_blocked(x, y):
        #         x, y = rng.randrange(0, 80), rng.randrange(0, 40)
        #     e = Actor(x=x, y=y, char=rng.choice(('#', '!', 'o')), blocks=False)
        #     self.dungeon.current_level.objects.append(e)

        px, py = rng.randrange(0, 80), rng.randrange(0, 40)
        while self.dungeon.current_level.is_blocked(px, py):
            px, py = rng.randrange(0, 80), rng.randrange(0, 40)
        self.player = Player(x=px, y=py, char='@')
        self.dungeon.current_level.compute_fov(self.player.x, self.player.y)

        super(DungeonState, self).__init__()

    def process_input(self):

        key = input.collect()

        gui.manager.process_input(key)

        if key.vk in (tcod.KEY_UP, tcod.KEY_KP8):
            self.player.move(0, -1, self.dungeon.current_level)
        elif key.vk in (tcod.KEY_DOWN, tcod.KEY_KP2):
            self.player.move(0, 1, self.dungeon.current_level)
        elif key.vk in (tcod.KEY_LEFT, tcod.KEY_KP4):
            self.player.move(-1, 0, self.dungeon.current_level)
        elif key.vk in (tcod.KEY_RIGHT, tcod.KEY_KP6):
            self.player.move(1, 0, self.dungeon.current_level)
        elif key.vk in (tcod.KEY_KP9, ):
            self.player.move(1, -1, self.dungeon.current_level)
        elif key.vk in (tcod.KEY_KP3, ):
            self.player.move(1, 1, self.dungeon.current_level)
        elif key.vk in (tcod.KEY_KP1, ):
            self.player.move(-1, 1, self.dungeon.current_level)
        elif key.vk in (tcod.KEY_KP7, ):
            self.player.move(-1, -1, self.dungeon.current_level)
        elif key.c == ord('m'):
            gui.manager.msg(
                rng.choice(('foo', 'bar', 'baz', 'moop')),
                rng.choice(('red', 'white', 'green', 'gray'))
            )
        elif key.c == ord('d'):
            gui.manager.show_widget('debug_console')
        elif key.vk == tcod.KEY_ESCAPE:
            self._replace_with(ShutDownState())

    def update(self):
        self.process_input()

    def render(self):
        renderer.clear()      # TODO: Clear only whats needed...
        renderer.dummy_draw_level(self.dungeon.current_level)
        renderer.dummy_draw_obj(self.player)
        gui.manager.render()