Simple quick way to do different attacks that play different shaders.
This commit is contained in:
parent
58981fd8ed
commit
bf8a2dc0c5
10 changed files with 25 additions and 18 deletions
|
@ -13,7 +13,7 @@ namespace gui {
|
||||||
"[*%(100,150)button_attack | *%(100,150)button_block | *%(100,150)button_evade | *%(100,150)button_heal]");
|
"[*%(100,150)button_attack | *%(100,150)button_block | *%(100,150)button_evade | *%(100,150)button_heal]");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CombatUI::make_button(std::string name, std::wstring label, Events::GUI event) {
|
void CombatUI::make_button(std::string name, std::wstring label, Events::GUI event, int action) {
|
||||||
auto button = $gui.entity(name);
|
auto button = $gui.entity(name);
|
||||||
$gui.set<Sprite>(button, {"leather_pouch-128"});
|
$gui.set<Sprite>(button, {"leather_pouch-128"});
|
||||||
$gui.set<Rectangle>(button, {});
|
$gui.set<Rectangle>(button, {});
|
||||||
|
@ -21,27 +21,22 @@ namespace gui {
|
||||||
$gui.set<Label>(button, {label});
|
$gui.set<Label>(button, {label});
|
||||||
$gui.set<Effect>(button, {.duration=0.1f});
|
$gui.set<Effect>(button, {.duration=0.1f});
|
||||||
$gui.set<Clickable>(button,
|
$gui.set<Clickable>(button,
|
||||||
guecs::make_action(*$level.world, event));
|
guecs::make_action(*$level.world, event, {action}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CombatUI::init() {
|
void CombatUI::init() {
|
||||||
$gui.world().set_the<Background>({$gui.$parser, ColorValue::DARK_MID});
|
$gui.world().set_the<Background>({$gui.$parser, ColorValue::DARK_MID});
|
||||||
make_button("button_attack", L"Attack", Events::GUI::ATTACK);
|
make_button("button_attack", L"Attack", Events::GUI::ATTACK, 1);
|
||||||
make_button("button_block", L"Block", Events::GUI::BLOCK);
|
make_button("button_block", L"Block", Events::GUI::ATTACK, 2);
|
||||||
make_button("button_evade", L"Evade", Events::GUI::EVADE);
|
make_button("button_evade", L"Evade", Events::GUI::EVADE, 0);
|
||||||
make_button("button_heal", L"Heal", Events::GUI::HEAL);
|
make_button("button_heal", L"Heal", Events::GUI::HEAL, 0);
|
||||||
$gui.init();
|
$gui.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CombatUI::render(sf::RenderWindow& window) {
|
void CombatUI::render(sf::RenderWindow& window) {
|
||||||
auto& player_combat = $level.world->get<components::Combat>($level.player);
|
|
||||||
set_damage(float(player_combat.hp) / float(player_combat.max_hp));
|
|
||||||
$gui.render(window);
|
$gui.render(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CombatUI::set_damage(float) {
|
|
||||||
}
|
|
||||||
|
|
||||||
void CombatUI::update_level(GameLevel &level) {
|
void CombatUI::update_level(GameLevel &level) {
|
||||||
$level = level;
|
$level = level;
|
||||||
init();
|
init();
|
||||||
|
|
|
@ -16,8 +16,7 @@ namespace gui {
|
||||||
void init();
|
void init();
|
||||||
void render(sf::RenderWindow& window);
|
void render(sf::RenderWindow& window);
|
||||||
void update_level(GameLevel &level);
|
void update_level(GameLevel &level);
|
||||||
void set_damage(float percent);
|
|
||||||
bool mouse(float x, float y, bool hover);
|
bool mouse(float x, float y, bool hover);
|
||||||
void make_button(std::string name, std::wstring label, Events::GUI event);
|
void make_button(std::string name, std::wstring label, Events::GUI event, int action);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -307,4 +307,11 @@ namespace guecs {
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Clickable make_action(DinkyECS::World& target, Events::GUI event, std::any data) {
|
||||||
|
return {[&, event, data](auto ent, auto){
|
||||||
|
// remember that ent is passed in from the UI::mouse handler
|
||||||
|
target.send<Events::GUI>(event, ent, data);
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -232,5 +232,6 @@ namespace guecs {
|
||||||
};
|
};
|
||||||
|
|
||||||
Clickable make_action(DinkyECS::World& target, Events::GUI event);
|
Clickable make_action(DinkyECS::World& target, Events::GUI event);
|
||||||
|
Clickable make_action(DinkyECS::World& target, Events::GUI event, std::any data);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ namespace gui {
|
||||||
using enum Event;
|
using enum Event;
|
||||||
switch(ev) {
|
switch(ev) {
|
||||||
case TICK: {
|
case TICK: {
|
||||||
System::combat($level);
|
System::combat($level, $temp_attack_id);
|
||||||
run_systems();
|
run_systems();
|
||||||
state(State::IN_COMBAT);
|
state(State::IN_COMBAT);
|
||||||
} break;
|
} break;
|
||||||
|
@ -400,6 +400,8 @@ namespace gui {
|
||||||
dbc::log("YOU NEED TO IMPLEMENT THIS!!!!!");
|
dbc::log("YOU NEED TO IMPLEMENT THIS!!!!!");
|
||||||
break;
|
break;
|
||||||
case eGUI::ATTACK:
|
case eGUI::ATTACK:
|
||||||
|
$temp_attack_id = std::any_cast<int>(data);
|
||||||
|
fmt::println("ATTACK with action={}", $temp_attack_id);
|
||||||
event(Event::ATTACK);
|
event(Event::ATTACK);
|
||||||
break;
|
break;
|
||||||
case eGUI::STAIRS_DOWN:
|
case eGUI::STAIRS_DOWN:
|
||||||
|
|
|
@ -48,6 +48,7 @@ namespace gui {
|
||||||
bool $draw_stats = false;
|
bool $draw_stats = false;
|
||||||
bool autowalking = false;
|
bool autowalking = false;
|
||||||
bool $map_open = false;
|
bool $map_open = false;
|
||||||
|
int $temp_attack_id = 0;
|
||||||
LevelManager $levels;
|
LevelManager $levels;
|
||||||
DebugUI $debug_ui;
|
DebugUI $debug_ui;
|
||||||
MainUI $main_ui;
|
MainUI $main_ui;
|
||||||
|
|
|
@ -11,12 +11,14 @@
|
||||||
#include "dbc.hpp"
|
#include "dbc.hpp"
|
||||||
#include "shiterator.hpp"
|
#include "shiterator.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace matrix {
|
namespace matrix {
|
||||||
using Row = shiterator::BaseRow<int>;
|
using Row = shiterator::BaseRow<int>;
|
||||||
using Matrix = shiterator::Base<int>;
|
using Matrix = shiterator::Base<int>;
|
||||||
|
|
||||||
using viewport = shiterator::viewport_t<Matrix>;
|
using viewport = shiterator::viewport_t<Matrix>;
|
||||||
|
|
||||||
|
|
||||||
using each_cell = shiterator::each_cell_t<Matrix>;
|
using each_cell = shiterator::each_cell_t<Matrix>;
|
||||||
|
|
||||||
using each_row = shiterator::each_row_t<Matrix>;
|
using each_row = shiterator::each_row_t<Matrix>;
|
||||||
|
|
|
@ -204,7 +204,7 @@ inline void animate_entity(DinkyECS::World &world, DinkyECS::Entity entity) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void System::combat(GameLevel &level) {
|
void System::combat(GameLevel &level, int attack_id) {
|
||||||
auto &collider = *level.collision;
|
auto &collider = *level.collision;
|
||||||
auto &world = *level.world;
|
auto &world = *level.world;
|
||||||
auto player = world.get_the<Player>();
|
auto player = world.get_the<Player>();
|
||||||
|
@ -238,7 +238,7 @@ void System::combat(GameLevel &level) {
|
||||||
};
|
};
|
||||||
|
|
||||||
if(result.player_did > 0) {
|
if(result.player_did > 0) {
|
||||||
auto effect = shaders::get("lightning");
|
auto effect = shaders::get(attack_id == 1 ? "flame" : "lightning");
|
||||||
world.set<SpriteEffect>(enemy.entity, {100, effect});
|
world.set<SpriteEffect>(enemy.entity, {100, effect});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ namespace System {
|
||||||
std::wstring draw_map(GameLevel level, size_t view_x, size_t view_y, int compass_dir);
|
std::wstring draw_map(GameLevel level, size_t view_x, size_t view_y, int compass_dir);
|
||||||
|
|
||||||
void enemy_ai(GameLevel &level);
|
void enemy_ai(GameLevel &level);
|
||||||
void combat(GameLevel &level);
|
void combat(GameLevel &level, int attack_id);
|
||||||
|
|
||||||
std::shared_ptr<sf::Shader> sprite_effect(GameLevel &level, DinkyECS::Entity entity);
|
std::shared_ptr<sf::Shader> sprite_effect(GameLevel &level, DinkyECS::Entity entity);
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
dbc::check(sf::Shader::isAvailable(), "You apparently are a time traveler from the 80s who doesn't have shaders.");
|
dbc::check(sf::Shader::isAvailable(), "You apparently are a time traveler from the 80s who doesn't have shaders.");
|
||||||
|
|
||||||
while((opt = getopt(argc, argv, "-hs:f:-x:-y:")) != -1) {
|
while((opt = getopt(argc, argv, "hs:f:x:y:")) != -1) {
|
||||||
switch(opt) {
|
switch(opt) {
|
||||||
case 's':
|
case 's':
|
||||||
sprite_name = optarg;
|
sprite_name = optarg;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue