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";
|
std::string player_move = Random::uniform(0, 1) == 0 ? "player1" : "player3";
|
||||||
$ui.move_actor("player", player_move);
|
$ui.move_actor("player", player_move);
|
||||||
if(result.player_did > 0) $ui.animate_actor("player");
|
if(result.player_did > 0) $ui.animate_actor("player");
|
||||||
$ui.damage("boss", result.player_did);
|
$ui.damage("player", result.player_did);
|
||||||
} break;
|
} break;
|
||||||
case BattleHostState::not_host: {
|
case BattleHostState::not_host: {
|
||||||
std::string boss_move = Random::uniform(0, 1) == 0 ? "boss5" : "boss6";
|
std::string boss_move = Random::uniform(0, 1) == 0 ? "boss5" : "boss6";
|
||||||
|
|
||||||
$ui.move_actor("boss", boss_move);
|
$ui.move_actor("boss", boss_move);
|
||||||
if(result.enemy_did > 0) $ui.animate_actor("boss");
|
if(result.enemy_did > 0) $ui.animate_actor("boss");
|
||||||
$ui.damage("player", result.enemy_did);
|
$ui.damage("boss", result.enemy_did);
|
||||||
} break;
|
} break;
|
||||||
case BattleHostState::out_of_ap:
|
case BattleHostState::out_of_ap:
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -109,11 +109,10 @@ namespace boss {
|
||||||
}
|
}
|
||||||
|
|
||||||
void UI::damage(const std::string& actor, int amount) {
|
void UI::damage(const std::string& actor, int amount) {
|
||||||
// BUG: the $arena should really do this
|
$arena.attach_text(actor, fmt::format("{}", amount));
|
||||||
if(amount == 0) {
|
|
||||||
$arena.attach_text(actor, "MISS!");
|
if(amount > 0) {
|
||||||
} else {
|
$arena.apply_effect(actor, "flame");
|
||||||
$arena.attach_text(actor, "HIT!");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
21
scene.cpp
21
scene.cpp
|
|
@ -1,6 +1,7 @@
|
||||||
#include "scene.hpp"
|
#include "scene.hpp"
|
||||||
#include "animation.hpp"
|
#include "animation.hpp"
|
||||||
#include <ranges>
|
#include <ranges>
|
||||||
|
#include "shaders.hpp"
|
||||||
|
|
||||||
const bool DEBUG=false;
|
const bool DEBUG=false;
|
||||||
|
|
||||||
|
|
@ -27,7 +28,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, 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) :
|
||||||
|
|
@ -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) {
|
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);
|
||||||
|
|
@ -88,15 +94,14 @@ namespace scene {
|
||||||
$ui.render(window);
|
$ui.render(window);
|
||||||
|
|
||||||
for(auto& fixture : $fixtures) {
|
for(auto& fixture : $fixtures) {
|
||||||
window.draw(*fixture.st.sprite);
|
window.draw(*fixture.st.sprite, fixture.effect.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
for(auto& actor : $actors) {
|
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(actor.anim.playing) window.draw(actor.text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(DEBUG) $ui.debug_layout(window);
|
if(DEBUG) $ui.debug_layout(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -119,6 +124,8 @@ namespace scene {
|
||||||
for(auto& fixture : $fixtures) {
|
for(auto& fixture : $fixtures) {
|
||||||
if(fixture.anim.playing) {
|
if(fixture.anim.playing) {
|
||||||
fixture.anim.apply(*fixture.st.sprite, fixture.pos);
|
fixture.anim.apply(*fixture.st.sprite, fixture.pos);
|
||||||
|
} else {
|
||||||
|
fixture.effect = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -126,6 +133,12 @@ namespace scene {
|
||||||
if(actor.anim.playing) {
|
if(actor.anim.playing) {
|
||||||
actor.anim.apply(*actor.st.sprite, actor.pos);
|
actor.anim.apply(*actor.st.sprite, actor.pos);
|
||||||
actor.anim.apply(actor.text, 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;
|
float y = 0;
|
||||||
bool at_mid=false;
|
bool at_mid=false;
|
||||||
bool flipped=false;
|
bool flipped=false;
|
||||||
|
std::shared_ptr<sf::Shader> effect = nullptr;
|
||||||
sf::Text text;
|
sf::Text text;
|
||||||
sf::Vector2f pos{0,0};
|
sf::Vector2f pos{0,0};
|
||||||
};
|
};
|
||||||
|
|
@ -46,6 +47,7 @@ namespace scene {
|
||||||
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);
|
||||||
void play_animations();
|
void play_animations();
|
||||||
|
void apply_effect(const std::string& actor, const std::string& shader);
|
||||||
Element& actor_config(const std::string& actor);
|
Element& actor_config(const std::string& actor);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ void craft_weapon() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int, char*[]) {
|
int main(int, char*[]) {
|
||||||
|
shaders::init();
|
||||||
components::init();
|
components::init();
|
||||||
sfml::Backend backend;
|
sfml::Backend backend;
|
||||||
guecs::init(&backend);
|
guecs::init(&backend);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue