Пример #1
0
def handle_keys():
    global player_x, player_y, fov_recompute

    key = get_key_event(TURN_BASED)

    if key.vk == tcod.KEY_ENTER and key.lalt:
        # Alt+Enter: toggle fullscreen
        tcod.console_set_fullscreen(not tcod.console_is_fullscreen())

    elif key.vk == tcod.KEY_ESCAPE:
        return True  # exit game

    # movement keys
    if tcod.console_is_key_pressed(tcod.KEY_UP):
        player.move(0, -1)
        fov_recompute = True

    elif tcod.console_is_key_pressed(tcod.KEY_DOWN):
        player.move(0, 1)
        fov_recompute = True

    elif tcod.console_is_key_pressed(tcod.KEY_LEFT):
        player.move(-1, 0)
        fov_recompute = True

    elif tcod.console_is_key_pressed(tcod.KEY_RIGHT):
        player.move(1, 0)
        fov_recompute = True
Пример #2
0
def handle_keys():
    global fov_recompute

    #key = tcod.console_check_for_keypress()  #real-time
    key = tcod.console_wait_for_keypress(True)  #turn-based

    if key.vk == tcod.KEY_ENTER and key.lalt:
        #Alt+Enter: toggle fullscreen
        tcod.console_set_fullscreen(not tcod.console_is_fullscreen())

    elif key.vk == tcod.KEY_ESCAPE:
        return True  #exit game

    #movement keys
    if tcod.console_is_key_pressed(tcod.KEY_UP):
        player.move(0, -1)
        fov_recompute = True

    elif tcod.console_is_key_pressed(tcod.KEY_DOWN):
        player.move(0, 1)
        fov_recompute = True

    elif tcod.console_is_key_pressed(tcod.KEY_LEFT):
        player.move(-1, 0)
        fov_recompute = True

    elif tcod.console_is_key_pressed(tcod.KEY_RIGHT):
        player.move(1, 0)
        fov_recompute = True
Пример #3
0
def handle_keys():
    global fov_recompute

    key = get_key_event(TURN_BASED)
 
    if key.vk == tcod.KEY_ENTER and key.lalt:
        # Alt+Enter: toggle fullscreen
        tcod.console_set_fullscreen(not tcod.console_is_fullscreen())
 
    elif key.vk == tcod.KEY_ESCAPE:
        return 'exit'  # exit game
    
    # movement and combat only possible in playing game state
    if game_state == 'playing':

         # movement keys
        if tcod.console_is_key_pressed(tcod.KEY_UP):
            player.move(0,-1)
            fov_recompute = True
 
        elif tcod.console_is_key_pressed(tcod.KEY_DOWN):
            player.move(0,1)
            fov_recompute = True
 
        elif tcod.console_is_key_pressed(tcod.KEY_LEFT):
            player.move(-1,0)
            fov_recompute = True
 
        elif tcod.console_is_key_pressed(tcod.KEY_RIGHT):
            player.move(1,0)
            fov_recompute = True
        
        # testing if turn was taken
        else:
            return 'turn_not_taken'
Пример #4
0
    def handle_keys(self):
        #key = libtcod.console_check_for_keypress()  #real-time
        key = libtcodpy.console_wait_for_keypress(True)  #turn-based

        #let monsters take their turn
        if self.game_state == 'playing' and self.player_action != 'didnt-take-turn':
            for obj in self.objects:
                if obj.ai:
                    obj.ai.take_turn(self.game_map, self.player)

        if self.game_state == 'playing':
            if key.vk == libtcodpy.KEY_ENTER and key.lalt:
                #Alt+Enter: toggle fullscreen
                libtcodpy.console_set_fullscreen(not libtcodpy.console_is_fullscreen())

            elif key.vk == libtcodpy.KEY_ESCAPE:
                return 'exit'  #exit game

            #movement keys
            if libtcodpy.console_is_key_pressed(libtcodpy.KEY_UP):
                self.game_map.fov_recompute = self.player.move(0, -1, self.is_blocked_and_target)

            elif libtcodpy.console_is_key_pressed(libtcodpy.KEY_DOWN):
                self.game_map.fov_recompute = self.player.move(0, 1, self.is_blocked_and_target)

            elif libtcodpy.console_is_key_pressed(libtcodpy.KEY_LEFT):
                self.game_map.fov_recompute = self.player.move(-1, 0, self.is_blocked_and_target)

            elif libtcodpy.console_is_key_pressed(libtcodpy.KEY_RIGHT):
                self.game_map.fov_recompute = self.player.move(1, 0, self.is_blocked_and_target)

            else:
                return 'didnt-take-turn'
def handle_keys():
    #key = libtcod.console_check_for_keypress()  #real-time
    key = libtcod.console_wait_for_keypress(True)  #turn-based
 
    if key.vk == libtcod.KEY_ENTER and key.lalt:
        #Alt+Enter: toggle fullscreen
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
 
    elif key.vk == libtcod.KEY_ESCAPE:
        return 'exit'  #exit game
 
    if game_state == 'playing':
        #movement keys
        if libtcod.console_is_key_pressed(libtcod.KEY_UP):
            player_move_or_attack(0, -1)
 
        elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN):
            player_move_or_attack(0, 1)
 
        elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT):
            player_move_or_attack(-1, 0)
 
        elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT):
            player_move_or_attack(1, 0)
 
        else:
            return 'didnt-take-turn'
def handle_keys():
    global fov_recompute
 
    #key = libtcod.console_check_for_keypress()  #real-time
    key = libtcod.console_wait_for_keypress(True)  #turn-based
 
    if key.vk == libtcod.KEY_ENTER and key.lalt:
        #Alt+Enter: toggle fullscreen
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
 
    elif key.vk == libtcod.KEY_ESCAPE:
        return True  #exit game
 
    #movement keys
    if libtcod.console_is_key_pressed(libtcod.KEY_UP):
        player.move(0, -1)
        fov_recompute = True
 
    elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN):
        player.move(0, 1)
        fov_recompute = True
 
    elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT):
        player.move(-1, 0)
        fov_recompute = True
 
    elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT):
        player.move(1, 0)
        fov_recompute = True
Пример #7
0
def menu(header, options, width):
    if len(options) > 26:
        raise ValueError("Cannot have a menu with more than 26 options.")
    header_height = libtcod.console_get_height_rect(con, 0, 0, width,
                                                    SCREEN_HEIGHT, header)
    if header == '':
        header_height = 0
    height = len(options) + header_height
    window = libtcod.console_new(width, height)
    libtcod.console_set_default_foreground(window, libtcod.white)
    libtcod.console_print_rect_ex(window, 0, 0, width, height,
                                  libtcod.BKGND_NONE, libtcod.LEFT, header)
    y = header_height
    letter_index = ord('a')
    for option_text in options:
        text = "(" + chr(letter_index) + ") " + option_text
        libtcod.console_print_ex(window, 0, y, libtcod.BKGND_NONE,
                                 libtcod.LEFT, text)
        y += 1
        letter_index += 1
    x = SCREEN_WIDTH / 2 - width / 2
    y = SCREEN_HEIGHT / 2 - height / 2
    libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
    libtcod.console_flush()
    key = libtcod.console_wait_for_keypress(True)
    if key.vk == libtcod.KEY_ENTER:
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
    index = key.c - ord('a')
    if index >= 0 and index < len(options):
        return index
    return None
Пример #8
0
def handle_keys():
    # key = libtcod.console_check_for_keypress()  #real-time
    key = libtcod.console_wait_for_keypress(True)  # turn-based

    if key.vk == libtcod.KEY_ENTER and key.lalt:
        # Alt+Enter: toggle fullscreen
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())

    elif key.vk == libtcod.KEY_ESCAPE:
        return 'exit'  # exit game

    if game_state == 'playing':
        # movement keys
        if libtcod.console_is_key_pressed(libtcod.KEY_UP):
            player_move_or_attack(0, -1)

        elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN):
            player_move_or_attack(0, 1)

        elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT):
            player_move_or_attack(-1, 0)

        elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT):
            player_move_or_attack(1, 0)

        else:
            return 'didnt-take-turn'
Пример #9
0
def options_menu(game):
    choice = generic_options_menu(
        'Game Options',
        '', ['Toggle Fullscreen', 'Change Font', f'Debug Options & Cheats'],
        game,
        sort_by=1,
        clear_screen=True)
    if choice == 0:
        tcod.console_set_fullscreen(not tcod.console_is_fullscreen())
    elif choice == 1:
        available_fonts = all_fonts()
        font_id = generic_options_menu(
            'Font Selection',
            f'Default font:\n{cfg.FONT_DEFAULT.capitalize()}',
            available_fonts,
            game,
            sort_by=1,
            clear_screen=True)
        if font_id is not None:
            initialize_font(available_fonts[font_id])
    elif choice == 2:
        debug_menu(game, clear=True)

    # Unless menu was exited with ESC, the menu remains open
    if choice is not None:
        options_menu(game)
Пример #10
0
def handle_keys():
    global player, fov_recompute, TURN_BASED

    key = get_key_event(TURN_BASED)

    if key.vk == tcod.KEY_ENTER and key.lalt:
        # Alt+Enter: toggle fullscreen
        tcod.console_set_fullscreen(not tcod.console_is_fullscreen())

    elif key.vk == tcod.KEY_ESCAPE:
        return 'exit'  # exit game

    if game_state == 'playing':
        if tcod.console_is_key_pressed(tcod.KEY_UP):
            player_move_or_attack(0, -1)

        elif tcod.console_is_key_pressed(tcod.KEY_DOWN):
            player_move_or_attack(0, 1)

        elif tcod.console_is_key_pressed(tcod.KEY_LEFT):
            player_move_or_attack(-1, 0)

        elif tcod.console_is_key_pressed(tcod.KEY_RIGHT):
            player_move_or_attack(1, 0)

    else:
        return 'didnt-take-turn'
Пример #11
0
def handle_keys():
    global exit_game

    player_dx = 0
    player_dy = 0

    #movement keys
    if tcod.console_is_key_pressed(tcod.KEY_UP):
        player_dy = -1
    elif tcod.console_is_key_pressed(tcod.KEY_DOWN):
        player_dy = 1
    elif tcod.console_is_key_pressed(tcod.KEY_LEFT):
        player_dx = -1
    elif tcod.console_is_key_pressed(tcod.KEY_RIGHT):
        player_dx = 1

    # move the player
    player.move(player_dx, player_dy)

    # check for specific key presses combos, etc
    key = tcod.console_check_for_keypress()

    if key.vk == tcod.KEY_ENTER and key.lalt:
        # Alt-enter toggle fullscreen
        tcod.console_set_fullscreen(not tcod.console_is_fullscreen())
    elif key.vk == tcod.KEY_ESCAPE:
        exit_game = True
def handle_keys():
    global playerx, playery
 
    #key = libtcod.console_check_for_keypress()  #real-time
    key = libtcod.console_wait_for_keypress(True)  #turn-based
 
    if key.vk == libtcod.KEY_ENTER and key.lalt:
        #Alt+Enter: toggle fullscreen
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
 
    elif key.vk == libtcod.KEY_ESCAPE:
        return True  #exit game
 
    #movement keys
    if libtcod.console_is_key_pressed(libtcod.KEY_UP):
        playery -= 1
 
    elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN):
        playery += 1
 
    elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT):
        playerx -= 1
 
    elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT):
        playerx += 1
Пример #13
0
def handle_keys():
    global fov_recompute
     
    key = tcod.console_check_for_keypress(True)
    
    if game_state == 'playing':
        if key.vk == tcod.KEY_ENTER and key.lalt:
            tcod.console_set_fullscreen(not tcod.console_is_fullscreen())
        elif key.vk == tcod.KEY_ESCAPE:
            return 'exit'

        if tcod.console_is_key_pressed(tcod.KEY_UP):
            player_move_atttack(0, -1)
            fov_recompute = True

        elif tcod.console_is_key_pressed(tcod.KEY_DOWN):
            player_move_atttack(0, 1)
            fov_recompute = True

        elif tcod.console_is_key_pressed(tcod.KEY_LEFT):
            player_move_atttack(-1, 0)
            fov_recompute = True

        elif tcod.console_is_key_pressed(tcod.KEY_RIGHT):
            player_move_atttack(1, 0)
            fov_recompute = True
        else:
             return 'no-turn'
Пример #14
0
def handleKeys():
    global fovRecompute, key
    #options
    if key.vk == tcod.KEY_ENTER and key.lalt:
        tcod.console_set_fullscreen(not tcod.console_is_fullscreen())
    elif key.vk == tcod.KEY_ESCAPE:
        return 'exit'

    #movement
    if gameState == 'playing':
        if key.vk == tcod.KEY_UP:
            playerMoveOrAttack(0, -1)
        elif key.vk == tcod.KEY_DOWN:
            playerMoveOrAttack(0, 1)
        elif key.vk == tcod.KEY_LEFT:
            playerMoveOrAttack(-1, 0)
        elif key.vk == tcod.KEY_RIGHT:
            playerMoveOrAttack(1, 0)
        else:
            keyChar = chr(key.c)
            if keyChar == 'g':
                for object in objects:
                    if object.x == player.x and object.y == player.y and object.item:
                        object.item.pickup()
                        break
            if keyChar == 'i':
                chosenItem = inventoryMenu('Press the key next to an item to use it, or any other to cancel. \n')
                if chosenItem is not None:
                    chosenItem.use()
            return 'didnt-take-turn'
Пример #15
0
def handle_keys():
    global key

    if key.vk == libtcod.KEY_ENTER and key.lalt:
        #Alt+Enter: toggle fullscreen
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())

    elif key.vk == libtcod.KEY_ESCAPE:
        return 'exit'  #exit game

    if game_state == 'playing':
        #movement keys
        if key.vk == libtcod.KEY_UP:
            player_move_or_attack(0, -1)

        elif key.vk == libtcod.KEY_DOWN:
            player_move_or_attack(0, 1)

        elif key.vk == libtcod.KEY_LEFT:
            player_move_or_attack(-1, 0)

        elif key.vk == libtcod.KEY_RIGHT:
            player_move_or_attack(1, 0)
        else:
            return 'didnt-take-turn'
Пример #16
0
def handle_keys():
    global key;
 
    if key.vk == libtcod.KEY_ENTER and key.lalt:
        #Alt+Enter: toggle fullscreen
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
 
    elif key.vk == libtcod.KEY_ESCAPE:
        return 'exit'  #exit game
 
    if game_state == 'playing':
        #movement keys
        if key.vk == libtcod.KEY_UP:
            player_move_or_attack(0, -1)
 
        elif key.vk == libtcod.KEY_DOWN:
            player_move_or_attack(0, 1)
 
        elif key.vk == libtcod.KEY_LEFT:
            player_move_or_attack(-1, 0)
 
        elif key.vk == libtcod.KEY_RIGHT:
            player_move_or_attack(1, 0)
        else:
            return 'didnt-take-turn'
Пример #17
0
def menu(header, options, width):
    global key, mouse

    if len(options) > 26:
        raise ValueError('Cannot have a menu with more than 26 options.')

    header_height = tcod.console_get_height_rect(con, 0, 0, width,
                                                 SCREEN_HEIGHT, header)

    if header == '':
        header_height = 0

    height = len(options) + header_height

    window = tcod.console_new(SCREEN_WIDTH, SCREEN_HEIGHT)

    tcod.console_set_default_foreground(window, tcod.white)
    tcod.console_print_rect_ex(window, 0, 1, width, height, tcod.BKGND_NONE,
                               tcod.LEFT, header)

    y = header_height
    letter_index = ord('a')
    for option_text in options:
        text = '(' + chr(letter_index) + ') ' + option_text
        tcod.console_print_ex(window, 0, y, tcod.BKGND_NONE, tcod.LEFT, text)
        y += 1
        letter_index += 1

    x = int(SCREEN_WIDTH / 2 - width / 2)
    y = int(SCREEN_HEIGHT / 2 - height / 2)

    tcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)

    x_offset = x
    y_offset = y + header_height

    while True:
        tcod.console_flush()
        tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS | tcod.EVENT_MOUSE, key,
                                 mouse)

        if mouse.lbutton_pressed:
            (menu_x, menu_y) = (mouse.cx - x_offset, mouse.cy - y_offset)

            if 0 <= menu_x and menu_x <= width and 0 <= menu_y and menu_y < height - header_height:
                return menu_y

        if mouse.rbutton_pressed or key.vk == tcod.KEY_ESCAPE:
            return None

        if key.vk == tcod.KEY_ENTER and key.lalt:
            tcod.console_set_fullscreen(not tcod.console_is_fullscreen())

        index = key.c - ord('a')
        if index >= 0 and index < len(options):
            return index

        if index >= 0 and index <= 26:
            return None
Пример #18
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())
Пример #19
0
 def ev_keydown(self, event):
     if event.scancode == tcod.event.SCANCODE_F:
         fullscreen = not tcod.console_is_fullscreen()
         tcod.console_set_fullscreen(fullscreen)
     elif event.scancode == tcod.event.SCANCODE_Q:
         self.next_state = None  # quit
     elif event.scancode == tcod.event.SCANCODE_W:
         self.next_state = State.ENDGAME  # win
Пример #20
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())        
Пример #21
0
 def ev_keydown(self, event):
     if event.scancode == tcod.event.SCANCODE_F:
         fullscreen = not tcod.console_is_fullscreen()
         tcod.console_set_fullscreen(fullscreen)
     elif event.scancode == tcod.event.SCANCODE_Q:
         self.next_state = None  # quit
     elif event.scancode == tcod.event.SCANCODE_R:
         self.next_state = State.MAP  # restart
         self.game = build_game(self.game.root_console, self.game.draw_console)
Пример #22
0
    def ev_keydown(self, event):
        # Handle Exit on ESC
        if event.sym == tcod.event.K_ESCAPE:
            raise SystemExit()

        # Alt+Enter to toggle fullscreen mode
        elif event.sym == tcod.event.K_RETURN and (event.mod
                                                   & tcod.event.KMOD_ALT):
            tcod.console_set_fullscreen(not tcod.console_is_fullscreen())
Пример #23
0
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())
Пример #24
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 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())
Пример #25
0
def handle_keys():
    global fov_recompute, key

    if key.vk == libtcod.KEY_ENTER:
        #Alt+Enter: toggle fullscreen
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())

    elif key.vk == libtcod.KEY_ESCAPE:
        return 'exit'  #exit game

    if game_state == 'playing':
        #movement keys
        if key.vk == libtcod.KEY_UP or key.vk == libtcod.KEY_KP8:
            player_move_or_attack(0, -1)

        elif key.vk == libtcod.KEY_DOWN or key.vk == libtcod.KEY_KP2:
            player_move_or_attack(0, 1)

        elif key.vk == libtcod.KEY_LEFT or key.vk == libtcod.KEY_KP4:
            player_move_or_attack(-1, 0)

        elif key.vk == libtcod.KEY_RIGHT or key.vk == libtcod.KEY_KP6:
            player_move_or_attack(1, 0)
        elif key.vk == libtcod.KEY_KP7:
            player_move_or_attack(-1, -1)
        elif key.vk == libtcod.KEY_KP9:
            player_move_or_attack(1, -1)
        elif key.vk == libtcod.KEY_KP1:
            player_move_or_attack(-1, 1)
        elif key.vk == libtcod.KEY_KP3:
            player_move_or_attack(1, 1)
        elif key.vk == libtcod.KEY_KP5:
            pass
        else:
            key_char = chr(key.c)
            if key_char == "g":
                for object in objects:
                    if object.x == player.x and object.y == player.y and object.item:
                        object.item.pick_up()
                        break
            if key_char == "i":
                chosen_item = inventory_menu(
                    "Press the key next to an item to use it, or any other to cancel.\n"
                )
                if chosen_item is not None:
                    chosen_item.use()
            if key_char == "d":
                chosen_item = inventory_menu(
                    "Press the key next to an item to drop it, or any other to cancel.\n"
                )
                if chosen_item is not None:
                    chosen_item.drop()
            if key_char == '<':
                if stairs.x == player.x and stairs.y == player.y:
                    next_level()
            return 'didnt-take-turn'
Пример #26
0
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
Пример #27
0
    def ev_keydown(self, event):
        scancode = event.scancode
        mod = event.mod

        if (scancode == tcod.event.SCANCODE_RETURN) and (mod %
                                                         tcod.event.KMOD_LALT):
            tcod.console_set_fullscreen(not tcod.console_is_fullscreen())

        elif scancode == tcod.event.SCANCODE_I:
            self.owner.gui.inventory_menu(
                'Press the key next to an item to use it, or any other to cancel.\n'
            )

        elif scancode == tcod.event.SCANCODE_ESCAPE:
            print('Exiting')
            raise SystemExit()

        if (self.owner.game_state == 'playing') and config.DIAGONAL:
            if scancode == tcod.event.SCANCODE_KP_7:
                self.owner.player.move_or_attack(-1, -1)
            elif scancode == tcod.event.SCANCODE_KP_9:
                self.owner.player.move_or_attack(1, -1)
            elif scancode == tcod.event.SCANCODE_KP_1:
                self.owner.player.move_or_attack(-1, 1)
            elif scancode == tcod.event.SCANCODE_KP_3:
                self.owner.player.move_or_attack(1, 1)

        if self.owner.game_state == 'playing':
            if (scancode == tcod.event.SCANCODE_KP_8) or (
                    scancode == tcod.event.SCANCODE_UP):
                self.owner.player.move_or_attack(0, -1)
            elif (scancode == tcod.event.SCANCODE_KP_2) or (
                    scancode == tcod.event.SCANCODE_DOWN):
                self.owner.player.move_or_attack(0, 1)
            elif (scancode == tcod.event.SCANCODE_KP_4) or (
                    scancode == tcod.event.SCANCODE_LEFT):
                self.owner.player.move_or_attack(-1, 0)
            elif (scancode == tcod.event.SCANCODE_KP_6) or (
                    scancode == tcod.event.SCANCODE_RIGHT):
                self.owner.player.move_or_attack(1, 0)

            elif (scancode == tcod.event.SCANCODE_KP_ENTER) or (
                    scancode == tcod.event.SCANCODE_RETURN):
                for obj in self.owner.objects:
                    if (obj.x == self.owner.player.x) and (
                            obj.y == self.owner.player.y) and (obj.type
                                                               == 'item'):
                        obj.pick_up()
                        break
            else:
                self.owner.player_action = 'didnt-take-turn'
                return

            self.owner.player_action = 'took-turn'
Пример #28
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())
Пример #29
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())
Пример #30
0
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())
Пример #31
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())
Пример #32
0
def handle_keys():
    global FOV, generateMonsters, player, game_state, key, ignore_FOV

    if key.vk == libtcod.KEY_ENTER and key.lalt:
        # This makes alt + enter toggle fullscreen
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
    elif key.vk == libtcod.KEY_ESCAPE:
        return "exit"
    elif key.vk == libtcod.KEY_F1:
        ignore_FOV = not ignore_FOV

    if game_state == "playing":
        return player.get_input()
Пример #33
0
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())
def handle_keys():
    global key;
 
    if key.vk == libtcod.KEY_ENTER and key.lalt:
        #Alt+Enter: toggle fullscreen
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
 
    elif key.vk == libtcod.KEY_ESCAPE:
        return 'exit'  #exit game
 
    if game_state == 'playing':
        #movement keys
        if key.vk == libtcod.KEY_UP:
            player_move_or_attack(0, -1)
 
        elif key.vk == libtcod.KEY_DOWN:
            player_move_or_attack(0, 1)
 
        elif key.vk == libtcod.KEY_LEFT:
            player_move_or_attack(-1, 0)
 
        elif key.vk == libtcod.KEY_RIGHT:
            player_move_or_attack(1, 0)
        else:
            #test for other keys
            key_char = chr(key.c)
 
            if key_char == 'g':
                #pick up an item
                for object in objects:  #look for an item in the player's tile
                    if object.x == player.x and object.y == player.y and object.item:
                        object.item.pick_up()
                        break
 
            if key_char == 'i':
                #show the inventory; if an item is selected, use it
                chosen_item = inventory_menu('Press the key next to an item to use it, or any other to cancel.\n')
                if chosen_item is not None:
                    chosen_item.use()
 
            if key_char == 'd':
                #show the inventory; if an item is selected, drop it
                chosen_item = inventory_menu('Press the key next to an item to drop it, or any other to cancel.\n')
                if chosen_item is not None:
                    chosen_item.drop()
 
            return 'didnt-take-turn'
