Esempio n. 1
0
def render_main(console: tcod.console.Console, visible_callbacks: Iterable[Layer] = ()) -> None:
    """Rendeer the main view.  With the world tiles, any objects, and the UI."""
    # Render map view.
    console_shape = (console.width - UI_SIZE[0], console.height - UI_SIZE[1])
    screen_view, world_view = g.world.map.camera.get_views(g.world.map.tiles.shape, console_shape)
    console.tiles_rgb[: console_shape[0], : console_shape[1]] = SHROUD
    console.tiles_rgb[screen_view] = render_map(
        g.world.map, world_view, fullbright=g.debug_fullbright, visible_callbacks=visible_callbacks
    )

    render_slots(console)

    STATUS_WIDTH = 20
    console.tiles_rgb[: -UI_SIZE[0], -UI_SIZE[1]] = 0x2592, BORDER_COLOR, BLACK  # Bar along the lower end of the map.
    console.tiles_rgb[-UI_SIZE[0] - STATUS_WIDTH - 1, -UI_SIZE[1] :] = (0x2592, BORDER_COLOR, BLACK)  # log/status bar.

    log_console = tcod.Console(console.width - UI_SIZE[0] - STATUS_WIDTH - 1, UI_SIZE[1] - 1)
    render_log(log_console)
    log_console.blit(console, 0, console.height - UI_SIZE[1] + 1)

    status_console = tcod.Console(STATUS_WIDTH, UI_SIZE[1] - 1)
    status_console.print(0, 0, f"Status - {g.world.player.x},{g.world.player.y}")
    status_console.print(0, 1, f"HP {g.world.player.hp}")
    status_console.print(0, status_console.height - 1, f"Dungeon level {g.world.map.level}")
    status_console.blit(console, console.width - UI_SIZE[0] - STATUS_WIDTH, console.height - UI_SIZE[1] + 1)
Esempio n. 2
0
def main() -> None:
    """Example program for tcod.event"""

    event_log: List[str] = []
    motion_desc = ""

    with tcod.context.new_window(WIDTH, HEIGHT,
                                 sdl_window_flags=FLAGS) as context:
        console = tcod.Console(*context.recommended_console_size())
        while True:
            # Display all event items.
            console.clear()
            console.print(0, console.height - 1, motion_desc)
            for i, item in enumerate(event_log[::-1]):
                y = console.height - 3 - i
                if y < 0:
                    break
                console.print(0, y, item)
            context.present(console, integer_scaling=True)

            # Handle events.
            for event in tcod.event.wait():
                context.convert_event(event)  # Set tile coordinates for event.
                print(repr(event))
                if event.type == "QUIT":
                    raise SystemExit()
                if event.type == "WINDOWRESIZED":
                    console = tcod.Console(*context.recommended_console_size())
                if event.type == "MOUSEMOTION":
                    motion_desc = str(event)
                else:
                    event_log.append(str(event))
Esempio n. 3
0
def main() -> None:
    screen_width = 64
    screen_height = 35

    tileset = tcod.tileset.load_tilesheet(
        get_app_path() + "/ceefax_teletext_6x10.png", 16, 16,
        tcod.tileset.CHARMAP_CP437)

    with tcod.context.new_terminal(screen_width * 2,
                                   screen_height * 2,
                                   tileset=tileset,
                                   title="Teletext",
                                   vsync=True,
                                   sdl_window_flags=tcod.context.
                                   SDL_WINDOW_BORDERLESS) as root_context:

        root_console = tcod.Console(screen_width, screen_height, order="F")
        engine = Engine()

        cycle = 0
        while True:
            root_console.clear()

            engine.event_handler.on_render(root_console=root_console)

            root_context.present(root_console)

            engine.handle_events(root_context)

            cycle += 1
            if cycle % 2 == 0:
                engine.update()
    def on_render(self, console: tcod.Console) -> None:
        """Renders the history viewer"""
        super().on_render(console)  # Draw the main state as the background.

        log_console = tcod.Console(console.width - 6, console.height - 6)

        # Draw a frame with a custom banner title.
        log_console.draw_frame(0, 0, log_console.width, log_console.height)
        log_console.print_box(0,
                              0,
                              log_console.width,
                              1,
                              "┤Message history├",
                              alignment=tcod.CENTER)

        # Render the message log using the cursor parameter.
        self.engine.message_log.render_messages(
            log_console,
            1,
            1,
            log_console.width - 2,
            log_console.height - 2,
            self.engine.message_log.messages[:self.cursor + 1],
        )
        log_console.blit(console, 3, 3)
