コード例 #1
0
def main():
    screen_width = 80
    screen_height = 50

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

    libtcod.console_set_custom_font(
        'arial10x10.png',
        libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)

    libtcod.console_init_root(screen_width, screen_height,
                              'libtcod tutorial revised', False)

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, mouse)

        libtcod.console_set_default_foreground(0, libtcod.white)
        libtcod.console_put_char(0, player_x, player_y, '@',
                                 libtcod.BKGND_NONE)
        libtcod.console_flush()

        key = libtcod.console_check_for_keypress()

        if key.vk == libtcod.KEY_ESCAPE:
            return True
コード例 #2
0
    def run(self):
        # initialize controls.
        key = libtcod.Key()
        mouse = libtcod.Mouse()

        self.app_states = AppStates.MAIN_MENU
        self.current_menu = MainMenu(self)

        # main loop
        while not libtcod.console_is_window_closed():
            # check key / mouse event
            libtcod.sys_check_for_event(
                libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)

            self.render_engine.render_app(self, mouse)

            if self.game and self.game.reset_game_windows:
                self.render_engine.reset_render_windows()

            self.input_handler.press(key)

            if self.app_states == AppStates.GAME:
                self.game.game_turn()

            if self.quit_app:
                break
コード例 #3
0
def test_handle_mouse__TARGETING_rclick_returns_ExitAction():
    state = States.TARGETING
    rclick = tcod.Mouse(x=100, y=115, cx=11, cy=19, rbutton_pressed=True)
    result = input_handling.handle_mouse(state, rclick)

    # Test cx/cy because that is the cell the cursor is over in the console
    assert isinstance(result, actions.ExitAction)
コード例 #4
0
def play_game():
    global key, mouse

    player_action = None

    mouse = libtcod.Mouse()
    key = libtcod.Key()
    #main loop
    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(
            libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)
        #render the screen
        render_all()

        libtcod.console_flush()

        #level up if needed
        check_level_up()

        #erase all objects at their old locations, before they move
        for object in objects:
            object.clear()

        #handle keys and exit game if needed
        player_action = handle_keys()
        if player_action == 'exit':
            save_game()
            break

        #let monsters take their turn
        if game_state == 'playing' and player_action != 'didnt-take-turn':
            for object in objects:
                if object.ai:
                    object.ai.take_turn()
コード例 #5
0
    def __init__(self, world=None, game_map=None, create_player=True, level_type=const.lvl_default):
        self.start_pos = None
        self.world = world
        self.game_map = game_map
        if world is None:
            self.world = esper.CachedWorld()
        if game_map is None:
            self._create_level(create_player, level_type)
        self.astar = tcod.path.AStar(self.game_map.walkable)

        self.processor_group = processor.PROCESSOR_GROUP
        self.change_processors('player_turn')

        self.fov_recompute = True
        self.message = collections.deque()
        self.action = {}
        self.mouse = tcod.Mouse()

        self.con = tcod.console.Console(
            width=const.MAP_WIDTH,
            height=const.MAP_HEIGHT
        )
        self._render_unexplored_map()

        self.panel = tcod.console.Console(
            width=const.SCREEN_WIDTH,
            height=const.PANEL_HEIGHT
        )
コード例 #6
0
def play_game():
    global key, mouse

    mouse = tcod.Mouse()
    key = tcod.Key()

    while not tcod.console_is_window_closed():
        tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS | tcod.EVENT_MOUSE, key,
                                 mouse)

        render_all()

        tcod.console_flush()

        check_level_up()

        for object in objects:
            object.clear()

        player_action = handle_keys()
        if player_action == 'exit':
            save_game()
            break

        if game_state == "playing" and player_action != "didnt-take-turn":
            for object in objects:
                if object.ai:
                    object.ai.take_turn()
コード例 #7
0
ファイル: window.py プロジェクト: Dajamante/Socket_based_game
    def __init__(self, width=50, height=50):

        self.key = libtcod.Key()
        self.mouse = libtcod.Mouse()
        self.screen_width = width
        self.screen_height = height
        start(self.screen_width, self.screen_height)
