def main() -> None:
    """  """
    # console screen size
    screen_width = 80
    screen_height = 50

    # player location variables: use of int() prevents floats being returned from division

    player_x = int(screen_width / 2)
    player_y = int(screen_height / 2)

    # load image with the tileset to be used (I stored this in a 'data' folder)
    tileset = tcod.tileset.load_tilesheet(
        "data/dejavu10x10_gs_tc.png", 32, 8, tcod.tileset.CHARMAP_TCOD
    )

    # create an event handler
    event_handler = EventHandler()

    # create the console window, set the tileset & title
    with tcod.context.new_terminal(
            screen_width,
            screen_height,
            tileset=tileset,
            title="Yet Another Roguelike Tutorial",
            vsync=True,
    ) as context:

        # create and size a 'console' to draw too &
        # tell numpy to use [x,y] instead of [y,x] by setting 'order' to 'F'
        root_console = tcod.Console(screen_width, screen_height, order="F")

        # the game loop
        while True:
            # place an '@' on screen at the location of x & y
            root_console.print(player_x, player_y, string="@")
            # update the screen so we can actually see the '@'
            context.present(root_console)
            # clear console to prevent 'trailing'
            root_console.clear()
            # event handling: wait for some user input and loop through each 'event'
            for event in tcod.event.wait():
                # pass the event to our 'EventHandler'
                action = event_handler.dispatch(event)
                # if no valid actions exist keep looping
                if action is None:
                    continue
                # handle 'MovementAction'
                if isinstance(action, MovementAction):
                    # move the player
                    player_x += action.dx
                    player_y += action.dy
                # handle 'EscapeAction' (for now quit/could be a menu)
                elif isinstance(action, EscapeAction):
                    raise SystemExit()
示例#2
0
def main() -> None:
    screen_width = 80
    screen_height = 50

    tileset = tcod.tileset.load_tilesheet(
        "dejavu10x10_gs_tc.png", 32, 8, tcod.tileset.CHARMAP_TCOD
    )

    event_handler = EventHandler()

    player = Entity(int(screen_width / 2), int(screen_height/2), "@", (255, 255, 255))
    npc = Entity(int(screen_width / 2 - 5), int(screen_height / 2 - 5), "@", (255, 255, 0))
    entities = {npc, player}

    engine = Engine(entities = entities, event_handler = event_handler, player=player)

    with tcod.context.new_terminal(
        screen_width,
        screen_height,
        tileset=tileset,
        title="Ferule",
        vsync=True,
    ) as context:
        root_console = tcod.Console(screen_width, screen_height, order="F")
        while True:
            engine.render(console=root_console, context=context)

            events = tcod.event.wait()

            engine.handle_events(events)
示例#3
0
文件: main.py 项目: hubice/Roguelike
def main() -> None:

    # 屏幕的高度
    screen_width = 80
    screen_height = 50

    # map
    map_width = 80
    map_height = 45

    # 房间大小
    room_max_size = 10
    room_min_size = 6
    max_rooms = 30

    # 加载字体
    tileset = tcod.tileset.load_tilesheet("dejavu10x10_gs_tc.png", 32, 8,
                                          tcod.tileset.CHARMAP_TCOD)

    # 消息处理器
    event_handler = EventHandler()

    # 生成实体(这个只是显示,没有逻辑)
    player = Entity(int(screen_width / 2), int(screen_height / 2), "@",
                    (255, 255, 255))
    npc = Entity(int(screen_width / 2 - 5), int(screen_height / 2), "@",
                 (255, 255, 0))
    entities = {npc, player}

    # 生成地图
    game_map = generate_dungeon(max_rooms=max_rooms,
                                room_min_size=room_min_size,
                                room_max_size=room_max_size,
                                map_width=map_width,
                                map_height=map_height,
                                player=player)

    # 游戏引擎
    engine = Engine(entities=entities,
                    event_handler=event_handler,
                    game_map=game_map,
                    player=player)

    # 创建一个窗口
    with tcod.context.new_terminal(screen_width,
                                   screen_height,
                                   tileset=tileset,
                                   title="游戏-Roguelike",
                                   vsync=True) as context:

        # 创建控制台
        root_console = tcod.Console(screen_width, screen_height, order="F")

        # 游戏循环
        while True:
            # 消息
            engine.handler_events(events=tcod.event.wait())
            # 渲染
            engine.render(console=root_console, context=context)
示例#4
0
def main() -> None:
    screen_width = 80
    screen_height = 50

    map_width = 80
    map_height = 45

    room_max_size = 10
    room_min_size = 6
    max_rooms = 30

    max_monsters_per_room = 2

    #player_x = int(screen_width / 2)
    #player_y = int(screen_height / 2)

    tileset = tcod.tileset.load_tilesheet("dejavu10x10_gs_tc.png", 32, 8,
                                          tcod.tileset.CHARMAP_TCOD)

    event_handler = EventHandler()

    player = copy.deepcopy(entity_factories.player)

    #engine = Engine(entities, event_handler, player)

    #game_map = GameMap(map_width, map_height)
    #game_map = generate_dungeon(map_width, map_height)
    game_map = generate_dungeon(max_rooms=max_rooms,
                                room_min_size=room_min_size,
                                room_max_size=room_max_size,
                                map_width=map_width,
                                map_height=map_height,
                                max_monsters_per_room=max_monsters_per_room,
                                player=player)

    engine = Engine(event_handler=event_handler,
                    game_map=game_map,
                    player=player)

    with tcod.context.new_terminal(
            screen_width,
            screen_height,
            tileset=tileset,
            title="Dungeon Crawler",
            vsync=True,
    ) as context:
        root_console = tcod.Console(screen_width, screen_height, order="F")
        while True:

            engine.render(root_console, context)

            events = tcod.event.wait()

            engine.handle_events(events)
            """
def main() -> None:
    screen_width = 80
    screen_height = 50

    map_width = 80
    map_height = 45

    room_max_size = 10
    room_min_size = 6
    max_rooms = 30

    max_monsters_per_room = 2

    # tells tcod which font to use
    tileset = tcod.tileset.load_tilesheet(
        "dejavu10x10_gs_tc.png", 32, 8, tcod.tileset.CHARMAP_TCOD
    )

    # event_handler is an instance of our EventHandler class
    event_handler = EventHandler()

    player = copy.deepcopy(entity_factories.player)

    game_map = generate_dungeon(
        max_rooms=max_rooms,
        room_min_size=room_min_size,
        room_max_size=room_max_size,
        map_width=map_width,
        map_height=map_height,
        max_monsters_per_room=max_monsters_per_room,
        player=player
    )

    engine = Engine(event_handler=event_handler, game_map=game_map, player=player)

    # creates the screen
    with tcod.context.new_terminal(
            screen_width,
            screen_height,
            tileset=tileset,
            title="Untitled Roguelike Project",
            vsync=True,
    ) as context:
        # creates our console.
        # order="F" changes numpy to access 2D arrays in [x, y] order.
        root_console = tcod.Console(screen_width, screen_height, order="F")
        # game loop
        while True:
            engine.render(console=root_console, context=context)

            events = tcod.event.wait()

            engine.handle_events(events)
示例#6
0
def main() -> None:
    # Okno gry i zestaw elementow
    screen_width = 80
    screen_height = 50

    tileset = tcod.tileset.load_tilesheet("dejavu10x10_gs_tc.png", 32, 8,
                                          tcod.tileset.CHARMAP_TCOD)
    # Zmienne pozycja rogue
    player_x = int(screen_width / 2)
    player_y = int(screen_height / 2)

    event_handler = EventHandler()
    # nowe okno
    with tcod.context.new_terminal(
            screen_width,
            screen_height,
            tileset=tileset,
            title="Yet Another Roguelike Tutorial",
            vsync=True,
    ) as context:
        # okno x i y F odwraca
        root_console = tcod.Console(screen_width, screen_height, order="F")
        while True:
            root_console.print(x=player_x, y=player_y, string="@")

            context.present(root_console)
            root_console.clear()

            for event in tcod.event.wait():
                action = event_handler.dispatch(event)

                if action is None:
                    continue
                # akcja ruchu
                if isinstance(action, MovementAction):
                    player_x += action.dx
                    player_y += action.dy
                # akcja escape
                elif isinstance(action, EscapeAction):
                    raise SystemExit()
示例#7
0
def main() -> None:
    screen_width = 80
    screen_height = 50

    player_x = int(screen_width / 2)
    player_y = int(screen_height / 2)

    tileset = tcod.tileset.load_tilesheet("dejavu10x10_gs_tc.png", 32, 8,
                                          tcod.tileset.CHARMAP_TCOD)

    event_handler = EventHandler()

    with tcod.context.new_terminal(
            screen_width,
            screen_height,
            tileset=tileset,
            title="Roguelike Practice",
            vsync=True,
    ) as context:
        root_console = tcod.Console(screen_width, screen_height, order="F")
        while True:
            root_console.print(x=player_x, y=player_y, string="@")

            context.present(root_console)

            root_console.clear()

            for event in tcod.event.wait():
                action = event_handler.dispatch(event)

                if action is None:
                    continue

                if isinstance(action, MovementAction):
                    player_x += action.dx
                    player_y += action.dy

                elif isinstance(action, EscapeAction):
                    raise SystemExit()
示例#8
0
def main() -> None:
    screen_width = 80
    screen_height = 50

    map_width = 80
    map_height = 45

    room_max_size = 10
    room_min_size = 6
    max_rooms = 30

    # loading font from png
    tileset = tcod.tileset.load_tilesheet("dejavu10x10_gs_tc.png", 32, 8,
                                          tcod.tileset.CHARMAP_TCOD)

    event_handler = EventHandler()

    player = Entity(int(screen_width / 2), int(screen_height / 2), "@",
                    (255, 255, 255))
    npc = Entity(int(screen_width / 2 - 5), int(screen_height / 2), "@",
                 (255, 255, 0))
    entities = {npc, player}

    game_map = generate_dungeon(max_rooms=max_rooms,
                                room_min_size=room_min_size,
                                room_max_size=room_max_size,
                                map_width=map_width,
                                map_height=map_height,
                                player=player)
    engine = Engine(entities=entities,
                    event_handler=event_handler,
                    game_map=game_map,
                    player=player)

    with tcod.context.new_terminal(
            screen_width,
            screen_height,
            tileset=tileset,
            title="First Roguelike",
            vsync=True,
    ) as context:
        # creating console
        root_console = tcod.Console(
            screen_width, screen_height,
            order="F")  # order = "F" flips (y,x) to (x,y)
        while True:
            engine.render(console=root_console, context=context)

            events = tcod.event.wait()

            engine.handle_events(events)
示例#9
0
文件: zephyr.py 项目: kflasch/zephyr
def main() -> None:
    screen_width = 80
    screen_height = 60
    map_width = 80
    map_height = 45
    room_max_size = 10
    room_min_size = 6
    max_rooms = 30

    tileset = tcod.tileset.load_tilesheet(
        "arial10x10.png",
        32,
        8,
        tcod.tileset.CHARMAP_TCOD,
    )

    event_handler = EventHandler()

    player = Entity(int(screen_width / 2), int(screen_height / 2), '@',
                    tcod.white)
    npc = Entity(int(screen_width / 2 - 5), int(screen_height / 2), '@',
                 tcod.yellow)
    entities = {npc, player}

    game_map = generate_dungeon(max_rooms=max_rooms,
                                room_min_size=room_min_size,
                                room_max_size=room_max_size,
                                map_width=map_width,
                                map_height=map_height,
                                player=player)

    engine = Engine(entities=entities,
                    event_handler=event_handler,
                    game_map=game_map,
                    player=player)

    with tcod.context.new_terminal(screen_width,
                                   screen_height,
                                   tileset=tileset,
                                   title='zephyr',
                                   vsync=True) as context:
        # order='F' changes numpy's 2d array ordering to be x,y instead of y,x
        root_console = tcod.Console(screen_width, screen_height, order='F')
        while True:
            engine.render(console=root_console, context=context)

            events = tcod.event.wait()

            engine.handle_events(events)
示例#10
0
def main() -> None:
    """  """
    # console screen size
    screen_width = 80
    screen_height = 50

    # map size
    map_width = 80
    map_height = 45

    # load image with the tileset to be used (I stored this in a 'data' folder)
    tileset = tcod.tileset.load_tilesheet(
        "data/dejavu10x10_gs_tc.png", 32, 8, tcod.tileset.CHARMAP_TCOD
    )

    # create an event handler
    event_handler = EventHandler()

    # create entities: player & npc
    player = Entity(int(screen_width / 2), int(screen_height / 2), '@', (255, 255, 255))
    npc = Entity(int(screen_width / 2 - 5), int(screen_height / 2), '@', (255, 255, 0))
    entities = {npc, player}

    # create an instance of the GameMap
    game_map = GameMap(map_width, map_height)

    # create game engine for event handling and rendering
    engine = Engine(entities=entities, event_handler=event_handler, game_map=game_map, player=player)

    # create the console window, set the tileset & title
    with tcod.context.new_terminal(
            screen_width,
            screen_height,
            tileset=tileset,
            title="Yet Another Roguelike Tutorial",
            vsync=True,
    ) as context:
        # create and size a 'console' to draw too &
        # tell numpy to use [x,y] instead of [y,x] by setting 'order' to 'F'
        root_console = tcod.Console(screen_width, screen_height, order="F")

        # the game loop
        while True:
            # handle game display
            engine.render(console=root_console, context=context)
            # get game events
            events = tcod.event.wait()
            # handle events and determine actions
            engine.handle_events(events)
示例#11
0
def main():
    screen_width: int = 80
    screen_height: int = 50

    map_width = 80
    map_height = 45

    room_max_size = 10
    room_min_size = 6
    max_rooms = 30

    max_monsters_per_room = 2

    tileset = tcod.tileset.load_tilesheet("dejavu10x10_gs_tc.png", 32, 8,
                                          tcod.tileset.CHARMAP_TCOD)

    event_handler = EventHandler()

    player = copy.deepcopy(entity_factories.player)

    game_map = generate_dungeon(
        max_rooms=max_rooms,
        room_min_size=room_min_size,
        room_max_size=room_max_size,
        map_width=map_width,
        map_height=map_height,
        max_monsters_per_room=max_monsters_per_room,
        player=player,
    )

    engine = Engine(
        event_handler=event_handler,
        game_map=game_map,
        player=player,
    )

    with tcod.context.new_terminal(
            screen_width,
            screen_height,
            tileset=tileset,
            title="Yet Another Roguelike Tutorial",
            vsync=True,
    ) as context:
        root_console = tcod.Console(screen_width, screen_height, order="F")
        while True:
            engine.render(console=root_console, context=context)
            events = tcod.event.wait()
            engine.handle_events(events)
示例#12
0
def main() -> None:
    screen_width = 160
    screen_height = 90

    player = copy.deepcopy(entity_factories.player)

    engine = Engine(player=player)


    map_width = 160
    map_height = 90

    room_max_size = 10
    room_min_size = 6
    max_rooms = 30

    max_monsters_per_room=2

    tileset = tcod.tileset.load_tilesheet("dejavu10x10_gs_tc.png", 32, 8, tcod.tileset.CHARMAP_TCOD)

    event_handler = EventHandler(engine)

    player = copy.deepcopy(entity_factories.player)

    engine.game_map = generate_dungeon(
        max_rooms=max_rooms,
        room_min_size=room_min_size,
        room_max_size=room_max_size,
        map_width=map_width,
        map_height=map_height,
        max_monsters_per_room=max_monsters_per_room,
        engine=engine,
    )
    engine.update_fov()

    with tcod.context.new_terminal(
        screen_width,
        screen_height,
        tileset=tileset,
        title="Nhan's Perilous Dungeon",
        vsync=True
    ) as context:
        root_console = tcod.Console(screen_width, screen_height, order="F")
        while True:
            engine.render(console=root_console, context=context)

            engine.event_handler.handle_events()
示例#13
0
def main() -> None:
    screen_width = 80
    screen_height = 50

    map_width = 80
    map_height = 45

    room_max_size = 10
    room_min_size = 6
    max_rooms = 30

    max_monster_per_room = 2

    tileset = tcod.tileset.load_tilesheet("dejavu10x10_gs_tc.png", 32, 8,
                                          tcod.tileset.CHARMAP_TCOD)

    event_handler = EventHandler()

    player = Entity(int(screen_width / 2), int(screen_height / 2), "@",
                    (255, 255, 255))

    game_map = generate_dungeon(max_rooms=max_rooms,
                                room_min_size=room_min_size,
                                room_max_size=room_max_size,
                                map_width=map_width,
                                map_height=map_height,
                                max_monsters_per_room=max_monster_per_room,
                                player=player)

    engine = Engine(event_handler=event_handler,
                    game_map=game_map,
                    player=player)

    with tcod.context.new_terminal(
            screen_width,
            screen_height,
            tileset=tileset,
            title="roguelike2",
            vsync=True,
    ) as context:
        root_console = tcod.Console(screen_width, screen_height, order="F")
        while True:
            engine.render(console=root_console, context=context)

            events = tcod.event.wait()

            engine.handle_events(events)
示例#14
0
def main() -> None:
    screen_width = 160
    screen_height = 90
    map_width = screen_width
    map_height = screen_height - 5

    room_max_size = 15
    room_min_size = 6
    max_rooms = 30

    #Tileset found in the data folder. Standard Ascii pattern letters, could change in future
    tileset = tcod.tileset.load_tilesheet(
        "data\dejavu10x10_gs_tc.png", 32, 8, tcod.tileset.CHARMAP_TCOD
    )
    event_handler = EventHandler()
    player = Entity(int(screen_width / 2), int(screen_height / 2), "@", (255,255,255))
    npc = Entity(int(screen_width / 2), int(screen_height / 2), "@", (255,0,0))
    entities = {npc, player}

    game_map = generate_dungeon(
        max_rooms=max_rooms,
        room_min_size=room_min_size,
        room_max_size=room_max_size,
        map_width=map_width,
        map_height=map_height,
        player=player
    )

    engine = Engine(entities=entities, event_handler=event_handler, game_map=game_map, player=player)
    #Actually creates the window
    with tcod.context.new_terminal(
        screen_width,
        screen_height,
        tileset=tileset,
        title="Yet Another Roguelike Tutorial",
        vsync=True,
    ) as context:
        root_console = tcod.Console(screen_width, screen_height, order="F")
        while True:
            engine.render(console=root_console, context=context)

            events = tcod.event.wait()

            engine.handle_events(events)
示例#15
0
def main() -> None:
    # this tells tcod what font to use
    tileset = tcod.tileset.load_tilesheet("dejavu10x10_gs_tc.png", 32, 8,
                                          tcod.tileset.CHARMAP_TCOD)

    # event handler initialization
    event_handler = EventHandler()

    # initializing player as an entity
    player = Entity(int(SCREEN_WIDTH / 2), int(SCREEN_HEIGHT / 2), "A",
                    (255, 255, 255))
    npc = Entity(int(SCREEN_WIDTH / 2 - 5), int(SCREEN_HEIGHT / 2), "@",
                 (255, 255, 0))
    entities = {npc, player}

    game_map = generate_dungeon(
        max_rooms=MAX_ROOMS,
        room_min_size=ROOM_MIN_SIZE,
        room_max_size=ROOM_MAX_SIZE,
        map_width=MAP_WIDTH,
        map_height=MAP_HEIGHT,
        player=player,
    )

    engine = Engine(entities=entities,
                    event_handler=event_handler,
                    game_map=game_map,
                    player=player)
    # this creates the screen, its title, the tileset
    with tcod.context.new_terminal(SCREEN_WIDTH,
                                   SCREEN_HEIGHT,
                                   tileset=tileset,
                                   title="bug-free-eureka",
                                   vsync=True) as context:
        # this creates the "console" (what we will be drawing to)
        root_console = tcod.Console(SCREEN_WIDTH, SCREEN_HEIGHT, order="F")

        # game loop
        while True:
            engine.render(console=root_console, context=context)
            events = tcod.event.wait()
            engine.handle_events(events)
示例#16
0
def main():
    screen_width = 80
    screen_height = 50

    map_width = 80
    map_height = 45

    tileset = tcod.tileset.load_tilesheet("dejavu10x10_gs_tc.png", 32, 8,
                                          tcod.tileset.CHARMAP_TCOD)

    event_handler = EventHandler()

    player = Entity(int(screen_width / 2), int(screen_height / 2), "@",
                    (255, 255, 255))
    npc = Entity(int(screen_width / 2 - 5), int(screen_height / 2), "@",
                 (255, 255, 0))
    entities = {npc, player}

    game_map = GameMap(map_width, map_height)

    engine = Engine(entities=entities,
                    event_handler=event_handler,
                    game_map=game_map,
                    player=player)

    with tcod.context.new_terminal(
            screen_width,
            screen_height,
            tileset=tileset,
            title="Yet Another Roguelike Tutorial",
            vsync=True,
    ) as context:
        root_console = tcod.Console(screen_width, screen_height, order="F")
        while True:

            engine.render(console=root_console, context=context)

            events = tcod.event.wait()

            engine.handle_events(events)

            context.present(root_console)
示例#17
0
def main() -> None:
    screen_width = 100
    screen_height = 80

    mapwidth = 100
    mapheight = 80

    #define tileset
    #tileset = tcod.tileset.load_tilesheet(
    #    "terminal.png", 16, 16, tcod.tileset.CHARMAP_TCOD
    #)

    event_handler = EventHandler()

    player = Entity(35, 35, "@", (0, 255, 213))
    creature = Entity(35, 15, "S", (255, 0, 0))
    entities = {creature, player}
    gamemap = Map(mapwidth, mapheight)

    engine = Engine(entities=entities,
                    event_handler=event_handler,
                    gamemap=gamemap,
                    player=player)

    #init terminal window
    with tcod.context.new_terminal(
            150,
            120,
            #tileset = tileset,
            title="Hartbrook",
            vsync=True) as context:
        root_console = tcod.Console(screen_width, screen_height, order="F")
        while True:

            engine.render(console=root_console, context=context)

            events = tcod.event.wait()

            engine.handle_events(events)
示例#18
0
def main() -> None:
    screen_width = 80
    screen_height = 50

    map_width = 80
    map_height = 45

    tileset = tcod.tileset.load_tilesheet(
        path.realpath('assets/dejavu10x10_gs_tc.png'), 32, 8,
        tcod.tileset.CHARMAP_TCOD)

    event_handler = EventHandler()

    player = Entity(int(screen_width / 2), int(screen_height / 2), "@",
                    (255, 255, 255))
    npc = Entity(int(screen_width / 2 - 5), int(screen_height / 2), "@",
                 (255, 255, 0))
    entities = {npc, player}

    game_map = GameMap(map_width, map_height)

    engine = Engine(entities=entities,
                    event_handler=event_handler,
                    game_map=game_map,
                    player=player)

    with tcod.context.new_terminal(screen_width,
                                   screen_height,
                                   tileset=tileset,
                                   title='Roguelike-py',
                                   vsync=True) as context:
        root_console = tcod.Console(screen_width, screen_height, order='F')
        while True:
            engine.render(console=root_console, context=context)

            events = tcod.event.wait()

            engine.handler_events(events)
示例#19
0
def main() -> None:
    screen_width = 120
    screen_height = 70

    map_width = screen_width
    map_height = screen_height

    room_max_size = 10
    room_min_size = 6
    max_rooms = 100

    tileset = tcod.tileset.load_tilesheet("dejavu10x10_gs_tc.png", 32, 8,
                                          tcod.tileset.CHARMAP_TCOD)
    #tileset = tcod.tileset.load_tilesheet("terminal32x32.png", 16, 16, tcod.tileset.CHARMAP_CP437)

    event_handler = EventHandler()

    player = Entity(int(screen_width / 2), int(screen_height / 2), "@",
                    (255, 255, 0))
    npc = Entity(int(screen_width / 2 - 12), int(screen_height / 2 - 5), "@",
                 (255, 255, 255))
    entities = {npc, player}

    map_type = 2

    if map_type == 1:
        game_map = generate_dungeon(max_rooms=max_rooms,
                                    room_min_size=room_min_size,
                                    room_max_size=room_max_size,
                                    map_width=map_width,
                                    map_height=map_height,
                                    player=player,
                                    npc=npc)

    else:
        game_map = initialize_cave(map_width=map_width,
                                   map_height=map_height,
                                   player=player,
                                   npc=npc)

        generate_cave(game_map)

    engine = Engine(entities=entities,
                    event_handler=event_handler,
                    game_map=game_map,
                    player=player)

    with tcod.context.new_terminal(
            screen_width,
            screen_height,
            tileset=tileset,
            title="New Roguelike 2020 Version 2",
            vsync=True,
    ) as context:
        root_console = tcod.Console(screen_width, screen_height, order="F")
        while True:

            engine.render(console=root_console, context=context)

            events = tcod.event.wait()

            engine.handle_events(events)
示例#20
0
 def __init__(self, player: Entity):
     self.event_handler: EventHandler = EventHandler(self)
     self.player = player
示例#21
0
def main() -> None:
    screen_width = 80
    screen_height = 50

    bar_width = 20
    panel_height = 7
    panel_y = screen_height - panel_height

    message_x = bar_width + 2
    message_width = screen_width - bar_width - 2
    message_height = panel_height - 1

    map_width = 80
    map_height = 43

    room_max_size = 10
    room_min_size = 6
    max_rooms = 30

    fov_algorithm = 0
    fov_light_walls = True
    fov_radius = 10

    max_monsters_per_room = 3


    colors = {
        'dark_wall': tcod.Color(0,0,100),
        'dark_ground': tcod.Color(50,50,100),
        'light_wall': tcod.Color(130,110,50),
        'light_ground': tcod.Color(200,180,50)
    }

    fighter_component = Fighter(hp=30, defence=2, power=5)
    player = Entity(0, 0, '@', tcod.white, 'Player', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component)
    entities = [player]

    tileset = tcod.tileset.load_tilesheet(
        "dejavu10x10_gs_tc.png", 32, 8, tcod.tileset.CHARMAP_TCOD
    )

    event_handler = EventHandler()

    game_map = GameMap(map_width, map_height)
    game_map.make_map(max_rooms, room_min_size, room_max_size, map_width, map_height, player, entities, max_monsters_per_room)

    fov_recompute = True

    fov_map = initialise_fov(game_map)

    game_state = GameStates.PLAYERS_TURN

    message_log = MessageLog(message_x, message_width, message_height)

    
    with tcod.context.new_terminal(
        screen_width,
        screen_height,
        tileset=tileset,
        title="Yet Another Roguelike Tutorial",
        vsync=True,
    ) as context:
        root_console = tcod.Console(screen_width, screen_height, order="F")
        play_area = tcod.Console(map_width, map_height, order="F")
        panel = tcod.Console(screen_width, panel_height, order="F")
    
        while True:
            
            clear_all(root_console, entities)
            root_console.clear()

            if fov_recompute:
                recompute_fov(fov_map, player.x, player.y, fov_radius, fov_light_walls, fov_algorithm)
            
            render_all(root_console, play_area, panel, entities, player, game_map, fov_map, fov_recompute, message_log, screen_width, screen_height, map_width, map_height, bar_width, panel_height, panel_y, colors)

            fov_recompute = False                      

            context.present(root_console)

            # ======= PLAYER TURN ========================== # 

            player_turn_results = []

            for event in tcod.event.wait():
                
                #send events to EventHandler.dispatch method - check libtcod for details ...
                action = event_handler.dispatch(event)

                if action is None:
                    continue
                
                if isinstance(action, MovementAction):
                    if game_state == GameStates.PLAYERS_TURN:
                        if not game_map.is_blocked(player.x + action.dx, player.y + action.dy):
                            target = get_blocking_entities_at_location(entities, player.x + action.dx, player.y + action.dy)

                            if target:
                                attack_results = player.fighter.attack(target)
                                player_turn_results.extend(attack_results)
                            else:
                                player.move(action.dx,action.dy)
                                fov_recompute = True
                        game_state = GameStates.ENEMY_TURN

                elif isinstance(action, EscapeAction):
                    raise SystemExit()

            for player_turn_result in player_turn_results:
                message = player_turn_result.get('message')
                dead_entity = player_turn_result.get('dead')

                if message:
                    message_log.add_message(message)

                if dead_entity:
                    if dead_entity == player:
                        message, game_state = kill_player(dead_entity)
                    else:
                        message = kill_monster(dead_entity)

                    message_log.add_message(message)

            # === END PLAYER TURN ========================== # 

            # ======== ENEMY TURN ========================== # 

            if game_state == GameStates.ENEMY_TURN:
                for entity in entities:
                    if entity.ai:
                        enemy_turn_results = entity.ai.take_turn(player, fov_map, game_map, entities)

                        for enemy_turn_result in enemy_turn_results:
                            message = enemy_turn_result.get('message')
                            dead_entity = enemy_turn_result.get('dead')

                            if message:
                                message_log.add_message(message)

                            if dead_entity:
                                if dead_entity == player:
                                    message, game_state = kill_player(dead_entity)
                                else:
                                    message = kill_monster(dead_entity)

                                message_log.add_message(message)

                                if game_state == GameStates.PLAYER_DEAD:
                                    break
                            
                        if game_state == GameStates.PLAYER_DEAD:
                            break
                else:    
                    game_state = GameStates.PLAYERS_TURN
示例#22
0
def main() -> None:
    #defining the variables of the screen
    screen_width = 80
    screen_height = 50

    player_x = int(screen_width / 2)
    player_y = int(screen_height / 2)

    tileset = tcod.tileset.load_tilesheet(
        #here we tell tcod what font to use
        "dejavu10x10_gs_tc.png",
        32,
        8,
        tcod.tileset.CHARMAP_TCOD)

    #event_handler is an instance of an EventHandler class.
    #we use it to receive events and process them
    event_handler = EventHandler()

    #this part creates the screen
    with tcod.context.new_terminal(
            screen_width,
            screen_width,
            tileset=tileset,
            title="Yet Another Roguelike Tutorial",
            vsync=True,
    ) as context:

        #this is the console that we are drawing to. We set the width & height
        root_console = tcod.Console(screen_width, screen_height, order="F")

        #this is our game loop
        while True:
            #this line tells the program to put the '@' on the screen in the proper place
            root_console.print(x=player_x, y=player_y, string="@")

            #this line puts the info onto the screen
            #context.present updates the screen with what we've given it
            context.present(root_console)

            root_console.clear()

            #capture user input
            for event in tcod.event.wait():

                #We send event to event_handler's "dispatch" method which sends it to the proper place
                #The Action returned will be assigned to action
                action = event_handler.dispatch(event)

                #if we receive no action we skip the rest of the loop
                if action is None:
                    continue

                #if action is an instance of the class MovementAction we move our '@' symbol
                #We grab the dx and dy values we gave earlier
                #Add dx and dy to player_x and player_y
                #Console is using player_x and player_y so this causes the symbol to move
                if isinstance(action, MovementAction):
                    player_x += action.dx
                    player_y += action.dy

                #how to exit the program if Esc key is pressed
                elif isinstance(action, EscapeAction):
                    raise SystemExit()