|
|
@ -20,7 +20,6 @@ |
|
|
|
#include "dbc.hpp" |
|
|
|
#include "dbc.hpp" |
|
|
|
#include "gui.hpp" |
|
|
|
#include "gui.hpp" |
|
|
|
#include "rand.hpp" |
|
|
|
#include "rand.hpp" |
|
|
|
#include "components.hpp" |
|
|
|
|
|
|
|
#include "systems.hpp" |
|
|
|
#include "systems.hpp" |
|
|
|
#include "collider.hpp" |
|
|
|
#include "collider.hpp" |
|
|
|
#include "events.hpp" |
|
|
|
#include "events.hpp" |
|
|
@ -59,11 +58,16 @@ GUI::GUI() : |
|
|
|
$map_screen(0,0), |
|
|
|
$map_screen(0,0), |
|
|
|
$view_port{0,0}, |
|
|
|
$view_port{0,0}, |
|
|
|
$map_font_size(BASE_MAP_FONT_SIZE), |
|
|
|
$map_font_size(BASE_MAP_FONT_SIZE), |
|
|
|
$line_spacing(0) |
|
|
|
$line_spacing(0), |
|
|
|
|
|
|
|
$sounds("./assets"), |
|
|
|
|
|
|
|
$log({{"Welcome to the game!"}}) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
// this needs a config file soon
|
|
|
|
$font.loadFromFile("./assets/text.otf"); |
|
|
|
$font.loadFromFile("./assets/text.otf"); |
|
|
|
resize_map(BASE_MAP_FONT_SIZE); |
|
|
|
resize_map(BASE_MAP_FONT_SIZE); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$sounds.load("hit", "hit.wav"); |
|
|
|
|
|
|
|
|
|
|
|
$ui_text.setFont($font); |
|
|
|
$ui_text.setFont($font); |
|
|
|
$ui_text.setPosition(0,0); |
|
|
|
$ui_text.setPosition(0,0); |
|
|
|
$ui_text.setCharacterSize(UI_FONT_SIZE); |
|
|
|
$ui_text.setCharacterSize(UI_FONT_SIZE); |
|
|
@ -82,12 +86,10 @@ void GUI::create_renderer() { |
|
|
|
|
|
|
|
|
|
|
|
$document = Renderer([&, player]{ |
|
|
|
$document = Renderer([&, player]{ |
|
|
|
const auto& player_combat = $world.get<Combat>(player.entity); |
|
|
|
const auto& player_combat = $world.get<Combat>(player.entity); |
|
|
|
const auto& log = $world.get_the<ActionLog>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$status_text = player_combat.hp > 0 ? "NOT DEAD" : "DEAD!!!!!!"; |
|
|
|
$status_text = player_combat.hp > 0 ? "NOT DEAD" : "DEAD!!!!!!"; |
|
|
|
|
|
|
|
|
|
|
|
std::vector<Element> log_list; |
|
|
|
std::vector<Element> log_list; |
|
|
|
for(auto msg : log.messages) { |
|
|
|
for(auto msg : $log.messages) { |
|
|
|
log_list.push_back(text(msg)); |
|
|
|
log_list.push_back(text(msg)); |
|
|
|
} |
|
|
|
} |
|
|
|
auto log_box = vbox(log_list) | yflex_grow | border; |
|
|
|
auto log_box = vbox(log_list) | yflex_grow | border; |
|
|
@ -107,12 +109,8 @@ void GUI::create_renderer() { |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool GUI::handle_events() { |
|
|
|
void GUI::handle_world_events() { |
|
|
|
sf::Event event; |
|
|
|
|
|
|
|
bool event_happened = false; |
|
|
|
|
|
|
|
auto& log = $world.get_the<ActionLog>(); |
|
|
|
|
|
|
|
auto player = $world.get_the<Player>(); |
|
|
|
auto player = $world.get_the<Player>(); |
|
|
|
auto sounds = $world.get_the<SoundManager>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while($world.has_event<GUIEvent>()) { |
|
|
|
while($world.has_event<GUIEvent>()) { |
|
|
|
auto [evt, entity] = $world.recv<GUIEvent>(); |
|
|
|
auto [evt, entity] = $world.recv<GUIEvent>(); |
|
|
@ -121,29 +119,35 @@ bool GUI::handle_events() { |
|
|
|
auto combat = $world.get<Combat>(entity); |
|
|
|
auto combat = $world.get<Combat>(entity); |
|
|
|
|
|
|
|
|
|
|
|
if(entity == player.entity) { |
|
|
|
if(entity == player.entity) { |
|
|
|
log.log(format("Enemy HIT YOU, you have {} HP!", combat.hp)); |
|
|
|
$log.log(format("Enemy HIT YOU, you have {} HP!", combat.hp)); |
|
|
|
sounds.play("hit"); |
|
|
|
$sounds.play("hit"); |
|
|
|
shake(); |
|
|
|
shake(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
log.log(format("You HIT enemy, they have {} HP!", combat.hp)); |
|
|
|
$log.log(format("You HIT enemy, they have {} HP!", combat.hp)); |
|
|
|
sounds.play("hit"); |
|
|
|
$sounds.play("hit"); |
|
|
|
shake(); |
|
|
|
shake(); |
|
|
|
} |
|
|
|
} |
|
|
|
} break; |
|
|
|
} break; |
|
|
|
case GUIEvent::MISS: |
|
|
|
case GUIEvent::MISS: |
|
|
|
if(entity == player.entity) { |
|
|
|
if(entity == player.entity) { |
|
|
|
log.log("You MISSED the enemy."); |
|
|
|
$log.log("You MISSED the enemy."); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
log.log("Enemy MISSED YOU."); |
|
|
|
$log.log("Enemy MISSED YOU."); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case GUIEvent::DEAD: |
|
|
|
case GUIEvent::DEAD: |
|
|
|
log.log("--- ENEMY DEAD!"); |
|
|
|
$log.log("--- ENEMY DEAD!"); |
|
|
|
break; |
|
|
|
break; |
|
|
|
default: |
|
|
|
default: |
|
|
|
log.log(format("INVALID EVENT! {},{}", evt, entity)); |
|
|
|
$log.log(format("INVALID EVENT! {},{}", evt, entity)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool GUI::handle_ui_events() { |
|
|
|
|
|
|
|
sf::Event event; |
|
|
|
|
|
|
|
bool event_happened = false; |
|
|
|
|
|
|
|
auto player = $world.get_the<Player>(); |
|
|
|
|
|
|
|
|
|
|
|
while($window.pollEvent(event)) { |
|
|
|
while($window.pollEvent(event)) { |
|
|
|
if(event.type == sf::Event::Closed) { |
|
|
|
if(event.type == sf::Event::Closed) { |
|
|
@ -293,8 +297,8 @@ void GUI::draw_screen(bool clear, float map_off_x, float map_off_y) { |
|
|
|
|
|
|
|
|
|
|
|
void GUI::shake() { |
|
|
|
void GUI::shake() { |
|
|
|
for(int i = 0; i < 10; ++i) { |
|
|
|
for(int i = 0; i < 10; ++i) { |
|
|
|
int x = Random::uniform<int>(-20,20); |
|
|
|
int x = Random::uniform<int>(-10,10); |
|
|
|
int y = Random::uniform<int>(-20,20); |
|
|
|
int y = Random::uniform<int>(-10,10); |
|
|
|
// add x/y back to draw screen
|
|
|
|
// add x/y back to draw screen
|
|
|
|
draw_screen(true, x, y); |
|
|
|
draw_screen(true, x, y); |
|
|
|
std::this_thread::sleep_for(1ms); |
|
|
|
std::this_thread::sleep_for(1ms); |
|
|
@ -302,9 +306,7 @@ void GUI::shake() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void GUI::configure_world() { |
|
|
|
void GUI::configure_world() { |
|
|
|
SoundManager sounds("./assets"); |
|
|
|
// this sets up the gui event system
|
|
|
|
sounds.load("hit", "hit.wav"); |
|
|
|
|
|
|
|
$world.set_the<SoundManager>(sounds); |
|
|
|
|
|
|
|
$world.set_the<GUIEvent>(GUIEvent::START); |
|
|
|
$world.set_the<GUIEvent>(GUIEvent::START); |
|
|
|
|
|
|
|
|
|
|
|
dbc::check($game_map.room_count() > 1, "not enough rooms in map."); |
|
|
|
dbc::check($game_map.room_count() > 1, "not enough rooms in map."); |
|
|
@ -312,9 +314,6 @@ void GUI::configure_world() { |
|
|
|
Player player{$world.entity()}; |
|
|
|
Player player{$world.entity()}; |
|
|
|
$world.set_the<Player>(player); |
|
|
|
$world.set_the<Player>(player); |
|
|
|
|
|
|
|
|
|
|
|
ActionLog log{{"Welcome to the game!"}}; |
|
|
|
|
|
|
|
$world.set_the<ActionLog>(log); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spatial_map collider; |
|
|
|
spatial_map collider; |
|
|
|
$world.set_the<spatial_map>(collider); |
|
|
|
$world.set_the<spatial_map>(collider); |
|
|
|
|
|
|
|
|
|
|
@ -360,9 +359,11 @@ int GUI::main() { |
|
|
|
while($window.isOpen()) { |
|
|
|
while($window.isOpen()) { |
|
|
|
render_scene(); |
|
|
|
render_scene(); |
|
|
|
|
|
|
|
|
|
|
|
if(handle_events()) { |
|
|
|
if(handle_ui_events()) { |
|
|
|
run_systems(); |
|
|
|
run_systems(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
handle_world_events(); |
|
|
|
std::this_thread::sleep_for(10ms); |
|
|
|
std::this_thread::sleep_for(10ms); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|