def break_wall_action(the_game): #THIS IS BROKEN FOR NOW player_turn_results = [] the_game.game_state = GameStates.TARGETING_MODE ''' ############## NOTE ##############33 THIS WHILE LOOP WILL GENERATE PROBLEMS IN THE FUTURE, specifically with rendering animations(if i so wish to implement it) Need to find a better solution, maybe do targeting function first, and then after u get the direction u activate break_wall() ''' while the_game.game_state == GameStates.TARGETING_MODE: tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS, the_game.key, the_game.mouse) x, y = handle_keys(the_game.key, the_game.game_state).get('move', (None, None)) if x is not None: the_game.game_state = GameStates.ENEMY_TURN if handle_keys(the_game.key, the_game.game_state).get('exit'): the_game.game_state = GameStates.PLAYERS_TURN return False dx, dy = the_game.player.x + x, the_game.player.y + y the_game.game_map.tiles[dx][dy].destroy_wall() the_game.fov_map = set_tile_fov(dx, dy, the_game.game_map, the_game.fov_map) the_game.fov_recompute = True
def main(): consoles, entities, game, game_map, game_state_machine, key, message_log, mouse, neighborhood, player = initialize_new_game( ) event_queue = [] action = True render_borders(consoles['root']) render_all(action, consoles, entities, game, game_map, game_state_machine, message_log, mouse, neighborhood, player) while True: # Process input. libtcod.sys_check_for_event( libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse) action = handle_keys(game_state_machine, key) # Update game. update(action, entities, event_queue, game, game_map, game_state_machine, message_log, neighborhood, player) # Render results. render_all(action, consoles, entities, game, game_map, game_state_machine, message_log, mouse, neighborhood, player) if game_state_machine.state.__str__() == 'Exit': consoles['root'].__exit__() return False warnings.simplefilter("default")
def sender(self): while True: # Check for tangenttryckning libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, self.key, self.mouse) # Save action in dictionary action = handle_keys(self.key) # print(action) # if the dictionary in handle keys have key word move: if "move" in action: # The client sends the move dictionary to the server # in the form of a json object json_dump = json.dumps(action).encode('utf-8') # print(json_dump) print(sys.getsizeof(json_dump)) self.client_socket.sendall(json_dump) # if the dictionary in handle keys have key word exit we close the window: if "exit" in action: print("Thank you for playing, good bye.") self.client_socket.close() break
def main(): # Initializing pygame session pygame.init() pygame.display.set_caption("Shooter Dude") # Initializing Game Surface screen = pygame.display.set_mode((screen_width, screen_height)) test_map = GameMap(map_width, map_height) test_map.make_map() player = Entity(int(screen_width / 2), int(screen_height / 2), 'PLAYER') # Main Game Loop while True: render_all(screen, test_map, player) # Event Handling for event in pygame.event.get(): action = handle_keys(event) move = action.get('move') if move: dx, dy = move destination_x = player.x + dx destination_y = player.y + dy if not test_map.is_blocked(destination_x, destination_y): player.move(dx, dy) pygame.display.update()
def main(): screen_width = 80 screen_height = 80 map_width = 80 map_height = 70 colors = { 'dark_wall': libtcod.Color(45, 65, 100), 'dark_ground': libtcod.Color(13, 23, 15) } player = Entity(int(screen_width / 2), int(screen_height / 2), '@', libtcod.white) entities = [player] libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD) libtcod.console_init_root(screen_width, screen_height, 'table tosser', 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 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())
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())
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())
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())
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.fuchsia) npc = Entity(int(screen_width / 2 - 5), int(screen_height / 2), "@", libtcod.yellow) entities = [npc, player] # http://roguecentral.org/doryen/data/libtcod/doc/1.5.1/html2/console_set_custom_font.html?c=false&cpp=false&cs=false&py=true&lua=false libtcod.console_set_custom_font( "arial10x10.png", libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD) # Creates the window, title, and fullscreen libtcod.console_init_root(screen_width, screen_height, "B@rd", False) # Draw a new console con = libtcod.console_new(screen_width, screen_height) game_map = GameMap(map_width, map_height) # Holds keyboard and mouse input key = libtcod.Key() mouse = libtcod.Mouse() # Game loop (until screen is closed) 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())
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())
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())
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) # imports font, tells libtcod how to interpret font png libtcod.console_init_root(screen_width, screen_height, 'libtcod tutorial revised', False) # creates main screen (width, height, title, fullscreen T/F) con = libtcod.console_new(screen_width, screen_height) key = libtcod.Key() # captures keyboard input mouse = libtcod.Mouse() # captures mouse input while not libtcod.console_is_window_closed(): # keeps game running as long as window is open libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, mouse) # checks for mouse or keyboard input 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() # flushes everything to printout 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())
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
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())
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())
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(screen_width // 2, screen_height // 2, '@', libtcod.white) npc = Entity(screen_width // 2 - 5, screen_height // 2, '@', libtcod.red) 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 revisited", 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') playerquit = 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 playerquit: return True if fullscreen: libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
def main(): screen_width = 80 #set screen width and height as integers 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_GREYSCALE | libtcod.FONT_LAYOUT_TCOD) #set a font libtcod.console_init_root(screen_width, screen_height, 'py rogue', False) #actually generate the window con = libtcod.console_new(screen_width, screen_height) key = libtcod.Key() #holds keyboard and mouse input in variables mouse = libtcod.Mouse() while not libtcod.console_is_window_closed( ): #a loop that keeps the game running esentially libtcod.sys_check_for_event( libtcod.EVENT_KEY_PRESS, key, mouse) #updates key and mouse with user inputs 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() #updates the screen constantly 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 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 main(): #DIMENSOES DA TELA screen_width = 80 screen_height = 50 player_x = int(screen_width / 2) player_y = int(screen_height / 2) #FONTE A SER USADA 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) #TECLADO E MOUSE key = libtcod.Key() mouse = libtcod.Mouse() while not libtcod.console_is_window_closed(): #LOOP PRO JOGO FUNCIONAR 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) #COORDENADAS E SIMBOLO DO JOGADOR libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0) libtcod.console_flush() #PRINTA AS PARADAS NA TELA 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())
def fire_action(the_game): ''' This is repeating code, create a better attack func that covers both move and fire actions Maybe create a range_attack for it to be used on entity.actor?? ''' player_turn_results = [] entities_in_fov = get_entities_in_fov(the_game.fov_map, the_game.entities) if entities_in_fov: #GOD MODE FIRING ALL TARGETS ON SIGHT if the_game.god.tog: for target in entities_in_fov: attack_results = the_game.player.actor.attack_target(target) player_turn_results.extend(attack_results) process_player_turn_results(the_game, player_turn_results) #NORMAL MODE FIRING 1 TARGET W/ MOUSE CLICK else: the_game.game_state = GameStates.TARGETING_MODE while the_game.game_state == GameStates.TARGETING_MODE: tcod.sys_check_for_event( tcod.EVENT_KEY_PRESS | tcod.EVENT_MOUSE, the_game.key, the_game.mouse) entities_under_mouse = get_entities_under_mouse( the_game.god, the_game.mouse, the_game.entities, the_game.fov_map) exit = handle_keys(the_game.key, the_game.game_state).get('exit') if the_game.mouse.lbutton_pressed or exit: if exit: the_game.game_state = GameStates.PLAYERS_TURN return False else: the_game.game_state = GameStates.ENEMY_TURN for entity in entities_under_mouse: if entity.actor: target = entity attack_results = the_game.player.actor.attack_target( target) player_turn_results.extend(attack_results) process_player_turn_results(the_game, player_turn_results) else: message = Message("There are no targets in range", tcod.red) the_game.msg_log.add_msg(message) the_game.game_state = GameStates.ENEMY_TURN
def ev_keydown(self, event: tcod.event.KeyDown): #--------------------------------------------------------------------- # Get key input from the self.player. #--------------------------------------------------------------------- input_result = handle_keys(event, self.game_state) if (len(input_result) == 0): if CONFIG.get('debug'): #logging.info("No corresponding result for key press.") pass return action, action_value = unpack_single_key_dict(input_result) self.process_turn(action, action_value)
def intro_menu_select(window): intro_board = create_intro() horizontal_offset = int((ui.SCREEN_WIDTH / 2) - (len(intro_board[0]) / 2)) vertical_offset = int((ui.SCREEN_HEIGHT / 2) - (len(intro_board) / 2)) key = libtcod.Key() mouse = libtcod.Mouse() introduction_menu = True libtcod.console_clear(window) while introduction_menu: libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, mouse) for i, line in enumerate(intro_board): for j, char in enumerate(line): if char == '#': libtcod.console_set_default_foreground( window, libtcod.light_chartreuse) else: libtcod.console_set_default_foreground( window, libtcod.white) libtcod.console_put_char(window, j + horizontal_offset, i + vertical_offset, char, libtcod.BKGND_NONE) libtcod.console_blit(window, 0, 0, ui.SCREEN_WIDTH, ui.SCREEN_HEIGHT, 0, 0, 0) libtcod.console_flush() action = handle_keys(key) start_game = action.get('start_game') help = action.get('help') fullscreen = action.get('fullscreen') quit_menu = action.get('exit_menu') if start_game: libtcod.console_clear(window) return 0 #display info/screen 'how to play' if help: libtcod.console_clear(window) how_to_play(window) if fullscreen: libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen()) if quit_menu: introduction_menu = False return -1
def main(): screen_width = 80 screen_height = 50 player = Entity(screen_width // 2, screen_height // 2, '@', libtcod.white) npc = Entity(screen_width // 2 - 5, 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', 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) render_all(con, entities, screen_width, screen_height) libtcod.console_flush() clear_all(con, entities) action = handle_keys(key) move = action.get( 'move' ) #returns relative coordinates as a tuple if the action was 'move' exit_game = action.get('exit') #gets True if action was 'exit' fullscreen = action.get( 'fullscreen') #gets True if action was 'fullscreen' if move: dx, dy = move # player_x += dx # player_y += dy player.move(dx, dy) # if key.vk == libtcod.KEY_ESCAPE: if exit_game: return True if fullscreen: libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
def create_wall_action(the_game): player_turn_results = [] the_game.game_state = GameStates.TARGETING_MODE ''' ############## NOTE ############## THIS WHILE LOOP WILL GENERATE PROBLEMS IN THE FUTURE, specifically with rendering animations(if i so wish to implement it) Need to find a better solution, maybe do targeting function first, and then after u get the direction u activate break_wall() ''' while the_game.game_state == GameStates.TARGETING_MODE: tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS, the_game.key, the_game.mouse) x, y = handle_keys(the_game.key, the_game.game_state).get('move', (None, None)) if x is not None: the_game.game_state = GameStates.ENEMY_TURN if handle_keys(the_game.key, the_game.game_state).get('exit'): the_game.game_state = GameStates.PLAYERS_TURN return False dx, dy = the_game.player.x + x, the_game.player.y + y if get_blocking_entity(the_game.entities, dx, dy): msg = { 'message': Message( "It's too heavy for you to create a wall here, there is someone there!", tcod.orange) } player_turn_results.append(msg) process_player_turn_results(the_game, player_turn_results) return None the_game.game_map.tiles[dx][dy].create_wall() the_game.fov_map = set_tile_fov(dx, dy, the_game.game_map, the_game.fov_map) the_game.fov_recompute = True
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), 'E', 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, 'virtual_existence', 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_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 if exit: return True if fullscreen: libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
def update(event): render_all(entities, game_map, screen_width, screen_height, colors) action = handle_keys(event) move = action.get('move') exit = action.get('exit') if move: dx, dy = move if not game_map.is_blocked(player.x + dx, player.y + dy): player.move(dx, dy) if exit: rl.quit()
def main(): screen_width = 80 screen_height = 50 player_x = int(screen_width / 2) player_y = int(screen_height / 2) map_width = 80 map_height = 45 player = Entity(player_x, player_y, '@', libtcod.white) npc = Entity(int(screen_width/2-5), int(screen_height/2-5), '@', 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, '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) render_all(con, entities, screen_width, screen_height) 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)
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( '../assets/arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD) libtcod.console_init_root(screen_width, screen_height, 'Chausson-like', 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_flush() libtcod.console_put_char( con, player_x, player_y, ' ', libtcod.BKGND_NONE) #permet d'effacer nos traces de pas action = handle_keys(key) #actions : on détecte les booléens move = action.get('move') exit = action.get('exit') fullscreen = action.get('fullscreen') #Le dict renvoyée nous donne l(action (clef) et les spécificités (valeurs) 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())
def run_game(self): libtcodconsole.default_fg = libtcod.white if self.fov_recompute: recompute_fov(self.fov_map, self.player.x, self.player.y) render_all(self.root_console, self.panel, self.entities, self.player, self.game_map, self.fov_map, self.fov_recompute, self.message_log, self.game_state) self.fov_recompute = False libtcod.console_flush() if self.agent is None: action = {'pass': False} for event in libtcodevent.get(): if event.type == "QUIT": return if event.type == "KEYDOWN": action = handle_keys(event.sym, self.game_state) else: if self.player.equipment.head is not None: head_name = self.player.equipment.head.name else: head_name = "Nothing" if self.player.equipment.body is not None: body_name = self.player.equipment.body.name else: body_name = "Nothing" if self.player.equipment.main_hand is not None: main_name = self.player.equipment.main_hand.name else: main_name = "Nothing" if self.player.equipment.off_hand is not None: off_name = self.player.equipment.off_hand.name else: off_name = "Nothing" print( "Head: {0} Body: {1} Main hand: {2} Off hand: {3} Coins: {4}" .format(head_name, body_name, main_name, off_name, self.player.coin_pouch.get_amount())) action = self.agent.get_action() self.handle_action(action)
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())
def play_game(player, entities, game_map, message_log, game_state, con, panel, constants): fov_recompute = True fov_map = initialize_fov(game_map) key = libtcod.Key() mouse = libtcod.Mouse() game_state = GameStates.PLAYERS_TURN previous_game_state = game_state targeting_item = None while not libtcod.console_is_window_closed(): libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse) if fov_recompute: recompute_fov(fov_map, player.x, player.y, constants['fov_radius'], constants['fov_light_walls'], constants['fov_algorithm']) render_all(con, panel, entities, player, game_map, fov_map, fov_recompute, message_log, constants['screen_width'], constants['screen_height'], constants['bar_width'], constants['panel_height'], constants['panel_y'], mouse, constants['colors'], game_state) fov_recompute = False libtcod.console_flush() clear_all(con, entities) action = handle_keys(key, game_state) mouse_action = handle_mouse(mouse) move = action.get('move') wait = action.get('wait') pickup = action.get('pickup') show_inventory = action.get('show_inventory') drop_inventory = action.get('drop_inventory') inventory_index = action.get('inventory_index') take_stairs = action.get('take_stairs') level_up = action.get('level_up') show_character_screen = action.get('show_character_screen') exit = action.get('exit') fullscreen = action.get('fullscreen') left_click = mouse_action.get('left_click') right_click = mouse_action.get('right_click') player_turn_results = [] if move and game_state == GameStates.PLAYERS_TURN: dx, dy = move destination_x = player.x + dx destination_y = player.y + dy if not game_map.is_blocked(destination_x, destination_y): target = get_blocking_entities_at_location(entities, destination_x, destination_y) if target: attack_results = player.fighter.attack(target) player_turn_results.extend(attack_results) else: player.move(dx, dy) fov_recompute = True game_state = GameStates.ENEMY_TURN elif wait: game_state = GameStates.ENEMY_TURN elif pickup and game_state == GameStates.PLAYERS_TURN: for entity in entities: if entity.item and entity.x == player.x and entity.y == player.y: pickup_results = player.inventory.add_item(entity) player_turn_results.extend(pickup_results) break else: message_log.add_message(Message('There is nothing here to pick up.', libtcod.yellow)) if show_inventory: previous_game_state = game_state game_state = GameStates.SHOW_INVENTORY if drop_inventory: previous_game_state = game_state game_state = GameStates.DROP_INVENTORY if inventory_index is not None and previous_game_state != GameStates.PLAYER_DEAD and inventory_index < len( player.inventory.items): item = player.inventory.items[inventory_index] if game_state == GameStates.SHOW_INVENTORY: player_turn_results.extend(player.inventory.use(item, entities=entities, fov_map=fov_map)) elif game_state == GameStates.DROP_INVENTORY: player_turn_results.extend(player.inventory.drop_item(item)) if take_stairs and game_state == GameStates.PLAYERS_TURN: for entity in entities: if entity.stairs and entity.x == player.x and entity.y == player.y: entities = game_map.next_floor(player, message_log, constants) fov_map = initialize_fov(game_map) fov_recompute = True libtcod.console_clear(con) break else: message_log.add_message(Message('There are no stairs here.', libtcod.yellow)) if level_up: if level_up == 'hp': player.fighter.max_hp += 20 player.fighter.hp += 20 elif level_up == 'str': player.fighter.power += 1 elif level_up == 'def': player.fighter.defense += 1 game_state = previous_game_state if show_character_screen: previous_game_state = game_state game_state = GameStates.CHARACTER_SCREEN if game_state == GameStates.TARGETING: if left_click: target_x, target_y = left_click item_use_results = player.inventory.use(targeting_item, entities=entities, fov_map=fov_map, target_x=target_x, target_y=target_y) player_turn_results.extend(item_use_results) elif right_click: player_turn_results.append({'targeting_cancelled': True}) if exit: if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY, GameStates.CHARACTER_SCREEN): game_state = previous_game_state elif game_state == GameStates.TARGETING: player_turn_results.append({'targeting_cancelled': True}) else: save_game(player, entities, game_map, message_log, game_state) return True if fullscreen: libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen()) for player_turn_result in player_turn_results: message = player_turn_result.get('message') dead_entity = player_turn_result.get('dead') item_added = player_turn_result.get('item_added') item_consumed = player_turn_result.get('consumed') item_dropped = player_turn_result.get('item_dropped') targeting = player_turn_result.get('targeting') targeting_cancelled = player_turn_result.get('targeting_cancelled') xp = player_turn_result.get('xp') if message: message_log.add_message(message) if dead_entity: if dead_entity == player: message, game_state = kill_player(dead_entity) else: message = kill_monster(dead_entity) message_log.add_message(message) if item_added: entities.remove(item_added) game_state = GameStates.ENEMY_TURN if item_consumed: game_state = GameStates.ENEMY_TURN if item_dropped: entities.append(item_dropped) game_state = GameStates.ENEMY_TURN if targeting: previous_game_state = GameStates.PLAYERS_TURN game_state = GameStates.TARGETING targeting_item = targeting message_log.add_message(targeting_item.item.targeting_message) if targeting_cancelled: game_state = previous_game_state message_log.add_message(Message('Targeting cancelled')) if xp: leveled_up = player.level.add_xp(xp) message_log.add_message(Message('You gain {0} experience points.'.format(xp))) if leveled_up: message_log.add_message(Message( 'Your battle skills grow stronger! You reached level {0}'.format( player.level.current_level) + '!', libtcod.yellow)) previous_game_state = game_state game_state = GameStates.LEVEL_UP if game_state == GameStates.ENEMY_TURN: for entity in entities: if entity.ai: enemy_turn_results = entity.ai.take_turn(player, fov_map, game_map, entities) for enemy_turn_result in enemy_turn_results: message = enemy_turn_result.get('message') dead_entity = enemy_turn_result.get('dead') if message: message_log.add_message(message) if dead_entity: if dead_entity == player: message, game_state = kill_player(dead_entity) else: message = kill_monster(dead_entity) message_log.add_message(message) if game_state == GameStates.PLAYER_DEAD: break if game_state == GameStates.PLAYER_DEAD: break else: game_state = GameStates.PLAYERS_TURN