Can now see an enemy take damage, and a damage number, but the effect is inverted.
This commit is contained in:
parent
f175a5d4aa
commit
8208d146de
5 changed files with 26 additions and 11 deletions
|
|
@ -129,14 +129,14 @@ namespace boss {
|
|||
std::string player_move = Random::uniform(0, 1) == 0 ? "player1" : "player3";
|
||||
$ui.move_actor("player", player_move);
|
||||
if(result.player_did > 0) $ui.animate_actor("player");
|
||||
$ui.damage("boss", result.player_did);
|
||||
$ui.damage("player", result.player_did);
|
||||
} break;
|
||||
case BattleHostState::not_host: {
|
||||
std::string boss_move = Random::uniform(0, 1) == 0 ? "boss5" : "boss6";
|
||||
|
||||
$ui.move_actor("boss", boss_move);
|
||||
if(result.enemy_did > 0) $ui.animate_actor("boss");
|
||||
$ui.damage("player", result.enemy_did);
|
||||
$ui.damage("boss", result.enemy_did);
|
||||
} break;
|
||||
case BattleHostState::out_of_ap:
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -109,11 +109,10 @@ namespace boss {
|
|||
}
|
||||
|
||||
void UI::damage(const std::string& actor, int amount) {
|
||||
// BUG: the $arena should really do this
|
||||
if(amount == 0) {
|
||||
$arena.attach_text(actor, "MISS!");
|
||||
} else {
|
||||
$arena.attach_text(actor, "HIT!");
|
||||
$arena.attach_text(actor, fmt::format("{}", amount));
|
||||
|
||||
if(amount > 0) {
|
||||
$arena.apply_effect(actor, "flame");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
21
scene.cpp
21
scene.cpp
|
|
@ -1,6 +1,7 @@
|
|||
#include "scene.hpp"
|
||||
#include "animation.hpp"
|
||||
#include <ranges>
|
||||
#include "shaders.hpp"
|
||||
|
||||
const bool DEBUG=false;
|
||||
|
||||
|
|
@ -27,7 +28,7 @@ namespace scene {
|
|||
|
||||
sf::Text text(*$ui.$font, "", 60);
|
||||
|
||||
return {name, st, anim, cell, scale_x, scale_y, x, y, at_mid, flipped, text};
|
||||
return {name, st, anim, cell, scale_x, scale_y, x, y, at_mid, flipped, nullptr, text};
|
||||
}
|
||||
|
||||
Engine::Engine(components::AnimatedScene& scene) :
|
||||
|
|
@ -70,6 +71,11 @@ namespace scene {
|
|||
}
|
||||
}
|
||||
|
||||
void Engine::apply_effect(const std::string& actor, const std::string& shader) {
|
||||
auto& element = actor_config(actor);
|
||||
element.effect = shaders::get(shader);
|
||||
}
|
||||
|
||||
void Engine::attach_text(const std::string& actor, const std::string& text) {
|
||||
auto& element = actor_config(actor);
|
||||
element.text.setPosition(element.pos);
|
||||
|
|
@ -88,15 +94,14 @@ namespace scene {
|
|||
$ui.render(window);
|
||||
|
||||
for(auto& fixture : $fixtures) {
|
||||
window.draw(*fixture.st.sprite);
|
||||
window.draw(*fixture.st.sprite, fixture.effect.get());
|
||||
}
|
||||
|
||||
for(auto& actor : $actors) {
|
||||
window.draw(*actor.st.sprite);
|
||||
window.draw(*actor.st.sprite, actor.effect.get());
|
||||
if(actor.anim.playing) window.draw(actor.text);
|
||||
}
|
||||
|
||||
|
||||
if(DEBUG) $ui.debug_layout(window);
|
||||
}
|
||||
|
||||
|
|
@ -119,6 +124,8 @@ namespace scene {
|
|||
for(auto& fixture : $fixtures) {
|
||||
if(fixture.anim.playing) {
|
||||
fixture.anim.apply(*fixture.st.sprite, fixture.pos);
|
||||
} else {
|
||||
fixture.effect = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -126,6 +133,12 @@ namespace scene {
|
|||
if(actor.anim.playing) {
|
||||
actor.anim.apply(*actor.st.sprite, actor.pos);
|
||||
actor.anim.apply(actor.text, actor.pos);
|
||||
if(actor.effect) {
|
||||
actor.effect->setUniform("u_time", actor.anim.subframe);
|
||||
actor.effect->setUniform("u_duration", 1000);
|
||||
}
|
||||
} else {
|
||||
actor.effect = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ namespace scene {
|
|||
float y = 0;
|
||||
bool at_mid=false;
|
||||
bool flipped=false;
|
||||
std::shared_ptr<sf::Shader> effect = nullptr;
|
||||
sf::Text text;
|
||||
sf::Vector2f pos{0,0};
|
||||
};
|
||||
|
|
@ -46,6 +47,7 @@ namespace scene {
|
|||
void move_actor(const std::string& actor, const std::string& cell_name);
|
||||
void animate_actor(const std::string& actor);
|
||||
void play_animations();
|
||||
void apply_effect(const std::string& actor, const std::string& shader);
|
||||
Element& actor_config(const std::string& actor);
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ void craft_weapon() {
|
|||
}
|
||||
|
||||
int main(int, char*[]) {
|
||||
shaders::init();
|
||||
components::init();
|
||||
sfml::Backend backend;
|
||||
guecs::init(&backend);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue