def test_sys_time(console): libtcodpy.sys_set_fps(0) libtcodpy.sys_get_fps() libtcodpy.sys_get_last_frame_length() libtcodpy.sys_sleep_milli(0) libtcodpy.sys_elapsed_milli() libtcodpy.sys_elapsed_seconds()
def _printStats(self, console): c = self.coords[self._selectedX][self._selectedY] messages = [ (1, str(tcod.sys_get_fps()) + " FPS"), (2, "Coord: (" + str(self._selectedX)+","+str(self._selectedY)+")"), (3, "X-Offset: " + str(self._offsetX)), (4, "Y-Offset: " + str(self._offsetY)), (5, "Altitude: " + str(c.altitude)), (6, "Temp : " + str(c.temp)), (7, "Rain : " + str(c.rainfall)), (8, "Salinity: " + str(c.salinity)), (9, "Spring : " + str(c.hasSpring)), (10, "Water : " + str(c.depth)), (11, "Source : " + str(c.source)), (12, "Biome : " + str(c.biome.name))] tcod.console_set_foreground_color(console, tcod.Color(255,0,127)); tcod.console_set_background_color(console, tcod.Color(0,0,0)); for y, msg in messages: tcod.console_print_right(console, self._displayWidth-1, y, tcod.BKGND_NONE, msg) tcod.console_set_foreground_color(console, tcod.Color(255,255,255)); ###///////////////////////////////////////////////////////////////////////////////////////////////// ### EOF
def _printStats(self, console): c = self.coords[self._selectedX][self._selectedY] messages = [(1, str(tcod.sys_get_fps()) + " FPS"), (2, "Coord: (" + str(self._selectedX) + "," + str(self._selectedY) + ")"), (3, "X-Offset: " + str(self._offsetX)), (4, "Y-Offset: " + str(self._offsetY)), (5, "Altitude: " + str(c.altitude)), (6, "Temp : " + str(c.temp)), (7, "Rain : " + str(c.rainfall)), (8, "Salinity: " + str(c.salinity)), (9, "Spring : " + str(c.hasSpring)), (10, "Water : " + str(c.depth)), (11, "Source : " + str(c.source)), (12, "Biome : " + str(c.biome.name))] tcod.console_set_foreground_color(console, tcod.Color(255, 0, 127)) tcod.console_set_background_color(console, tcod.Color(0, 0, 0)) for y, msg in messages: tcod.console_print_right(console, self._displayWidth - 1, y, tcod.BKGND_NONE, msg) tcod.console_set_foreground_color(console, tcod.Color(255, 255, 255)) ###///////////////////////////////////////////////////////////////////////////////////////////////// ### EOF
def updateMessages(self) : self._gui.frames['Info'].addMessage("Position : " + str((self.player.x, self.player.y)), 1 ) self._gui.frames['Info'].addMessage("Health : " + str(int(self.player.health)), 2 ) self._gui.frames['Info'].addMessage("Pick Axe : " + str(self.player.pickAxe), 3 ) self._gui.frames['Info'].addMessage("Torch : " + str(self.player.torchStrength), 4 ) self._gui.frames['Info'].addMessage("Anchors : " + str(self.player.anchors), 5 ) self._gui.frames['Info'].addMessage("Ropes : " + str(self.player.ropes), 6 ) self._gui.frames['Info'].addMessage("Clipped : " + str(len(self.player.clippedRopes)), 7 ) self._gui.frames['Info'].addMessage("FPS : " + str(libtcod.sys_get_fps()), 8 )
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 render_all(self): for obj in self.level.iter_objects(): if obj != self.player: obj.draw(self.player) self.player.draw() if self.game_state == 'selecting': self.cursor.draw() if self.player.fov_recompute: self.level.recompute_fov() libtcod.console_blit(self.con, 0,0, self.SCREEN_WIDTH,self.SCREEN_HEIGHT, 0,0, 0) libtcod.console_set_default_background(self.panel, libtcod.black) libtcod.console_clear(self.panel) utilities.render_bar(self.panel, 1,1, self.BAR_WIDTH, 'HP', self.player.fighter.hp, self.player.fighter.max_hp, libtcod.red, libtcod.darker_red ) libtcod.console_print_ex(self.panel, self.BAR_WIDTH/2,3, libtcod.BKGND_NONE, libtcod.CENTER, '%s p %s d' %(self.player.fighter.power, self.player.fighter.defense) ) fps = libtcod.sys_get_fps() libtcod.console_print_ex(self.panel, self.BAR_WIDTH/2,4, libtcod.BKGND_NONE, libtcod.CENTER, '%s FPS' %(libtcod.sys_get_fps()) ) libtcod.console_set_default_foreground(self.panel, libtcod.light_gray) libtcod.console_print(self.panel, 1, 0, self.get_names_under_mouse()) y = 1 for line, color in self.game_msgs: libtcod.console_set_default_foreground(self.panel, color) libtcod.console_print_ex(self.panel, self.MSG_X, y, libtcod.BKGND_NONE, libtcod.LEFT, line) y += 1 libtcod.console_blit(self.panel, 0,0, self.SCREEN_WIDTH,self.PANEL_HEIGHT, 0,0, self.PANEL_Y)
def tick(self): self.tc_events.tick() self.fps_display.set_text('%d', tc.sys_get_fps()) self.update_actors() self.map.draw(self.console) self.console.blit() self.message_console.blit() tc.console_flush() if tc.console_is_window_closed(): reactor.stop() else: reactor.callLater(0, self.tick)
def draw_bottom_ui_terraform(): """Controls the drawing of the UI under the map.""" _string = '%s fps ' % str(tcod.sys_get_fps()) _string += 'X: %s Y: %s Z: %s' % (MAP_CURSOR[0],MAP_CURSOR[1],CAMERA_POS[2]) blit_string(MAP_WINDOW_SIZE[0]-len(_string), MAP_WINDOW_SIZE[1]-1, _string, console=MAP_WINDOW, fore_color=tcod.Color(255,255,255), back_color=tcod.Color(0,0,0), flicker=0)
def draw_bottom_ui_terraform(): """Controls the drawing of the UI under the map.""" _string = '%s fps ' % str(tcod.sys_get_fps()) _string += 'X: %s Y: %s Z: %s' % (MAP_CURSOR[0], MAP_CURSOR[1], CAMERA_POS[2]) blit_string(MAP_WINDOW_SIZE[0] - len(_string), MAP_WINDOW_SIZE[1] - 1, _string, console=MAP_WINDOW, fore_color=tcod.Color(255, 255, 255), back_color=tcod.Color(0, 0, 0), flicker=0)
def gods_knowledge(self, mouse=False): """add info on the console""" fps = libtcod.sys_get_fps() knowledge = ("Generation: " + str(self.generation) + " Living: " + str(self.living) + " Dead: " + str(self.dead) + " FPS: " + str(fps)) if mouse: mx, my = self.mouse.cx, self.mouse.cy knowledge = [knowledge + " mx: " + str(mx) + " my: " + str(my)] knowledge = ("").join(knowledge) libtcod.console_set_default_foreground(0, libtcod.white) libtcod.console_print_ex(0, 0, self.height - 1, libtcod.BKGND_NONE, libtcod.LEFT, knowledge)
def display_status(self, state, console): tcod.console_clear(console.console) if self.status.pause: display_text(console.console, "*PAUSED*", 0, 0) display_text(console.console, str(tcod.sys_get_fps()), 10, 0) display_text(console.console, self.status.current_state, 15, 0) cash_display = 'Cash: %s' % self.status.money display_text(console.console, cash_display, 50, 0) if self.status.last_money_movement: color = tcod.red to_display = str(self.status.last_money_movement) if self.status.last_money_movement > 0: color = tcod.yellow to_display = '+ %s' % to_display display_text(console.console, to_display, 52 + len(cash_display), 0, color) self.status.delta_increment() for idx, f in enumerate(self.status.flags): display_highlighted_text(console.console, f, console.w - idx - 1, 0)
def stats(): libtcod.console_set_default_foreground(None, libtcod.grey) libtcod.console_print_ex ( None, 79, 46, libtcod.BKGND_NONE, libtcod.RIGHT, 'last frame : %3d ms (%3d fps)' % ( int(libtcod.sys_get_last_frame_length() * 1000.0), libtcod.sys_get_fps() ) ) libtcod.console_print_ex ( None, 79, 47, libtcod.BKGND_NONE, libtcod.RIGHT, 'elapsed : %8d ms %4.2fs' % ( libtcod.sys_elapsed_milli(), libtcod.sys_elapsed_seconds() ) )
def render(): global map, camera, player, SCREEN_WIDTH, SCREEN_HEIGHT, FOV_RECOMPUTE camera.move_camera(player.x, player.y, map.width, map.height) libtcod.console_set_default_foreground(0, libtcod.white) temp_player_x, temp_player_y = camera.to_camera_coordinates(player.x, player.y) if FOV_RECOMPUTE: libtcod.console_clear(0) libtcod.map_compute_fov(map.fov_map, player.x, player.y, 7, True, 1) FOV_RECOMPUTE = False for x in range(DISPLAY_WIDTH): for y in range(DISPLAY_HEIGHT): (map_x, map_y) = (camera.x + x, camera.y + y) distance = get_distance(player.x, map_x, player.y, map_y) map.map[map_x][map_y].draw(camera, map, distance) libtcod.console_print(FPS_CONSOLE, 0, 0, 'FPS: ' + str(libtcod.sys_get_fps())) libtcod.console_blit(FPS_CONSOLE, 0, 0, 10, 1, 0, 0, 0) libtcod.console_flush()
def display_status(self, state, console): tcod.console_clear(console.console) if self.status.pause: display_text(console.console, "*PAUSED*", 0, 0) display_text(console.console, str(tcod.sys_get_fps()), 10, 0) display_text(console.console, self.status.current_state, 15, 0) cash_display = 'Cash: %s' % self.status.money display_text(console.console, cash_display, 50, 0) if self.status.last_money_movement: color = tcod.red to_display = str(self.status.last_money_movement) if self.status.last_money_movement > 0: color = tcod.yellow to_display = '+ %s' % to_display display_text( console.console, to_display, 52 + len(cash_display), 0, color ) self.status.delta_increment() for idx, f in enumerate(self.status.flags): display_highlighted_text(console.console, f, console.w - idx - 1, 0)
mouse = libtcod.Mouse() key = libtcod.Key() # Keeps running as long as the window is not closed # This is effectively the main loop while not libtcod.console_is_window_closed(): libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS|libtcod.EVENT_MOUSE,key,mouse) # Render to the offscreen console render_all() libtcod.console_flush() # draw the console # Clear objects from their old locations before we move them next time for obj in objects: obj.clear() if key.vk == libtcod.KEY_SPACE: fps = libtcod.sys_get_fps() print "FPS: " + str(fps) player_action = handle_keys() if player_action == "exit": break #let monsters take their turn # if game_state == 'playing' and player_action != 'didnt-take-turn': # for object in objects: # if object != player: # print 'The ' + object.name + ' growls!'
def showfps(): # print FPS libtcod.console_print_ex(0,SCREEN_WIDTH-1,0, libtcod.BKGND_NONE, libtcod.RIGHT, 'FPS:' + libtcod.sys_get_fps().__str__())
def play_game(): sys.setrecursionlimit(10000) #to ensure saving works player_action = None fps = 0 #main loop while not libtcod.console_is_window_closed(): libtcod.sys_check_for_event( libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, cfg.key, cfg.mouse) #render the screen gui.render_all() libtcod.console_flush() #update objects map object.update_objects_map() #level up if needed object.check_level_up() #erase all objects at their old locations, before they move for obj in cfg.objects: obj.clear() #handle keys and exit game if needed player_action = handle_keys() if player_action == 'exit': save_game() break #let monsters take their turn if cfg.game_state == 'playing' and player_action != 'didnt-take-turn': for obj in cfg.objects: if obj.ai: obj.ai.take_turn() if obj.item: obj.item.age_up() if random.random() < cfg.PLANT_GROWTH_PROBABILITY: #grow PLANT_GROWTH_RATE number of plants for i in range(cfg.NEW_PLANT_RATE): #choose random tile x = libtcod.random_get_int(0, 1, cfg.MAP_WIDTH) y = libtcod.random_get_int(0, 1, cfg.MAP_HEIGHT) #if the tile is unoccupied, grow plant occupant = object.is_occupied(x, y) if not occupant: object.make_plant(x, y) elif type(occupant) is object.Food: if not occupant.corpse: occupant.item.grow() #update population counts #update_population() object.update_max_population() #print fps if cfg.PRINT_FPS: new_fps = libtcod.sys_get_fps() #only print when it changes if new_fps != fps: fps = new_fps print 'FPS: ' + str(fps)
def render_all(self): ##============================================================================ #self.gEngine.console_clear(self.con) if self.fov_recompute: #recompute FOV if needed (the player moved or something) fov_recompute = False libtcod.map_compute_fov(self.fov_map, self.player.x, self.player.y, TORCH_RADIUS, FOV_LIGHT_WALLS, FOV_ALGO) #self.gEngine.map_draw_scrolling(self.con, self, self.player.x,self.player.y) self.gEngine.light_mask.add_light(self.player.x, self.player.y, 1.0) #self.gEngine.light_mask.compute_mask(self.Map.map) #self.gEngine.map_draw(self.con, self.player.x, self.player.y, self.gEngine.light_mask) #draw all objects in the list, except the player. we want it to #always appear over all other objects! so it's drawn later. for object in self.objects: if object.fighter: self.gEngine.lightmask_add_light(object.x, object.y, 0.5) self.gEngine.particle_update(self.Map.map) self.gEngine.light_mask.compute_mask(self.Map.map) for object in self.objects: if object is not self.player: if object.misc: if object.misc.type is 'up' or object.misc.type is 'down': #Draw stairs if they are already found if self.gEngine.map_is_explored(object.x,object.y): object.draw(self.fov_map,self.gEngine,force_display=True) else: object.draw(self.fov_map,self.gEngine) else: object.draw(self.fov_map,self.gEngine) self.gEngine.map_draw(self.con, self.player.x, self.player.y, self.gEngine.light_mask) self.gEngine.blit_map(self.con) self.player.draw(self.fov_map, self.gEngine) for particle in self.particles:#770 559 8132 particle.draw(self.fov_map,self.gEngine,True) #blit the contents of "con" to the root console self.gEngine.console_print(self.con, 1, 1, "Depth: %i" % self.depth) self.gEngine.console_blit(self.con, 0, 0, MAP_WIDTH, MAP_HEIGHT, 0, 0, 0, 1.0, 1.0) #prepare to render the GUI panel r,g,b = libtcod.black self.gEngine.console_set_default_background(self.panel, r, g, b) self.gEngine.console_clear(self.panel) #print the game messages self.message.flush_messages(self.gEngine) #show the player's stats self.player_hp_bar.render(1,1,self.gEngine) self.player_xp_bar.render(1,3,self.gEngine) #display names of objects under the mouse r,g,b = libtcod.light_gray self.gEngine.console_set_default_foreground(self.panel,r,g,b) self.gEngine.console_set_alignment(self.panel,libtcod.LEFT) self.gEngine.console_print(self.panel, 1, 5, "(%dfps)" % (libtcod.sys_get_fps())) self.gEngine.console_print(self.panel, 1, 0, self.get_names_under_mouse()) self.hotbar.render() self.gEngine.console_blit(self.toolbar, 0, 0, SCREEN_WIDTH, 5, 0, 0, PANEL_Y-5, 1.0, 1.0) #print a message with the names of objects under the player self.get_names_under_player() #blit the contents of "panel" to the root console r, g, b = libtcod.black self.gEngine.console_set_default_background(0, r, g, b) self.gEngine.console_blit(self.panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0, PANEL_Y,1.0,1.0)
#move the light around in a circle t += 0.02 lightx = HALF_W + HALF_H * math.cos(t) lighty = HALF_H + HALF_H * math.sin(t) for x in range(SCREEN_W): for y in range(SCREEN_H): #define the brightness of a light in a tile as the inverse of the #squared distance from that tile to the light. sqr_distance = (x - lightx)**2 + (y - lighty)**2 brightness = 5.0 / sqr_distance #convert to 0-255 range brightness = int(brightness * 255) #truncate values outside that range brightness = max(min(brightness, 255), 0) #make a blue light by only setting the blue component and leaving others at 0 B[SCREEN_W * y + x] = brightness #fill the screen with these background colors libtcod.console_fill_background(0, R, G, B) #show FPS libtcod.console_set_foreground_color(0, libtcod.white) libtcod.console_print_right(None, SCREEN_W-1, SCREEN_H-1, libtcod.BKGND_SET, '%3d FPS' % libtcod.sys_get_fps()) libtcod.console_flush()
_RB = zeros((SCREEN_H,SCREEN_W)) _GB = zeros((SCREEN_H,SCREEN_W)) _BB = zeros((SCREEN_H,SCREEN_W)) _RB = add(_RB,255) _GB = add(_GB,255) _BB = add(_BB,255) render = zeros((SCREEN_H,SCREEN_W)) for light in lights: if lights.index(light) == 0: light['x'] -= 0.01 sqr_distance = (x - light['x'])**2 + (y - light['y'])**2 brightness = light['brightness'] / sqr_distance brightness = clip(brightness * 255, 0, 255) _RB = subtract(_RB,brightness).clip(0,255) _GB = subtract(_GB,brightness).clip(0,255) _BB = subtract(_BB,brightness).clip(0,255) _R = subtract(_R,_RB).clip(0,255) _G = subtract(_G,_GB).clip(0,255) _B = subtract(_B,_BB).clip(0,255) libtcod.console_fill_background(0, _R, _G, _B) libtcod.console_fill_foreground(0, _R, _G, _B) print libtcod.sys_get_fps() libtcod.console_flush()
def main(): _player_moved = False _refresh_map = False get_input() handle_input() if not LIFE[SETTINGS["controlling"]]["dead"]: if LIFE[SETTINGS["controlling"]]["asleep"]: gfx.fade_to_black(255) gfx.start_of_frame() gfx.end_of_frame() while LIFE[SETTINGS["controlling"]]["asleep"]: _played_moved = True _refresh_map = True gfx.title(LIFE[SETTINGS["controlling"]]["asleep_reason"]) logic.tick_all_objects(ignore_tickrate=True, ignore_pause=True) if LIFE[SETTINGS["controlling"]]["dead"]: break else: _player_moved = True if _refresh_map: gfx.refresh_view("map") if not _player_moved: logic.tick_all_objects(ignore_tickrate=True) draw_targeting() move_camera(SETTINGS["camera_track"]) # TODO: Deselect so we can get rid of this call if SELECTED_TILES[0]: gfx.refresh_view("map") if not SETTINGS["last_camera_pos"] == SETTINGS["camera_track"][:]: if EVENTS or MENUS: _visible_chunks = sight.scan_surroundings(LIFE[SETTINGS["following"]], judge=False, get_chunks=True) alife.brain.flag(LIFE[SETTINGS["following"]], "visible_chunks", value=_visible_chunks) _cam_x = numbers.clip( LIFE[SETTINGS["following"]]["pos"][0] - MAP_WINDOW_SIZE[0] / 2, 0, MAP_SIZE[0] - MAP_WINDOW_SIZE[0] / 2 ) _cam_y = numbers.clip( LIFE[SETTINGS["following"]]["pos"][1] - MAP_WINDOW_SIZE[1] / 2, 0, MAP_SIZE[1] - MAP_WINDOW_SIZE[1] / 2 ) else: _visible_chunks = sight.scan_surroundings(LIFE[SETTINGS["controlling"]], judge=False, get_chunks=True) alife.brain.flag(LIFE[SETTINGS["controlling"]], "visible_chunks", value=_visible_chunks) SETTINGS["last_camera_pos"] = SETTINGS["camera_track"][:] _cam_x = numbers.clip( LIFE[SETTINGS["controlling"]]["pos"][0] - MAP_WINDOW_SIZE[0] / 2, 0, MAP_SIZE[0] - MAP_WINDOW_SIZE[0] / 2 ) _cam_y = numbers.clip( LIFE[SETTINGS["controlling"]]["pos"][1] - MAP_WINDOW_SIZE[1] / 2, 0, MAP_SIZE[1] - MAP_WINDOW_SIZE[1] / 2 ) maps.render_lights() if "--worldmap" in sys.argv: render_map.render_map(WORLD_INFO["map"], force_camera_pos=(_cam_x, _cam_y, 2)) else: render_map.render_map( WORLD_INFO["map"], los=LIFE[SETTINGS["controlling"]]["fov"], force_camera_pos=(_cam_x, _cam_y, 2) ) items.draw_items() life.draw_life() if LIFE[SETTINGS["controlling"]]["dead"] and not EVENTS: if not death(): return False if SETTINGS["draw life info"] and SETTINGS["following"]: life.draw_life_info() gfx.draw_message_box() menus.align_menus() menus.draw_menus() gfx.draw_status_line() gfx.draw_console() gfx.start_of_frame() gfx.end_of_frame() if "--fps" in sys.argv: print tcod.sys_get_fps() if (SETTINGS["recording"] and logic.can_tick()) or "--worldmap" in sys.argv: gfx.screenshot() if "--worldmap" in sys.argv: SETTINGS["running"] = False
# start render Renderer.RenderAll(panels) #show FPS and color under mouse cursor (x, y) = (mouse.cx, mouse.cy) if Core.mainScene.MainWindow.Contains(x, y): x, y = Core.mainScene.ScreenToWorldPoint(x, y) libtcod.console_set_default_foreground(0, libtcod.white) libtcod.console_print_ex(None, EngineSettings.ScreenWidth-1, EngineSettings.ScreenHeight-4, libtcod.BKGND_SET, libtcod.RIGHT, 'Tile FG: {0}'.format(Core.mainScene.MainWindow.GetForegroundRGB(x, y))) libtcod.console_print_ex(None, EngineSettings.ScreenWidth-1, EngineSettings.ScreenHeight-3, libtcod.BKGND_SET, libtcod.RIGHT, 'Tile BG: {0}'.format(Core.mainScene.MainWindow.GetBackgroundRGB(x, y))) libtcod.console_print_ex(None, EngineSettings.ScreenWidth-1, EngineSettings.ScreenHeight-2, libtcod.BKGND_SET, libtcod.RIGHT, 'Light: {0}'.format(Core.mainScene.GetLightAt(x, y))) libtcod.console_print_ex(None, EngineSettings.ScreenWidth-1, EngineSettings.ScreenHeight-1, libtcod.BKGND_SET, libtcod.RIGHT, '%3d FPS' % libtcod.sys_get_fps()) libtcod.console_flush() # draw the console # end render if mouse.lbutton_pressed: Core.mainScene.AddPointLight(Light(x=mouse.cx, y=mouse.cy, col=libtcod.white, brightness=0.5)) Core.mainScene.CalculateLightmap() Core.logWin.Log("New light at " + str(mouse.cx) + ", " + str(mouse.cy)) gamelog.Log("There are {0} point lights".format(len(Core.mainScene.PointLights))) if mouse.rbutton_pressed: Core.mainScene.PointLights.pop() Core.mainScene.CalculateLightmap() gamelog.Log("There are {0} point lights".format(len(Core.mainScene.PointLights))) if key.c in (ord('C'), ord('c')):
def play_arena(ui_con): console_buffer = tcod.ConsoleBuffer(constant.SCREEN_WIDTH, constant.SCREEN_HEIGHT) map_size = (constant.SCREEN_WIDTH * 1, constant.SCREEN_HEIGHT * 1) the_map = game_map.make_map(*map_size) fov_map = tcod.map_new(*map_size) player = entity.Entity(map_size[0] / 2, map_size[1] / 2, "@", tcod.black) player.inventory_component = item.Inventory(player, constant.INENTORY_SIZE[0], constant.INENTORY_SIZE[1], constant.WEIGHT_LIMIT) blah = "Makarov PM" test_makarov = item.Item(blah, item_types.firearms[blah][-1]) test_makarov.gun_component = item.Gun(test_makarov, *item_types.firearms[blah][:-1]) makarov_entity = entity.Entity(map_size[0] / 2 + 1, map_size[1] / 2 + 1, "]", tcod.dark_grey, item_component=test_makarov, is_walkable=True) entity_list = [player, makarov_entity] camera_x, camera_y = (player.x, player.y) fov_map = fov.update_fov_map(the_map, fov_map) tcod.map_compute_fov(fov_map, player.x, player.y, constant.VISION_RANGE, True, tcod.FOV_BASIC) fov_recompute = True in_menu = False selected_inv_square = None test = tcod.image_load(os.path.join("images", "weapons", "Makarov PM.png")) tcod.image_set_key_color(test, tcod.pink) # Set initial values for key and mouse event; required to pass into sys_check_for_event key = tcod.console_check_for_keypress(tcod.KEY_PRESSED) mouse_status = tcod.mouse_get_status() while True: # Get input tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS | tcod.EVENT_MOUSE, key, mouse_status) if not in_menu: # Update camera. This must be done before rendering (center_x, center_y) = geometry.get_point_ahead(player.x, player.y, mouse_status.cx + camera_x, mouse_status.cy + camera_y, constant.CAMERA_DISTANCE) (camera_x, camera_y) = geometry.update_camera(center_x, center_y, the_map.width, the_map.height) player_facing_point = (mouse_status.cx, mouse_status.cy) # Update FOV if fov_recompute: tcod.map_compute_fov(fov_map, player.x, player.y, constant.VISION_RANGE, True, tcod.FOV_BASIC) fov.update_entity_fov(entity_list, the_map, fov_map) # Render the map and entities the_map.render(console_buffer, fov_map, camera_x, camera_y, player.x, player.y, *player_facing_point) console_buffer.blit(0) # Only entities in the player's line of sight should be drawn for _entity in reversed(entity_list): if fov.in_player_fov(_entity.x, _entity.y, player.x, player.y, mouse_status.cx + camera_x, mouse_status.cy + camera_y, fov_map): _entity.render(0, camera_x, camera_y) # fps display tcod.console_print_ex(0, constant.SCREEN_WIDTH - 1, 0, tcod.BKGND_NONE, tcod.RIGHT, str(tcod.sys_get_fps())) # If in inventory, draw inventory grid if in_menu == "inventory": tcod.mouse_show_cursor(True) tcod.console_clear(ui_con) ui.draw_checkerboard(ui_con, constant.INENTORY_SIZE[0], constant.INENTORY_SIZE[1], constant.SQUARE_SIZE, tcod.grey, tcod.dark_grey) ui.draw_inventory_items(ui_con, player.inventory_component) if selected_inv_square is not None: tcod.console_print_frame(ui_con, selected_inv_square[0] * constant.SQUARE_SIZE, selected_inv_square[1] * constant.SQUARE_SIZE, constant.SQUARE_SIZE, constant.SQUARE_SIZE, False, tcod.BKGND_NONE, False) tcod.console_blit(ui_con, 0, 0, constant.INENTORY_SIZE[0] * constant.SQUARE_SIZE, constant.INENTORY_SIZE[1] * constant.SQUARE_SIZE, 0, constant.INVENTORY_X, constant.INVENTORY_Y) tcod.console_flush() fov_recompute = False # Handle input if not in_menu: if key.vk == tcod.KEY_LEFT: # Move left if not entity.check_collision(player.x - 1, player.y, the_map, entity_list): player.x -= 0 if player.x == 0 else 1 fov_recompute = True elif key.vk == tcod.KEY_RIGHT: # Move right if not entity.check_collision(player.x + 1, player.y, the_map, entity_list): player.x += 0 if player.x == the_map.width else 1 fov_recompute = True elif key.vk == tcod.KEY_UP: # Move up if not entity.check_collision(player.x, player.y - 1, the_map, entity_list): player.y -= 0 if player.y == 0 else 1 fov_recompute = True elif key.vk == tcod.KEY_DOWN: # Move down if not entity.check_collision(player.x, player.y + 1, the_map, entity_list): player.y += 0 if player.y == the_map.height else 1 fov_recompute = True elif key.c == ord("i"): in_menu = "inventory" elif key.c == ord(","): for _entity in entity_list: if (_entity.item_component is not None and _entity.x == player.x and _entity.y == player.y): player.inventory_component.add(_entity.item_component) entity_list.remove(_entity) elif key.vk == tcod.KEY_ESCAPE: # Quit back to main menu break elif in_menu == "inventory": if mouse_status.lbutton_pressed: prev_square = selected_inv_square selected_inv_square = ((mouse_status.cx - constant.INVENTORY_X) / constant.SQUARE_SIZE, (mouse_status.cy - constant.INVENTORY_Y) / constant.SQUARE_SIZE) if selected_inv_square == prev_square: selected_inv_square = None elif not ((0 <= selected_inv_square[0] < constant.INENTORY_SIZE[0]) and (0 <= selected_inv_square[1] < constant.INENTORY_SIZE[1])): selected_inv_square = prev_square elif key.c == ord("i"): tcod.mouse_show_cursor(False) in_menu = ""
def get_fps(): return tcod.sys_get_fps()
def get_fps(): return libtcod.sys_get_fps()
def render_map(): # recompute FOV if needed (the player moved or something) libtcod.console_rect(0, game.MAP_X, game.MAP_Y, game.MAP_WIDTH, game.MAP_HEIGHT, True) if game.fov_recompute: find_map_viewport() fov_radius() initialize_fov(True) libtcod.map_compute_fov(game.fov_map, game.char.x, game.char.y, game.FOV_RADIUS, game.FOV_LIGHT_WALLS, game.FOV_ALGO) game.fov_recompute = False # 'torch' animation if game.fov_torch: game.fov_torchx += 0.2 tdx = [game.fov_torchx + 20.0] dx = libtcod.noise_get(game.fov_noise, tdx, libtcod.NOISE_SIMPLEX) * 1.5 tdx[0] += 30.0 dy = libtcod.noise_get(game.fov_noise, tdx, libtcod.NOISE_SIMPLEX) * 1.5 di = 0.4 * libtcod.noise_get(game.fov_noise, [game.fov_torchx], libtcod.NOISE_SIMPLEX) # go through all tiles, and set their background color according to the FOV for y in range(game.MAP_HEIGHT): for x in range(game.MAP_WIDTH): px = x + game.curx py = y + game.cury if not libtcod.map_is_in_fov(game.fov_map, px, py): if game.draw_map and game.current_map.tile_is_explored(px, py): if game.current_map.tile_is_animated(px, py): libtcod.console_put_char_ex(game.con, x, y, game.current_map.tile[px][py]['icon'], game.current_map.tile[px][py]['dark_color'], game.current_map.tile[px][py]['dark_back_color']) else: libtcod.console_put_char_ex(game.con, x, y, game.current_map.tile[px][py]['icon'], game.current_map.tile[px][py]['dark_color'], game.current_map.tile[px][py]['back_dark_color']) else: if not game.fov_torch: if 'animate' in game.current_map.tile[px][py] or 'duration' in game.current_map.tile[px][py]: (front, back, game.current_map.tile[px][py]['lerp']) = render_tiles_animations(px, py, game.current_map.tile[px][py]['color'], game.current_map.tile[px][py]['back_light_color'], game.current_map.tile[px][py]['back_dark_color'], game.current_map.tile[px][py]['lerp']) libtcod.console_put_char_ex(game.con, x, y, game.current_map.tile[px][py]['icon'], front, back) elif game.draw_map: libtcod.console_put_char_ex(game.con, x, y, game.current_map.tile[px][py]['icon'], game.current_map.tile[px][py]['color'], game.current_map.tile[px][py]['back_light_color']) else: base = game.current_map.tile[px][py]['back_light_color'] r = float(px - game.char.x + dx) * (px - game.char.x + dx) + (py - game.char.y + dy) * (py - game.char.y + dy) if r < game.SQUARED_TORCH_RADIUS: l = (game.SQUARED_TORCH_RADIUS - r) / game.SQUARED_TORCH_RADIUS + di if l < 0.0: l = 0.0 elif l > 1.0: l = 1.0 base = libtcod.color_lerp(base, libtcod.gold, l) libtcod.console_put_char_ex(game.con, x, y, game.current_map.tile[px][py]['icon'], game.current_map.tile[px][py]['color'], base) if not game.current_map.tile_is_explored(px, py): game.current_map.tile[px][py].update({'explored': True}) # draw all objects in the map (if in the map viewport), except the player who his drawn last for obj in reversed(game.current_map.objects): if obj.y in range(game.cury, game.cury + game.MAP_HEIGHT) and obj.x in range(game.curx, game.curx + game.MAP_WIDTH) and game.current_map.tile_is_explored(obj.x, obj.y) and obj.name != 'player': if game.draw_map and obj.entity is not None: if libtcod.map_is_in_fov(game.fov_map, obj.x, obj.y) and not obj.entity.is_identified(): skill = game.player.find_skill('Mythology') if (game.player.skills[skill].level * 0.8) + 20 >= roll_dice(1, 100): obj.entity.flags.append('identified') game.message.new('You properly identify the ' + obj.entity.unidentified_name + ' as ' + obj.entity.get_name(True) + '.', game.turns) game.player.skills[skill].gain_xp(3) if obj.entity is not None and not obj.entity.is_identified(): obj.draw(game.con, libtcod.white) else: obj.draw(game.con) game.char.draw(game.con) libtcod.console_blit(game.con, 0, 0, game.MAP_WIDTH, game.MAP_HEIGHT, 0, game.MAP_X, game.MAP_Y) game.draw_map = False # move the player if using mouse if game.mouse_move: if mouse_auto_move() and not libtcod.path_is_empty(game.path): game.char.x, game.char.y = libtcod.path_walk(game.path, True) game.fov_recompute = True game.player_move = True else: items_at_feet() game.mouse_move = False # check where is the mouse cursor if not in the act of moving while using the mouse if not game.mouse_move: (mx, my) = (game.mouse.cx - game.MAP_X, game.mouse.cy - 1) px = mx + game.curx py = my + game.cury game.path_dx = -1 game.path_dy = -1 if my in range(game.MAP_HEIGHT) and mx in range(game.MAP_WIDTH): libtcod.console_set_char_background(0, mx + game.MAP_X, my + 1, libtcod.white, libtcod.BKGND_SET) if game.current_map.tile_is_explored(px, py) and not game.current_map.tile_is_blocked(px, py): game.path_dx = px game.path_dy = py if game.mouse.lbutton_pressed: target = [obj for obj in game.current_map.objects if obj.y == py and obj.x == px and obj.entity] if target: mouse_auto_attack(px, py, target[0]) else: game.mouse_move = mouse_auto_move() # draw a line between the player and the mouse cursor if not game.current_map.tile_is_blocked(game.path_dx, game.path_dy): libtcod.path_compute(game.path, game.char.x, game.char.y, game.path_dx, game.path_dy) for i in range(libtcod.path_size(game.path)): x, y = libtcod.path_get(game.path, i) if (y - game.cury) in range(game.MAP_HEIGHT) and (x - game.curx) in range(game.MAP_WIDTH): libtcod.console_set_char_background(0, game.MAP_X + x - game.curx, game.MAP_Y + y - game.cury, libtcod.desaturated_yellow, libtcod.BKGND_SET) libtcod.console_set_default_foreground(0, libtcod.light_yellow) libtcod.console_print_rect(0, game.MAP_X, game.MAP_Y, game.MAP_WIDTH - 18, game.MAP_HEIGHT, get_names_under_mouse()) if game.debug.enable: libtcod.console_print_ex(0, game.MAP_X + game.MAP_WIDTH - 1, game.MAP_Y, libtcod.BKGND_NONE, libtcod.RIGHT, str(game.gametime.hour) + ':' + str(game.gametime.minute).rjust(2, '0') + ' (%3d fps)' % libtcod.sys_get_fps()) if game.hp_anim: render_floating_text_animations()
x = snake[0].x + speed[0] y = snake[0].y + speed[1] if not tcod.map_is_walkable(grid, x, y): # try up speed = [0, -1] x = snake[0].x + speed[0] y = snake[0].y + speed[1] if not tcod.map_is_walkable(grid, x, y): # try down speed = [0, 1] x = snake[0].x + speed[0] y = snake[0].y + speed[1] if not tcod.map_is_walkable(grid, x, y): # try left speed = [-1, 0] x = snake[0].x + speed[0] y = snake[0].y + speed[1] if not tcod.map_is_walkable(grid, x, y): # try right speed = [1, 0] x = snake[0].x + speed[0] y = snake[0].y + speed[1] if not tcod.map_is_walkable(grid, x, y): #you're f****d pass tcod.console_flush() tcod.console_clear(None) # fps tcod.console_print_ex(None, RW - 2, RH - 2, tcod.BKGND_NONE, tcod.RIGHT, '%3d fps' % tcod.sys_get_fps())
def render_fps(self): tcod.console_set_default_foreground(0, tcod.white) tcod.console_print_ex(0, 0, self.height - 1, tcod.BKGND_NONE, tcod.LEFT, "%d FPS" % tcod.sys_get_fps())
def main(): _player_moved = False _refresh_map = False get_input() handle_input() if not LIFE[SETTINGS['controlling']]['dead']: if LIFE[SETTINGS['controlling']]['asleep']: gfx.fade_to_black(255) gfx.start_of_frame() gfx.end_of_frame() while LIFE[SETTINGS['controlling']]['asleep']: _played_moved = True _refresh_map = True gfx.title(LIFE[SETTINGS['controlling']]['asleep_reason']) logic.tick_all_objects(ignore_tickrate=True, ignore_pause=True) if LIFE[SETTINGS['controlling']]['dead']: break else: _player_moved = True if _refresh_map: gfx.refresh_view('map') if not _player_moved: if logic.tick_all_objects(ignore_tickrate=True): _player_moved = True draw_targeting() move_camera(SETTINGS['camera_track']) #TODO: Deselect so we can get rid of this call if SELECTED_TILES[0]: gfx.refresh_view('map') if not SETTINGS['last_camera_pos'] == SETTINGS['camera_track'][:]: if EVENTS or MENUS: _visible_chunks = sight.scan_surroundings( LIFE[SETTINGS['following']], judge=False, get_chunks=True) alife.brain.flag(LIFE[SETTINGS['following']], 'visible_chunks', value=_visible_chunks) _cam_x = numbers.clip( LIFE[SETTINGS['following']]['pos'][0] - MAP_WINDOW_SIZE[0] / 2, 0, MAP_SIZE[0] - MAP_WINDOW_SIZE[0] / 2) _cam_y = numbers.clip( LIFE[SETTINGS['following']]['pos'][1] - MAP_WINDOW_SIZE[1] / 2, 0, MAP_SIZE[1] - MAP_WINDOW_SIZE[1] / 2) else: _visible_chunks = sight.scan_surroundings( LIFE[SETTINGS['controlling']], judge=False, get_chunks=True) alife.brain.flag(LIFE[SETTINGS['controlling']], 'visible_chunks', value=_visible_chunks) SETTINGS['last_camera_pos'] = SETTINGS['camera_track'][:] _cam_x = numbers.clip( LIFE[SETTINGS['controlling']]['pos'][0] - MAP_WINDOW_SIZE[0] / 2, 0, MAP_SIZE[0] - MAP_WINDOW_SIZE[0] / 2) _cam_y = numbers.clip( LIFE[SETTINGS['controlling']]['pos'][1] - MAP_WINDOW_SIZE[1] / 2, 0, MAP_SIZE[1] - MAP_WINDOW_SIZE[1] / 2) maps.render_lights() if '--worldmap' in sys.argv: render_map.render_map(WORLD_INFO['map'], force_camera_pos=(_cam_x, _cam_y, 2)) else: render_map.render_map(WORLD_INFO['map'], los=LIFE[SETTINGS['controlling']]['fov'], force_camera_pos=(_cam_x, _cam_y, 2)) items.draw_items() life.draw_life() if LIFE[SETTINGS['controlling']]['dead'] and not EVENTS: if not death(): return False if SETTINGS['draw life info'] and SETTINGS['following']: life.draw_life_info() gfx.draw_message_box() menus.align_menus() menus.draw_menus() gfx.draw_status_line() gfx.draw_console() gfx.start_of_frame() gfx.end_of_frame() if '--fps' in sys.argv: print tcod.sys_get_fps() if (SETTINGS['recording'] and _player_moved and not EVENTS and not MENUS) or '--worldmap' in sys.argv: gfx.screenshot() if '--worldmap' in sys.argv: SETTINGS['running'] = False