AnimatedScene now defines how a scene with animated sprites and actors is structured and played.
This commit is contained in:
parent
e1da089600
commit
25f7096489
10 changed files with 43 additions and 48 deletions
|
|
@ -84,7 +84,7 @@ namespace boss {
|
|||
break;
|
||||
case ATTACK: {
|
||||
$ui.status(L"PLAYER TURN");
|
||||
$ui.move_player(run % 10 < 5 ? "player1" : "player2");
|
||||
$ui.move_actor($ui.$player_sprite, "player", run % 10 < 5 ? "player1" : "player2");
|
||||
int attack_id = std::any_cast<int>(data);
|
||||
boss::System::combat(attack_id);
|
||||
state(State::PLAYER_TURN);
|
||||
|
|
@ -105,7 +105,7 @@ namespace boss {
|
|||
break;
|
||||
case ATTACK: {
|
||||
$ui.status(L"BOSS TURN");
|
||||
$ui.move_boss(run % 10 < 5 ? "boss5" : "boss6");
|
||||
$ui.$boss_pos = $ui.move_actor($ui.$boss_sprite, "boss", run % 10 < 5 ? "boss5" : "boss6");
|
||||
$ui.$boss_anim.play();
|
||||
int attack_id = std::any_cast<int>(data);
|
||||
boss::System::combat(attack_id);
|
||||
|
|
|
|||
31
boss/ui.cpp
31
boss/ui.cpp
|
|
@ -14,10 +14,10 @@ namespace boss {
|
|||
UI::UI(shared_ptr<World> world, Entity boss_id) :
|
||||
$world(world),
|
||||
$boss_id(boss_id),
|
||||
$scene(world->get<components::BossFight>($boss_id)),
|
||||
$scene(world->get<components::AnimatedScene>($boss_id)),
|
||||
$combat_ui(true)
|
||||
{
|
||||
std::string sprite_name = $scene.boss["sprite"];
|
||||
std::string sprite_name = $scene.actors["boss"]["sprite"];
|
||||
$boss_sprite = textures::get_sprite(sprite_name);
|
||||
|
||||
// floor is std::optional
|
||||
|
|
@ -25,7 +25,7 @@ namespace boss {
|
|||
$floor_sprite = textures::get_sprite(*$scene.floor);
|
||||
}
|
||||
|
||||
$player_sprite = textures::get_sprite($scene.player["sprite"]);
|
||||
$player_sprite = textures::get_sprite($scene.actors["player"]["sprite"]);
|
||||
|
||||
dbc::check(animation::has(sprite_name), "add boss animation to animations.json");
|
||||
$boss_anim = animation::load(sprite_name);
|
||||
|
|
@ -66,8 +66,8 @@ namespace boss {
|
|||
"[floor4|player5|player6|player7|player8|_]"
|
||||
);
|
||||
|
||||
move_boss($scene.boss["start_pos"]);
|
||||
move_player($scene.player["start_pos"]);
|
||||
$boss_pos = move_actor($boss_sprite, "boss", $scene.actors["boss"]["start_pos"]);
|
||||
move_actor($player_sprite, "player", $scene.actors["player"]["start_pos"]);
|
||||
|
||||
if($scene.floor) {
|
||||
position_sprite($floor_sprite, $scene.floor_pos, 1.0f, 1.0f, false);
|
||||
|
|
@ -100,13 +100,16 @@ namespace boss {
|
|||
$combat_ui.init(cell.x, cell.y, cell.w, cell.h);
|
||||
}
|
||||
|
||||
void UI::position_sprite(textures::SpriteTexture& st, const std::string& cell_name, float scale_x, float scale_y, bool at_mid, float x_diff, float y_diff) {
|
||||
sf::Vector2f UI::position_sprite(textures::SpriteTexture& st, const std::string& cell_name, float scale_x, float scale_y, bool at_mid, float x_diff, float y_diff) {
|
||||
auto& cell = $arena.cell_for(cell_name);
|
||||
float x = float(at_mid ? cell.mid_x : cell.x);
|
||||
float y = float(at_mid ? cell.mid_y : cell.y);
|
||||
|
||||
st.sprite->setPosition({x + x_diff, y + y_diff});
|
||||
sf::Vector2f pos{x + x_diff, y + y_diff};
|
||||
st.sprite->setPosition(pos);
|
||||
st.sprite->setScale({scale_x, scale_y});
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
void UI::render(sf::RenderWindow& window) {
|
||||
|
|
@ -139,17 +142,9 @@ namespace boss {
|
|||
$arena.show_text("status", msg);
|
||||
}
|
||||
|
||||
void UI::move_boss(const std::string& cell_name) {
|
||||
float scale = $scene.boss["scale"];
|
||||
position_sprite($boss_sprite, cell_name, scale, scale, $scene.boss["mid_cell"]);
|
||||
|
||||
auto& cell = $arena.cell_for(cell_name);
|
||||
$boss_pos = {float(cell.mid_x), float(cell.mid_y)};
|
||||
}
|
||||
|
||||
void UI::move_player(const std::string& cell_name) {
|
||||
float scale = $scene.player["scale"];
|
||||
position_sprite($player_sprite, cell_name, scale, scale, $scene.player["mid_cell"]);
|
||||
sf::Vector2f UI::move_actor(textures::SpriteTexture& st, const std::string& actor, const std::string& cell_name) {
|
||||
float scale = $scene.actors[actor]["scale"];
|
||||
return position_sprite(st, cell_name, scale, scale, $scene.actors[actor]["mid_cell"]);
|
||||
}
|
||||
|
||||
void UI::play_animations() {
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ namespace boss {
|
|||
struct UI {
|
||||
shared_ptr<World> $world = nullptr;
|
||||
Entity $boss_id = NONE;
|
||||
components::BossFight& $scene;
|
||||
components::AnimatedScene $scene;
|
||||
gui::CombatUI $combat_ui;
|
||||
SpriteTexture $boss_sprite;
|
||||
SpriteTexture $player_sprite;
|
||||
|
|
@ -44,10 +44,9 @@ namespace boss {
|
|||
void init();
|
||||
void render(sf::RenderWindow& window);
|
||||
bool mouse(float x, float y, guecs::Modifiers mods);
|
||||
void position_sprite(textures::SpriteTexture& st, const std::string& cell_name, float scale_x, float scale_y, bool at_mid, float x_diff=0.0f, float y_diff=0.0f);
|
||||
sf::Vector2f position_sprite(textures::SpriteTexture& st, const std::string& cell_name, float scale_x, float scale_y, bool at_mid, float x_diff=0.0f, float y_diff=0.0f);
|
||||
void status(const std::wstring& msg);
|
||||
void move_boss(const std::string& cell_name);
|
||||
void move_player(const std::string& cell_name);
|
||||
sf::Vector2f move_actor(SpriteTexture& st, const std::string& actor, const std::string& cell_name);
|
||||
void play_animations();
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue