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()
Beispiel #2
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()
Beispiel #3
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()
Beispiel #4
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()
Beispiel #5
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