def clear(self): terminal.layer(self.layer) terminal.clear_area(self.x, self.y, self.xlen, self.ylen) if self.wtype == 'normal' and self.multi_layer: self.fx.clear()
def clear_layer(layer, color='black'): terminal.bkcolor(color) terminal.layer(layer) terminal.clear_area(0, 0, Constants.SCREEN_WIDTH, Constants.SCREEN_HEIGHT)
def draw_stats(self, target=None): # TODO: Clean up this function player = self.owner.player power_msg = "[color=light azure]Spirit power left: " + str( player.player.spirit_power) blt.layer(0) blt.clear_area( 2, self.owner.ui.viewport.offset_h + self.ui_offset_y + 3, self.owner.ui.viewport.offset_center_x + int(len(power_msg) / 2 + 5) - 5, 3) blt.color("gray") # Draw spirit power left and position it depending on window size if self.owner.ui.viewport.offset_w > 90: blt.color("default") blt.puts(self.owner.ui.viewport.offset_center_x, self.owner.ui.viewport.offset_h + self.ui_offset_y - 1, "[offset=0,0]" + power_msg, 0, 0, blt.TK_ALIGN_CENTER) else: blt.color("default") blt.puts(self.owner.ui.viewport.offset_w - len(power_msg), self.owner.ui.viewport.offset_h + self.ui_offset_y + 1, "[offset=0,-2]" + power_msg, 0, 0, blt.TK_ALIGN_LEFT) # Draw player stats if player.fighter.hp / player.fighter.max_hp < 0.34: hp_player = "[color=light red]HP:" + \ str(player.fighter.hp) + "/" + \ str(player.fighter.max_hp) + " " else: hp_player = "[color=default]HP:" + \ str(player.fighter.hp) + "/" + \ str(player.fighter.max_hp) + " " ev_player = "EV:" + str(player.fighter.ev) + " " active_effects = [] for x in player.status_effects.items: active_effects.append("[color={0}]{1} ({2} turns)".format( x.color, x.description, str(x.duration + 1))) if x.name == "poison": hp_player = "[color={0}]HP:{1}/{2} ".format( x.color, str(player.fighter.hp), str(player.fighter.max_hp)) elif x.name == "fly": ev_player = "[color={0}]EV:{1} ".format( x.color, str(player.fighter.ev)) if active_effects: blt.puts(4, self.owner.ui.viewport.offset_h + self.ui_offset_y + 3, "[offset=0,-2]" + " ".join(active_effects) + " ", 0, 0, blt.TK_ALIGN_LEFT) ac_player = "[color=default]AC:" + str(player.fighter.ac) + " " power_player = "[color=default]ATK:" + str(player.fighter.power) + " " lvl_player = "LVL:" + str(player.player.char_level) + " " exp_player = "EXP:" + str(player.player.char_exp["player"]) + "/" + \ str(player.player.char_level * player.player.exp_lvl_interval) blt.puts( 4, self.owner.ui.viewport.offset_h + self.ui_offset_y + 1, "[offset=0,-2]" + "[color=lightest green]Player: " + hp_player + ac_player + ev_player + power_player + lvl_player + exp_player, 0, 0, blt.TK_ALIGN_LEFT) # Draw target stats if target and not target == player: blt.clear_area( self.owner.ui.viewport.offset_center_x - int(len(power_msg) / 2) - 5, self.owner.ui.viewport.offset_h + self.ui_offset_y + 1, self.owner.ui.viewport.offset_w, 3) if target.fighter.hp / target.fighter.max_hp < 0.34: hp_target = "[color=light red]HP:" + \ str(target.fighter.hp) + "/" + \ str(target.fighter.max_hp) + " " else: hp_target = "[color=default]HP:" + \ str(target.fighter.hp) + "/" + \ str(target.fighter.max_hp) + " " ev_target = "EV:" + str(target.fighter.ev) + " " active_effects = [] for x in target.status_effects.items: if x.duration > 0: active_effects.append("[color={0}]{1} ({2})".format( x.color, x.description, str(x.duration + 1))) if x.name == "poison": hp_target = "[color={0}]HP:{1}/{2} ".format( x.color, str(target.fighter.hp), str(target.fighter.max_hp)) elif x.name == "fly": ev_target = "[color={0}]EV:{1} ".format( x.color, str(target.fighter.ev)) if active_effects: blt.puts( self.owner.ui.viewport.offset_w, self.owner.ui.viewport.offset_h + self.ui_offset_y + 3, "[offset=0,-2]" + " ".join(active_effects) + " ", 0, 0, blt.TK_ALIGN_RIGHT) ac_target = "[color=default]AC:" + str(target.fighter.ac) + " " power_target = "ATK:" + str(target.fighter.power) + " " blt.puts( self.owner.ui.viewport.offset_w - 1, self.owner.ui.viewport.offset_h + self.ui_offset_y + 1, "[offset=0,-2]" + target.colored_name + ": " + hp_target + ac_target + ev_target + power_target, 0, 0, blt.TK_ALIGN_RIGHT) if target.fighter.hp <= 0: blt.clear_area( 2, self.owner.ui.viewport.offset_h + self.ui_offset_y + 1, self.owner.ui.viewport.offset_w, 3)
def clear(self): #print "Clearing Layer: {0}".format(self.layer) terminal.layer(self.layer) terminal.clear_area(self.pos.x, self.pos.y, self.width, self.height)
def clear_layer_points(layer, returnlayer, x, y): terminal.layer(layer) terminal.clear_area(x, y, 1, 1) terminal.layer(returnlayer)
def clear(self): # print "Clearing Layer: {0}".format(self.layer) terminal.layer(self.owner.layer - 1) terminal.clear_area(self.x, self.y, self.width, 1)
# def move_cursor(x, y): terminal.open() # Width x Height terminal_size = list(map(int, terminal.get("window.size").split("x"))) terminal.printf(0, 0, "Width: " + str(terminal_size[0])) terminal.printf(0, 1, "Height: " + str(terminal_size[1])) sidebar = Sidebar(2, 8) #Input Variables mouse_pressed = False mouse_map = [] terminal.refresh() while (handle_keys() != 0): terminal.refresh() terminal.layer(2) terminal.clear_area(0, 0, terminal_size[0], terminal_size[1]) terminal.layer(0) terminal.close()
def test_pick(): blt.set("window.title='Omni: examining cell contents'") blt.set("input.filter={keyboard, mouse}") blt.clear() blt.color("white") blt.puts(2, 1, "Move mouse over characters:") blt.bkcolor("darkest gray") blt.clear_area(2, 3, 76, 19) blt.bkcolor("none") colors = ("red", "orange", "yellow", "green", "cyan", "light blue", "violet") combining = (0x02C6, 0x02C9, 0x02DC, 0x2014, 0x2044, 0x2017, 0x203E) seed() for i in range(100): combined = randrange(5) == 0 n = randrange(2, 4) if combined else 1 x = randrange(2, 78) y = randrange(3, 22) blt.color(choice(colors)) blt.put(x, y, choice(ascii_lowercase)) blt.composition(True) for i in range(1, n): blt.color(choice(colors)) blt.put(x, y, choice(combining)) blt.composition(False) blt.color("white") while True: x = blt.state(blt.TK_MOUSE_X) y = blt.state(blt.TK_MOUSE_Y) blt.clear_area(2, 23, 76, 1) if 2 <= x < 78 and 3 <= y < 22: n = 0 while True: code = blt.pick(x, y, n) if code == 0: break color = blt.pick_color(x, y, n) blt.puts(2 + n * 2, 23, u"[color=#%x]%c" % (color, code)) n += 1 if n == 0: blt.puts(2, 23, "Empty cell") blt.refresh() key = blt.read() if key in (blt.TK_CLOSE, blt.TK_ESCAPE): break blt.set("input.filter={keyboard}")
def cast_fireball(): """Player targeted aoe spell""" (x, y) = target_tile(6) if x is None: message("Cancelled") return 'cancelled' message('The fireball explodes!', colours.orange) t.layer(EFFECT_LAYER) effected_points = [ (x + dx, y + dy) for (dx, dy) in ((-1, -1), (-1, 1), (-1, 0), (0, -1), (0, 0), (0, +1), (+1, 0), (+1, -1), (+1, +1)) ] set_colour(colours.red) for (x, y) in effected_points[4:-4]: t.put(x, y, chr(177)) t.refresh() t.delay(50) set_colour(colours.orange) for (x, y) in effected_points[2:-2]: t.put(x, y, chr(177)) t.refresh() t.delay(50) set_colour(colours.red) for (x, y) in effected_points: t.put(x, y, chr(177)) t.refresh() t.delay(50) set_colour(colours.orange) for (x, y) in effected_points: t.put(x, y, chr(177)) t.refresh() t.delay(50) set_colour(colours.red) for (x, y) in effected_points: t.put(x, y, chr(177)) t.refresh() t.delay(100) t.clear_area(effected_points[0][0], effected_points[0][1], effected_points[-1][0], effected_points[-1][1]) set_colour(colours.orange) for (x, y) in effected_points[2:-2]: t.put(x, y, chr(177)) t.refresh() t.delay(100) t.clear_area(effected_points[0][0], effected_points[0][1], effected_points[-1][0], effected_points[-1][1]) set_colour(colours.dark_red) for (x, y) in effected_points[4:-4]: t.put(x, y, chr(177)) t.refresh() t.delay(150) t.clear_area(effected_points[0][0], effected_points[0][1], effected_points[-1][0], effected_points[-1][1]) t.refresh() for obj in objects: if (obj.x, obj.y) in effected_points and obj.fighter: message('The ' + obj.name + ' takes 15 damage.', colours.orange) obj.fighter.take_damage(15)
'Fireball Scroll', colours.dark_blue, item=item_component) objects.append(item) item.item.pick_up() message( 'Welcome stranger! Prepare to perish in the Tombs of the Ancient Kings.', colours.red) make_map() fov_recompute = True while player_action != 'exit': render_all() player_action = handle_keys() t.layer(OBJECT_LAYER) t.clear_area(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) if game_state == 'playing' and player_action != 'no-turn': for obj in objects: if obj.ai: obj.ai.take_turn() t.close()
def clear(self): terminal.layer(self.layer) terminal.clear_area(self.x, self.y, self.w, self.h)
def w_clear(self, y, x, w=1, h=1): terminal.layer(self.layer) terminal.clear_area(self.x + x, self.y + y, w, h) if self.wtype == 'normal' and self.multi_layer: self.fx.clear(self, y, x, w, h)
def _clear_area(self): blt.clear_area(0, 0, blt.state(blt.TK_WIDTH), blt.state(blt.TK_HEIGHT))
def render_all(entities, player, game_map, camera, fov_map, fov_recompute, message_log, sidebar_x, sidebar_width, panel_y, panel_height, screen_width, screen_height, game_state, mouse): camera.move_camera(player.x, player.y, game_map) if fov_recompute: create_window(0, 0, camera.width + 2, camera.height + 1) create_window(0, panel_y, camera.width + 2, panel_height, 'MESSAGE LOG') create_window(sidebar_x, 0, sidebar_width, screen_height - 1, 'PLAYER STATS') names = get_names_under_mouse(mouse, entities, fov_map, camera) for y in range(camera.height): for x in range(camera.width): map_x = camera.x + x map_y = camera.y + y visible = tcod.map_is_in_fov(fov_map, map_x, map_y) wall = game_map.tiles[map_x][map_y].block_sight # print("map coord " + str(map_x) + ' ' + str(map_y)) # if visible: if wall: blt.puts(x + 1, y + 1, '[font][color=light_wall][U+0023]') else: blt.puts(x + 1, y + 1, '[font][color=light_ground][U+002E]') game_map.tiles[map_x][map_y].explored = True elif game_map.tiles[map_x][map_y].explored: if wall: blt.puts(x + 1, y + 1, '[font][color=dark_wall][U+0023]') else: blt.puts(x + 1, y + 1, '[font][color=dark_ground][U+002E]') # entities.append(entities.pop(0)) entities_in_render_order = sorted(entities, key=lambda x: x.render_order.value) for entity in entities_in_render_order: draw_entity(entity, camera, fov_map) # for y in range(camera.height): # blt.puts(camera.width, y, '[color=white][U+2551]') # for x in range(camera.width): # blt.puts(x, camera.height, '[color=white][U+2550]') # blt.puts(camera.width, camera.height, '[color=white][U+2569]') render_bar(sidebar_x + 1, 1, sidebar_width - 2, 'HP', player.fighter.hp, player.fighter.max_hp, 'dark red', 'darkest red') y = 1 for message in message_log.messages: # print(message.text) blt.color(message.color) blt.puts(message_log.x, panel_y + y, '[font=small]' + message.text) y += 1 blt.color('white') if names: blt.clear_area(mouse[0] + 1, mouse[1], len(names), 1) blt.puts(mouse[0] + 1, mouse[1], names) if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY): if game_state == GameStates.SHOW_INVENTORY: inventory_title = 'Press the key next to an item to use it' else: inventory_title = 'Press the key next to an item to drop it' inventory_menu(inventory_title, player.inventory, 50, screen_width, screen_height)
def _clear_entity(self, entity): # erase the character that represents this object blt.clear_area(entity.x, entity.y, entity.x, entity.y)
def message_console(self, text, priority): terminal.layer(self.map_depth + 3) terminal.clear_area(0, self.console_pos + priority, self.window_width, 1) terminal.printf(self.center_text(text), self.console_pos + priority, text)
def render_all(entities, player, targeting_cursor, game_map, fov_map, fov_recompute, message_log, constants, game_state, equip_index, left_click, active_turrets, lineshot_pts, lineshot_clr, explosion_shape): render = True while render: terminal.layer(0) if fov_recompute: terminal.clear() # draw bounding boxes for the message and health bars for x in range(constants['screen_width']): terminal.print_(x, game_map.height, '[color=white][U+2550]') terminal.print_(constants['bar_width'] + 2, game_map.height, '[color=white][U+2566]') for y in range(game_map.height + 1, constants['screen_height']): terminal.print_(constants['bar_width'] + 2, y, '[color=white][U+2551]') # Draw all the tiles in the game map for y in range(game_map.height): for x in range(game_map.width): visible = libtcod.map_is_in_fov(fov_map, x, y) wall = game_map.tiles[x][y].block_sight if visible: if wall: terminal.color( constants['colors'].get('light_wall')) terminal.print_(x, y, '#') else: terminal.bkcolor('darkest grey') terminal.print_(x, y, ' ') terminal.bkcolor('black') game_map.tiles[x][y].explored = True elif game_map.tiles[x][y].explored: if wall: terminal.print_( x, y, '[color=' + constants['colors'].get('dark_wall') + ']#') else: terminal.print_(x, y, ' ') # Draw stars for star in game_map.stars_pts: draw_star(star, fov_map) if game_state == GameStates.TARGETING: draw_targeting_line(player, targeting_cursor, fov_map, game_map) # Draw all entities in the list entities_in_render_order = sorted(entities, key=lambda x: x.render_order.value) for entity in entities_in_render_order: draw_entity(entity, fov_map) if entity.combatship: if entity.combatship.targeted: draw_targeting_box(entity.x, entity.y) terminal.layer(1) terminal.clear_area(0, 0, constants['screen_width'], constants['screen_height']) # print the game messages one line at a time y = 1 for message in message_log.messages: terminal.color(message.color) terminal.print_(message_log.x, y + constants['panel_y'], message.text) y += 1 render_bar(1, 1 + constants['panel_y'], constants['bar_width'], 'Hull', player.combatship.hull, player.combatship.max_hull, 'light red', 'darker red') render_bar(1, 3 + constants['panel_y'], constants['bar_width'], 'Shields', player.combatship.shields, player.combatship.max_shields, 'light azure', 'darker azure') # if you are in inventory mode, highlight the item selected (equip index) if game_state in [GameStates.GOTO_EQUIP, GameStates.DROP_EQUIP]: render_equip_panel(1 + constants['equip_x'], 1, constants['equip_width'], constants['equip_height'], player.inventory.items, active_turrets, game_state, equip_index=equip_index) else: render_equip_panel(1 + constants['equip_x'], 1, constants['equip_width'], constants['equip_height'], player.inventory.items, active_turrets, game_state) render_tactical_panel(1 + constants['tactical_x'], constants['tactical_y'], constants['tactical_width'], constants['tactical_height'], entities, player) # display names of objects under the mouse # name, x, y = get_names_under_mouse(entities, fov_map) # txt = '{}, [{},{}]'.format(name, x, y) # terminal.print_(1, int(constants['panel_y']), '[color=white]' + txt) animate_line_draw(game_state, lineshot_pts, lineshot_clr) animate_explosion(game_state, explosion_shape) terminal.refresh() fov_recompute = clear_explosion(game_state, explosion_shape, constants) fov_recompute, lineshot_pts = clear_line_draw(game_state, lineshot_pts, fov_recompute, constants) if lineshot_pts: render = True else: render = False # just in case return to 'root' terminal.layer(0)
def dev_console(self, text, priority): terminal.layer(self.map_depth + 3) terminal.clear_area(0, priority, self.window_width, 1) terminal.printf(0, priority, text)
def clear(self, color=COLOR['BLACK']): term.layer(0) term.bkcolor(term.color_from_argb(255, *color)) term.clear_area(self.pos[X], self.pos[Y], *self.size)
def ship_console(self, text, priority): terminal.layer(self.map_depth + 3) terminal.clear_area(self.ship_console_pos, priority, self.window_width, 1) terminal.printf(self.ship_console_pos, priority, text)
def test_text_alignment(): blt.set("window: title='Omni: text alignment', resizeable=true, minimum-size=44x12") blt.composition(True) names = { blt.TK_ALIGN_LEFT: "TK_ALIGN_LEFT", blt.TK_ALIGN_CENTER: "TK_ALIGN_CENTER", blt.TK_ALIGN_RIGHT: "TK_ALIGN_RIGHT", blt.TK_ALIGN_TOP: "TK_ALIGN_TOP", blt.TK_ALIGN_MIDDLE: "TK_ALIGN_MIDDLE", blt.TK_ALIGN_BOTTOM: "TK_ALIGN_BOTTOM", } horizontal_align = blt.TK_ALIGN_LEFT vertical_align = blt.TK_ALIGN_TOP frame = update_geometry() while True: blt.clear() # Background square blt.bkcolor("darkest gray") blt.clear_area(*frame) blt.bkcolor("none") # Comment blt.puts( frame.left, frame.top - padding_v - 2, "Use arrows to change text alignment.\n" "Current alignment is [c=orange]%s[/c] | [c=orange]%s[/c]." % (names[vertical_align], names[horizontal_align]) ) #Text origin x, y = frame.left, frame.top blt.color("white") blt.puts( x, y, lorem_ipsum, frame.width, frame.height, vertical_align | horizontal_align ) blt.puts(80-14, 3, "[c=orange][U+2588]") blt.puts(80-14, 3, "12345\nabc\n-=#=-", align=vertical_align | horizontal_align) blt.refresh() key = blt.read() if key in (blt.TK_CLOSE, blt.TK_ESCAPE): break elif key == blt.TK_LEFT: horizontal_align = blt.TK_ALIGN_CENTER if horizontal_align == blt.TK_ALIGN_RIGHT else blt.TK_ALIGN_LEFT elif key == blt.TK_RIGHT: horizontal_align = blt.TK_ALIGN_CENTER if horizontal_align == blt.TK_ALIGN_LEFT else blt.TK_ALIGN_RIGHT elif key == blt.TK_UP: vertical_align = blt.TK_ALIGN_MIDDLE if vertical_align == blt.TK_ALIGN_BOTTOM else blt.TK_ALIGN_TOP elif key == blt.TK_DOWN: vertical_align = blt.TK_ALIGN_MIDDLE if vertical_align == blt.TK_ALIGN_TOP else blt.TK_ALIGN_BOTTOM elif key == blt.TK_RESIZED: frame = update_geometry() blt.composition(False) blt.set("window.resizeable=false")
def render_all(game_map, camera, player, mouse, entities, items, corpses, fov_cells): terrain = game_map.terrain water = game_map.water camera.move_camera(player.x, player.y, game_map) # print('Camera x: ' + str(camera.x)) # print('Camera y: ' + str(camera.y)) # start = time.time() decor = get_names_under_mouse(mouse, fov_cells, camera, terrain) creatures = get_names_under_mouse(mouse, fov_cells, camera, entities) itms = get_names_under_mouse(mouse, fov_cells, camera, items) remains = get_names_under_mouse(mouse, fov_cells, camera, corpses) layers = [] if creatures: layers.append(creatures) if itms: layers.append(itms) if remains: layers.append(remains) if decor: layers.append(decor) screen_width = blt.state(blt.TK_WIDTH) screen_height = blt.state(blt.TK_HEIGHT) sidebar_width = screen_width - camera.width - 2 sidebar_x = camera.width + 2 panel_height = screen_height - camera.height - 3 panel_y = camera.height + 2 create_window(0, 0, camera.width + 2, camera.height + 1) create_window(0, panel_y, camera.width + 2, panel_height, 'MESSAGE LOG') create_window(sidebar_x, 0, sidebar_width, screen_height - 1, 'PLAYER STATS') render_bar(sidebar_x + 1, 1, sidebar_width - 2, 'HP', player.fighter.hp, player.fighter.max_hp, 'dark red', 'darkest red') # print(items) for x in range(1, camera.width): for y in range(1, camera.height): map_x, map_y = camera.to_map_coordinates(x, y) if (map_x, map_y) in fov_cells: if (map_x, map_y) in water: render_obj((map_x, map_y), water, camera, 'blue') water.get((map_x, map_y)).explored = True elif (map_x, map_y) in terrain: render_obj((map_x, map_y), terrain, camera, 'gray') terrain.get((map_x, map_y)).explored = True else: blt.puts(x, y, '[color=dark yellow][U+4055]') if (map_x, map_y) in corpses: obj = corpses.get((map_x, map_y)) render_obj((map_x, map_y), corpses, camera, obj.color) if (map_x, map_y) in items: print("found item", map_x, map_y) obj = items.get((map_x, map_y)) render_obj((map_x, map_y), items, camera, obj.color) if (map_x, map_y) in entities: obj = entities.get((map_x, map_y)) # blt.puts(x, y, '[color=yellow][U+2146]') render_obj((map_x, map_y), entities, camera, obj.color) elif ((map_x, map_y) in terrain and terrain.get((map_x, map_y)).explored): render_obj((map_x, map_y), terrain, camera, 'darker orange') elif ((map_x, map_y) in water and water.get((map_x, map_y)).explored): render_obj((map_x, map_y), water, camera, 'darker blue') names = '' for i in layers: if i == layers[0]: names = i elif i: names = names + ', ' + i blt.clear_area(mouse[0] + 1, mouse[1], len(names), 1) blt.puts(mouse[0] + 1, mouse[1], names)
def draw_side_panel_content(self): game_map = self.owner.levels.current_map player = self.owner.player side_panel = self.owner.ui.side_panel # Draw side panel content blt.layer(1) blt.color(None) x_margin = self.owner.ui.side_panel.x_margin map_title = fill(game_map.title, 21) blt.clear_area(side_panel.offset_x + x_margin, side_panel.offset_y + 20, side_panel.offset_w - x_margin, side_panel.offset_h - 40) blt.puts(side_panel.offset_x + x_margin, side_panel.offset_y + 21, "Location: " + map_title, 0, 0, blt.TK_ALIGN_LEFT) blt.puts(side_panel.offset_x + x_margin, side_panel.offset_y + 24 + map_title.count('\n'), "World tendency: " + str(self.owner.levels.world_tendency), 0, 0, blt.TK_ALIGN_LEFT) # Fetch player skills and draw icons weapon = [] attack = [] utility = [] for skill in player.abilities.items: if skill.skill_type == "weapon": weapon.append(skill) elif skill.skill_type == "attack": attack.append(skill) elif skill.skill_type == "utility": utility.append(skill) blt.color(None) # Weapon skills y_margin = 0 first_heading_y = 30 fill_chars = 32 for i, wpn in enumerate(weapon): if wpn.name == player.player.sel_weapon.name: # heading title = "Weapon (Switch: 'W')" blt.color("lighter yellow") blt.puts(side_panel.offset_x + x_margin, side_panel.offset_y + first_heading_y, fill(title, fill_chars), 0, 0, blt.TK_ALIGN_LEFT) # name of the selected skill blt.color(None) skill_str = "{0}, {1}+{2} dmg".format(wpn.name.capitalize(), wpn.damage[wpn.rank], player.fighter.str_bonus) blt.puts(side_panel.offset_x + x_margin, side_panel.offset_y + first_heading_y + 2, fill(skill_str, fill_chars), 0, 0, blt.TK_ALIGN_LEFT) # highlight icon of the selected skill blt.color("dark amber") y_margin += skill_str.count('\n') if i > 4: y_margin += 3 i = 0 blt.put(side_panel.offset_x + x_margin + 1 + i * 6, side_panel.offset_y + first_heading_y + 4, wpn.icon) blt.color(None) second_heading_y = first_heading_y + 9 # Attack skills for i, atk in enumerate(attack): if player.player.sel_attack and atk.name == player.player.sel_attack.name: # heading title = "Skills (Switch: 'A', Use: 'TAB')" blt.color("lighter green") blt.puts(side_panel.offset_x + x_margin, side_panel.offset_y + second_heading_y + y_margin, fill(title, fill_chars), 0, 0, blt.TK_ALIGN_LEFT) blt.color(None) skill_str = "{0}: ".format(atk.name) chance_str, atk_str, effect_str, duration_str = "", "", "", "" if atk.chance: # chance_str = str(int(1 / atk.chance[atk.rank])) + "% chance of " chance_str = "100% chance of " if atk.effect: effect_str = ", ".join(atk.effect) + ", " if atk.duration: duration_str = atk.duration[atk.rank] + " turns" if atk.damage: atk_str = ", " + atk.damage[atk.rank] + "+" + str(player.fighter.str_bonus) + " dmg" if duration_str \ else atk.damage[atk.rank] + "+" + str(player.fighter.str_bonus) + " dmg" skill_str += chance_str + effect_str + duration_str + atk_str blt.puts(side_panel.offset_x + x_margin, side_panel.offset_y + second_heading_y + 2 + y_margin, fill(skill_str.capitalize(), fill_chars), 0, 0, blt.TK_ALIGN_LEFT) # highlight icon of the selected skill blt.color("dark amber") y_margin += skill_str.count('\n') if i > 4: y_margin += 3 i = 0 blt.put(side_panel.offset_x + x_margin + 1 + i * 6, side_panel.offset_y + second_heading_y + 5 + y_margin, atk.icon) blt.color(None) third_heading_y = second_heading_y + 10 # Utility skills for i, utl in enumerate(utility): if player.player.sel_utility and utl.name == player.player.sel_utility.name: title = "Utility (Use: 'Z')" blt.color("lighter blue") blt.puts(side_panel.offset_x + x_margin, side_panel.offset_y + third_heading_y + y_margin, fill(title, fill_chars), 0, 0, blt.TK_ALIGN_LEFT) # name of the selected skill blt.color(None) skill_str = utl.name blt.puts(side_panel.offset_x + x_margin, side_panel.offset_y + third_heading_y + 2 + y_margin, fill(skill_str.capitalize(), fill_chars), 0, 0, blt.TK_ALIGN_LEFT) y_margin += skill_str.count('\n') blt.puts(side_panel.offset_x + x_margin, side_panel.offset_y + third_heading_y + 8 + y_margin, fill(utl.description.capitalize(), fill_chars), 46 + y_margin, 0, blt.TK_ALIGN_LEFT) # highlight icon of the selected skill blt.color("dark amber") if i > 4: y_margin += 3 i = 0 blt.put(side_panel.offset_x + x_margin + 1 + i * 6, side_panel.offset_y + third_heading_y + 5 + y_margin, utl.icon) blt.layer(0) blt.put_ext(side_panel.offset_x + x_margin + i * 6, side_panel.offset_y + third_heading_y + 5 + y_margin, -2, -14, str(i + 1)) blt.layer(1) blt.color(None)
def render_all(): """Goes through object list and renders everything""" global fov_recompute global visible_tiles if fov_recompute: fov_recompute = False visible_tiles = quickFOV(player.x, player.y, gmap.is_visible_tile, fov=FOV_ALGO, radius=TORCH_RADIUS, lightWalls=FOV_LIGHT_WALLS, sphere=False) #Set to the background layer before drawing the area t.layer(BASE_LAYER) for y in range(MAP_HEIGHT): for x in range(MAP_WIDTH): set_colour(colours.black, 255) visible = (x, y) in visible_tiles wall = gmap.Map[x][y].block_sight if not visible: if gmap.Map[x][y].explored: if wall: set_colour(colours.darkest_gray, 255) else: set_colour(colours.darker_gray, 255) else: if wall: set_colour(colours.gray, 255) else: set_colour(colours.light_gray, 255) #add visible tile as explored gmap.Map[x][y].explored = True #Draw the character on the map t.put(x, y, BLOCK_CHAR) t.layer(OBJECT_LAYER) for obj in objects: if obj != player: obj.draw() for stair in stairs: stair.draw() player.draw() #GUI Panel cleared for redraw #panel.clear(fg=colours.white, bg=colours.black) #Print out all game messages t.layer(UI_TEXT_LAYER) t.clear_area(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) y = PANEL_Y for (line, colour) in game_msgs: set_colour(colour) t.puts(MSG_X, y, line) #panel.draw_str(MSG_X, y, line, bg=None, fg=colour) y += 1 #Contents under mouse set_colour(colours.light_gray) t.puts(1, PANEL_Y - 1, get_names_under_mouse()) #Statbar render_bar(1, PANEL_Y, BAR_WIDTH, 'HP', player.fighter.hp, player.fighter.max_hp, colours.dark_red, colours.darker_red) t.refresh()
def init_new_game(self, params): choice = params self.player = None self.levels = None self.time_counter = None # Create player inventory_component = Inventory(26) f_data = self.data.fighters["player"] fighter_component = Fighter(hp=f_data["hp"], ac=f_data["ac"], ev=f_data["ev"], power=f_data["power"], mv_spd=f_data["mv_spd"], atk_spd=f_data["atk_spd"], size=f_data["size"], fov=f_data["fov"]) light_component = LightSource(radius=fighter_component.fov) player_component = Player(50) abilities_component = Abilities("player") status_effects_component = StatusEffects("player") summoner_component = Summoner() player = Entity(1, 1, 3, player_component.char["player"], "default", "player", blocks=True, player=player_component, fighter=fighter_component, inventory=inventory_component, light_source=light_component, summoner=summoner_component, indicator_color="gray", abilities=abilities_component, status_effects=status_effects_component, stand_on_messages=False) player.player.avatar["player"] = fighter_component avatar_f_data = self.data.fighters[choice] a_fighter_component = Fighter(hp=avatar_f_data["hp"], ac=avatar_f_data["ac"], ev=avatar_f_data["ev"], power=avatar_f_data["power"], mv_spd=avatar_f_data["mv_spd"], atk_spd=avatar_f_data["atk_spd"], size=avatar_f_data["size"], fov=avatar_f_data["fov"]) player.player.avatar[choice] = a_fighter_component player.player.avatar[choice].owner = player player.abilities.initialize_abilities(choice) player.player.char[choice] = tilemap()["monsters"][choice] player.player.char_exp[choice] = 20 player.player.avatar[choice].max_hp += 20 player.player.avatar[choice].hp += 20 player.player.avatar[choice].power += 1 player.player.insights = 200 self.player = player character_menu = MenuData(name="avatar_info", params=self.player) self.menus.create_or_show_menu(character_menu) message_log = MessageLog(4) self.message_log = message_log self.message_log.owner = self # Initialize game camera game_camera = Camera(1, 1, self.ui.viewport.w, self.ui.viewport.h, self.options) self.game_camera = game_camera self.game_camera.owner = self levels = Levels(tileset=self.options.gfx) self.levels = levels self.levels.owner = self blt.clear_area(2, self.ui.viewport.offset_h + self.ui.offset_y + 1, self.ui.viewport.x, 1) # if settings.gfx == "ascii": # player.char = tilemap()["player"] # player.color = "lightest green" self.levels.change("hub") self.fov_recompute = True self.game_state = GameStates.PLAYER_TURN self.time_counter = self.TimeCounter(owner=self)
def show_msg_history(message_log, name, viewport_w, viewport_h): messages = MessageList() frame = FrameWithScrollbar(messages) message_log.reverse() for message in message_log: messages.append(message.msg) # Initial update frame.update_geometry(padding_left + 1, padding_top, viewport_w + 5 - (padding_left + padding_right), viewport_h - (padding_top + padding_bottom)) prompt = \ "Message history: \n" if name == "Inventory": prompt = \ "Inventory: \n" while True: frame.draw() blt.color("white") blt.layer(0) w = viewport_w h = viewport_h i = 0 while i < 5: blt.layer(i) blt.clear_area(1, 1, w, h) i += 1 current_line = 0 blt.puts(padding_left, padding_top - frame.offset, prompt, frame.width) for text, height in messages: if current_line + height >= frame.offset: # stop when message is below frame if current_line - frame.offset > frame.height: break # drawing message blt.puts(padding_left, padding_top + current_line - frame.offset + 5, text, frame.width) current_line += height + 1 blt.crop(padding_left, padding_top, frame.width, frame.height) # Render blt.refresh() key = blt.read() if key in (blt.TK_CLOSE, blt.TK_ESCAPE, blt.TK_M): blt.clear() break elif key == blt.TK_I and name == "Inventory": blt.clear() break elif key == blt.TK_UP: frame.scroll(-1) elif key == blt.TK_DOWN: frame.scroll(1) elif key == blt.TK_RESIZED: frame.update_geometry( padding_left, padding_top, blt.state(blt.TK_WIDTH) - (padding_left + padding_right + 1), blt.state(blt.TK_HEIGHT) - (padding_top + padding_bottom))