aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2016-10-11 19:02:04 -0500
committerClyne Sullivan <tullivan99@gmail.com>2016-10-11 19:02:04 -0500
commit8a71861846c41c5f432570262b398c7627743c91 (patch)
tree8246864aa8a713d8905e93d656a55779d600aeb7 /src
parentb19265bfa91e55c564b75aadcabd212ac89cf349 (diff)
more entityx, main.cpp cleanup
Diffstat (limited to 'src')
-rw-r--r--src/entities.cpp28
-rw-r--r--src/render.cpp1
-rw-r--r--src/ui.cpp21
-rw-r--r--src/ui_menu.cpp3
-rw-r--r--src/world.cpp23
5 files changed, 37 insertions, 39 deletions
diff --git a/src/entities.cpp b/src/entities.cpp
index fbab59f..544b1c8 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -10,6 +10,7 @@
#include <brice.hpp>
#include <render.hpp>
+#include <engine.hpp>
extern std::istream *names;
@@ -47,7 +48,6 @@ void PlayerSystem::configure(entityx::EventManager &ev)
ev.subscribe<KeyUpEvent>(*this);
}
-extern std::array<SDL_Keycode, 6> controlMap;
extern World *currentWorldToLeft;
extern World *currentWorldToRight;
extern bool gameRunning;
@@ -61,13 +61,13 @@ void PlayerSystem::receive(const KeyUpEvent &kue)
if (kc == SDLK_ESCAPE) {
ui::menu::toggle();
p->save();
- } else if (kc == controlMap[1]) {
+ } else if (kc == getControl(1)) {
m_MoveLeft = false;
- } else if (kc == controlMap[2]) {
+ } else if (kc == getControl(2)) {
m_MoveRight = false;
- } else if (kc == controlMap[3] || kc == controlMap[4]) {
+ } else if (kc == getControl(3) || kc == getControl(4)) {
player->speed = 1;
- } else if (kc == controlMap[5]) {
+ } else if (kc == getControl(5)) {
if (p->inv->invHover) {
p->inv->invHover = false;
} else {
@@ -94,10 +94,10 @@ void PlayerSystem::receive(const KeyDownEvent &kde)
ui::toggleBlackFast();
ui::waitForCover();
wsi.first->bgmPlay(currentWorld);
- std::tie(currentWorld, p->loc) = wsi;
+ std::tie(currentWorld, player->loc) = wsi; // using p causes segfault
ui::toggleBlackFast();
ui::waitForUncover();
- p->canMove = true;
+ player->canMove = true; // using p causes segfault
};
if ((kc == SDLK_SPACE) && (game::canJump & p->ground)) {
@@ -107,7 +107,7 @@ void PlayerSystem::receive(const KeyDownEvent &kde)
}
if (!ui::dialogBoxExists || ui::dialogPassive) {
- if (kc == controlMap[0]) {
+ if (kc == getControl(0)) {
if (inBattle) {
std::thread([&](void){
auto thing = dynamic_cast<Arena *>(currentWorld)->exitArena(p);
@@ -121,7 +121,7 @@ void PlayerSystem::receive(const KeyDownEvent &kde)
worldSwitch(thing);
}).detach();
}
- } else if (kc == controlMap[1]) {
+ } else if (kc == getControl(1)) {
if (!ui::fadeEnable) {
p->vel.x = -PLAYER_SPEED_CONSTANT;
if (std::stoi(game::getValue("Slow")) == 1)
@@ -136,7 +136,7 @@ void PlayerSystem::receive(const KeyDownEvent &kde)
}).detach();
}
}
- } else if (kc == controlMap[2]) {
+ } else if (kc == getControl(2)) {
if (!ui::fadeEnable) {
p->vel.x = PLAYER_SPEED_CONSTANT;
if (std::stoi(game::getValue("Slow")) == 1)
@@ -151,12 +151,12 @@ void PlayerSystem::receive(const KeyDownEvent &kde)
}).detach();
}
}
- } else if (kc == controlMap[3]) {
+ } else if (kc == getControl(3)) {
if (game::canSprint)
p->speed = 2.0f;
- } else if (kc == controlMap[4]) {
+ } else if (kc == getControl(4)) {
p->speed = .5;
- } else if (kc == controlMap[5]) {
+ } else if (kc == getControl(5)) {
static int heyOhLetsGo = 0;
//edown = true;
@@ -176,7 +176,7 @@ void PlayerSystem::receive(const KeyDownEvent &kde)
}
}
} else if (kc == SDLK_DELETE) {
- gameRunning = false;
+ game::endGame();
} else if (kc == SDLK_t) {
game::time::tick(50);
}
diff --git a/src/render.cpp b/src/render.cpp
index 0c522f6..908b620 100644
--- a/src/render.cpp
+++ b/src/render.cpp
@@ -62,5 +62,4 @@ void drawRect(vec2 ll, vec2 ur, float z)
currentShader->disable();
}
-
}
diff --git a/src/ui.cpp b/src/ui.cpp
index a7e3777..f7cc099 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -6,6 +6,7 @@
#include <gametime.hpp>
#include <render.hpp>
+#include <engine.hpp>
#include <events.hpp>
extern Menu* currentMenu;
@@ -22,12 +23,6 @@ extern World *currentWorldToLeft;
extern World *currentWorldToRight;
/**
- * In the case of dialog, some NPC quests can be preloaded so that they aren't assigned until
- * the dialog box closes. Reference variables for that here.
- */
-extern std::vector<NPC *> aipreload;
-
-/**
* Pressing ESC or closing the window will set this to false.
*/
extern bool gameRunning;
@@ -1214,9 +1209,9 @@ namespace ui {
void quitGame() {
dialogBoxExists = false;
currentMenu = NULL;
- gameRunning = false;
game::config::update();
game::config::save();
+ game::endGame();
}
void closeBox() {
@@ -1281,16 +1276,6 @@ EXIT:
}
}
- void handleEvents(void) {
- // Flush preloaded AI functions if necessary
- if (!dialogBoxExists) {
- while (!aipreload.empty()) {
- aipreload.front()->addAIFunc(false);
- aipreload.erase(std::begin(aipreload));
- }
- }
- }
-
void drawFade(void) {
auto SCREEN_WIDTH = game::SCREEN_WIDTH;
auto SCREEN_HEIGHT = game::SCREEN_HEIGHT;
@@ -1474,7 +1459,7 @@ void InputSystem::update(entityx::EntityManager &en, entityx::EventManager &ev,
// escape - quit game
case SDL_QUIT:
- gameRunning = false;
+ game::endGame();
break;
// mouse movement - update mouse vector
diff --git a/src/ui_menu.cpp b/src/ui_menu.cpp
index f0299c6..4b4b05c 100644
--- a/src/ui_menu.cpp
+++ b/src/ui_menu.cpp
@@ -1,5 +1,6 @@
#include <ui_menu.hpp>
+#include <engine.hpp>
#include <render.hpp>
#include <fstream>
@@ -211,7 +212,7 @@ namespace ui {
while(SDL_PollEvent(&e)) {
switch (e.type) {
case SDL_QUIT:
- gameRunning = false;
+ game::endGame();
return;
break;
case SDL_MOUSEMOTION:
diff --git a/src/world.cpp b/src/world.cpp
index 3871867..320c1db 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -236,11 +236,8 @@ generate(int width)
weather = WorldWeather::None;
}
-/**
- * The world draw function.
- * This function will draw the background layers, entities, and player to the
- * screen.
- */
+static Color ambient;
+
void World::drawBackgrounds(void)
{
auto SCREEN_WIDTH = game::SCREEN_WIDTH;
@@ -515,6 +512,22 @@ void World::draw(Player *p)
uint lpIndex = 0;
uint lcIndex = 0;
+ static bool ambientUpdaterStarted = false;
+ if (!ambientUpdaterStarted) {
+ ambientUpdaterStarted = true;
+ std::thread([&](void) {
+ while (true) {
+ float v = 75 * sin((game::time::getTickCount() + (DAY_CYCLE / 2)) / (DAY_CYCLE / PI));
+ float rg = std::clamp(.5f + (-v / 100.0f), 0.01f, .9f);
+ float b = std::clamp(.5f + (-v / 80.0f), 0.03f, .9f);
+
+ ambient = Color(rg, rg, b, 1.0f);
+
+ std::this_thread::sleep_for(std::chrono::milliseconds(1));
+ }
+ }).detach();
+ }
+
for (uint i = 0; i < ls; i++) {
auto &l = light[i];
if (l.belongsTo) {