Torches are now flipped, but next is that same crash.
This commit is contained in:
parent
0e8b661273
commit
2484802d93
7 changed files with 23 additions and 32 deletions
|
|
@ -70,8 +70,7 @@ namespace animate2 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// replaces step
|
void Animate2::update() {
|
||||||
void Animate2::update_frame() {
|
|
||||||
dbc::check(playing, "attempt to update animation that's not playing");
|
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()");
|
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()");
|
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) {
|
void Animate2::motion(sf::Sprite& sprite, sf::Vector2f pos, sf::Vector2f scale) {
|
||||||
transform.lerp(sequence, pos, scale);
|
transform.lerp(sequence, pos, scale);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -118,7 +118,6 @@ namespace animate2 {
|
||||||
void set_form(const std::string& form);
|
void set_form(const std::string& form);
|
||||||
void apply(sf::Sprite& sprite);
|
void apply(sf::Sprite& sprite);
|
||||||
void apply_effect(std::shared_ptr<sf::Shader> effect);
|
void apply_effect(std::shared_ptr<sf::Shader> effect);
|
||||||
void update_frame();
|
|
||||||
void update();
|
void update();
|
||||||
void motion(sf::Sprite& sprite, sf::Vector2f pos, sf::Vector2f scale);
|
void motion(sf::Sprite& sprite, sf::Vector2f pos, sf::Vector2f scale);
|
||||||
std::pair<int, double> commit();
|
std::pair<int, double> commit();
|
||||||
|
|
|
||||||
|
|
@ -116,7 +116,7 @@
|
||||||
"max_y": 0,
|
"max_y": 0,
|
||||||
"flipped": false,
|
"flipped": false,
|
||||||
"ease_rate": 3.0,
|
"ease_rate": 3.0,
|
||||||
"scaled": false,
|
"scaled": true,
|
||||||
"toggled": false,
|
"toggled": false,
|
||||||
"looped": true,
|
"looped": true,
|
||||||
"easing": "sine",
|
"easing": "sine",
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ namespace boss {
|
||||||
using enum game::Event;
|
using enum game::Event;
|
||||||
|
|
||||||
switch(ev) {
|
switch(ev) {
|
||||||
case BOSS_START:
|
case COMBAT_START:
|
||||||
$ui.status(L"PLAYER REQUESTS", L"COMMIT");
|
$ui.status(L"PLAYER REQUESTS", L"COMMIT");
|
||||||
$battle.ap_refresh();
|
$battle.ap_refresh();
|
||||||
state(State::PLAYER_REQUESTS);
|
state(State::PLAYER_REQUESTS);
|
||||||
|
|
@ -56,7 +56,7 @@ namespace boss {
|
||||||
|
|
||||||
switch(ev) {
|
switch(ev) {
|
||||||
// this is only if using the debug X key to skip it
|
// this is only if using the debug X key to skip it
|
||||||
case BOSS_START:
|
case BOSS_END:
|
||||||
state(State::END);
|
state(State::END);
|
||||||
break;
|
break;
|
||||||
case COMBAT_START:
|
case COMBAT_START:
|
||||||
|
|
@ -72,8 +72,6 @@ namespace boss {
|
||||||
fmt::println("NO MORE ACTION!");
|
fmt::println("NO MORE ACTION!");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TICK:
|
|
||||||
break; // ignore tick
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -84,7 +82,7 @@ namespace boss {
|
||||||
|
|
||||||
switch(ev) {
|
switch(ev) {
|
||||||
// this is only if using the debug X key to skip it
|
// this is only if using the debug X key to skip it
|
||||||
case BOSS_START:
|
case BOSS_END:
|
||||||
state(State::END);
|
state(State::END);
|
||||||
break;
|
break;
|
||||||
case COMBAT_START:
|
case COMBAT_START:
|
||||||
|
|
@ -242,7 +240,7 @@ namespace boss {
|
||||||
switch($router.scancode) {
|
switch($router.scancode) {
|
||||||
// REALLY? just go to state end or use another event
|
// REALLY? just go to state end or use another event
|
||||||
case KEY::X:
|
case KEY::X:
|
||||||
event(game::Event::BOSS_START, {});
|
event(game::Event::BOSS_END, {});
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fmt::println("key press!");
|
fmt::println("key press!");
|
||||||
|
|
|
||||||
22
scene.cpp
22
scene.cpp
|
|
@ -18,11 +18,12 @@ namespace scene {
|
||||||
float y = config["y"];
|
float y = config["y"];
|
||||||
bool flipped = config["flipped"];
|
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);
|
auto anim = animate2::load("./assets/animate2.json", sprite_name);
|
||||||
anim.transform.flipped = flipped;
|
|
||||||
if(and_play) anim.play();
|
if(and_play) anim.play();
|
||||||
|
|
||||||
|
anim.transform.flipped = flipped;
|
||||||
|
|
||||||
std::string cell = config["cell"];
|
std::string cell = config["cell"];
|
||||||
std::string name = config["name"];
|
std::string name = config["name"];
|
||||||
|
|
||||||
|
|
@ -30,7 +31,7 @@ namespace scene {
|
||||||
|
|
||||||
sf::Text text(*$ui.$font, "", 60);
|
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) :
|
Engine::Engine(components::AnimatedScene& scene) :
|
||||||
|
|
@ -64,12 +65,12 @@ namespace scene {
|
||||||
|
|
||||||
for(auto& actor : $actors) {
|
for(auto& actor : $actors) {
|
||||||
actor.pos = position_sprite(actor.st, actor.cell,
|
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) {
|
for(auto& fixture : $fixtures) {
|
||||||
fixture.pos = position_sprite(fixture.st, fixture.cell,
|
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) {
|
void Engine::attach_text(const std::string& actor, const std::string& text) {
|
||||||
auto& element = actor_config(actor);
|
auto& element = actor_config(actor);
|
||||||
element.text.setPosition(element.pos);
|
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.setFillColor(sf::Color::Red);
|
||||||
element.text.setOutlineThickness(2.0f);
|
element.text.setOutlineThickness(2.0f);
|
||||||
element.text.setOutlineColor(sf::Color::Black);
|
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) {
|
void Engine::move_actor(const std::string& actor, const std::string& cell_name) {
|
||||||
auto& config = actor_config(actor);
|
auto& config = actor_config(actor);
|
||||||
config.cell = cell_name;
|
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) {
|
void Engine::animate_actor(const std::string& actor) {
|
||||||
|
|
@ -128,8 +129,8 @@ namespace scene {
|
||||||
for(auto& fixture : $fixtures) {
|
for(auto& fixture : $fixtures) {
|
||||||
if(fixture.anim.playing) {
|
if(fixture.anim.playing) {
|
||||||
fixture.anim.update();
|
fixture.anim.update();
|
||||||
|
fixture.anim.motion(*fixture.st.sprite, fixture.pos, fixture.scale);
|
||||||
fixture.anim.apply(*fixture.st.sprite);
|
fixture.anim.apply(*fixture.st.sprite);
|
||||||
// REFACTOR: fixture.anim.apply(*fixture.st.sprite);
|
|
||||||
} else {
|
} else {
|
||||||
fixture.effect = nullptr;
|
fixture.effect = nullptr;
|
||||||
}
|
}
|
||||||
|
|
@ -138,6 +139,7 @@ namespace scene {
|
||||||
for(auto& actor : $actors) {
|
for(auto& actor : $actors) {
|
||||||
if(actor.anim.playing) {
|
if(actor.anim.playing) {
|
||||||
actor.anim.update();
|
actor.anim.update();
|
||||||
|
actor.anim.motion(*actor.st.sprite, actor.pos, actor.scale);
|
||||||
actor.anim.apply(*actor.st.sprite);
|
actor.anim.apply(*actor.st.sprite);
|
||||||
// REFACTOR: actor.anim.apply(actor.text, actor.pos);
|
// REFACTOR: actor.anim.apply(actor.text, actor.pos);
|
||||||
// if(actor.effect != nullptr) actor.anim.apply_effect(actor.effect);
|
// 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);
|
auto& cell = $ui.cell_for(cell_name);
|
||||||
float x = float(at_mid ? cell.mid_x : cell.x);
|
float x = float(at_mid ? cell.mid_x : cell.x);
|
||||||
float y = float(at_mid ? cell.mid_y : cell.y);
|
float y = float(at_mid ? cell.mid_y : cell.y);
|
||||||
|
|
||||||
sf::Vector2f pos{x + x_diff, y + y_diff};
|
sf::Vector2f pos{x + x_diff, y + y_diff};
|
||||||
st.sprite->setPosition(pos);
|
st.sprite->setPosition(pos);
|
||||||
st.sprite->setScale({scale_x, scale_y});
|
st.sprite->setScale(scale);
|
||||||
|
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,15 +18,12 @@ namespace scene {
|
||||||
textures::SpriteTexture st;
|
textures::SpriteTexture st;
|
||||||
animate2::Animate2 anim;
|
animate2::Animate2 anim;
|
||||||
std::string cell;
|
std::string cell;
|
||||||
float scale_x = 1.0f;
|
sf::Vector2f scale{1.0f, 1.0f};
|
||||||
float scale_y = 1.0f;
|
sf::Vector2f pos{0.0f, 0.0f};
|
||||||
float x = 0;
|
|
||||||
float y = 0;
|
|
||||||
bool at_mid=false;
|
bool at_mid=false;
|
||||||
bool flipped=false;
|
bool flipped=false;
|
||||||
std::shared_ptr<sf::Shader> effect = nullptr;
|
std::shared_ptr<sf::Shader> effect = nullptr;
|
||||||
sf::Text text;
|
sf::Text text;
|
||||||
sf::Vector2f pos{0,0};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Engine {
|
struct Engine {
|
||||||
|
|
@ -47,7 +44,7 @@ namespace scene {
|
||||||
void attach_text(const std::string& actor, const std::string& text);
|
void attach_text(const std::string& actor, const std::string& text);
|
||||||
Element config_scene_element(nlohmann::json& config, bool and_play, bool duped);
|
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 move_actor(const std::string& actor, const std::string& cell_name);
|
||||||
void animate_actor(const std::string& actor);
|
void animate_actor(const std::string& actor);
|
||||||
|
|
|
||||||
|
|
@ -53,11 +53,11 @@ int main(int, char*[]) {
|
||||||
main->$ui.$arena.tick();
|
main->$ui.$arena.tick();
|
||||||
main->render(window);
|
main->render(window);
|
||||||
|
|
||||||
if(main->handle_keyboard_mouse() ||
|
if(main->handle_keyboard_mouse() || main->handle_world_events())
|
||||||
main->handle_world_events())
|
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
window.display();
|
window.display();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue