Пример #1
0
def handle_keys(hero, sta):
    keypress = False
    for event in tdl.event.get():
        if event.type == 'KEYDOWN':
            user_input = event
            keypress = True
    if not keypress:
        return

    if user_input.key == 'ENTER' and user_input.alt:
        # Alt+Enter: toggle fullscreen
        tdl.set_fullscreen(not tdl.get_fullscreen())

    elif user_input.key == 'ESCAPE':
        return True  # exit game

    # movement keys
    if user_input.key == 'UP':
        hero.move(0, -1, sta)

    elif user_input.key == 'DOWN':
        hero.move(0, 1, sta)

    elif user_input.key == 'LEFT':
        hero.move(-1, 0, sta)

    elif user_input.key == 'RIGHT':
        hero.move(1, 0, sta)
Пример #2
0
def handle_keys():
    global playerx, playery
    global fov_recompute
    global mouse_coord

    keypress = False
    for event in tdl.event.get():
        if event.type == 'KEYDOWN':
            user_input = event
            keypress = True
        if event.type == 'MOUSEMOTION':
            mouse_coord = event.cell

    if not keypress:
        return 'didnt-take-turn'  # TODO: Add to tutorial

    if user_input.key == 'ENTER' and user_input.alt:
        # Alt+Enter: toggle fullscreen
        tdl.set_fullscreen(not tdl.get_fullscreen())

    elif user_input.key == 'ESCAPE':
        return 'exit'  # exit game

    if game_state == 'playing':
        # movement keys
        if user_input.key == 'UP':
            player_move_or_attack(0, -1)

        elif user_input.key == 'DOWN':
            player_move_or_attack(0, 1)

        elif user_input.key == 'LEFT':
            player_move_or_attack(-1, 0)

        elif user_input.key == 'RIGHT':
            player_move_or_attack(1, 0)
        else:
            # test for other keys
            if user_input.text == 'g':
                # pick up an item
                for obj in objects:  # look for an item in the player's tile
                    if obj.x == player.x and obj.y == player.y and obj.item:
                        obj.item.pick_up()
                        break

            if user_input.text == '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 user_input.text == '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'
Пример #3
0
def handle_keys():
	global playerx, playery
	global fov_recompute

	user_input = tdl.event.key_wait()

	if user_input.key == 'ENTER' and user_input.alt:
		#Alt-Enter: toggle fullscreen
		tdl.set_fullscreen(not tdl.get_fullscreen())

	elif user_input.key == 'ESCAPE':
		return 'exit'   # exit game

	if game_state == 'playing':
		# Movement keys
		if user_input.key == 'UP':
			player_move_or_attack(0, -1)
			fov_recompute = True

		elif user_input.key == 'DOWN':
			player_move_or_attack(0, 1)
			fov_recompute = True

		elif user_input.key == 'LEFT':
			player_move_or_attack(-1, 0)
			fov_recompute = True

		elif user_input.key == 'RIGHT':
			player_move_or_attack(1, 0)
			fov_recompute = True
		else:
			return 'didnt_take_turn'
Пример #4
0
def handle_keys():
    global fov_recompute

    user_input = tdl.event.key_wait()  #I don't understand what this does?

    if user_input.key == "ENTER" and user_input.alt:  #Fullscreen, enter/exit
        tdl.set_fullscreen(not tdl.get_fullscreen())

    elif user_input.key == "ESCAPE":  #quit game
        return "exit"

    if game_state == "playing":
        if user_input.key == "UP":
            player_move_or_attack(0, -1)

        elif user_input.key == "DOWN":
            player_move_or_attack(0, 1)

        elif user_input.key == "LEFT":
            player_move_or_attack(-1, 0)

        elif user_input.key == "RIGHT":
            player_move_or_attack(1, 0)

        else:
            return "didnt-take-turn"
Пример #5
0
def handle_keys():
    global playerx, playery
    """
    # realtime-based game
    keypress = False
    for event in tdl.event.get():
        if event.type == 'KEYDOWN':
           user_input = event
           keypress = True
    if not keypress:
        return
    """

    # turn-based game
    user_input = tdl.event.key_wait()

    if user_input.key == 'ENTER' and user_input.alt:
        # Alt+Enter: toggle fullscreen
        tdl.set_fullscreen(not tdl.get_fullscreen())
    elif user_input.key == 'ESCAPE':
        return True  # exit game

    # movement keys
    if user_input.key == 'UP':
        playery -= 1
    elif user_input.key == 'DOWN':
        playery += 1
    elif user_input.key == 'LEFT':
        playerx -= 1
    elif user_input.key == 'RIGHT':
        playerx += 1
Пример #6
0
def handle_keys(realtime):

    if realtime:
        keypress = False
        for event in tdl.event.get():
            if event.type == 'KEYDOWN':
                user_input = event
                keypress = True
        if not keypress:
            return

    else:  # turn-based
        user_input = tdl.event.key_wait()

    if user_input.key == 'ENTER' and user_input.alt:
        # Alt+Enter: toggle fullscreen
        tdl.set_fullscreen(not tdl.get_fullscreen())

    elif user_input.key == 'ESCAPE':
        return True  # exit game

    # movement keys
    if user_input.key == 'UP':
        player.move(0, -1)
    elif user_input.key == 'DOWN':
        player.move(0, 1)
    elif user_input.key == 'LEFT':
        player.move(-1, 0)
    elif user_input.key == 'RIGHT':
        player.move(1, 0)
Пример #7
0
def handle_keys():
    global fov_recompute
    user_input = tdl.event.key_wait()

    if user_input.key == 'ENTER' and user_input.alt:
        #Alt+Enter: toggle fullscreen
        tdl.set_fullscreen(not tdl.get_fullscreen())

    elif user_input.key == 'ESCAPE':
        return True  #exit game
    #movement keys
    if user_input.key == 'UP':
        player.move(0, -1)
        fov_recompute = True

    elif user_input.key == 'DOWN':
        player.move(0, 1)
        fov_recompute = True

    elif user_input.key == 'LEFT':
        player.move(-1, 0)
        fov_recompute = True

    elif user_input.key == 'RIGHT':
        player.move(1, 0)
        fov_recompute = True
Пример #8
0
def handle_keys():
    global playerx, playery
    global fov_recompute

    user_input = tdl.event.key_wait()

    if user_input.key == "ENTER" and user_input.alt:
        # Alt+enter: toggle fullscreen mode
        tdl.set_fullscreen(not tdl.get_fullscreen())

    elif user_input.key == "ESCAPE":
        return "exit"  # escape to exit game

    if game_state == "playing":
        # movement keys
        if user_input.key == "UP":
            player_move_or_attack(0, -1)

        elif user_input.key == "DOWN":
            player_move_or_attack(0, 1)

        elif user_input.key == "LEFT":
            player_move_or_attack(-1, 0)

        elif user_input.key == "RIGHT":
            player_move_or_attack(1, 0)

        else:
            return "didnt-take-turn"
Пример #9
0
    def _handle_keys(self):
        user_input = tdl.event.key_wait()

        if user_input.key == 'ENTER' and user_input.alt:
            # Alt+Enter: toggle fullscreen
            tdl.set_fullscreen(not tdl.get_fullscreen())
        elif user_input.key == '0':
            return True  # exit game

        if user_input.key == 'KP8':
            if self._is_legal_move(0, -1):
                self.player.move(0, -1)
        elif user_input.key == 'KP9':
            if self._is_legal_move(1, -1):
                self.player.move(1, -1)
        elif user_input.key == 'KP6':
            if self._is_legal_move(1, 0):
                self.player.move(1, 0)
        elif user_input.key == 'KP3':
            if self._is_legal_move(1, 1):
                self.player.move(1, 1)
        elif user_input.key == 'KP2':
            if self._is_legal_move(0, 1):
                self.player.move(0, 1)
        elif user_input.key == 'KP1':
            if self._is_legal_move(-1, 1):
                self.player.move(-1, 1)
        elif user_input.key == 'KP4':
            if self._is_legal_move(-1, 0):
                self.player.move(-1, 0)
        elif user_input.key == 'KP7':
            if self._is_legal_move(-1, -1):
                self.player.move(-1, -1)
        elif user_input.key == 'KP5':
            print(str(self.player.x) + ', ' + str(self.player.y))
Пример #10
0
def handle_keys():
    global playerx, playery

    #turn base mode
    user_input = tdl.event.key_wait()

    #realtime
    # =============================================================================
    #     keypress = False
    #     for event in tdl.event.get():
    #         if event.type == 'KEYDOWN':
    #            user_input = event
    #            keypress = True
    #     if not keypress:
    #         return
    #
    # =============================================================================
    #extra functions
    if user_input.key == 'ENTER' and user_input.alt:
        #Alt+Enter: toggle fullscreen
        tdl.set_fullscreen(not tdl.get_fullscreen())
    elif user_input.key == 'ESCAPE':
        return True  #exit game

    #movement keys
    if user_input.key == 'UP':
        playery -= 1
    elif user_input.key == 'DOWN':
        playery += 1
    elif user_input.key == 'LEFT':
        playerx -= 1
    elif user_input.key == 'RIGHT':
        playerx += 1
Пример #11
0
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 textwrap) and one
    # line per option
    header_wrapped = []
    for header_line in header.splitlines():
        header_wrapped.extend(textwrap.wrap(header_line, width))
    header_height = len(header_wrapped)
    if header == '':
        header_height = 0
    height = len(options) + header_height

    # create an off-screen console that represents the menu's window
    window = tdl.Console(width, height)

    window.draw_rect(0,
                     0,
                     width,
                     height,
                     None,
                     fg=roguecolors.white,
                     bg=roguecolors.dark_grey)
    # print the header, with wrapped text
    for i, line in enumerate(header_wrapped):
        window.draw_str(0, 0 + i, header_wrapped[i], bg=None)

    y = header_height
    # now, print each item, one by line
    letter_index = ord('a')
    for option_text in options:
        text = '(' + chr(letter_index) + ') ' + option_text
        window.draw_str(0, y, text, bg=None)
        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
    root.blit(window, x, y, width, height, 0, 0)

    # present the root console to the player and wait for a key-press
    tdl.flush()
    key = tdl.event.key_wait()
    key_char = key.char
    if key_char == '':
        key_char = ' '  # placeholder

    if key.key == 'ENTER' and key.alt:  # Alt+Enter: toggle fullscreen
        tdl.set_fullscreen(not tdl.get_fullscreen())

    # convert the ASCII code to an index; if it corresponds to an
    # option, return it
    index = ord(key_char) - ord('a')
    if index >= 0 and index < len(options):
        return index
    return None
Пример #12
0
def main():
    screen_width = 80
    screen_height = 50
    map_width = 80
    map_height = 45

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

    player = Entity(int(screen_width / 2), int(screen_height / 2), '@',
                    (255, 255, 255))
    npc = Entity(int(screen_width / 2 - 5), int(screen_height / 2), '@',
                 (255, 255, 0))
    entities = [npc, player]

    tdl.set_font('arial10x10.png', greyscale=True, altLayout=True)

    root_console = tdl.init(screen_width,
                            screen_height,
                            title='Roguelike Tutorial Revised')
    con = tdl.Console(screen_width, screen_height)

    game_map = tdl.map.Map(map_width, map_height)
    make_map(game_map)

    while not tdl.event.is_window_closed():
        render_all(con, entities, game_map, root_console, screen_width,
                   screen_height, colors)
        tdl.flush()

        clear_all(con, entities)

        for event in tdl.event.get():
            if event.type == 'KEYDOWN':
                user_input = event
                break
        else:
            user_input = None

        if not user_input:
            continue

        action = handle_keys(user_input)

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

        if move:
            dx, dy = move

            if game_map.walkable[player.x + dx, player.y + dy]:
                player.move(dx, dy)

        if exit:
            return True

        if fullscreen:
            tdl.set_fullscreen(not tdl.get_fullscreen())
Пример #13
0
    def handle_key_input(cls):
        """
        Use tdl's user input features to react to keyborad input.

        Returns:
            True if an action that consumes a turn was performed by the player, False otherwise.
        """
        # TODO: Have key mapping in config file and use enums (or something similar) instead
        if not cls.user_input:
            return False

        key_char = cls.user_input.char

        move_direction = None
        # Vertical and horizontal movement
        if cls.user_input.key == 'UP' or key_char == 'k':
            move_direction = Vector(0, -1)
        elif cls.user_input.key == 'DOWN' or key_char == 'j':
            move_direction = Vector(0, 1)
        elif cls.user_input.key == 'LEFT' or key_char == 'h':
            move_direction = Vector(-1, 0)
        elif cls.user_input.key == 'RIGHT' or key_char == 'l':
            move_direction = Vector(1, 0)

        # Diagonal movement
        elif key_char == 'y':
            move_direction = Vector(-1, -1)
        elif key_char == 'u':
            move_direction = Vector(1, -1)
        elif key_char == 'b':
            move_direction = Vector(-1, 1)
        elif key_char == 'n':
            move_direction = Vector(1, 1)

        # Check if the action is a movement action
        if move_direction is not None:
            return cls.movement_action(move_direction)

        if cls.user_input.key == 'ENTER' and cls.user_input.alt:
            # Alt+Enter: toggle fullscreen
            tdl.set_fullscreen(not tdl.get_fullscreen())
            return False

        elif cls.user_input.key == 'ESCAPE':
            # Exit game
            # TODO: Find more elegant way to terminate the program
            exit()

        elif cls.user_input.char == 'g':
            return cls.pickup_action()

        elif cls.user_input.char == 'e':
            return cls.interact_action()

        else:
            return False
Пример #14
0
def handle_keys():
    user_input = handle_realtime_keys() if REALTIME else handle_turnbased_keys(
    )
    if not user_input:
        return
    if user_input.key == 'ENTER' and user_input.alt:
        tdl.set_fullscreen(not tdl.get_fullscreen())
    elif user_input.key == 'ESCAPE':
        return True  # exit game
    moved = objects['player'].handle_key(key=user_input.key,
                                         tile_map=map.tiles)
def handle_keys():
    global playerx, playery, fov_recompute, mouse_coord

    keypress = False
    for event in tdl.event.get():
        if event.type == 'KEYDOWN':
            user_input = event
            keypress = True
        if event.type == 'MOUSEMOTION':
            mouse_coord = event.cell

    if not keypress:
        return 'didnt-take-turn'

    if game_state == 'playing':
        #movement keys
        if user_input.key == 'UP':
            player_move_or_attack(0, -1)
            fov_recompute = True

        elif user_input.key == 'DOWN':
            player_move_or_attack(0, 1)
            fov_recompute = True

        elif user_input.key == 'LEFT':
            player_move_or_attack(-1, 0)
            fov_recompute = True

        elif user_input.key == 'RIGHT':
            player_move_or_attack(1, 0)
            fov_recompute = True

        elif user_input.key == 'ENTER' and user_input.alt:
            #Alt+Enter: toggle fullscreen
            tdl.set_fullscreen(not tdl.get_fullscreen())

        elif user_input.key == 'ESCAPE':
            return 'exit'  #exit game

        elif user_input.text == 'g':
            #pick up an item
            for obj in objects:  #look for an item in the player's tile
                if obj.x == player.x and obj.y == player.y and obj.item:
                    obj.item.pick_up(message, inventory, objects)
                    break
        elif user_input.text == 'i':
            #show the inventory
            inventory_menu(
                'Press the key next to an item to use it, or any other to cancel.\n'
            )

        else:

            return 'didnt-take-turn'
Пример #16
0
def menu(header,options,width):
    if len(options) > 26: raise ValueError('Cannot have a menu with more than 26 options')
    header_wrapped = []
    for header_line in header.splitlines():
        header_wrapped.extend(textwrap.wrap(header_line, width))

    header_height = len(header_wrapped)
    height = len(options) + header_height

    #create an off-screen console that represents the menu's window
    window = tdl.Console(width,height)

    #print header with wrapped text
    window.draw_rect(0,0,width,height,None,fg=colors.white,bg=None)
    for i, line in enumerate(header_wrapped):
        window.draw_str(0,0+i,header_wrapped[i])

    y = header_height
    letter_index = ord('a') #this returns ASCII code of "a"
    for option_text in options:
        text = '('+chr(letter_index) + ')  ' + option_text
        window.draw_str(0,y,text,bg=None)
        y += 1
        letter_index += 1

    #blit contents of window to root
    x = SCREEN_WIDTH//2 - width//2
    y = SCREEN_HEIGHT//2 - height//2
    root.blit(window,x,y,width,height,0,0)

    #present root and wait for key press
    tdl.flush()
    key = tdl.event.key_wait()
    key_char = key.char
    if key_char == '':
        key_char = ' ' #placeholder

    if key.key == 'ENTER' and key.alt:
        #toggle fullscreen
        tdl.set_fullscreen(not tdl.get_fullscreen())

    #convert ASCII code to an index, if it corrosponds to option, return it
    index = ord(key_char) - ord('a')
    if index >= 0 and index < len(options):
        return index
    return None
Пример #17
0
    def input(self):
        for event in tdl.event.get():
            action = self.handle_input(event)

            if action:
                if action.get('move'):
                    self.player.move_or_attack(*action.get('move'))
                if action.get('rest'):
                    self.update_sim = True
                if action.get('exit'):
                    self.is_done = True
                if action.get('open'):
                    print(
                        "Example of a command that does **not** update simulation"
                    )
                if action.get('fullscreen'):
                    tdl.set_fullscreen(not tdl.get_fullscreen())
Пример #18
0
def handle_keys():

    user_input = tdl.event.key_wait()  #I don't understand what this does?

    if user_input.key == "ENTER" and user_input.alt:  #Fullscreen, enter/exit
        tdl.set_fullscreen(not tdl.get_fullscreen())
    elif user_input.key == "ESCAPE":  #quit game
        return True

    if user_input.key == "UP":
        player.move(0, -1)
    elif user_input.key == "DOWN":
        player.move(0, 1)
    elif user_input.key == "LEFT":
        player.move(-1, 0)
    elif user_input.key == "RIGHT":
        player.move(1, 0)
Пример #19
0
def handle_keys():
    global player_x, player_y
    user_input = tdl.event.key_wait()
    #movement keys
    if user_input.key == 'UP':
        player_y -= 1
    elif user_input.key == 'DOWN':
        player_y += 1
    elif user_input.key == 'LEFT':
        player_x -= 1
    elif user_input.key == 'RIGHT':
        player_x += 1
    #toggle fullscreen and exit game
    if user_input.key == 'ENTER' and user_input.alt:
        tdl.set_fullscreen(not tdl.get_fullscreen())
    elif user_input.key == 'ESCAPE':
        return True
Пример #20
0
def handle_keys(realtime):
    # global playerx, playery

    if realtime:
        keypress = False
        for event in tdl.event.get():
            if event.type == 'KEYDOWN':
                user_input = event
                keypress = True
        if not keypress:
            return

    else:  #turn-based
        user_input = tdl.event.key_wait()

    if user_input.key == 'ENTER' and user_input.alt:
        #Alt+Enter: toggle fullscreen
        tdl.set_fullscreen(tdl.get_fullscreen())

    elif user_input.key == 'ESCAPE':
        return True  #exit game

    #movement keys
    if user_input.key == 'KP8':
        player.move(0, -1)

    elif user_input.key == 'KP2':
        player.move(0, 1)

    elif user_input.key == 'KP4':
        player.move(-1, 0)

    elif user_input.key == 'KP6':
        player.move(1, 0)

    elif user_input.key == 'KP7':
        player.move(-1, -1)

    elif user_input.key == 'KP9':
        player.move(1, -1)

    elif user_input.key == 'KP1':
        player.move(-1, 1)

    elif user_input.key == 'KP3':
        player.move(1, 1)
Пример #21
0
def handle_keys():
    """
        This version use keypad (hence KP?). Not tested.
    """
    global fov_recompute
    global mouse_coord

    keypress = False
    for event in tdl.event.get():
        if event.type == 'KEYDOWN':
            user_input = event
            keypress = True
        if event.type == 'MOUSEMOTION':
            mouse_coord = event.cell

    if not keypress:
        return 'didnt-take-turn'

    if user_input.key == 'ENTER' and user_input.alt:
        # Alt+Enter: toggle fullscreen
        tdl.set_fullscreen(not tdl.get_fullscreen())

    elif user_input.key == 'ESCAPE':
        return 'exit'  # exit game

    if game_state == 'playing':
        # movement keys
        if user_input.key == 'UP' or user_input.key == 'KP8':
            player_move_or_attack(0, -1)
        elif user_input.key == 'DOWN' or user_input.key == 'KP2':
            player_move_or_attack(0, 1)
        elif user_input.key == 'LEFT' or user_input.key == 'KP4':
            player_move_or_attack(-1, 0)
        elif user_input.key == 'RIGHT' or user_input.key == 'KP6':
            player_move_or_attack(1, 0)
        elif user_input.key == 'HOME' or user_input.key == 'KP7':
            player_move_or_attack(-1, -1)
        elif user_input.key == 'PAGEUP' or user_input.key == 'KP9':
            player_move_or_attack(1, -1)
        elif user_input.key == 'END' or user_input.key == 'KP1':
            player_move_or_attack(-1, 1)
        elif user_input.key == 'PAGEDOWN' or user_input.key == 'KP3':
            player_move_or_attack(1, 1)
        elif user_input.key == 'KP5':
            pass  # do nothing ie wait for the monster to come to you
Пример #22
0
def main():
    screen_width = 80
    screen_height = 50

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

    tdl.set_font('arial10x10.png', greyscale=True, altLayout=True)

    root_console = tdl.init(screen_width, screen_height, title='Cloudstar')
    con = tdl.Console(screen_width, screen_height)

    while not tdl.event.is_window_closed():
        con.draw_char(player_x, player_y, '@', bg=None, fg=(255, 255, 255))
        root_console.blit(con, 0, 0, screen_width, screen_height, 0, 0)
        tdl.flush()

        con.draw_char(player_x, player_y, ' ', bg=None)

        for event in tdl.event.get():
            if event.type == 'KEYDOWN':
                user_input = event
                break
        else:
            user_input = None

        if not user_input:
            continue

        action = handle_keys(user_input)

        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:
            tdl.set_fullscreen(not tdl.get_fullscreen())
Пример #23
0
def handle_keys():
    global playerx, playery
    global fov_recompute

    if REALTIME:
        keypress = False
        for event in tdl.event.get():
            if event.type == 'KEYDOWN':
                user_input = event
                keypress = True

    user_input = tdl.event.key_wait()
    if game_state == 'playing':

        if user_input.key == 'UP':
            player_move_or_attack(0, -1)
            fov_recompute = True

        elif user_input.key == 'DOWN':
            player_move_or_attack(0, 1)
            fov_recompute = True

        elif user_input.key == 'LEFT':
            player_move_or_attack(-1, 0)
            fov_recompute = True

        elif user_input.key == 'RIGHT':
            player_move_or_attack(1, 0)
            fov_recompute = True

    if user_input.key == 'ENTER' and user_input.alt:
        tdl.set_fullscreen(not tdl.get_fullscreen())

    elif user_input.key == 'ESCAPE':
        return 'exit'

    else:
        return 'didnt-take-turn'

    for obj in objects:
        obj.clear()

    for obj in objects:
        obj.draw()
Пример #24
0
def handle_keys():
    global playerx, playery
    global fov_recompute
 
    if REALTIME:
        keypress = False
        for event in tdl.event.get():
            if event.type == 'KEYDOWN':
               user_input = event
               keypress = True
        if not keypress:
            return

    else: #turn-based
        user_input = tdl.event.key_wait()
 
    if user_input.key == 'ENTER' and user_input.alt:
        #Alt+Enter: toggle fullscreen
        tdl.set_fullscreen(not tdl.get_fullscreen())
 
    elif user_input.key == 'ESCAPE':
        return 'exit'  #exit game
 
    if game_state == 'playing':
        #movement keys
        if user_input.key == 'UP':
            player_move_or_attack(0, -1)
            fov_recompute = True
    
        elif user_input.key == 'DOWN':
            player_move_or_attack(0, 1)
            fov_recompute = True
        
        elif user_input.key == 'LEFT':
            player_move_or_attack(-1, 0)
            fov_recompute = True
        
        elif user_input.key == 'RIGHT':
            player_move_or_attack(1, 0)
            fov_recompute = True

    else:
        return 'didnt_take_turn'
Пример #25
0
def handle_keys():
    """ """
    global fov_recompute
    global mouse_coord

    keypress = False
    for event in tdl.event.get():
        if event.type == 'KEYDOWN':
            user_input = event
            keypress = True
        if event.type == 'MOUSEMOTION':
            mouse_coord = event.cell

    if not keypress:
        return 'didnt-take-turn'

    if user_input.key == 'ENTER' and user_input.alt:
        # Alt+Enter: toggle fullscreen
        tdl.set_fullscreen(not tdl.get_fullscreen())

    elif user_input.key == 'ESCAPE':
        return 'exit'  # exit game

    if game_state == 'playing':
        # movement keys
        if user_input.key == 'UP':
            player_move_or_attack(0, -1)

        elif user_input.key == 'DOWN':
            player_move_or_attack(0, 1)

        elif user_input.key == 'LEFT':
            player_move_or_attack(-1, 0)

        elif user_input.key == 'RIGHT':
            player_move_or_attack(1, 0)

        elif user_input.key == 'SPACE':
            return 'didnt-take-turn'

        else:
            return 'didnt-take-turn'
Пример #26
0
def handle_keys():
    global fov_recompute
    global game_state
    global mouse_coord

    keypress = False
    for event in tdl.event.get():
        if event.type == "KEYDOWN":
            user_input = event
            keypress = True
        if event.type == "MOUSEMOTION":
            mouse_coord = event.cell

    if not keypress:
        return "didnt_take_a_turn"

    if user_input.key == "ENTER" and user_input.alt:
        tdl.set_fullscreen(not tdl.get_fullscreen())
    elif user_input.key == "ESCAPE":
        return "exit"

    if game_state == "playing":
        if user_input.key == "KP8":
            player_move_or_attack(0, -1)
        elif user_input.key == "CHAR":
            player_move_or_attack(0, 0)
        elif user_input.key == "KP9":
            player_move_or_attack(1, -1)
        elif user_input.key == "KP7":
            player_move_or_attack(-1, -1)
        elif user_input.key == "KP2":
            player_move_or_attack(0, 1)
        elif user_input.key == "KP4":
            player_move_or_attack(-1, 0)
        elif user_input.key == "KP6":
            player_move_or_attack(1, 0)
        elif user_input.key == "KP1":
            player_move_or_attack(-1, 1)
        elif user_input.key == "KP3":
            player_move_or_attack(1, 1)
        else:
            return "didnt_take_a_turn"
Пример #27
0
def handle_keys(game_object):
    user_input = tdl.event.key_wait()

    if user_input.key == 'ESCAPE':
        return True

    if user_input.key == 'ENTER' and user_input.alt:
        tdl.set_fullscreen(not tdl.get_fullscreen())

    if user_input.key == 'UP':
        game_object.move(0, -1)

    if user_input.key == 'DOWN':
        game_object.move(0, 1)

    if user_input.key == 'LEFT':
        game_object.move(-1, 0)

    if user_input.key == 'RIGHT':
        game_object.move(1, 0)
Пример #28
0
def handle_keys():
    global player, map

    user_input = tdl.event.key_wait()
    if user_input.key == 'ENTER' and user_input.alt:
        # Alt+Enter: toggle fullscreen
        tdl.set_fullscreen(not tdl.get_fullscreen())

    elif user_input.key == 'ESCAPE':
        return True  # exit game
    # movement keys
    if user_input.key == 'UP':
        map.moveobject((player.x, player.y), (player.x, player.y - 1))

    elif user_input.key == 'DOWN':
        map.moveobject((player.x, player.y), (player.x, player.y + 1))

    elif user_input.key == 'LEFT':
        map.moveobject((player.x, player.y), (player.x - 1, player.y))

    elif user_input.key == 'RIGHT':
        map.moveobject((player.x, player.y), (player.x + 1, player.y))
Пример #29
0
def handle_keys(realtime):  # TODO: Add tests
    """Handle user input.

    Alt+Enter toggles full-screen mode.
    Escape exits the game.
    Arrow keys move the player character.

    """
    global player_x, player_y

    if realtime:
        keypress = False
        for event in tdl.event.get():
            if event.type == 'KEYDOWN':
                user_input = event
                keypress = True
        if not keypress:
            return
    else:
        user_input = tdl.event.key_wait()

    if user_input.key == 'ENTER' and user_input.alt:
        tdl.set_fullscreen(not tdl.get_fullscreen())

    elif user_input.key == 'ESCAPE':
        return True

    if user_input.key == 'UP':
        player.move(0, -1)

    elif user_input.key == 'DOWN':
        player.move(0, 1)

    elif user_input.key == 'LEFT':
        player.move(-1, 0)

    elif user_input.key == 'RIGHT':
        player.move(1, 0)
Пример #30
0
def handle_keys():
    # turn-based (because "key_wait", well, waits for user input
    user_input = tdl.event.key_wait()

    if user_input.key == 'ENTER' and user_input.alt:
        # Alt+Enter: toggle fullscreen
        tdl.set_fullscreen(not tdl.get_fullscreen())

    elif user_input.key == 'ESCAPE':
        return True  # exit game

    # movement keys
    if user_input.key == 'UP':
        player.move(0, -1)

    elif user_input.key == 'DOWN':
        player.move(0, 1)

    elif user_input.key == 'LEFT':
        player.move(-1, 0)

    elif user_input.key == 'RIGHT':
        player.move(1, 0)