def main() -> object:
    screen_width = 80
    screen_height = 50

    map_width = 80
    map_height = 43

    room_max_size = 10
    room_min_size = 6
    max_rooms = 30

    max_monsters_per_room = 2
    max_items_per_room = 2

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

    player = copy.deepcopy(entity_factories.player)

    engine = Engine(player=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,
        max_items_per_room=max_items_per_room,
        engine=engine
    )

    engine.update_fov()

    engine.message_log.add_message(
        "Hello and welcome, adventurer, to yet another dungeon!", color.welcome_text
    )

    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:
            root_console.clear()
            engine.event_handler.on_render(console=root_console)
            context.present(root_console)

            try:
                for event in tcod.event.wait():
                    context.convert_event(event)
                    engine.event_handler.handle_events(event)
            except Exception:  # Handle exceptions in game.
                traceback.print_exc()  # Print error to stderr
                # Then print the error to the message log.
                engine.message_log.add_message(traceback.format_exc(), color.error)
    def on_render(self, console: tcod.Console) -> None:
        super().on_render(console)  # Draw the main state as the background.

        knobs_console = tcod.Console(console.width - 6, console.height - 6)

        # Draw a frame with a custom banner title.
        knobs_console.draw_frame(0, 0, knobs_console.width,
                                 knobs_console.height)
        knobs_console.print_box(0,
                                0,
                                knobs_console.width,
                                1,
                                "┤Knobs├",
                                alignment=tcod.CENTER)

        for index, knob in enumerate(self.knobs):
            knob_console = KnobConsole(knob, index == self.cursor)
            knob_console.draw()
            knob_console.blit(knobs_console, 3 + knob_console.width * index, 3)

        # # Render the message log using the cursor parameter.
        # self.engine.message_log.render_messages(
        #     log_console,
        #     1,
        #     1,
        #     knobs_console.width - 2,
        #     knobs_console.height - 2,
        #     self.engine.message_log.messages[: self.cursor + 1],
        # )

        knobs_console.blit(console, self.origin[0], self.origin[1])
Esempio n. 7
0
def main():
    TILESET = tcod.tileset.load_tilesheet(path=TILESET_PATH,
                                          columns=TILESET_COL,
                                          rows=TILESET_ROW,
                                          charmap=tcod.tileset.CHARMAP_CP437)

    handler = temp_startup()

    with tcod.context.new_terminal(
            CONSOLE_WIDTH,
            CONSOLE_HEIGHT,
            tileset=TILESET,
            title='TEMP FUNNY NAME HERE',
            # sdl_window_flags=tcod.context.SDL_WINDOW_MAXIMIZED,
            vsync=True,
    ) as context:
        console = tcod.Console(CONSOLE_WIDTH, CONSOLE_HEIGHT, order='F')

        while True:
            console.clear()
            handler.on_render(console=console)
            context.present(console)
            for event in tcod.event.wait():
                context.convert_event(event)
                handler = handler.handle_events(event)
Esempio n. 8
0
    def __init__(self, screen_title, screen_width, screen_height, font):
        """Sets key variables."""

        # Screen appearance
        self.screen_title = screen_title
        self.screen_width = screen_width
        self.screen_height = screen_height
        self.font = font
        self.tileset = tcod.tileset.load_tilesheet("./assets/arial12x12.png",
                                                   32, 8,
                                                   tcod.tileset.CHARMAP_TCOD)

        # Drawing console
        # Order=F flips x and y, for easier drawing
        self.console = tcod.Console(self.screen_width,
                                    self.screen_height,
                                    order="F")

        # Starting state
        self.state = MainMenu(self)

        # Mouse location
        self.m_loc = (0, 0)

        # Message storage
        self.message_log = MessageLog()
Esempio n. 9
0
def main() -> None:

    player_x = int(SCREEN_WIDTH / 2)
    player_y = int(SCREEN_HEIGHT / 2)

    event_handler = EventHandler()

    with tcod.context.new_terminal(
        SCREEN_WIDTH,
        SCREEN_HEIGHT,
        tileset=TILE_SET,
        title="Yet Another Roguelike Tutorial",
        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()
Esempio n. 10
0
File: main.py Progetto: voynix/7drl
def main() -> None:
    tileset = tcod.tileset.load_tilesheet("dejavu10x10_gs_tc.png", 32, 8,
                                          tcod.tileset.CHARMAP_TCOD)

    handler: input_handlers.BaseEventHandler = setup_game.MainMenu()

    with tcod.context.new(
            columns=SCREEN_WIDTH,
            rows=SCREEN_HEIGHT,
            tileset=tileset,
            title=constants.TITLE,
            vsync=True,
    ) as context:
        root_console = tcod.Console(SCREEN_WIDTH, SCREEN_HEIGHT, order="F")
        try:
            while True:
                root_console.clear()
                handler.on_render(console=root_console)
                context.present(root_console)

                try:
                    for event in tcod.event.wait():
                        context.convert_event(event)
                        handler = handler.handle_events(event)
                except Exception:
                    traceback.print_exc()  # print stacktrace to stderr
                    if isinstance(handler, input_handlers.EventHandler):
                        handler.engine.message_log.add_message(
                            traceback.format_exc(), color.ERROR)
        except exceptions.QuitWithoutSaving:
            raise
        except SystemExit:  # save and quit
            save_game(handler, constants.SAVE_FILE)
        except BaseException:  # save on unexpected exceptions
            save_game(handler, constants.SAVE_FILE)
Esempio n. 11
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)
Esempio n. 12
0
def main() -> None:
    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 = generate_dungeon(map_width, map_height)
    engine = Engine(entities, event_handler, game_map, player)

    with tcod.context.new_terminal(
            screen_width,
            screen_height,
            tileset=tileset,
            title="Rouge",
            vsync=True,
    ) as context:
        root_console = tcod.Console(screen_width, screen_height, order="F")
        while True:
            engine.render(root_console, context)
            engine.handle_events(tcod.event.wait())
Esempio n. 13
0
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)
Esempio n. 14
0
def main() -> None:
    screen_width = 80
    screen_height = 50

    map_width = screen_width
    map_height = screen_height - 7

    room_max_size = 10
    room_min_size = 6
    max_rooms = 100

    max_monsters_per_room = 2
    max_monsters_per_cave = 30

    #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)

    player = copy.deepcopy(entity_factories.player)
    engine = Engine(player=player)

    if map_type == 1:
        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()

    elif map_type == 2:
        engine.game_map = generate_cave_map(
            map_width=map_width,
            map_height=map_height,
            max_monsters_per_cave=max_monsters_per_cave,
            engine=engine,
        )
        engine.update_fov()

    engine.message_log.add_message("Welcome adventurer, to a new dungeon!",
                                   color.welcome_text)

    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:
            root_console.clear()
            engine.event_handler.on_render(console=root_console)
            context.present(root_console)

            engine.event_handler.handle_events(context)
Esempio n. 15
0
def init_console():
    """
    화면 출력
    """
    context = tcod.context.new_window(WIDTH,
                                      HEIGHT,
                                      renderer=tcod.context.RENDERER_OPENGL2,
                                      tileset=TILESET_TTF,
                                      sdl_window_flags=FLAGS,
                                      title="MARY")

    console = tcod.Console(MAP_WIDTH, MAP_HEIGHT)
    animation = tcod.Console(MAP_WIDTH, MAP_HEIGHT)
    panel = tcod.Console(SCREEN_WIDTH, PANEL_HEIGHT)
    root = tcod.Console(*context.recommended_console_size())

    return root, console, panel, animation, context
