diff --git a/animate2.cpp b/animate2.cpp index c056a07..66f0e47 100644 --- a/animate2.cpp +++ b/animate2.cpp @@ -70,8 +70,7 @@ namespace animate2 { } } - // replaces step - void Animate2::update_frame() { + void Animate2::update() { dbc::check(playing, "attempt to update animation that's not playing"); dbc::check(sequence.frame_count == sequence.frames.size(), "frame_count doesn't match frame.size()"); @@ -106,10 +105,6 @@ namespace animate2 { dbc::check(sequence.current < sequence.frame_count, "onLoop fail: current frame out of frames.size()"); } - void Animate2::update() { - update_frame(); - } - void Animate2::motion(sf::Sprite& sprite, sf::Vector2f pos, sf::Vector2f scale) { transform.lerp(sequence, pos, scale); diff --git a/animate2.hpp b/animate2.hpp index 33061d6..09f439d 100644 --- a/animate2.hpp +++ b/animate2.hpp @@ -118,7 +118,6 @@ namespace animate2 { void set_form(const std::string& form); void apply(sf::Sprite& sprite); void apply_effect(std::shared_ptr effect); - void update_frame(); void update(); void motion(sf::Sprite& sprite, sf::Vector2f pos, sf::Vector2f scale); std::pair commit(); diff --git a/assets/animate2.json b/assets/animate2.json index 9b3124a..f767330 100644 --- a/assets/animate2.json +++ b/assets/animate2.json @@ -116,7 +116,7 @@ "max_y": 0, "flipped": false, "ease_rate": 3.0, - "scaled": false, + "scaled": true, "toggled": false, "looped": true, "easing": "sine", diff --git a/boss/fight.cpp b/boss/fight.cpp index a7a5ead..46bb910 100644 --- a/boss/fight.cpp +++ b/boss/fight.cpp @@ -41,7 +41,7 @@ namespace boss { using enum game::Event; switch(ev) { - case BOSS_START: + case COMBAT_START: $ui.status(L"PLAYER REQUESTS", L"COMMIT"); $battle.ap_refresh(); state(State::PLAYER_REQUESTS); @@ -56,7 +56,7 @@ namespace boss { switch(ev) { // this is only if using the debug X key to skip it - case BOSS_START: + case BOSS_END: state(State::END); break; case COMBAT_START: @@ -72,8 +72,6 @@ namespace boss { fmt::println("NO MORE ACTION!"); } break; - case TICK: - break; // ignore tick default: break; } @@ -84,7 +82,7 @@ namespace boss { switch(ev) { // this is only if using the debug X key to skip it - case BOSS_START: + case BOSS_END: state(State::END); break; case COMBAT_START: @@ -242,7 +240,7 @@ namespace boss { switch($router.scancode) { // REALLY? just go to state end or use another event case KEY::X: - event(game::Event::BOSS_START, {}); + event(game::Event::BOSS_END, {}); break; default: fmt::println("key press!"); diff --git a/scene.cpp b/scene.cpp index 5c3f6b7..afbd1ca 100644 --- a/scene.cpp +++ b/scene.cpp @@ -18,11 +18,12 @@ namespace scene { float y = config["y"]; bool flipped = config["flipped"]; - // BUG: need to make animation optional + // BUG: put the .json file to load as a default/optional arg auto anim = animate2::load("./assets/animate2.json", sprite_name); - anim.transform.flipped = flipped; if(and_play) anim.play(); + anim.transform.flipped = flipped; + std::string cell = config["cell"]; std::string name = config["name"]; @@ -30,7 +31,7 @@ namespace scene { sf::Text text(*$ui.$font, "", 60); - return {name, st, anim, cell, scale_x, scale_y, x, y, at_mid, flipped, nullptr, text}; + return {name, st, anim, cell, {scale_x, scale_y}, {x, y}, at_mid, flipped, nullptr, text}; } Engine::Engine(components::AnimatedScene& scene) : @@ -64,12 +65,12 @@ namespace scene { for(auto& actor : $actors) { actor.pos = position_sprite(actor.st, actor.cell, - actor.scale_x, actor.scale_y, actor.at_mid, actor.x, actor.y); + actor.scale, actor.at_mid, actor.pos.x, actor.pos.y); } for(auto& fixture : $fixtures) { fixture.pos = position_sprite(fixture.st, fixture.cell, - fixture.scale_x, fixture.scale_y, fixture.at_mid, fixture.x, fixture.y); + fixture.scale, fixture.at_mid, fixture.pos.x, fixture.pos.y); } } @@ -81,7 +82,7 @@ namespace scene { void Engine::attach_text(const std::string& actor, const std::string& text) { auto& element = actor_config(actor); element.text.setPosition(element.pos); - element.text.setScale({element.scale_x, element.scale_y}); + element.text.setScale(element.scale); element.text.setFillColor(sf::Color::Red); element.text.setOutlineThickness(2.0f); element.text.setOutlineColor(sf::Color::Black); @@ -116,7 +117,7 @@ namespace scene { void Engine::move_actor(const std::string& actor, const std::string& cell_name) { auto& config = actor_config(actor); config.cell = cell_name; - config.pos = position_sprite(config.st, config.cell, config.scale_x, config.scale_y, config.at_mid); + config.pos = position_sprite(config.st, config.cell, config.scale, config.at_mid); } void Engine::animate_actor(const std::string& actor) { @@ -128,8 +129,8 @@ namespace scene { for(auto& fixture : $fixtures) { if(fixture.anim.playing) { fixture.anim.update(); + fixture.anim.motion(*fixture.st.sprite, fixture.pos, fixture.scale); fixture.anim.apply(*fixture.st.sprite); - // REFACTOR: fixture.anim.apply(*fixture.st.sprite); } else { fixture.effect = nullptr; } @@ -138,6 +139,7 @@ namespace scene { for(auto& actor : $actors) { if(actor.anim.playing) { actor.anim.update(); + actor.anim.motion(*actor.st.sprite, actor.pos, actor.scale); actor.anim.apply(*actor.st.sprite); // REFACTOR: actor.anim.apply(actor.text, actor.pos); // if(actor.effect != nullptr) actor.anim.apply_effect(actor.effect); @@ -147,14 +149,14 @@ namespace scene { } } - sf::Vector2f Engine::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 Engine::position_sprite(textures::SpriteTexture& st, const std::string& cell_name, sf::Vector2f scale, bool at_mid, float x_diff, float y_diff) { auto& cell = $ui.cell_for(cell_name); float x = float(at_mid ? cell.mid_x : cell.x); float y = float(at_mid ? cell.mid_y : cell.y); sf::Vector2f pos{x + x_diff, y + y_diff}; st.sprite->setPosition(pos); - st.sprite->setScale({scale_x, scale_y}); + st.sprite->setScale(scale); return pos; } diff --git a/scene.hpp b/scene.hpp index 261ed46..1be1321 100644 --- a/scene.hpp +++ b/scene.hpp @@ -18,15 +18,12 @@ namespace scene { textures::SpriteTexture st; animate2::Animate2 anim; std::string cell; - float scale_x = 1.0f; - float scale_y = 1.0f; - float x = 0; - float y = 0; + sf::Vector2f scale{1.0f, 1.0f}; + sf::Vector2f pos{0.0f, 0.0f}; bool at_mid=false; bool flipped=false; std::shared_ptr effect = nullptr; sf::Text text; - sf::Vector2f pos{0,0}; }; struct Engine { @@ -47,7 +44,7 @@ namespace scene { void attach_text(const std::string& actor, const std::string& text); Element config_scene_element(nlohmann::json& config, bool and_play, bool duped); - 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); + sf::Vector2f position_sprite(textures::SpriteTexture& st, const std::string& cell_name, sf::Vector2f scale, bool at_mid, float x_diff=0.0f, float y_diff=0.0f); void move_actor(const std::string& actor, const std::string& cell_name); void animate_actor(const std::string& actor); diff --git a/tools/arena.cpp b/tools/arena.cpp index 0678f83..c06e783 100644 --- a/tools/arena.cpp +++ b/tools/arena.cpp @@ -53,11 +53,11 @@ int main(int, char*[]) { main->$ui.$arena.tick(); main->render(window); - if(main->handle_keyboard_mouse() || - main->handle_world_events()) + if(main->handle_keyboard_mouse() || main->handle_world_events()) { return 0; } + window.display(); }