When there's actions in the arena the camera moves.

This commit is contained in:
Zed A. Shaw 2025-11-22 14:53:52 -05:00
parent 63a17d7efa
commit d244106981
4 changed files with 52 additions and 14 deletions

View file

@ -20,7 +20,7 @@ namespace boss {
$view_sprite($view_texture.getTexture())
{
$view_sprite.setPosition({BOSS_VIEW_X, BOSS_VIEW_Y});
$camera.style("bounce");
$camera.style("shake");
}
void UI::init() {
@ -50,8 +50,37 @@ namespace boss {
auto& player_combat = $world->get<components::Combat>($player_id);
auto& boss_combat = $world->get<components::Combat>($boss_id);
$actions.show_text("stats", fmt::format(
L"PLAYER: {}\nBOSS: {}", player_combat.hp, boss_combat.hp));
std::wstring status = fmt::format(
L"PLAYER: {}\nBOSS: {}", player_combat.hp, boss_combat.hp);
if($world->has_event<Events::GUI>()) {
auto [evt, entity, data] = $world->recv<Events::GUI>();
auto result = std::any_cast<Events::Combat>(data);
auto& player_is = $arena.$actors.at($arena.$actor_name_ids.at("player"));
auto& boss_is = $arena.$actors.at($arena.$actor_name_ids.at("boss"));
if(result.player_did > 0) {
status += L"\nYOU HIT!";
} else {
status += L"\nYOU MISSED!";
}
if(result.enemy_did > 0) {
status += L"\nBOSS HIT!";
} else {
status += L"\nBOSS MISSED!";
}
if(result.player_did > 0) {
zoom(boss_is.cell);
} else if(result.enemy_did > 0) {
zoom(player_is.cell);
} else {
zoom("");
}
}
$actions.show_text("stats", status);
}
void UI::render(sf::RenderWindow& window) {
@ -59,6 +88,7 @@ namespace boss {
$combat_ui.render(window);
$arena.render($view_texture);
$camera.render($view_texture);
$view_texture.display();
window.draw($view_sprite);
}
@ -86,9 +116,15 @@ namespace boss {
}
void UI::zoom(const std::string &cell_name) {
auto& cell = $arena.$ui.cell_for(cell_name);
if(cell_name == "") {
dbc::log("!!!!!!!!! you should add this to guecs");
$camera.reset($view_texture, BOSS_VIEW_WIDTH, BOSS_VIEW_HEIGHT);
} else {
auto& cell = $arena.$ui.cell_for(cell_name);
$camera.resize(BOSS_VIEW_WIDTH/2, BOSS_VIEW_HEIGHT/2);
$camera.move(float(cell.mid_x), float(cell.mid_y));
$camera.resize(BOSS_VIEW_WIDTH/2, BOSS_VIEW_HEIGHT/2);
$camera.move(float(cell.mid_x), float(cell.mid_y));
$camera.play();
}
}
}