Esempio n. 16
0
def main() -> None:
    # Declare the size of the window
    screen_width = 80
    screen_height = 50

    map_width = 80
    map_height = 45

    room_max_size = 10
    room_min_size = 6
    max_rooms = 30

    # We need to set what font/tileset we're using
    # The most common is CHARMAP_CP437 (16x16 grid, previously "ASCII_INROW")
    tileset = tcod.tileset.load_tilesheet(
        "fonts/CGA8x8thick.png",  # font file
        16,  # how many rows across
        16,  # how many columns
        tcod.tileset.CHARMAP_CP437)

    # Let's process some events! How vague.
    event_handler = EventHandler()

    # Let's create the player object
    player = Entity(int(screen_width / 2), int(screen_height / 2), "@",
                    (255, 255, 255))

    entities = {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="ultima frog",
            vsync=True,
    ) as context:
        # The main off-screen console that we'll draw things to.
        # It will only temporarily have everything drawn to it directly.
        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)
Esempio n. 17
0
    def __init__(self):
        self.WIDTH = 80
        self.HEIGHT = 60

        # Load font as tileset:
        self.tileset = tcod.tileset.load_tilesheet('assets/arial10x10.png', 32,
                                                   8,
                                                   tcod.tileset.CHARMAP_TCOD)
        self.console = tcod.Console(self.WIDTH, self.HEIGHT, order='F')
        self.event_dispatch = event_handling.State()
Esempio n. 18
0
 def __init__(self, parent=None, console=None, x=0, y=0, width=0, height=0, color_set=None):
     super(List, self).__init__(parent, console, x, y, 0, 0, color_set=color_set)
     self.max_width = max(0, width-1) # leave 1 character of width for the scrollbar, if fixed-width
     self.max_height = height
     self.selected_item = None
     self.sub_console = tcod.Console(max(self.max_width, 20), max(self.max_height, 10))
     self.scroll_top = 0
     self.selected_bgcolor = tcod.color.AZURE
     self.disabled_fgcolor = tcod.color.DARK_GREY
     self.last_child = None
Esempio n. 19
0
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()
Esempio n. 20
0
def main() -> None:
    # Defining Variables for Screen Size
    screen_width = 80
    screen_height = 50

    # Defining variables for Map Size
    map_width = 80
    map_height = 45

    # Defining variables for procedural generation
    room_max_size = 10
    room_min_size = 6
    max_rooms = 30

    # Defining variables for enemies
    max_monsters_per_room = 2

    # Telling TCOD which font to use
    tileset = tcod.tileset.load_tilesheet('tileset.png', 32, 8,
                                          tcod.tileset.CHARMAP_TCOD)

    # initializing a player and npc and creating a set to hold them
    player = copy.deepcopy(entity_factories.player)

    # initializing engine
    engine = Engine(player=player)

    # initialize game map
    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()

    # Creating the screen, giving it width and height and other variables
    with tcod.context.new_terminal(
            screen_width,
            screen_height,
            tileset=tileset,
            title="Practice",
            vsync=True,
    ) as context:
        # Creates our console, which is what we are drawing to
        # The order argument affects the order of our x and y variables
        # setting order to "F" makes coordinates work as (x,y) instead of (y,x)
        root_console = tcod.Console(screen_width, screen_height, order="F")
        # Creates our game loop, This loop wont end until we close the game
        while True:
            # runs engine
            engine.render(console=root_console, context=context)
            engine.event_handler.handle_events()