コード例 #8
0
ファイル: ui.py プロジェクト: Spferical/frogue
 def handle_input(self, game):
     """Returns true if an action was taken."""
     key = tcod.Key()
     mouse = tcod.Mouse()
     tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS | tcod.EVENT_MOUSE,
                              key, mouse)
     if key.c:
         char = chr(key.c)
         if self.state == States.DEFAULT:
             if char in DIRECTION_KEYS:
                 return game.attempt_player_move(DIRECTION_KEYS[char])
             elif char == 'x':
                 self.state = States.EXAMINE
                 self.map_window.center(game.world.player.pos)
                 self.map_window.draw_cursor_at_center()
                 self.examine_pos(game.world.player.pos)
             elif char == '.':
                 return True
         elif self.state == States.EXAMINE:
             if char in DIRECTION_KEYS:
                 self.map_window.move(DIRECTION_KEYS[char])
                 self.map_window.redraw_level(self.memory, self.vision)
                 self.map_window.draw_cursor_at_center()
                 self.examine_pos(self.map_window.center_pos)
             elif key.vk == tcod.KEY_ESCAPE:
                 self.state = States.DEFAULT
                 self.map_window.center(game.world.player.pos)
                 self.map_window.redraw_level(self.memory, self.vision)
                 self.examine_window.clear()
コード例 #9
0
def run():
    console.init()

    key = tcod.Key()
    mouse = tcod.Mouse()

    player = Player(int(variables.screen_width / 2),
                    int(variables.screen_height / 2))
    game_map = BoundedMap(80, 50)

    while not tcod.console_is_window_closed():
        tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS, key, mouse)
        console.update(player, game_map)

        action = input.handle_keys(key)

        move = action.get('move')
        quit_game = action.get('exit')

        if move:
            dx, dy = move
            if not game_map.is_blocked(player.x + dx, player.y + dy):
                player.move(dx, dy)

        if quit_game:
            return True

        if key.vk == tcod.KEY_ESCAPE:
            return True
コード例 #10
0
ファイル: pystars.py プロジェクト: gregoryfinley/pystars
def run():
    # TODO: create own font and stop using URR's
    tcod.console_set_custom_font('urr12x12.png', tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_ASCII_INROW, 16, 48)
    root_console = tcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'PyStars Test', renderer=2)
    tcod.sys_set_fps(FPS_LIMIT)
    key = tcod.Key()
    mouse = tcod.Mouse()
    game = GameData()
    tcod.console_flush()
    dt = 0.0
    while tcod.console_is_window_closed() == 0:
        dt += tcod.sys_get_last_frame_length()
        while tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS | tcod.EVENT_MOUSE, key, mouse) > 0:
            if key.vk == tcod.KEY_SPACE:
                game.time = 0.0
                game.time_scale = 360.0
            elif key.vk == tcod.KEY_TAB:
                game.top = not game.top
            elif key.vk == tcod.KEY_PAUSE:
                game.running = not game.running
            elif key.vk == tcod.KEY_UP:
                game.time_scale = game.time_scale + 30
            elif key.vk == tcod.KEY_DOWN:
                game.time_scale = game.time_scale - 30
            if mouse.rbutton:
                game.camera_rot_x -= math.radians(mouse.dx * game.camera_sensitivity)
                game.camera_rot_z -= math.radians(mouse.dy * game.camera_sensitivity)
        while dt >= FIXED_STEP:
            update(game, FIXED_STEP)
            dt = dt - FIXED_STEP
        draw(game, root_console)
        tcod.console_flush()
        time.sleep(0.001)
コード例 #11
0
def main():
    screen_width = 80
    screen_height = 50
    map_width = 80
    map_height = 45

    room_max_size = 10
    room_min_size = 6
    max_rooms = 30

    colors = {
        'dark_wall': libtcod.Color(0, 0, 100),
        'dark_ground': libtcod.Color(50, 50, 150)
    }

    player = Entity(40, 25, '@', libtcod.white, name="Player")
    npc = Entity(25, 20, 'N', libtcod.yellow, name="NPC")
    entities = [npc, player]

    libtcod.console_set_custom_font(
        'arial10x10.png',
        libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)

    libtcod.console_init_root(screen_width, screen_height,
                              'libtcod tutorial revised', False)
    con = libtcod.console_new(screen_width, screen_height)

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

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, mouse)

        render_all(con, entities, game_map, screen_width, screen_height,
                   colors)

        libtcod.console_flush()

        clear_all(con, entities)

        action = handle_keys(key)

        move = action.get('move')
        exit_game = action.get('exit')
        full_screen = action.get('fullscreen')

        if move:
            dx, dy = move
            if not game_map.is_blocked(player.x + dx, player.y + dy):
                player.move(dx, dy)
        if exit_game:
            return True

        if full_screen:
            libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
コード例 #12
0
def main():
    constants = get_constants()

    libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GRAYSCALE | libtcod.FONT_LAYOUT_TCOD)
    libtcod.console_init_root(constants['screen_width'], constants['screen_height'], constants['window_title'], False)

    con = libtcod.console_new(constants['screen_width'], constants['screen_height'])
    panel = libtcod.console_new(constants['screen_width'], constants['panel_height'])

    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False

    main_menu_background_image = libtcod.image_load('menu_background.png')

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)

        if show_main_menu:
            main_menu(con, main_menu_background_image, constants['screen_width'], constants['screen_height'])

            if show_load_error_message:
                message_box(con, 'No save game to load', 50, constants['screen_width'], constants['screen_height'])

            libtcod.console_flush()

            action = handle_main_menu(key)

            new_game = action.get('new_game')
            load_saved_game = action.get('load_game')
            exit_game = action.get('exit')

            if show_load_error_message and (new_game or load_saved_game or exit_game):
                show_load_error_message = False
            elif new_game:
                player, entities, game_map, message_log, game_state = get_game_variables(constants)
                game_state = GameStates.PLAYERS_TURN
                show_main_menu = False
            elif load_saved_game:
                try:
                    player, entities, game_map, message_log, game_state = load_game()
                    show_main_menu = False
                except FileNotFoundError:
                    show_load_error_message = True
            elif exit_game:
                break

        else:
            libtcod.console_clear(con)
            play_game(player, entities, game_map, message_log, game_state, con, panel, constants)
            show_main_menu = True
コード例 #13
0
ファイル: engine.py プロジェクト: ralphbarac/Python-Roguelike
def main():

    constants = get_constants()

    # Reads image file for font type
    tcod.console_set_custom_font(
        'arial10x10.png', tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_TCOD)

    # Creates the screen given width, height, title, and a boolean for fullscreen
    tcod.console_init_root(constants['screen_width'],
                           constants['screen_height'],
                           constants['window_title'], False)

    console_main = tcod.console_new(constants['screen_width'],
                                    constants['screen_height'])
    console_panel = tcod.console_new(constants['screen_width'],
                                     constants['panel_height'])

    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True

    key = tcod.Key()
    mouse = tcod.Mouse()

    while not tcod.console_is_window_closed():
        tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS | tcod.EVENT_MOUSE, key,
                                 mouse)

        if show_main_menu:
            main_menu(console_main, constants['screen_width'],
                      constants['screen_height'])

            tcod.console_flush()

            action = handle_main_menu_input(key)

            new_game = action.get('new_game')
            exit_game = action.get('exit')

            if new_game:
                player, entities, game_map, message_log, game_state = get_game_variables(
                    constants)
                game_state = GameStates.PLAYERS_TURN

                show_main_menu = False
            elif exit_game:
                break
        else:
            tcod.console_clear(console_main)
            game(player, entities, game_map, message_log, game_state,
                 console_main, console_panel, constants)

            show_main_menu = True
コード例 #14
0
def main():
    screen_width = 80
    screen_height = 50
    map_width = 80
    map_height = 45

    room_max_size = 10
    room_min_size = 6
    max_rooms = 1000

    colors = {
        # Gray
        'dark_wall': libtcod.darkest_gray,
        # Brown
        'dark_ground': libtcod.orange * libtcod.darker_gray
    }

    player = Entity(int(screen_width / 2), int(screen_height / 2), '@', libtcod.white)
    npc = Entity(int(screen_width / 2 - 5), int(screen_height / 2), '@', libtcod.yellow)
    entities = [player, npc]

    libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)

    libtcod.console_init_root(screen_width, screen_height, 'RoguelikeDev Tutorial', False)

    con = libtcod.console_new(screen_width, screen_height)

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

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, mouse)
        
        render_all(con, entities, game_map, screen_width, screen_height, colors)
    
        libtcod.console_flush()

        clear_all(con, entities)

        action = handle_keys(key)

        move = action.get('move')
        exit = action.get('exit')
        fullscreen = action.get('fullscreen')

        if move:
            dx, dy = move
            if not game_map.is_blocked(player.x + dx, player.y + dy):
                player.move(dx, dy)

        if exit:
            return True

        if fullscreen:
            libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())        
コード例 #15
0
 def mouse(self) -> tcod.Mouse:
     """Mouse is a tcod.Mouse object.
     """
     try:
         return self._mouse
     except AttributeError:
         pass
     self._mouse = tcod.Mouse()
     return self._mouse
コード例 #16
0
ファイル: engine.py プロジェクト: BrianRusk/RogueLike
def main():
    screen_width = 80
    screen_height = 50
    map_width = 80
    map_height = 45

    colors = {
        'dark_wall': libtcod.Color(0, 0, 100),
        'dark_ground': libtcod.Color(50, 50, 150)
    }

    player = Entity(int(screen_width / 2), int(screen_height / 2), '@',
                    libtcod.green)
    npc = Entity(int(screen_width / 2 - 5), int(screen_height / 2), '@',
                 libtcod.yellow)
    entities = [npc, player]

    libtcod.console_set_custom_font(
        'arial10x10.png',
        libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)

    libtcod.console_init_root(screen_width, screen_height,
                              'libtcod tutorial revised', False)

    con = libtcod.console_new(screen_width, screen_height)

    game_map = GameMap(map_width, map_height)

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, mouse)

        render_all(con, entities, game_map, screen_width, screen_height,
                   colors)

        libtcod.console_flush()

        clear_all(con, entities)

        action = handle_keys(key)

        move = action.get('move')
        exit = action.get('exit')
        fullscreen = action.get('fullscreen')

        if move:
            dx, dy = move
            player.move(dx, dy)

        if exit:
            return True

        if fullscreen:
            libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
コード例 #17
0
ファイル: Engine.py プロジェクト: JezzyDeves/TepisRL
def main():
    screen_width = 80
    screen_height = 50
    map_width = 80
    map_height = 45

    room_max_size = 10
    room_min_size = 6
    max_rooms = 30

    colors = {
        'dark_wall': libtcod.Color(0, 0 ,100),
        'dark_ground': libtcod.Color(50, 50, 150)
    }
#Player and NPC settings. Defines entities
    player = Entity(int(screen_width / 2), int(screen_height / 2), '@', libtcod.white)
    npc = Entity(int(screen_width / 2 - 5), int(screen_height / 2), '@', libtcod.yellow)
    entities = [npc, player]
#Sets font img
    libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
#Init for root console(Width, Height, Window name, fullscreen)
    libtcod.console_init_root(screen_width, screen_height, 'TepisRL', False)
#Consoles
    con = libtcod.console_new(screen_width, screen_height)
#Calls map gen
    game_map = GameMap(map_width, map_height)
    game_map.make_map(max_rooms, room_min_size, room_max_size, map_width, map_height, player)
#Calls key functions
    key = libtcod.Key()
    mouse = libtcod.Mouse()
    #Game loop
    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, mouse)

        render_all(con, entities, game_map, screen_width, screen_height, colors)

        libtcod.console_flush()

        clear_all(con, entities)
        #Handles recognition of keypresses for movement
        action = handle_keys(key)
        
        move = action.get('move')
        exit = action.get('exit')
        fullscreen = action.get('fullscreen')

        if move:
            dx, dy = move
            if not game_map.is_blocked(player.x + dx, player.y + dy):
                player.move(dx, dy)

        if exit:
            return True

        if fullscreen:
            libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
コード例 #18
0
    def __init__(self, _game, render_eng):
        self.g = _game
        # self.g.fov_recompute = True
        self.g.redraw = True

        self.render_eng = render_eng
        self.key = tcod.Key()
        self.mouse = tcod.Mouse()

        self.activate_main_menu = False
コード例 #19
0
def test_handle_mouse__TARGETING_mclick_returns_TargetAction():
    state = States.TARGETING
    mclick = tcod.Mouse(x=50, y=22, cx=44, cy=2, lbutton_pressed=True)
    result = input_handling.handle_mouse(state, mclick)

    # Test cx/cy because that is the cell the cursor is over in the console
    assert isinstance(result, actions.TargetAction)
    assert result.x == 44
    assert result.y == 2
    assert result.mclick
コード例 #20
0
def character_selection(constants, con, panel):

    character_menu(con, constants['screen_width'], constants['screen_height'])
    libtcod.console_flush()

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(
            libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)
        action = handle_character_selection(key)
        BandL = action.get('B&L')
        SandV = action.get('S&V')
        Mix = action.get('Mix')
        if BandL:
            fighter_component = Fighter(
                const.Base_Line_Fighter_Component_Value['hp'],
                const.Base_Line_Fighter_Component_Value['defense'],
                const.Base_Line_Fighter_Component_Value['power'])
            character = const.Base_Line_Player_tile
            equipable_component = const.Base_Line_Equipable_Component
            wearable_component = const.Base_Line_Wearable_Component
            player, entities, game_map, message_log, game_state = get_game_variables(
                constants, fighter_component, character, equipable_component,
                wearable_component)
            play_game(player, entities, game_map, message_log, con, panel,
                      constants)
        elif SandV:
            fighter_component = Fighter(
                const.Serve_And_Volley_Fighter_Component_Value['hp'],
                const.Serve_And_Volley_Fighter_Component_Value['defense'],
                const.Serve_And_Volley_Fighter_Component_Value['power'])
            character = const.Serve_And_Volley_Player_tile
            equipable_component = const.Serve_And_Volley_Equipable_Component
            wearable_component = const.Serve_And_Volley_Wearable_Component
            player, entities, game_map, message_log, game_state = get_game_variables(
                constants, fighter_component, character, equipable_component,
                wearable_component)
            play_game(player, entities, game_map, message_log, con, panel,
                      constants)

        elif Mix:
            character = const.Mixed_Player_tile
            fighter_component = Fighter(
                const.Mixed_Fighter_Component_Value['hp'],
                const.Mixed_Fighter_Component_Value['defense'],
                const.Mixed_Fighter_Component_Value['power'])
            equipable_component = const.Mixed_Equipable_Component
            wearable_component = const.Mixed_Wearable_Component
            player, entities, game_map, message_log, game_state = get_game_variables(
                constants, fighter_component, character, equipable_component,
                wearable_component)
            play_game(player, entities, game_map, message_log, con, panel,
                      constants)
コード例 #21
0
ファイル: ui.py プロジェクト: Vig1lante/RogueGame
def final_screen(window, loose_or_win):
    if loose_or_win == 'win':
        screen = file_operations.import_board("youwon.txt")
    else:
        screen = file_operations.import_board("youlost.txt")
    horizontal_offset = int((SCREEN_WIDTH / 2) - (len(screen[0]) / 2))
    vertical_offset = int((SCREEN_HEIGHT / 2) - (len(screen) / 2))

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    libtcod.console_clear(window)

    while not libtcod.console_is_window_closed():
        # WAIT FOR INPUT
        libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, mouse)

        action = handle_keys(key)
        fullscreen = action.get('fullscreen')
        exit = action.get('exit')

        for i, line in enumerate(screen):
            for j, char in enumerate(line):
                if loose_or_win == 'win':
                    if char == "M":
                        libtcod.console_set_default_foreground(
                            window, libtcod.yellow)
                    elif char == "S":
                        libtcod.console_set_default_foreground(
                            window, libtcod.blue)
                    elif char == "#":
                        libtcod.console_set_default_foreground(
                            window, libtcod.light_chartreuse)
                    else:
                        libtcod.console_set_default_foreground(
                            window, libtcod.white)
                else:
                    if char == "#":
                        libtcod.console_set_default_foreground(
                            window, libtcod.red)
                    else:
                        libtcod.console_set_default_foreground(
                            window, libtcod.white)
                libtcod.console_put_char(window, j + horizontal_offset,
                                         i + vertical_offset, char,
                                         libtcod.BKGND_NONE)
                libtcod.console_blit(window, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
                                     0, 0, 0)
                libtcod.console_flush()

        if fullscreen:
            libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())

        if exit:
            return True
コード例 #22
0
def main():
    tcod.sys_set_fps(20)                # Prevents 100% CPU usage

    screen_width = 80
    screen_height = 50
    map_width = 80
    map_height = 45

    colors = {
        # Colors for objects outside of FOV
        'dark_wall': tcod.Color(0, 0, 100),
        'dark_ground': tcod.Color(50, 50, 150)
    }

    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]

    tcod.console_set_custom_font('arial10x10.png', tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_TCOD)
    tcod.console_init_root(screen_width, screen_height, 'RoguePy', False)    # Last boolean determines if game is fullscrean

    con = tcod.console_new(screen_width, screen_height)

    game_map = GameMap(map_width, map_height)

    key = tcod.Key()
    mouse = tcod.Mouse()

    # Game loop
    while not tcod.console_is_window_closed():
        tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS, key, mouse)

        render_all(con, entities, game_map, screen_width, screen_height, colors)

        tcod.console_flush()

        clear_all(con, entities)

        action = handle_keys(key)

        move = action.get('move')
        exit = action.get('exit')
        fullscreen = action.get('fullscreen')

        if move:
            dx, dy = move
            if not game_map.is_blocked(player.x + dx, player.y + dy):
                player.move(dx, dy)

        if exit:
            return True

        if fullscreen:
            tcod.console_set_fullscreen(not tcod.console_is_fullscreen())
コード例 #23
0
def main():
    screen_width = 80
    screen_height = 50

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

    libtcod.console_set_custom_font(
        'arial10x10.png',
        libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)

    libtcod.console_init_root(screen_width,
                              screen_height,
                              'libtcod tutorial revised',
                              False,
                              libtcod.RENDERER_SDL2,
                              vsync=True)

    #con = libtcod.console_new(screen_width, screen_height)
    con = libtcod.console.Console(screen_width, screen_height)

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    while not libtcod.console_is_window_closed():

        libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, mouse)

        libtcod.console_set_default_foreground(con, libtcod.white)
        libtcod.console_put_char(con, player_x, player_y, '@',
                                 libtcod.BKGND_NONE)
        libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)

        libtcod.console_flush()
        libtcod.console_put_char(con, player_x, player_y, ' ',
                                 libtcod.BKGND_NONE)

        action = handle_keys(key)

        move = action.get('move')
        exit = action.get('exit')
        fullscreen = action.get('fullscreen')

        if move:
            dx, dy = move
            player_x += dx
            player_y += dy

        if exit:
            return True

        if fullscreen:
            libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
コード例 #24
0
ファイル: Engine.py プロジェクト: Rossety/RoguelikeCyberpunk
def main():
    # tamaño de la pantalla
    screen_width = 80
    screen_height = 50

    # track del jugador
    player_x = int(screen_width / 2)
    player_y = int(screen_height / 2)

    # accion movimiento
    key = libtcod.Key()
    mouse = libtcod.Mouse()

    # Lectura de la fuente, una imagen que refleja los "sprites"
    libtcod.console_set_custom_font(
        'arial10x10.png',
        libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)

    # llama a la pantalla
    libtcod.console_init_root(screen_width, screen_height, 'Cyberpunk', False)

    con = libtcod.console_new(screen_width, screen_height)
    # Loop del juego (para no cerrarlo con cada movimiento)
    while not libtcod.console_is_window_closed():
        # accion movimientos
        libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, mouse)
        # parametros del jugador
        libtcod.console_set_default_foreground(
            con, libtcod.red)  # color del jugador
        libtcod.console_put_char(con, player_x, player_y, '@',
                                 libtcod.BKGND_NONE)  # ubicacion fisica
        libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)
        libtcod.console_flush()

        libtcod.console_put_char(
            con, player_x, player_y, ' ',
            libtcod.BKGND_NONE)  # quitar el area de espacio recorrido
        action = Acciones(key)

        Mover = action.get('Mover')
        Salir = action.get('Salir')
        PantallaCompleta = action.get('PantallaCompleta')

        if Mover:
            dx, dy = Mover
            player_x += dx
            player_y += dy
        if Salir:
            return True

        if PantallaCompleta:
            libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
コード例 #25
0
def main():
    screenWidth = 111
    screenHeight = 80
    mapWidth = 76
    mapHeight = 64
    panel_x = mapWidth
    panelWidth = 35

    colors = {
        'HexDivider': libtcod.Color(50, 50, 100),
        'HexInterior': libtcod.Color(5, 5, 5)
    }

    entities = []
    hexes = []
    planets = []
    subsectorMap = ssMap(mapWidth, mapHeight)
    subsectorMap.make_map(hexes, planets)

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    con = libtcod.console_new(screenWidth, screenHeight)
    panel = libtcod.console_new(panelWidth, screenHeight)

    libtcod.console_set_custom_font('lefont.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
    libtcod.console_init_root(screenWidth, screenHeight, 'MGTMapper', False)

    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, mouse)

        libtcod.console_set_default_foreground(0, libtcod.white)
        libtcod.console_blit(con, 0, 0, screenWidth, screenHeight, 0, 0, 0)
        render_all(con, panel, entities, hexes, planets, subsectorMap, screenWidth, screenHeight, colors, mouse, panelWidth, panel_x,
                   mapWidth, mapHeight)
        libtcod.console_flush()
        clear_all(con, entities)

        action = handle_keys(key)
        mouse_action = handle_mouse(mouse)

        exit = action.get('exit')
        fullscreen = action.get('fullscreen')

        left_click = mouse_action.get('left_click')
        right_click = mouse_action.get('right_click')

        if exit:
            return True

        if fullscreen:
            libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
コード例 #26
0
    def run(self):
        """ Main game loop """
        show_main_menu = True
        show_load_error_message = False

        main_menu_background_image = tcod.image_load('menu_background.png')

        key = tcod.Key()
        mouse = tcod.Mouse()

        while not tcod.console_is_window_closed():
            tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS | tcod.EVENT_MOUSE,
                                     key, mouse)

            if show_main_menu:
                main_menu(self.main_console, main_menu_background_image,
                          self.constants['screen_width'],
                          self.constants['screen_height'])

                if show_load_error_message:
                    message_box(self.main_console, 'No save game to load', 50,
                                self.constants['screen_width'],
                                self.constants['screen_height'])

                tcod.console_flush()

                action = handle_main_menu(key)

                a_new_game = action.get('new_game')
                a_load_saved_game = action.get('load_game')
                a_exit_game = action.get('exit')

                if show_load_error_message and (a_new_game or a_load_saved_game
                                                or a_exit_game):
                    show_load_error_message = False
                elif a_new_game:
                    self.reset_game()
                    show_main_menu = False
                elif a_load_saved_game:
                    try:
                        self.load_saved_game()
                        show_main_menu = False
                    except FileNotFoundError:
                        show_load_error_message = True
                elif a_exit_game:
                    break

            else:
                tcod.console_clear(self.main_console)
                self.play_game()

                show_main_menu = True
コード例 #27
0
ファイル: engine.py プロジェクト: croese/rogue-tut
def main():
    screen_width = 80
    screen_height = 50

    player = Entity(int(screen_width / 2), int(screen_height / 2), "@",
                    libtcod.white)
    npc = Entity(int(screen_width / 2 - 5), int(screen_height / 2), "@",
                 libtcod.yellow)
    entities = [npc, player]

    libtcod.console_set_custom_font(
        "arial10x10.png",
        libtcod.FONT_TYPE_GRAYSCALE | libtcod.FONT_LAYOUT_TCOD)
    libtcod.console_init_root(screen_width, screen_height,
                              "libtcod tutorial revised", False)

    con = libtcod.console_new(screen_width, screen_height)

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, mouse)

        libtcod.console_set_default_foreground(con, libtcod.white)
        libtcod.console_put_char(con, player.x, player.y, "@",
                                 libtcod.BKGND_NONE)
        libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)

        libtcod.console_set_default_foreground(0, libtcod.white)

        libtcod.console_flush()

        libtcod.console_put_char(con, player_x, player_y, " ",
                                 libtcod.BKGND_NONE)

        action = handle_keys(key)

        move = action.get("move")
        exit = action.get("exit")
        fullscreen = action.get("fullscreen")

        if move:
            dx, dy = move
            player.move(dx, dy)

        if exit:
            return True

        if fullscreen:
            libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
コード例 #28
0
def intro_menu_select(window):
    intro_board = create_intro()
    horizontal_offset = int((ui.SCREEN_WIDTH / 2) - (len(intro_board[0]) / 2))
    vertical_offset = int((ui.SCREEN_HEIGHT / 2) - (len(intro_board) / 2))

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    introduction_menu = True
    libtcod.console_clear(window)
    while introduction_menu:

        libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, mouse)

        for i, line in enumerate(intro_board):
            for j, char in enumerate(line):
                if char == '#':
                    libtcod.console_set_default_foreground(
                        window, libtcod.light_chartreuse)
                else:
                    libtcod.console_set_default_foreground(
                        window, libtcod.white)
                libtcod.console_put_char(window, j + horizontal_offset,
                                         i + vertical_offset, char,
                                         libtcod.BKGND_NONE)
                libtcod.console_blit(window, 0, 0, ui.SCREEN_WIDTH,
                                     ui.SCREEN_HEIGHT, 0, 0, 0)
                libtcod.console_flush()

        action = handle_keys(key)
        start_game = action.get('start_game')
        help = action.get('help')
        fullscreen = action.get('fullscreen')
        quit_menu = action.get('exit_menu')

        if start_game:
            libtcod.console_clear(window)
            return 0

        #display info/screen 'how to play'
        if help:
            libtcod.console_clear(window)
            how_to_play(window)

        if fullscreen:
            libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())

        if quit_menu:
            introduction_menu = False
            return -1
コード例 #29
0
ファイル: console.py プロジェクト: millejoh/Islands
def sys_get_events():
    mouse = tcod.Mouse()
    key = tcod.Key()
    events = []
    while 1:
        event = tcod.sys_check_for_event(tcod.EVENT_ANY, key, mouse)
        if event == tcod.EVENT_NONE:
            break
        elif event == tcod.EVENT_KEY_PRESS or event == tcod.EVENT_KEY_RELEASE:
            events.append((event, key))
        elif event in (tcod.EVENT_MOUSE_MOVE, tcod.EVENT_MOUSE_PRESS,
                       tcod.EVENT_MOUSE_RELEASE):
            events.append((event, mouse))
    return events
コード例 #30
0
def run():
    # INIT

    # libtcod
    tcod.console_set_custom_font('pystars12x12.png', tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_ASCII_INROW, 16, 48)
    tcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'PyStars')
    tcod.sys_set_fps(LIMIT_FPS)
    key = tcod.Key()
    mouse = tcod.Mouse()

    # game data
    world = World(WORLD_WIDTH, WORLD_HEIGHT)

    # screen setup
    viewport = Window(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, True)
    action_menu = Window(0, 0, 30, 30)
    camera = {'x':0, 'y':0}

    starmap = stars.generate_stars(1602)
    projection = stars.get_cylindrical_projection(starmap)

    brightest = min(starmap, key=lambda star: star.radial)
    print brightest

    # GAME LOOP
    while tcod.console_is_window_closed() is False:
        # DRAWING
        #world.update()
        #tcod.console_blit(world.console, camera['x'], camera['y'], WORLD_WIDTH, WORLD_HEIGHT, None, 0, 0)
        # tcod.console_blit(projection, camera['x'], camera['y'], WORLD_WIDTH, WORLD_HEIGHT, None, 0, 0)
        tcod.console_flush()
        
        # USER INPUT
        while tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS|tcod.EVENT_MOUSE,key,mouse) > 0:
            if key.vk == tcod.KEY_UP:
                camera['y'] -= 1
            if key.vk == tcod.KEY_DOWN:
                camera['y'] += 1
            if key.vk == tcod.KEY_LEFT:
                camera['x'] -= 1
            if key.vk == tcod.KEY_RIGHT:
                camera['x'] += 1
            camera['x'] = max(0, min(camera['x'], WORLD_WIDTH-SCREEN_WIDTH))
            camera['y'] = max(0, min(camera['y'], WORLD_HEIGHT-SCREEN_HEIGHT))

        # GAME LOGIC
########
######## end old pystars.py
########