def menu(header, options, width):
    if len(options) > 26: raise ValueError('Cannot have a menu with more than 26 options.')
 
    #calculate total height for the header (after auto-wrap) and one line per option
    header_height = libtcod.console_get_height_rect(con, 0, 0, width, SCREEN_HEIGHT, header)
    if header == '':
        header_height = 0
    height = len(options) + header_height
 
    #create an off-screen console that represents the menu's window
    window = libtcod.console_new(width, height)
 
    #print the header, with auto-wrap
    libtcod.console_set_default_foreground(window, libtcod.white)
    libtcod.console_print_rect_ex(window, 0, 0, width, height, libtcod.BKGND_NONE, libtcod.LEFT, header)
 
    #print all the options
    y = header_height
    letter_index = ord('a')
    for option_text in options:
        text = '(' + chr(letter_index) + ') ' + option_text
        libtcod.console_print_ex(window, 0, y, libtcod.BKGND_NONE, libtcod.LEFT, text)
        y += 1
        letter_index += 1
 
    #blit the contents of "window" to the root console
    x = SCREEN_WIDTH//2 - width//2
    y = SCREEN_HEIGHT//2 - height//2
    libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
 
    #present the root console to the player and wait for a key-press
    libtcod.console_flush()
    key = libtcod.console_wait_for_keypress(True)
 
    if key.vk == libtcod.KEY_ENTER and key.lalt:  #(special case) Alt+Enter: toggle fullscreen
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
 
    #convert the ASCII code to an index; if it corresponds to an option, return it
    index = key.c - ord('a')
    if index >= 0 and index < len(options): return index
    return None
Пример #36
0
def test_console_fullscreen(console):
    libtcodpy.console_set_fullscreen(False)
def handle_keys():
    global key;
 
    if key.vk == libtcod.KEY_ENTER and key.lalt:
        #Alt+Enter: toggle fullscreen
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
 
    elif key.vk == libtcod.KEY_ESCAPE:
        return 'exit'  #exit game
 
    if game_state == 'playing':
        #movement keys
        if key.vk == libtcod.KEY_UP or key.vk == libtcod.KEY_KP8:
            player_move_or_attack(0, -1)
        elif key.vk == libtcod.KEY_DOWN or key.vk == libtcod.KEY_KP2:
            player_move_or_attack(0, 1)
        elif key.vk == libtcod.KEY_LEFT or key.vk == libtcod.KEY_KP4:
            player_move_or_attack(-1, 0)
        elif key.vk == libtcod.KEY_RIGHT or key.vk == libtcod.KEY_KP6:
            player_move_or_attack(1, 0)
        elif key.vk == libtcod.KEY_HOME or key.vk == libtcod.KEY_KP7:
            player_move_or_attack(-1, -1)
        elif key.vk == libtcod.KEY_PAGEUP or key.vk == libtcod.KEY_KP9:
            player_move_or_attack(1, -1)
        elif key.vk == libtcod.KEY_END or key.vk == libtcod.KEY_KP1:
            player_move_or_attack(-1, 1)
        elif key.vk == libtcod.KEY_PAGEDOWN or key.vk == libtcod.KEY_KP3:
            player_move_or_attack(1, 1)
        elif key.vk == libtcod.KEY_KP5:
            pass  #do nothing ie wait for the monster to come to you
        else:
            #test for other keys
            key_char = chr(key.c)
 
            if key_char == 'g':
                #pick up an item
                for object in objects:  #look for an item in the player's tile
                    if object.x == player.x and object.y == player.y and object.item:
                        object.item.pick_up()
                        break
 
            if key_char == 'i':
                #show the inventory; if an item is selected, use it
                chosen_item = inventory_menu('Press the key next to an item to use it, or any other to cancel.\n')
                if chosen_item is not None:
                    chosen_item.use()
 
            if key_char == 'd':
                #show the inventory; if an item is selected, drop it
                chosen_item = inventory_menu('Press the key next to an item to drop it, or any other to cancel.\n')
                if chosen_item is not None:
                    chosen_item.drop()
 
            if key_char == 'c':
                #show character information
                level_up_xp = LEVEL_UP_BASE + player.level * LEVEL_UP_FACTOR
                msgbox('Character Information\n\nLevel: ' + str(player.level) + '\nExperience: ' + str(player.fighter.xp) +
                    '\nExperience to level up: ' + str(level_up_xp) + '\n\nMaximum HP: ' + str(player.fighter.max_hp) +
                    '\nAttack: ' + str(player.fighter.power) + '\nDefense: ' + str(player.fighter.defense), CHARACTER_SCREEN_WIDTH)
 
            if key_char == '<':
                #go down stairs, if the player is on them
                if stairs.x == player.x and stairs.y == player.y:
                    next_level()
 
            return 'didnt-take-turn'