Esempio n. 21
0
def main(new_width=50):

    # Open image from user input (string)
    path = input("Enter a valid file name to an image.\nImage must be located in the main folder.\nDo not include the file extension name:")
    try:
        image = PIL.Image.open(path + ".png")
    except:
        try:
            image = PIL.Image.open(path + ".jpg")
        except:
            print(path, "is not a valid file name to an image.")
            return -1

    # grayify & convert to ascii
    new_image_data = pixels_to_ascii(grayify(resize_image(image, new_width)))
    
    # format (.txt)
    pixel_count = len(new_image_data)
    ascii_image = "\n".join(new_image_data[i:(i+new_width)] for i in range(0, pixel_count, new_width))

    # write result
    with open("ascii_img.txt", "w") as f:
        f.write(ascii_image)

    # print result
    with open("ascii_img.txt", "r") as f:
        f_read = f.read()
        print(f_read)
        # for line in f:
        #     print(line, end="")

    # Console settings
    screen_width = 90
    screen_height = 50

    # Font
    tileset = tcod.tileset.load_tilesheet(
        "sources\\Cheepicus-8x8x2.png", 16, 16, tcod.tileset.CHARMAP_CP437
    )

    # Open Terminal
    with tcod.context.new_terminal(
        screen_width,
        screen_height,
        tileset=tileset,
        title="Ascii-fier",
        # sdl_window_flags=tcod.context.SDL_WINDOW_FULLSCREEN_DESKTOP,
        vsync=True,
    ) as context:
        root_console = tcod.Console(screen_width, screen_height, order="F")
        testgraphic = open("ascii_img.txt").read()
        root_console.clear()
        root_console.print(0,0, string=testgraphic, fg=(253, 106, 2))
        context.present(root_console, keep_aspect=True)
        input()
Esempio n. 22
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)
Esempio n. 24
0
def debug_map(map_: engine.map.Map, sleep_time: float = 0) -> None:
    """Present the current map tiles.  This is ignored on release mode."""
    if not g.debug_dungeon_generation:
        return
    for ev in tcod.event.get():
        if isinstance(ev, tcod.event.KeyDown):
            g.debug_dungeon_generation = False
    g.world.map = map_
    console = tcod.Console(map_.width, map_.height, order="F")
    console.tiles_rgb[:] = render_map(map_, world_view=None, fullbright=True)
    g.context.present(console)
    time.sleep(sleep_time)
Esempio n. 25
0
def main() -> None:
    # Variables for screen dimensions
    screen_width = 80
    screen_height = 50

    map_width = 80
    map_height = 43

    room_max_size = 10
    room_min_size = 6
    max_rooms = 30

    max_monsters_per_room = 2

    # Sets the custom font based on the file
    tileset = tcod.tileset.load_tilesheet("data/dejavu10x10_gs_tc.png", 32, 8,
                                          tcod.tileset.CHARMAP_TCOD)

    player = copy.deepcopy(entity_factories.player)
    engine = Engine(player=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()

    engine.message_log.add_message("Hello and welcome to yet another dungeon!",
                                   color.welcome_text)

    # This function initializes and creates the screen
    with tcod.context.new_terminal(screen_width,
                                   screen_height,
                                   tileset=tileset,
                                   title="Yet Another Roguelike Tutorial",
                                   vsync=True) as context:
        # Order "F" means coordinates are x, y instead of y, x
        # Creates the console that we will be drawing to
        root_console = tcod.Console(screen_width, screen_height, order="F")
        # This is the game loop!
        while True:
            root_console.clear()
            engine.event_handler.on_render(console=root_console)
            context.present(root_console)

            engine.event_handler.handle_events(context)
Esempio n. 26
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)
Esempio n. 27
0
def main() -> None:
    # Variables for screen size
    screen_width = 80
    screen_height = 50

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

    handler: input_handlers.BaseEventHandler = setup_game.MainMenu()

    # Creates the screen with a title
    with tcod.context.new_terminal(
            screen_width,
            screen_height,
            tileset=tileset,
            title="CRAIG'S BASEMENT",
            vsync=True,
    ) as context:

        # Creates our console, which is what we'll be drawing to
        # order argument affects order of x and y variables in numpy (underlying library tcod uses)
        # Numpy accesses 2D arrays in y, x order. Setting at "F", we change this to x, y instead
        root_console = tcod.Console(screen_width, screen_height, order="F")

        # Game loop, a loop that doesn't end until we close the screen
        try:
            while True:
                root_console.clear()
                handler.on_render(console=root_console)
                context.present(root_console)

                try:
                    for event in tcod.event.wait():
                        context.convert_event(event)
                        handler = handler.handle_events(event)
                except Exception:  # handle exceptions in game
                    traceback.print_exc()  # print error
                    # print erro to message log
                    if isinstance(handler, input_handlers.EventHandler):
                        handler.engine.message_log.add_message(
                            traceback.format_exc(), color.error)
        except exceptions.QuitWithoutSaving:
            raise
        except SystemExit:  # save and quit
            save_game(handler, "savegame.sav")
            raise
        except BaseException:  # save on any other unexpected exception
            save_game(handler, "savegame.sav")
            raise
