|
|
@ -26,6 +26,7 @@ using std::string; |
|
|
|
using namespace fmt; |
|
|
|
using namespace fmt; |
|
|
|
using namespace std::chrono_literals; |
|
|
|
using namespace std::chrono_literals; |
|
|
|
using namespace ftxui; |
|
|
|
using namespace ftxui; |
|
|
|
|
|
|
|
using namespace Components; |
|
|
|
|
|
|
|
|
|
|
|
std::array<sf::Color, 10> VALUES{ |
|
|
|
std::array<sf::Color, 10> VALUES{ |
|
|
|
sf::Color{1, 4, 2}, // black
|
|
|
|
sf::Color{1, 4, 2}, // black
|
|
|
@ -116,8 +117,9 @@ void GUI::create_renderer() { |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void GUI::handle_events() { |
|
|
|
bool GUI::handle_events() { |
|
|
|
sf::Event event; |
|
|
|
sf::Event event; |
|
|
|
|
|
|
|
bool event_happened = false; |
|
|
|
auto player = $world.get<Player>(); |
|
|
|
auto player = $world.get<Player>(); |
|
|
|
auto& player_motion = $world.component<Motion>(player.entity); |
|
|
|
auto& player_motion = $world.component<Motion>(player.entity); |
|
|
|
|
|
|
|
|
|
|
@ -127,22 +129,29 @@ void GUI::handle_events() { |
|
|
|
} else if(event.type == sf::Event::KeyPressed) { |
|
|
|
} else if(event.type == sf::Event::KeyPressed) { |
|
|
|
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) { |
|
|
|
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) { |
|
|
|
player_motion.dx = -1; |
|
|
|
player_motion.dx = -1; |
|
|
|
|
|
|
|
event_happened = true; |
|
|
|
} else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) { |
|
|
|
} else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) { |
|
|
|
player_motion.dx = 1; |
|
|
|
player_motion.dx = 1; |
|
|
|
|
|
|
|
event_happened = true; |
|
|
|
} else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) { |
|
|
|
} else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) { |
|
|
|
player_motion.dy = -1; |
|
|
|
player_motion.dy = -1; |
|
|
|
|
|
|
|
event_happened = true; |
|
|
|
} else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) { |
|
|
|
} else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) { |
|
|
|
player_motion.dy = 1; |
|
|
|
player_motion.dy = 1; |
|
|
|
|
|
|
|
event_happened = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// COMPOSE system? You create a bunch of callbacks and then combine them into
|
|
|
|
return event_happened; |
|
|
|
// a single run over the data?
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GUI::run_systems() { |
|
|
|
|
|
|
|
auto player = $world.get<Player>(); |
|
|
|
System::enemy_pathing($world, $game_map, player); |
|
|
|
System::enemy_pathing($world, $game_map, player); |
|
|
|
System::motion($world, $game_map); |
|
|
|
System::motion($world, $game_map); |
|
|
|
System::combat($world, player); |
|
|
|
System::combat($world, player); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GUI::burn() { |
|
|
|
void GUI::burn() { |
|
|
|
for(int i = 0; i < 20; ++i) { |
|
|
|
for(int i = 0; i < 20; ++i) { |
|
|
@ -225,7 +234,10 @@ int GUI::main() { |
|
|
|
|
|
|
|
|
|
|
|
while($window.isOpen()) { |
|
|
|
while($window.isOpen()) { |
|
|
|
render_scene(); |
|
|
|
render_scene(); |
|
|
|
handle_events(); |
|
|
|
|
|
|
|
|
|
|
|
if(handle_events()) { |
|
|
|
|
|
|
|
run_systems(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::this_thread::sleep_for(10ms); |
|
|
|
std::this_thread::sleep_for(10ms); |
|
|
|
} |
|
|
|
} |
|
|
|