def key_input(self): ##============================================================================ ##Menu Keyboard Input key = libtcod.console_check_for_keypress() index = key.c - ord('a') if key.vk == libtcod.KEY_ENTER and key.lalt: libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen()) if key.vk == libtcod.KEY_ESCAPE: libtcod.console_check_for_keypress() return 'close' if key: if index >= 0 and index < len(self.options): libtcod.console_check_for_keypress() return index #if key.vk == libtcod.KEY_DOWN: # current_pick = (current_pick +1) % len(self.options) #if key.vk == libtcod.KEY_UP: # current_pick = (current_pick -1) % len(self.options) #if key.vk == libtcod.KEY_ENTER: # return current_pick return -1
def key_input(self): ##============================================================================ ##Menu Keyboard Input key = libtcod.console_check_for_keypress() index = key.c - ord('a') if key.vk == libtcod.KEY_ENTER and key.lalt: libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen()) if key.vk == libtcod.KEY_ESCAPE: libtcod.console_check_for_keypress() return 'close' if key: if index >= 0 and index < len(self.options): libtcod.console_check_for_keypress() return index #if key.vk == libtcod.KEY_DOWN: # current_pick = (current_pick +1) % len(self.options) #if key.vk == libtcod.KEY_UP: # current_pick = (current_pick -1) % len(self.options) #if key.vk == libtcod.KEY_ENTER: # return current_pick return -1
def display_box(self): ##============================================================================ input = -1 while input == -1: input = self.run() libtcod.mouse_get_status() libtcod.console_check_for_keypress() return input
def display_box(self): ##============================================================================ input = -1 while input == -1: input = self.run() libtcod.mouse_get_status() libtcod.console_check_for_keypress() return input
def key_input(self): key = libtcod.console_check_for_keypress() if key.vk == libtcod.KEY_ENTER or key.vk == libtcod.KEY_SPACE: libtcod.console_check_for_keypress() return 1 if key.vk == libtcod.KEY_ESCAPE: libtcod.console_check_for_keypress() return 0 return -1
def key_input(self): key = libtcod.console_check_for_keypress() if key.vk == libtcod.KEY_ENTER or key.vk == libtcod.KEY_SPACE: libtcod.console_check_for_keypress() return 1 if key.vk == libtcod.KEY_ESCAPE: libtcod.console_check_for_keypress() return 0 return -1
def take_turn(self): action = None control_map = { lt.KEY_ESCAPE: (self.leave_game, None), # Movement Keys lt.KEY_KP5: (self.move, (0, 0)), lt.KEY_KP7: (self.move, (-1, -1)), lt.KEY_KP8: (self.move, (0, -1)), lt.KEY_KP9: (self.move, (1, -1)), lt.KEY_KP4: (self.move, (-1, 0)), lt.KEY_KP6: (self.move, (1, 0)), lt.KEY_KP1: (self.move, (-1, 1)), lt.KEY_KP2: (self.move, (0, 1)), lt.KEY_KP3: (self.move, (1, 1)), # Item Keys ord('i'): (menus.render_inventory, (player, area.con)), ord('g'): (self.pickup, None), ord('d'): (self.drop, None) } while True: key = lt.console_check_for_keypress(lt.KEY_PRESSED) handler, param = (None, None) if key.vk in control_map.keys(): handler, param = control_map[key.vk] elif key.c in control_map.keys(): handler, param = control_map[key.c] if param: action = handler(param) elif handler: action = handler() if action: return action
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
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 True #exit game if libtcod.console_is_key_pressed(libtcod.KEY_SPACE): shoot() #movement keys if libtcod.console_is_key_pressed(libtcod.KEY_UP): player.move(0, -1) player.char = '^' elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN): player.move(0, 1) player.char = 'v' elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT): player.move(-1, 0) player.char = '<' elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT): player.move(1, 0) player.char = '>'
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' # change to 'playing' if real time
def splashScreen(console): libtcod.console_set_default_background(console, SPLASH_BACKGROUND_COLOUR) libtcod.console_clear(console) done = False counter = 0 blinkOn = True blinkSpeed = 10 while not done and not libtcod.console_is_window_closed(): key = libtcod.console_check_for_keypress(True) if not key.vk == libtcod.KEY_NONE: done = True #print the splash messages libtcod.console_set_default_foreground(console, SPLASH_FOREGROUND_COLOUR1) libtcod.console_print_rect(console, 4, 5, SCREEN_WIDTH, SCREEN_HEIGHT, "SWORD SHOP") libtcod.console_set_default_foreground(console, SPLASH_FOREGROUND_COLOUR2) libtcod.console_print_rect(console, 4, 8, SCREEN_WIDTH, SCREEN_HEIGHT, "by luke david\n fitzpatrick") if(blinkOn): libtcod.console_set_default_foreground(console, SPLASH_FOREGROUND_COLOUR3) libtcod.console_print_rect(console, 16, 13, SCREEN_WIDTH, SCREEN_HEIGHT, "press any key") # blit the panel to the screen libtcod.console_blit(console, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-(2*6), 0, 0, 6) libtcod.console_flush() counter += 1 if counter >= blinkSpeed: counter = 0 blinkOn = not blinkOn libtcod.console_clear(console)
def storyScreen(console): libtcod.console_set_default_background(console, STORY_BACKGROUND_COLOUR1) libtcod.console_clear(console) done = False counter = 0 blinkOn = True blinkSpeed = 10 while not done and not libtcod.console_is_window_closed(): key = libtcod.console_check_for_keypress(True) if not key.vk == libtcod.KEY_NONE: done = True #print the story message libtcod.console_set_default_foreground(console, STORY_FOREGROUND_COLOUR1) libtcod.console_print_rect(console, 1, 3, SCREEN_WIDTH, SCREEN_HEIGHT, STORY_TEXT1) if(blinkOn): libtcod.console_set_default_foreground(console, SPLASH_FOREGROUND_COLOUR3) libtcod.console_print_rect(console, 16, 22, SCREEN_WIDTH, SCREEN_HEIGHT, "press any key") # blit the panel to the screen libtcod.console_blit(console, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-(2*1), 0, 0, 1) libtcod.console_flush() counter += 1 if counter >= blinkSpeed: counter = 0 blinkOn = not blinkOn libtcod.console_clear(console) libtcod.console_clear(console)
def handle_keys(): global dirx, diry key = libtcod.console_check_for_keypress() #real-time 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) and diry == 0: dirx = 0 diry = -1 elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN) and diry == 0: dirx = 0 diry = 1 elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT) and dirx == 0: dirx = -1 diry = 0 elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT) and dirx == 0: dirx = 1 diry = 0
def handle_keys(): global playerx, playery #fullscreen mode key = libtcod.console_check_for_keypress(libtcod.KEY_PRESSED) if key.vk == libtcod.KEY_ENTER and key.lalt: #alt + enter toggles fullscreen libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen()) #exit game elif key.vk == libtcod.KEY_ESCAPE: return True #movement keys, WASD if key.vk == libtcod.KEY_CHAR: if key.c == ord('w'): playery -= 1 elif key.c == ord('s'): playery += 1 elif key.c == ord('a'): playerx -= 1 elif key.c == ord('d'): playerx += 1
def target_tile(max_range=None): #return the position of a tile left-clicked in player's FOV (optionally in a range), or (None,None) if right-clicked. while True: render_all(True) #render the screen. this erases the inventory and shows the names of objects under the mouse. libtcod.console_flush() for object in objects: object.draw() key = libtcod.console_check_for_keypress() mouse = libtcod.mouse_get_status() #get mouse position and click status (x, y) = (mouse.cx, mouse.cy) if mouse.rbutton_pressed or key.vk == libtcod.KEY_ESCAPE: for object in objects: object.clear() return (None, None) #cancel if the player right-clicked or pressed Escape #accept the target if the player clicked in FOV, and in case a range is specified, if it's in that range if (mouse.lbutton_pressed and libtcod.map_is_in_fov(fov_map, x, y) and (max_range is None or player.distance(x, y) <= max_range)): for object in objects: object.clear() return (x, y)
def handle_keys(): global player global fov_recompute # REAL TIME PLAY key = tcod.console_check_for_keypress() 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 game_state == 'playing': if player.wait > 0: player.wait -= 1 return 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'
def handle_keys(): key = libtcod.console_check_for_keypress(True) if key.vk == libtcod.KEY_ENTER and key.lalt: libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen()) elif key.vk == libtcod.KEY_ESCAPE: return 'exit' if game_state == 'playing': #Movement Keys if libtcod.console_is_key_pressed(libtcod.KEY_UP): player.move_attack(0, -1, game_map, objects) fov_recompute_set() elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN): player.move_attack(0, 1, game_map, objects) fov_recompute_set() elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT): player.move_attack(-1, 0, game_map, objects) fov_recompute_set() elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT): player.move_attack(1, 0, game_map, objects) fov_recompute_set() else: return 'didnt-take-turn'
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
def handle_keys(): global playerx, playery global fov_recompute # fullscreen and enter key = libtcod.console_check_for_keypress() 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 # movement if game_state == 'playing': 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 else: return 'didnt-take-turn'
def handle_keys(): global GUI_info global current_menu global draw_cursor #Gets current menu to make sure we haven't tryed to change menu_string = current_menu.title key = libtcod.console_check_for_keypress() #real-time 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 #Handle the key press with the Event Handler key_press = E.return_key() #Pass that to the menu to figure out what to do with it menu_string = current_menu.handle_input(key_press, GUI_info) #Should we render the cursor? if current_menu.title == "Look" or current_menu.title == "City": draw_cursor = True else: draw_cursor = False #Do we need to change our menu? Also check to make sure its not a null pointer if menu_string != current_menu.title and menu_string is not None: current_menu = menus[menu_string]
def handle_keys(state): """Handles key inputs from the PLAYER. UP/DOWN/LEFT/RIGHT keys will move the PLAYER in their respective directions. Fullscreen mode is toggled with LAlt+ENTER; Game exit is triggered with ESCAPE. Accesses and modifies PLAYER, ZONE, and the FOV_RECOMPUTE flag. """ # Fullscreen and Exit keys; # Use "True" arg for turn-based; omit for real-time if settings.TURN_BASED is True: key = libtcod.console_wait_for_keypress(True) else: key = libtcod.console_check_for_keypress() if key.vk == libtcod.KEY_ENTER and key.lalt: libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen()) elif key.vk == libtcod.KEY_ESCAPE: return 'exit' # Exit game if state["status"] == 'playing': # Movement Keys if libtcod.console_is_key_pressed(libtcod.KEY_UP): player_move_or_attack(state, 0, -1) elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN): player_move_or_attack(state, 0, 1) elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT): player_move_or_attack(state, -1, 0) elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT): player_move_or_attack(state, 1, 0) else: print 'Hero takes no action' return 'no_action'
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' # change to 'playing' if real time
def handle_keys(self): key = libtcod.console_check_for_keypress() # real-time if self.gui_wait == 0 and self.game_ui.cursor != None: for input, action in self.CONSOLE_KEY_ACTIONS.items(): if libtcod.console_is_key_pressed(input): action(self) self.game_ui.game_view.lock_cursor_to_view(self.game_ui.camera, self.game_ui.cursor) self.game_object.update_cursor_cartesian(self.game_ui.cursor) self.game_object.update_cursor_coordinates(self.game_ui.cursor) self.game_ui.cycle() self.game_object.cycle() if self.gui_wait > 0: self.gui_wait -= 1 if key.vk == libtcod.KEY_ESCAPE and self.game_object.game_map != None: self.game_object.unload_map(self.game_ui) elif key.vk == libtcod.KEY_ESCAPE and self.game_object.game_map == None: return True # Exit game if key.vk == libtcod.KEY_CHAR: action = self.CHAR_KEY_ACTIONS.get(key.c) if action: action(self)
def handle_keys(): raw_key = tcod.console_check_for_keypress(tcod.KEY_PRESSED) while raw_key.vk != tcod.KEY_NONE: key = ui.get_key(raw_key) for player in players: if player.controls: if key in player.controls: m = player.controls.index(key) d = directions[m] # make sure player isn't turning backwards, running into # his own trail backwards = (player.dx * -1, player.dy * -1) if d != backwards: player.dx, player.dy = d if key == tcod.KEY_ESCAPE: return 'exit' raw_key = tcod.console_check_for_keypress(tcod.KEY_PRESSED)
def check_interrupt(): # check the keyboard and window manager for an interrupt # if check_interrupt sees a key event for ESC returns True key = libtcod.console_check_for_keypress() if key.vk == libtcod.KEY_ESCAPE or libtcod.console_is_window_closed(): return True else: return False
def send(): try: nameAGV = int(w.nameAGV.get()) except: messagebox.showerror(title="Error", message="AGV's name is not correct") return dem = 0 count = 0 if len(data) > 0: for j in range(0, len(labelsLine)): for i in range(0, len(data)): if (labelsLine[j].getId() == data[i][0] and labelsLine[j].getFunction() == "Hook"): print(type(data[i][2])) count = count + 1 if count % 2 == 0: data[i][2] = "Line" count = 0 for i in range(0, len(data)): step = agv.process_step_data(data) print(data[i][2]) for i in range(0, len(step)): libtcod.console_check_for_keypress() if (agv.send_step(nameAGV, step[i])): dem = dem + 1 if (dem == len(step)): messagebox.showinfo(title="Information", message="Done") else: messagebox.showerror(title="Error", message="Communication error") else: messagebox.showinfo(title="Information", message="Route not found") def make_step(pathLine_Item, head, function, rotate_type, lenLine, degree_rote, command, status_line, nameRFID, speed_max, wait_time, data, step): for i in range(0, len(pathLine_Item)): data.append((head[i], function[i], rotate_type[i], lenLine[i], degree_rote[i], command[i], status_line[i], nameRFID[i + 1], speed_max[i], wait_time[i])) for i in range(0, len(data)): step = agv.process_step_data(data) return data, step
def get_key_event(turn_based=None): if turn_based: # Turn-based game play; wait for a key stroke key = tcod.console_wait_for_keypress(True) else: # Real-time game play; don't wait for a player's key stroke key = tcod.console_check_for_keypress() return key
def handleInput(self): key = libtcod.console_check_for_keypress() if key.vk != libtcod.KEY_NONE: self.handleKeyInput(key) self.gotInput = True else: self.gotInput = False
def get_filename(append=None): libtcod.console_disable_keyboard_repeat() height = 3 width = 50 filename = '' window = libtcod.console_new(width, height) while True: # Don't leave the menu until a valid filename has been written. # Print a nice border around the menu. libtcod.console_clear(window) frame = '#' * width * height back = ' ' * (width - 1) * (height - 1) libtcod.console_set_default_foreground(window, libtcod.white) libtcod.console_print_rect_ex(window, 0, 0, width, height, libtcod.BKGND_NONE, libtcod.LEFT, frame) libtcod.console_print_rect_ex(window, 1, 1, width - 2, height - 2, libtcod.BKGND_NONE, libtcod.LEFT, back) # Print the filename. libtcod.console_set_default_foreground(window, libtcod.white) if append: libtcod.console_print(window, 1, 1, filename + append) else: libtcod.console_print(window, 1, 1, filename) # 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. libtcod.console_flush() # Wait for a keypress. key = libtcod.console_check_for_keypress(libtcod.KEY_PRESSED) key_char = chr(key.c) key_letter_index = key.c - ord('a') key_number_index = key.c - ord('0') # Handle keys. if key.vk == libtcod.KEY_ENTER and key.lalt: # Special case: Alt + Enter toggles fullscreen. libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen()) if (key_letter_index >= 0 and key_letter_index < 27) or (key_number_index >= 0 and key_number_index < 10): filename += key_char elif key.vk == libtcod.KEY_BACKSPACE or key.vk == libtcod.KEY_DELETE: filename = filename[:len(filename)-1] elif key.vk == libtcod.KEY_ENTER: if append: filename += append return filename elif key.vk == libtcod.KEY_ESCAPE: return None
def handle_keys(): global game_state # key = libtcod.console_check_for_keypress() # real-time key = libtcod.console_check_for_keypress(libtcod.KEY_PRESSED) # 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 # movement keys # test for other keys key_char = chr(key.c) if game_state == 'playing': if key_char == 'k': player_move_or_attack(0, -1) elif key_char == 'j': player_move_or_attack(0, 1) elif key_char == 'h': player_move_or_attack(-1, 0) elif key_char == 'l': player_move_or_attack(1, 0) elif key_char == 'y': player_move_or_attack(-1, -1) elif key_char == 'u': player_move_or_attack(1, -1) elif key_char == 'b': player_move_or_attack(-1, 1) elif key_char == 'n': player_move_or_attack(1, 1) else: if key_char == ',': # 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 == '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 == 'i': # show the inventory 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() return 'didnt-take-turn'
def call(args): #global self, map, FOV_RECOMPUTE, enemy self = args['self'] map = args['map'] FOV_RECOMPUTE = False key = libtcod.console_check_for_keypress(True) 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 #Call a test script elif key.vk == libtcod.KEY_KP5: #enemy.tick(map) FOV_RECOMPUTE = True #movement keys if key.vk == (libtcod.KEY_KP8): self.move(0,-1, map) FOV_RECOMPUTE = True elif key.vk == (libtcod.KEY_KP2): self.move(0,1, map) FOV_RECOMPUTE = True elif key.vk == (libtcod.KEY_KP4): self.move(-1,0, map) FOV_RECOMPUTE = True elif key.vk == (libtcod.KEY_KP6): self.move(1,0, map) FOV_RECOMPUTE = True elif key.vk == (libtcod.KEY_KP7): self.move(-1,-1, map) FOV_RECOMPUTE = True elif key.vk == (libtcod.KEY_KP9): self.move(1,-1, map) FOV_RECOMPUTE = True elif key.vk == (libtcod.KEY_KP1): self.move(-1,1, map) FOV_RECOMPUTE = True elif key.vk == (libtcod.KEY_KP3): self.move(1,1, map) FOV_RECOMPUTE = True #if key.vk != libtcod.KEY_NONE: # return False return FOV_RECOMPUTE
def run(self): path = os.path.join(sys.path[0], 'content', 'prefabs', 'Prefabs.xp') #print path data = prefab_generator.load_prefab(path) #print data level = self.Map.make_map(empty=True) level.draw_map = self.Map.set_draw_map_2x(level.map, self.gEngine) level.draw_map = self.Map.set_draw_map(level.map, self.gEngine) level.fov_map = self.gEngine.get_fov_map() run_fov = True self.gEngine.lightmask_set_size(self.Map.MAP_WIDTH * 2, self.Map.MAP_HEIGHT * 2) #self.gEngine.light_mask.set_intensity(18.0) #lightmask = light_mask.LightMask(self.Map.MAP_WIDTH, self.Map.MAP_HEIGHT)''' self.gEngine.set_map_2x(self.gEngine.get_map_2x()) self.qmap = quick_convert(self.Map.map2x) while not libtcod.console_is_window_closed(): self.gEngine.console_clear(0) key = libtcod.console_check_for_keypress() mouse = libtcod.mouse_get_status() (x, y) = (mouse.cx, mouse.cy) self.gEngine.light_mask.reset() if key.vk == libtcod.KEY_SPACE: run_fov = not run_fov if x < self.Map.MAP_WIDTH and y < self.Map.MAP_HEIGHT: self.gEngine.light_mask.add_light(x * 2, y * 2, 1.0) pass self.gEngine.particle_update(self.Map.map2x) #self.gEngine.light_mask.add_light(40, 21, 1.0) #self.gEngine.lightmask_compute(self.Map.map2x) self.gEngine.map_draw(0, 40, 21, self.gEngine.light_mask) #self.gEngine.map_draw_2x(0, 40, 21) if mouse.lbutton: #self.gEngine.particle_cone(15,40, 21, x, y) #self.gEngine.particle_cone_spray(15,40, 21, x, y) self.gEngine.particle_projectile(1, 40 * 2, 21 * 2, x * 2, y * 2) #self.gEngine.particle_explosion(15, x, y) #self.gEngine.particle_nova(9, x, y) pass self.gEngine.particle_draw(0) self.gEngine.console_print(0, 1, 5, "(%dfps)" % (libtcod.sys_get_fps())) self.gEngine.console_put_char_ex(0, 40, 21, '@', 255, 255, 255, 0, 0, 0) self.gEngine.console_put_char_ex(0, x, y, "X", 255, 255, 255, 0, 0, 0) self.gEngine.console_flush()
def handle_keys(): global game_state, player, stairs # key = libtcod.console_check_for_keypress() # real-time key = libtcod.console_check_for_keypress(libtcod.KEY_PRESSED) # 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 # movement keys if game_state == 'playing': 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 == '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 == 'i': # show the inventory 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 == '<': # go down stairs, if the player is on them if stairs.x == player.x and stairs.y == player.y: next_level() 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) return 'didnt-take-turn'
def start_menu(): title.init_blood() libtcod.console_credits_reset() finished_libtcod_credits = False selection = 0 while True: title.update() libtcod.console_clear(0) title.draw_blood() title.draw_title() libtcod.console_set_background_color(0, libtcod.dark_grey) libtcod.console_rect(0, 24, 14, 32, 7, False, libtcod.BKGND_MULTIPLY) libtcod.console_set_foreground_color(0, libtcod.red) libtcod.console_print_center(0, 40, 15, libtcod.BKGND_NONE, "Brutal RL: Slaves to Slaughter") libtcod.console_set_foreground_color(0, libtcod.white) libtcod.console_print_left(0, 35, 17, libtcod.BKGND_NONE, "New Game") libtcod.console_print_left(0, 35, 18, libtcod.BKGND_NONE, "Load Game") libtcod.console_print_left(0, 35, 19, libtcod.BKGND_NONE, "Quit") libtcod.console_print_left(0, 33, 17 + selection, libtcod.BKGND_NONE, ">") libtcod.console_print_left(0, 45, 17 + selection, libtcod.BKGND_NONE, "<") if not finished_libtcod_credits: finished_libtcod_credits = libtcod.console_credits_render(65, 43, True) libtcod.console_flush() key = libtcod.console_check_for_keypress(libtcod.KEY_PRESSED) if key.vk == libtcod.KEY_ESCAPE: if selection == 2: raise SetState("quit") else: selection = 2 elif key.vk in DIRECTION_KEYS and DIRECTION_KEYS[key.vk][0] == 0: selection += DIRECTION_KEYS[key.vk][1] selection %= 3 elif key.vk in [libtcod.KEY_ENTER, libtcod.KEY_KPENTER]: raise SetState([new_game, load_game, "quit"][selection]) mouse = libtcod.mouse_get_status() if mouse.lbutton: title.set_full(mouse.cx, mouse.cy) elif mouse.rbutton: title.set_empty(mouse.cx, mouse.cy)
def update(self, delta): self.menu_frame.update(delta) key = libtcod.console_check_for_keypress(True) #libtcod.console_check_for_keypress if key.c == ord("a"): return MenuGame(self.width, self.height) if key.c == ord("b"): return MenuStatus.Exit return MenuStatus.Okay
def handle_keys(self): #key = libtcod.console_wait_for_keypress(True) key = libtcod.console_check_for_keypress() if key.vk == libtcod.KEY_ESCAPE: self.shutdown=True elif key.vk == libtcod.KEY_ENTER: self.screens.addProgressCut("Fooing bar", 5, libtcod.Color(random.randint(0,255), random.randint(0,255), random.randint(0,255)), libtcod.Color(random.randint(0,255), random.randint(0,255), random.randint(0,255)))
def player_input(): x = 0 y = 0 key = libtcod.console_check_for_keypress(libtcod.KEY_PRESSED) #movement keys if key.vk == libtcod.KEY_CHAR: fov_recompute = False if key.c == ord('w'): y -= 1 fov_recompute = True elif key.c == ord('s'): y += 1 fov_recompute = True elif key.c == ord('a'): x -= 1 fov_recompute = True elif key.c == ord('d'): x += 1 fov_recompute = True global mapCon player.clear(mapCon) global Map, objects player.move(x, y, Map, objects) # global client # try: # client.send(str(player.x)) # except: # print("") if fov_recompute: #recompute FOV if needed (the player moved or something) fov_recompute = False libtcod.map_compute_fov(fov_map, player.x, player.y, TORCH_RADIUS, FOV_LIGHT_WALLS, FOV_ALGO) if key.vk == libtcod.KEY_CHAR: if key.c == ord('c'): global Map for y in range(Map_Height): for x in range(Map_Width): Map.mappedArea[x][y].explored = False Map = MapObject.Map(80, 45, 'smalldungeon') (new_x, new_y) = Map.rooms[0].center() player.put(new_x, new_y) global fov_map fov_map = libtcod.map_new(Map_Width, Map_Height) for y in range(Map_Height): for x in range(Map_Width): libtcod.map_set_properties(fov_map, x, y, not Map.mappedArea[x][y].block_sight, not Map.mappedArea[x][y].blocked) libtcod.map_compute_fov(fov_map, player.x, player.y, TORCH_RADIUS, FOV_LIGHT_WALLS, FOV_ALGO) elif 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
def show_text_log(text, img=None, delay=True, center_first_line=False): # takes list of text and displays it line by line against a black screen # optional parameters: img = an image based in libtcod.image format, defaults to None (black screen) # delay = whether to use the text delay, defaults to True (for cinematic style sequences) if img is None: img = libtcod.image_new(160, 100) libtcod.image_blit_2x(img, 0, 0, 0) libtcod.console_set_default_foreground(0, libtcod.green) for y in range(len(text)): key = libtcod.console_check_for_keypress() if key.vk == libtcod.KEY_ESCAPE: return else: if center_first_line and y == 0: libtcod.console_print_ex(0, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 5 + y * 2, libtcod.BKGND_NONE, libtcod.CENTER, text[y]) else: libtcod.console_print_ex(0, SCREEN_WIDTH / 8, SCREEN_HEIGHT / 5 + y * 2, libtcod.BKGND_NONE, libtcod.LEFT, text[y]) if delay: libtcod.console_flush() time.sleep(1.3) key = libtcod.console_check_for_keypress() if key.vk == libtcod.KEY_SPACE: delay = False libtcod.console_set_default_foreground(0, libtcod.white) libtcod.console_print_ex(0, SCREEN_WIDTH / 2, SCREEN_HEIGHT - 2, libtcod.BKGND_NONE, libtcod.CENTER, 'Press any key to continue') libtcod.console_flush() input_valid = False while not input_valid: key = libtcod.console_wait_for_keypress(True) if key.pressed: key = libtcod.console_wait_for_keypress(False) if not key.pressed: input_valid = True
def handle_keys(self): #key = libtcod.console_wait_for_keypress(True) key = libtcod.console_check_for_keypress() if key.vk == libtcod.KEY_ESCAPE: self.shutdown = True elif key.vk == libtcod.KEY_ENTER: self.screens.addProgressCut( "Fooing bar", 5, libtcod.Color(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)), libtcod.Color(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)))
def handle_keys(): global game_state # key = libtcod.console_check_for_keypress() # real-time key = libtcod.console_check_for_keypress(libtcod.KEY_PRESSED) # 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 # movement keys # test for other keys key_char = chr(key.c) if game_state == 'playing': if key_char == 'k': player_move_or_attack(0, -1) elif key_char == 'j': player_move_or_attack(0, 1) elif key_char == 'h': player_move_or_attack(-1, 0) elif key_char == 'l': player_move_or_attack(1, 0) elif key_char == 'y': player_move_or_attack(-1, -1) elif key_char == 'u': player_move_or_attack(1, -1) elif key_char == 'b': player_move_or_attack(-1, 1) elif key_char == 'n': player_move_or_attack(1, 1) else: if key_char == ',': # 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 == '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 == 'i': # show the inventory 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() return 'didnt-take-turn'
def handle_keys(): key = libtcod.console_check_for_keypress(libtcod.KEY_PRESSED) keys = get_key(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 elif key.vk == libtcod.KEY_CONTROL and chr(key.c) == 'r': return 'restart' if game_state == 'playing': #movement keys if keys == libtcod.KEY_UP or keys == 'e' or keys == libtcod.KEY_KP8: player_move_or_attack(0, -1) elif keys == 'r' or keys == libtcod.KEY_KP9: player_move_or_attack(1, -1) elif keys == 'w' or keys == libtcod.KEY_KP7: player_move_or_attack(-1, -1) elif keys == libtcod.KEY_DOWN or keys == 'd' or keys == libtcod.KEY_KP2: player_move_or_attack(0, 1) elif keys == 'v' or keys == libtcod.KEY_KP3: player_move_or_attack(1, 1) elif keys == 'z' or keys == libtcod.KEY_KP1: player_move_or_attack(-1, 1) elif keys == libtcod.KEY_LEFT or keys == 's' or keys == libtcod.KEY_KP4: player_move_or_attack(-1, 0) # elif keys == libtcod.KEY_5 or libtcod.KEY_KP5: # player_move_or_attack(0, 0) elif keys == libtcod.KEY_RIGHT or keys == 'f' or keys == libtcod.KEY_KP6: 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 keys == '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() return 'didnt-take-turn'
def handle_keys(): global player, map, FOV_RECOMPUTE, enemy key = libtcod.console_check_for_keypress(True) 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 #Call a test script elif key.vk == libtcod.KEY_KP5: enemy.tick(map) FOV_RECOMPUTE = True #movement keys if key.vk == (libtcod.KEY_KP8): player.move(0,-1, map) FOV_RECOMPUTE = True elif key.vk == (libtcod.KEY_KP2): player.move(0,1, map) FOV_RECOMPUTE = True elif key.vk == (libtcod.KEY_KP4): player.move(-1,0, map) FOV_RECOMPUTE = True elif key.vk == (libtcod.KEY_KP6): player.move(1,0, map) FOV_RECOMPUTE = True elif key.vk == (libtcod.KEY_KP7): player.move(-1,-1, map) FOV_RECOMPUTE = True elif key.vk == (libtcod.KEY_KP9): player.move(1,-1, map) FOV_RECOMPUTE = True elif key.vk == (libtcod.KEY_KP1): player.move(-1,1, map) FOV_RECOMPUTE = True elif key.vk == (libtcod.KEY_KP3): player.move(1,1, map) FOV_RECOMPUTE = True if key.vk != libtcod.KEY_NONE: return False
def handle_input(self): raw_key = tcod.console_check_for_keypress( tcod.KEY_PRESSED | tcod.KEY_RELEASED) while raw_key.vk != tcod.KEY_NONE: key = util.get_key(raw_key) if key == tcod.KEY_ESCAPE: self.alive = False for player in self.players: if player.controls not in ['ai', None]: if key in player.controls: if raw_key.pressed: if player.controls.index(key) == 0: # up player.up = True else: player.down = True # down else: if player.controls.index(key) == 0: # up player.up = False else: player.down = False raw_key = tcod.console_check_for_keypress( tcod.KEY_PRESSED | tcod.KEY_RELEASED)
def controls(): this = libtcod.console_check_for_keypress(True) # wait for keypress if this.vk == libtcod.KEY_ESCAPE: # quit game return True elif this.vk == libtcod.KEY_0: # fullscreen mode libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen()) if this.vk == libtcod.KEY_ENTER: make_map() # resets console so each enter key is a new map basic_map_generator() # dungeon generator code render_all() # draw current rendition of map for object in objects: object.clear # clears all objects for object in objects: object.draw() # draws all objects
def update(self, delta): key = libtcod.console_check_for_keypress(True) self.update_blinky_cursor(delta) if self.input_enabled: if len(self.input_command) < self.max_command_size: if key.vk == libtcod.KEY_CHAR: self.input_command += chr(key.c) #add numbers, because these are separate keycodes for some godforsaken reason #really, libtcod? elif key.vk == libtcod.KEY_0: self.input_command += '0' elif key.vk == libtcod.KEY_1: self.input_command += '1' elif key.vk == libtcod.KEY_2: self.input_command += '2' elif key.vk == libtcod.KEY_3: self.input_command += '3' elif key.vk == libtcod.KEY_4: self.input_command += '4' elif key.vk == libtcod.KEY_5: self.input_command += '5' elif key.vk == libtcod.KEY_6: self.input_command += '6' elif key.vk == libtcod.KEY_7: self.input_command += '7' elif key.vk == libtcod.KEY_8: self.input_command += '8' elif key.vk == libtcod.KEY_9: self.input_command += '9' elif key.vk == libtcod.KEY_UP: self.input_command += chr(24) elif key.vk == libtcod.KEY_DOWN: self.input_command += chr(25) elif key.vk == libtcod.KEY_LEFT: self.input_command += chr(27) elif key.vk == libtcod.KEY_RIGHT: self.input_command += chr(26) #send command elif key.vk == libtcod.KEY_ENTER and self.input_command != "": self.add_line_to_history(self.prompt_string + self.input_command) self.frame_manager.parent_menu.handle_input_command( self.input_command) self.input_command = "" elif key.vk == libtcod.KEY_BACKSPACE: self.input_command = self.input_command[:-1]
def get(self): if libtcod.console_is_window_closed(): raise WindowClosedException() rv = libtcod.console_check_for_keypress( libtcod.KEY_PRESSED ) if rv.vk == libtcod.KEY_NONE: time.sleep( 0.01 ) return None try: ch = self.keymap[ rv.vk ] if ch != None: return KeypressEvent( ch ) except KeyError: if rv.c > 0: return KeypressEvent( chr( rv.c ) ) return None
def handle_keys(): global oldX, oldY, status key = libtcod.console_check_for_keypress() # real-time if key.vk == libtcod.KEY_ENTER and key.lalt: #Alt+Enter: toggle full screen libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen()) elif key.vk == libtcod.KEY_ESCAPE: return 'exit' elif libtcod.console_is_key_pressed(libtcod.KEY_UP) and status != 'dead': if oldX == 0 and oldY == 1: status = player_move_or_eat(0,1) else: status = player_move_or_eat(0, -1) oldX = 0 oldY = -1 elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN) and status != 'dead': if oldX == 0 and oldY == -1: status = player_move_or_eat(0, -1) else: status = player_move_or_eat(0, 1) oldX = 0 oldY = 1 elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT) and status != 'dead': if oldX == 1 and oldY == 0: status = player_move_or_eat(1,0) else: status = player_move_or_eat(-1, 0) oldX = -1 oldY = 0 elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT) and status != 'dead': if oldX == -1 and oldY == 0: status = player_move_or_eat(-1, 0) else: status = player_move_or_eat(1, 0) oldX = 1 oldY = 0 elif libtcod.console_is_key_pressed(libtcod.KEY_SPACE) and status == 'dead': status = 'restart' elif libtcod.console_is_key_pressed(libtcod.KEY_KPADD) and status == 'newgame': obj = snake_parts(snake[0].x, snake[0].y, '#', 'body', libtcod.white, True) snake.append(obj) elif libtcod.console_is_key_pressed(libtcod.KEY_KPSUB) and status == 'newgame': obj = snake_parts(snake[0].x, snake[0].y, '#', 'body', libtcod.white, True) del snake[-1] else: if status != 'dead': status = player_move_or_eat(oldX, oldY) return status
def handle_keys(): key = libtcod.console_check_for_keypress(libtcod.KEY_PRESSED) if key.vk == libtcod.KEY_ENTER and key.lalt: # Alt + Enter toggles fullscreen. libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen()) elif key.vk == libtcod.KEY_ESCAPE: pause = pause_menu() if pause == 'exit': return pause # Exit game. if player.wait > 0: # Don't take a turn until the wait's over. player.wait -= 1 return if game_state == 'playing' or game_state == 'custom playing': # Movement keys. if key.vk in [libtcod.KEY_UP, libtcod.KEY_KP8]: player_move_or_die(0, -1) elif key.vk in [libtcod.KEY_DOWN, libtcod.KEY_KP2]: player_move_or_die(0, 1) elif key.vk in [libtcod.KEY_LEFT, libtcod.KEY_KP4]: player_move_or_die(-1, 0) elif key.vk in [libtcod.KEY_RIGHT, libtcod.KEY_KP6]: player_move_or_die(1, 0) elif key.vk == libtcod.KEY_KP7: player_move_or_die(-1, -1) elif key.vk == libtcod.KEY_KP9: player_move_or_die(1, -1) elif key.vk == libtcod.KEY_KP1: player_move_or_die(-1, 1) elif key.vk == libtcod.KEY_KP3: player_move_or_die(1, 1) else: # Test for other keys. key_char = chr(key.c) if key_char == 'l': # Look. look_around()
def handle_keys(): global player_x, player_y key = tcod.console_check_for_keypress() if key.vk == tcod.KEY_ENTER and tcod.KEY_ALT: tcod.console_set_fullscreen(not tcod.console_is_fullscreen()) elif key.vk == tcod.KEY_ESCAPE: return True if tcod.console_is_key_pressed(tcod.KEY_UP): player_y = player_y - 1 elif tcod.console_is_key_pressed(tcod.KEY_DOWN): player_y = player_y + 1 elif tcod.console_is_key_pressed(tcod.KEY_LEFT): player_x = player_x - 1 elif tcod.console_is_key_pressed(tcod.KEY_RIGHT): player_x = player_x + 1
def handle_keys(): global fov_recompute key = libtcod.console_check_for_keypress() 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': #if player.wait > 0: #player.wait -= 1 #else: #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 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 elif key_char == 'i': chosen_item = inventory_menu( 'Press the key next to an item to use it, or any other key to cancel\n' ) if chosen_item is not None: chosen_item.use() elif key_char == 'd': chosen_item = inventory_menu( 'Press the key next to an item to drop it, or any other key to cancel\n' ) if chosen_item is not None: chosen_item.drop()
def main(): screen_width = 80 screen_height = 50 libtcod.console_set_custom_font('1.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD) libtcod.console_init_root(screen_width, screen_height, 'libtcod tutorial revised', False) while not libtcod.console_is_window_closed(): libtcod.console_set_default_foreground(0, libtcod.white) libtcod.console_put_char(0, 1, 1, '@', libtcod.BKGND_NONE) libtcod.console_flush() key = libtcod.console_check_for_keypress() if key.vk == libtcod.KEY_ESCAPE: return True
def handle_keys(): key = libtcod.console_check_for_keypress() 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 #Escape: Exits the game # Movement keys if libtcod.console_is_key_pressed(libtcod.KEY_UP): player.move(0, -1) elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN): player.move(0, 1) elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT): player.move(-1, 0) elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT): player.move(1, 0)
def handle_keys(): global playerx, playery key = libtcod.console_check_for_keypress() 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 if libtcod.console_is_key_pressed(libtcod.KEY_UP): player.move(0, -1) elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN): player.move(0, 1) elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT): player.move(-1, 0) elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT): player.move(1, 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 True #exit game if libtcod.console_is_key_pressed(libtcod.KEY_UP): world.hero.move(0, -1) elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN): world.hero.move(0, 1) if libtcod.console_is_key_pressed(libtcod.KEY_LEFT): world.hero.move(-1, 0) elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT): world.hero.move(1, 0)
def generateCave(self, x, y, main_console): newMap = [] for i in range(y): collector = [] for j in range(x): r = random() if (r <= 0.35): collector.append('#') else: collector.append(' ') newMap.append(collector) current_map = Map.Map(main_console) current_map.convert_crude(newMap, True) current_map.draw_map() libtcod.console_blit(main_console, 0, 0, x, y, 0, 0, 0) libtcod.console_set_default_foreground(None, libtcod.grey) libtcod.console_set_default_background(None, libtcod.black) libtcod.console_flush() for k in range(7): upMap = copy.deepcopy(newMap) for i in range(y): for j in range(x): n = better_check(newMap, j, i, 5) fill = False if (k < 3 or k == 5): if (n == 0): fill = True if ((n >= 5) or fill): upMap[i][j] = '#' else: upMap[i][j] = ' ' del newMap newMap = copy.deepcopy(upMap) time.sleep(1) key = libtcod.console_check_for_keypress() if key.vk == libtcod.KEY_ESCAPE: break current_map.convert_crude(newMap, True) current_map.draw_map() libtcod.console_blit(main_console, 0, 0, x, y, 0, 0, 0) libtcod.console_set_default_foreground(None, libtcod.grey) libtcod.console_set_default_background(None, libtcod.black) libtcod.console_flush() return newMap
def handle_keys(): global playerx, playery, SCREEN_WIDTH, SCREEN_HEIGHT, directionx, directiony key = libtcod.console_check_for_keypress() #real-time 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 directionx = 0 directiony = -1 elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN): playery += 1 directionx = 0 directiony = 1 elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT): playerx -= 1 directionx = -1 directiony = 0 elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT): playerx += 1 directionx = 1 directiony = 0 if playerx > SCREEN_WIDTH - 1: playerx = SCREEN_WIDTH -1 if playerx < 0: playerx = 0 if playery > SCREEN_HEIGHT -1: playery = SCREEN_HEIGHT -1 if playery < 0: playery = 0
def targetTile(maxRange=None): #Returns the position of the tile in player's FOV #Should be expanded to blink the radius of the spell with a given color while True: renderAll() libtcod.console_flush() key = libtcod.console_check_for_keypress() mouse = libtcod.mouse_get_status() (x, y) = mouse.cx, mouse.cy if (mouse.lbutton_pressed and libtcod.map_is_in_fov( fovMap, x, y)) and (maxRange == None or player.distance(x, y) <= maxRange): return (x, y) if mouse.rbutton_pressed: #cancel if they right click, might want to add more ways to cancel message("Spell canceled.", libtcod.white) return (None, None)
def target_tile(max_range=None): #return the position of a left-cliked in player's FoV, and optionally in a range, or (none, none) if right-clicked while True: render_all() libtcod.console_flush() key = libtcod.console_check_for_keypress() mouse = libtcod.mouse_get_status() (x, y) = (mouse.cx, mouse.cy) #Returns the mouse position if (mouse.lbutton_pressed and libtcod.map_is_in_fov(fov_map, x, y) and max_range is None or player.distance_to_coords(x, y) <= max_range): return (x, y) #Cancel if the player presses the right mouse or escape if mouse.rbutton_pressed or key.vk == libtcod.KEY_ESCAPE: return (None, None)