Esempio n. 28
0
def main() -> None:
    """ TODO """
    screen_width = 80  # X-Coordinate
    screen_height = 50  # Y-Coordinate

    tileset = tcod.tileset.load_tilesheet(
        "resources/tileset10x10.png",
        32,
        8,
        tcod.tileset.CHARMAP_TCOD,
    )

    handler: input_handlers.BaseEventHandler = setup_game.MainMenu()

    with tcod.context.new_terminal(
            screen_width,
            screen_height,
            tileset=tileset,
            title="What if *hits bong* we made a rogue-like?",
            vsync=True,
    ) as context:
        root_console = tcod.Console(
            screen_width, screen_height,
            order="F")  # `order="F"` sætter coordinat-systemet til `[x, y]`
        try:
            while True:
                root_console.clear()
                handler.on_render(console=root_console)
                context.present(root_console)

                try:
                    for event in tcod.event.wait():
                        context.convert_event(event)
                        handler = handler.handle_events(event)
                except Exception:  # Handle exceptions in game.
                    traceback.print_exc()
                    if isinstance(handler, input_handlers.EventHandler):
                        handler.engine.message_log.add_message(
                            traceback.format_exc(),
                            color.error,
                        )

        except exceptions.QuitWithoutSaving:
            raise
        except SystemExit:  # Save and quit
            save_game(handler, "savegame.sav")
            raise
        except BaseException:  # Save on any other unexpected exception
            save_game(handler, "savegame.sav")
            raise
Esempio n. 29
0
def main() -> None:
  screen_width = 100
  screen_height = 50

  map_width = 100
  map_height = 42

  room_max_size = 15
  room_min_size = 6
  max_rooms = 30

  max_monsters_per_room = 2

  tileset = tcod.tileset.load_tilesheet(
    "cursesvector.png", 16, 16, tcod.tileset.CHARMAP_CP437
  )

  player = copy.deepcopy(entity_factories.player)

  engine = Engine(player=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()

  engine.message_log.add_message(
    "Hello and welcome, adventurer, to yet another dungeon!", color.welcome_text
  )

  with tcod.context.new_terminal(
    screen_width,
    screen_height,
    tileset=tileset,
    title="Decension",
    vsync=True,
  ) as context:
    root_console = tcod.Console(screen_width, screen_height, order="F")
    while True:
      root_console.clear()
      engine.event_handler.on_render(console=root_console)
      context.present(root_console)

      engine.event_handler.handle_events(context)
Esempio n. 30
0
def main():
    """Main program function."""
    screen_width = 80
    screen_height = 50

    map_width = 80
    map_height = 43

    room_max_size = 10
    room_min_size = 6
    max_rooms = 30

    max_monsters_per_room = 2

    # set tcod to use the font image included in the project
    tileset = tcod.tileset.load_tilesheet("dejavu10x10_gs_tc.png", 32, 8,
                                          tcod.tileset.CHARMAP_TCOD)

    player = copy.deepcopy(entity_factories.player)

    engine = Engine(player=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()

    engine.message_log.add_message("Oh no! Not this again...",
                                   color.welcome_text)

    # set console parameters
    with tcod.context.new_terminal(screen_width,
                                   screen_height,
                                   tileset=tileset,
                                   title="The Worst Roguelike",
                                   vsync=True) as context:
        root_console = tcod.Console(screen_width, screen_height, order="F")
        # main loop
        while True:
            root_console.clear()
            engine.event_handler.on_render(console=root_console)
            context.present(root_console)

            engine.event_handler.handle_events(context)