def draw(self, surface, game_data, gfx_data, selected_slot): assert self.ingredient, f"{self.index} {self.ingredient}" text = "[" + self.ingredient.name.upper() + "]" if self.index is not None and selected_slot == self.index: text += " <--" display_text(surface, text, gfx_data.assets.font_message, self.pos.tuple())
def draw_mouse_over_info(self, surface, game_data, gfx_data): mx, my = pygame.mouse.get_pos() if self.health_bar.is_inside(mx, my): display_text( surface, "This is how much health you have", Assets.get().font_message, (mx, my), ) elif self.shield_bar.is_inside(mx, my): display_text( surface, "This is how much shield you have", Assets.get().font_message, (mx, my), ) for fm in self.formula_markers: if fm.is_inside(mx, my): display_text(surface, "A formula", Assets.get().font_message, (mx, my)) return for cm in self.consumable_markers: if cm.is_inside(mx, my): item = game_data.inventory.get_quickslot(cm.consumable_index) if item: display_text( gfx_data.main, item.DESCRIPTION, Assets.get().font_message, (mx, my), ) else: display_text( gfx_data.main, "No item equipped", Assets.get().font_message, (mx, my), ) return
def draw_ingredient_choices(self, surface, game_data, gfx_data): ingredient_to_key_map = [ [Ingredient.EMPTY, "Q"], [Ingredient.WATER, "W"], [Ingredient.FIRE, "E"], [Ingredient.RANGE, "R"], [Ingredient.AREA, "A"], [Ingredient.LIFE, "S"], [Ingredient.EARTH, "D"], ] x_base = 100 y_base = 200 ing_count = 0 for ing, key in ingredient_to_key_map: if ing == Ingredient.EMPTY: text = ing.name.capitalize() else: count = game_data.ingredient_storage.total_count(ing) if ing in self.ingredient_counts: count -= self.ingredient_counts[ing] text = "{} : {}".format(ing.name.capitalize(), count) display_text(surface, text, gfx_data.assets.font_message, (x_base, y_base)) display_text(surface, key, gfx_data.assets.font_message, (x_base, y_base + 30)) x_base += 90 ing_count += 1 if ing_count > 3: y_base += 60 x_base = 100 ing_count = 0
def draw(self, game_data, gfx_data): surface = pygame.Surface(self.size.tuple()) all_lines = [] for current in self.lines: if current.strip() == "": all_lines.append(current) else: split_lines = textwrap.wrap(current, 60) all_lines.extend(split_lines) show_lines = all_lines[self.offset:self.offset + self.num_lines] display_menu(gfx_data, show_lines, self.size.tuple(), surface=surface) hours, minutes, seconds = game_data.stats.total_play_time playtime_text = "{}h {}m {}s".format(hours, minutes, seconds) display_text( surface, "This took you {}".format(playtime_text), gfx_data.assets.font_message, (150, 475), ) display_text( surface, "Press Escape to quit, press Space to play again", gfx_data.assets.font_message, (150, 500), ) gfx_data.main.blit(surface, self.pos.tuple())
def draw_help(self, game_data, gfx_data, main): help_surface = pygame.Surface(game_data.constants.window_size.tuple(), pygame.SRCALPHA) if not game_data.run_planner.has_next: # last level for e in game_data.map.entities: if e.name == "Remains of Arina" and tcod.map_is_in_fov( game_data.fov_map, e.pos.x, e.pos.y): sx, sy = gfx_data.camera.map_to_screen(e.pos.x, e.pos.y) sx, sy = sx * CELL_WIDTH + 40, sy * CELL_HEIGHT display_text( help_surface, "The witch is dead, press E here to verify", gfx_data.assets.font_message, (sx, sy), text_color=colors.WHITE, bg_color=colors.BACKGROUND, ) return elif not game_data.run_planner.current_map.tutorial: return messages = Tutorial.get_messages(game_data, gfx_data) for msg in messages: display_text( help_surface, msg.text, gfx_data.assets.font_message, msg.pos.tuple(), text_color=colors.WHITE, bg_color=colors.BACKGROUND, ) main.blit(help_surface, (0, 0))
def draw_mouse_over_info(self, game_data, gfx_data, main): info_surface = pygame.Surface(game_data.constants.window_size.tuple(), pygame.SRCALPHA) pos = pygame.mouse.get_pos() px, py = pos map_screen_pos = self.global_screen_pos_to_map_screen_pos( px, py, game_data) tile_x, tile_y = self.map_screen_pos_to_tile(map_screen_pos[0], map_screen_pos[1], gfx_data) tile_pos = Pos(tile_x, tile_y) names = [] for e in game_data.map.entities: if e.pos == tile_pos and tcod.map_is_in_fov( game_data.fov_map, tile_pos.x, tile_pos.y): names.append(e.raw_name) if not names: return text = ", ".join(names) display_text( info_surface, text, gfx_data.assets.font_message, (px - self.pos.x + 20, py), text_color=colors.WHITE, bg_color=colors.BACKGROUND, ) main.blit(info_surface, (0, 0))
def draw(self, game_data, gfx_data): surface = pygame.Surface(self.size.tuple()) display_text( surface, "Press Escape again to quit, press Space to keep playing", gfx_data.assets.font_message, (150, 250), ) gfx_data.main.blit(surface, self.pos.tuple())
def draw(self, surface, game_data, gfx_data): x, y = self.pos.tuple() w, h = self.size.tuple() pygame.draw.rect(surface, (100, 50, 50), (x, y, w, h), 1) item = game_data.inventory.get_quickslot(self.consumable_index) if item: display_text(surface, f"{self.shortcut}: {item.name}", self.font, self.pos.tuple()) else: display_text(surface, f"{self.shortcut}: -", self.font, self.pos.tuple())
def draw(self, surface, game_data, gfx_data): coords = (self.pos.x - 5, self.pos.y - 5, 140, 40) if self.consumable_index == self.parent.selected: pygame.draw.rect(surface, (100, 150, 100), coords, 3) else: pygame.draw.rect(surface, (25, 50, 25), coords, 3) display_text( surface, self.consumable.name, gfx_data.assets.font_message, (self.pos.x, self.pos.y), )
def draw(self, surface, game_data, gfx_data): display_text( surface, "Slot {}".format(self.qs_index + 1), gfx_data.assets.font_message, (self.pos.x, self.pos.y), ) item = game_data.inventory.get_quickslot(self.qs_index) square_y = self.pos.y + 35 coords = (self.pos.x - 5, square_y - 5, self.parent.slot_width, 40) pygame.draw.rect(surface, (150, 150, 150), coords, 3) if item: display_text(surface, item.name, gfx_data.assets.font_message, (self.pos.x, square_y))
def draw(self, surface, game_data, formula): if self.player.caster.is_on_cooldown(self.formula_idx): self.cooldown_bar.draw( surface, self.player.caster.get_cooldown(self.formula_idx), formula.cooldown, ) elif self.formula_idx == game_data.targeting_formula_idx: msg = "{}: {}".format(self.formula_idx + 1, formula.text_repr) x, y = self.pos.x - 5, self.pos.y - 5 w, h = self.size.width, self.size.height pygame.draw.rect(surface, (150, 75, 75), (x, y, w, h), 5) display_text(surface, msg, self.font, self.pos.tuple()) else: msg = "{}: {}".format(self.formula_idx + 1, formula.text_repr) display_text(surface, msg, self.font, self.pos.tuple())
def draw(self, surface, game_data, gfx_data): display_text( surface, self.text, gfx_data.assets.font_message, self.pos.tuple(), text_color=IngredientMeta.INGREDIENT_COLORS[self.ingredient], ) x1 = self.pos.x x2 = self.pos.x + self.size.width y1 = self.pos.y y2 = self.pos.y + self.size.height color = (255, 0, 0)
def draw_quickslots(self, surface, game_data, gfx_data): x = self.pos.x + 10 y = 410 y += 40 for qs in range(self.num_quickslots): item = game_data.inventory.get_quickslot(qs) display_text(surface, "Slot {}".format(qs + 1), gfx_data.assets.font_message, (x, y)) square_y = y + 35 coords = (x - 5, square_y - 5, self.slot_width, 40) pygame.draw.rect(surface, (150, 150, 150), coords, 3) if item: display_text(surface, item.name, gfx_data.assets.font_message, (x, square_y)) x += self.slot_width + 20
def draw(self, game_data, gfx_data): if game_data.run_planner.gen_level_idx >= game_data.run_planner.level_count: # return self.close(game_data, WelcomeWindow) return self.close(game_data, None) surface = pygame.Surface(self.size.tuple()) display_text( surface, "Generating level {}/{}".format( game_data.run_planner.gen_level_idx + 1, game_data.run_planner.level_count, ), gfx_data.assets.font_title, (50, 200), ) gfx_data.main.blit(surface, self.pos.tuple())
def draw(self, game_data, gfx_data): surface = pygame.Surface(self.size.tuple()) for s in self.input_slots: s.draw(surface, game_data, gfx_data, self.current_slot) self.output_slot.draw(surface, game_data, gfx_data, self.current_slot) self.draw_ingredient_choices(surface, game_data, gfx_data) display_text( surface, "Press Space to confirm, Escape to quit, Tab for help", gfx_data.assets.font_message, (140, 500), ) gfx_data.main.blit(surface, self.pos.tuple())
def draw(self, game_data, gfx_data): surface = pygame.Surface(self.size.tuple()) show_lines = self.lines[self.offset:self.offset + self.num_lines] display_menu(gfx_data, show_lines, self.size.tuple(), surface=surface, x=self.pos.x + 10) if len(self.lines) > self.num_lines: pygame.draw.line(surface, (255, 255, 255), (100, 520), (500, 520)) display_text( surface, "Use W, S or mouse scroll to see more", gfx_data.assets.font_message, (130, 530), ) gfx_data.main.blit(surface, self.pos.tuple())
def draw(self, game_data, gfx_data): surface = pygame.Surface(self.size.tuple()) header = [ "You have expanded your skills and equipment, please choose:", "" ] linediff = gfx_data.assets.font_message_height y = 3 * linediff display_lines(surface, gfx_data.assets.font_message, header, starty=y) y += 2 * linediff if not self.choices: if config.conf.crafting: self.choices = [self.slots_message, self.formulas_message] elif "level_" in config.conf.unlock_mode: all_choices = [self.slots_message, self.formulas_message] for upgrade in game_data.formula_builder.available_upgrades(): all_choices.append(upgrade.description) if config.conf.unlock_mode == "level_2random": while len(self.choices) < 2: self.choices = set(random.choices(all_choices, k=2)) self.choices = list(self.choices) else: self.choices = all_choices else: self.choices = [self.slots_message, self.formulas_message] for idx, choice in enumerate(self.choices): text = str(choice) if idx == game_data.menu_data.currchoice: text += " <--" display_text(surface, text, gfx_data.assets.font_message, (50, y)) y += linediff display_text( surface, "W/S or up/down to change selection, space to choose", gfx_data.assets.font_message, (50, 500), ) gfx_data.main.blit(surface, self.pos.tuple())
def draw(self, game_data, gfx_data): surface = pygame.Surface(game_data.constants.message_log_size.tuple()) surface.fill(colors.BACKGROUND) messages = game_data.log.messages y = 0 start = max( 0, min( len(messages) - self.num_messages, len(messages) - self.num_messages + self.offset, ), ) end = min(len(messages), start + self.num_messages) for idx, msg in enumerate(messages[start:end]): display_text( surface, msg.text, Assets.get().font_message, (50, y + idx * 20), msg.color, ) gfx_data.main.blit(surface, self.pos.tuple())
def draw_ingredient_list(self, surface, game_data, gfx_data): ingredient_lines = [] ingredient_to_key_map = [ [[Ingredient.EMPTY], "Q"], [[Ingredient.WATER, Ingredient.SLEET, Ingredient.ICE, Ingredient.ICE_VORTEX, Ingredient.ICEBOLT,], "W",], [[Ingredient.FIRE, Ingredient.INFERNO, Ingredient.FIREBOLT, Ingredient.FIRESPRAY,], "E",], [[Ingredient.RANGE], "R"], [[Ingredient.AREA], "A"], [[Ingredient.LIFE, Ingredient.VITALITY], "S"], [[Ingredient.EARTH, Ingredient.MUD, Ingredient.MAGMA, Ingredient.ROCK], "D",], ] choices = game_data.formula_builder.current_ingredient_choices() for ing in choices: for group, key in ingredient_to_key_map: if ing in group: ingredient_lines.append((key, ing)) def get_ingredient_list_key(item): mapping = { "Q": 0, "W": 1, "E": 2, "R": 3, "A": 4, "S": 5, "D": 6, } return mapping[item[0]] ingredient_lines = sorted(ingredient_lines, key=get_ingredient_list_key) y = 120 linediff = 30 for key, ing in ingredient_lines: display_text(surface, f"{key}", gfx_data.assets.font_message, (400, y)) display_text( surface, ing.name, gfx_data.assets.font_message, (435, y), IngredientMeta.INGREDIENT_COLORS[ing], ) y += linediff
def draw(self, game_data, gfx_data): if not self.current_lines or self.current_content != self.story_data.current_content: self.current_content = self.story_data.current_content long_lines = self.story_data.current_content.split("\n") lines = [] for current in long_lines: if current.strip() == "": lines.append(current) else: split_lines = textwrap.wrap(current, 60) lines.extend(split_lines) self.current_lines = lines show_lines = self.current_lines[self.offset:self.offset + self.num_lines] display_menu(gfx_data, show_lines, self.size.tuple(), x=20, starty=20) display_text( gfx_data.main, "Press Space to continue", Assets.get().font_message, (350, 750), )
def draw(self, game_data, gfx_data): surface = pygame.Surface(game_data.constants.right_panel_size.tuple()) surface.fill(colors.BACKGROUND) if len(self.formula_markers) != len(game_data.player.caster.formulas): self.update_formula_markers(game_data.player, start_y=self.formula_label.pos.y + 40) self.health_bar.draw(surface, game_data.player.fighter.hp, game_data.player.fighter.max_hp) if game_data.player.fighter.shield: self.shield_bar.draw( surface, game_data.player.fighter.shield.level, game_data.player.fighter.shield.max_level, ) else: self.shield_bar.draw(surface, 0, 10) if config.conf.keys: if game_data.map.stairs_found or game_data.map.num_keys_found == game_data.map.num_keys_total: text = "Found {}/{} keys".format(game_data.map.num_keys_found, game_data.map.num_keys_total) else: text = "Found {}/? keys".format(game_data.map.num_keys_found) display_text( surface, text, Assets.get().font_message, (10, 105), ) else: display_text( surface, "Level {}".format(game_data.player.level.current_level), Assets.get().font_message, (10, 105), ) if config.conf.keys: self.xp_bar.draw( surface, game_data.player.level.current_xp, game_data.player.level.xp_to_next_level, ) self.formula_label.draw(surface) for idx, fm in enumerate(self.formula_markers): fm.draw(surface, game_data, game_data.player.caster.formulas[idx]) if config.conf.consumables: for cm in self.consumable_markers: cm.draw(surface, game_data, gfx_data) self.helplabel.draw(surface) display_text( surface, "Floor {}".format(game_data.run_planner.current_level_index + 1), Assets.get().font_message, (10, 850), ) gfx_data.main.blit(surface, self.pos.tuple()) self.draw_mouse_over_info(gfx_data.main, game_data, gfx_data)
def draw(self, game_data, gfx_data): surface = pygame.Surface(self.size.tuple()) hours, minutes, seconds = game_data.stats.total_play_time playtime_text = "{}h {}m {}s".format(hours, minutes, seconds) display_text( surface, "You died after {}".format(playtime_text), gfx_data.assets.font_message, (300, 100), ) display_text( surface, "Killed by a {} after killing...".format( game_data.player.fighter.killed_by.name), gfx_data.assets.font_message, (120, 150), ) kills = game_data.stats.monsters_per_type lines = [] if not kills: lines.append("...nothing. Well, better luck next time") else: for k in kills: lines.append("{} {}".format(kills[k], k)) display_lines(surface, gfx_data.assets.font_message, lines, x=120, starty=180) display_text( surface, "Press Escape again to quit, press Space to restart", gfx_data.assets.font_message, (120, 500), ) gfx_data.main.blit(surface, self.pos.tuple())
def draw(self, game_data, gfx_data): formulas = game_data.formula_builder.evaluate_entity(caster=game_data.player) formula = formulas[game_data.formula_builder.currformula] surface = pygame.Surface(self.size.tuple()) linediff = gfx_data.assets.font_message_height if game_data.map.tutorial: lines = [ "TUTORIAL: This is just to show you your current formulas for the tutorial", ] if not config.conf.pickup: lines.append("After this tutorial you'll be able to select these as you want") else: lines.append("After this tutorial you'll be able to find ingredients on the levels") display_lines(surface, gfx_data.assets.font_message, lines, 00, 20) y = 120 display_text(surface, "Formulas", gfx_data.assets.font_message, (50, y)) y += 3 * linediff text = "Formula {}/{}".format(game_data.formula_builder.currformula + 1, game_data.formula_builder.num_formula,) display_text(surface, text, gfx_data.assets.font_message, (50, y)) y += 2 * linediff display_text(surface, "Vial slots:", gfx_data.assets.font_message, (50, y)) y += linediff for idx, ing in enumerate(game_data.formula_builder.current_slots): if idx == game_data.formula_builder.currslot: display_text(surface, "-->", gfx_data.assets.font_message, (5, y)) display_text(surface, f"Slot {idx+1}:", gfx_data.assets.font_message, (50, y)) display_text( surface, ing.name, gfx_data.assets.font_message, (120, y), text_color=IngredientMeta.INGREDIENT_COLORS[ing], ) y += linediff y += linediff display_text(surface, "Formula stats:", gfx_data.assets.font_message, (50, y)) if formula.suboptimal: y += linediff display_text( surface, f"Note, this formula might not be what you want: {formula.suboptimal}", gfx_data.assets.font_message, (50, y), ) y += linediff * 2 cooldown_text = "Cooldown: {} rounds".format(formula.cooldown) display_text(surface, cooldown_text, gfx_data.assets.font_message, (50, y)) y += linediff * 2 lines = textwrap.wrap(formulas[game_data.formula_builder.currformula].text_stats, 60) display_lines(surface, gfx_data.assets.font_message, lines, 50, y) y += len(lines) * linediff y += 2 * linediff display_text( surface, "Arrow left/right or 1,2,3,...: select formula", gfx_data.assets.font_message, (50, y), ) y += linediff display_text( surface, "Arrow up/down or Mouse scroll: select slot", gfx_data.assets.font_message, (50, y), ) y += linediff display_text( surface, "Press Tab for help, or Space to confirm selection", gfx_data.assets.font_message, (50, y), ) if config.conf.pickup: if config.conf.crafting: self.draw_crafted_ingredient_list(surface, game_data, gfx_data) else: self.draw_counted_ingredient_list(surface, game_data, gfx_data) else: self.draw_ingredient_list(surface, game_data, gfx_data) gfx_data.main.blit(surface, self.pos.tuple())
def draw(self, surface): display_text(surface, self.text, self.font, self.pos.tuple())