aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/events.hpp8
-rw-r--r--include/player.hpp3
-rw-r--r--include/ui.hpp4
-rw-r--r--include/ui_action.hpp.bak21
-rw-r--r--include/world.hpp4
-rw-r--r--main.cpp15
-rw-r--r--src/player.cpp26
-rw-r--r--src/texture.cpp7
-rw-r--r--src/ui.cpp4
-rw-r--r--src/ui_action.cpp.bak143
-rw-r--r--src/world.cpp26
-rw-r--r--xml/!town.xml4
-rw-r--r--xml/bobshouse.xml2
13 files changed, 54 insertions, 213 deletions
diff --git a/include/events.hpp b/include/events.hpp
index 975855c..f38d4e6 100644
--- a/include/events.hpp
+++ b/include/events.hpp
@@ -1,4 +1,4 @@
-#ifndef EVENTS_HPP_
+z#ifndef EVENTS_HPP_
#define EVENTS_HPP_
/**
@@ -75,7 +75,7 @@ struct BGMToggleEvent {
struct WindowResizeEvent {
WindowResizeEvent(int w = 640, int h = 480)
: x(w), y(h) {}
-
+
int x;
int y;
};
@@ -83,9 +83,9 @@ struct WindowResizeEvent {
struct ScreenshotEvent {
ScreenshotEvent(int w = game::SCREEN_HEIGHT, int h = game::SCREEN_WIDTH)
: w(w), h(h) {}
-
+
int w;
- int h;
+ int h;
};
#endif // EVENTS_HPP_
diff --git a/include/player.hpp b/include/player.hpp
index 187e77e..59d6368 100644
--- a/include/player.hpp
+++ b/include/player.hpp
@@ -4,6 +4,7 @@
#include <entityx/entityx.h>
#include <events.hpp>
+#include <engine.hpp>
#include <components.hpp>
#include <common.hpp>
@@ -34,6 +35,8 @@ public:
vec2 getPosition(void) const;
inline void setX(const float& x)
{ player.component<Position>().get()->x = x; }
+ inline float getWidth(void) const
+ { return game::entities.component<Solid>(player.id())->width; }
};
#endif // PLAYER_HPP_
diff --git a/include/ui.hpp b/include/ui.hpp
index 5863cf0..85c5997 100644
--- a/include/ui.hpp
+++ b/include/ui.hpp
@@ -23,7 +23,7 @@
#include <config.hpp>
//#include <inventory.hpp>
#include <ui_menu.hpp>
-//#include <ui_action.hpp>
+#include <events.hpp>
// local library headers
#include <SDL2/SDL_opengl.h>
@@ -160,7 +160,7 @@ namespace ui {
/*
* Takes a screenshot of the game
*/
-
+
void takeScreenshot(GLubyte *pixels);
}
diff --git a/include/ui_action.hpp.bak b/include/ui_action.hpp.bak
deleted file mode 100644
index a275ab3..0000000
--- a/include/ui_action.hpp.bak
+++ /dev/null
@@ -1,21 +0,0 @@
-#ifndef ACTION_H_
-#define ACTION_H_
-
-#include <common.hpp>
-#include <ui.hpp>
-
-namespace ui {
- namespace action {
- extern bool make;
-
- // enables the action ui
- void enable(void);
- // disables the action ui
- void disable(void);
-
- // draws the action ui
- void draw(vec2 loc);
- }
-}
-
-#endif // ACTION_H_
diff --git a/include/world.hpp b/include/world.hpp
index cb8c30d..b8a80a4 100644
--- a/include/world.hpp
+++ b/include/world.hpp
@@ -168,6 +168,8 @@ private:
std::string currentXMLFile;
public:
+ std::thread thAmbient;
+
explicit WorldSystem(void);
~WorldSystem(void);
@@ -206,7 +208,7 @@ public:
// worlddata2 stuff
WorldData2 worldData;
- void generate(unsigned int width = 0);
+ void generate(int width = 0);
void addHole(const unsigned int& start, const unsigned int& end);
void addHill(const ivec2& peak, const unsigned int& width);
diff --git a/main.cpp b/main.cpp
index 982d70b..298fc6b 100644
--- a/main.cpp
+++ b/main.cpp
@@ -199,7 +199,7 @@ int main(int argc, char *argv[])
if (!worldDontReallyRun) {
// the main loop, in all of its gloriousness..
- std::thread([&] {
+ std::thread thMain ([&] {
const bool &run = game::engine.shouldRun;
while (run) {
game::time::mainLoopHandler();
@@ -211,10 +211,10 @@ int main(int argc, char *argv[])
std::this_thread::sleep_for(1ms);
}
- }).detach();
+ });
// the debug loop, gets debug screen values
- std::thread([&] {
+ std::thread thDebug ([&] {
const bool &run = game::engine.shouldRun;
while (run) {
fps = 1000 / game::time::getDeltaTime();
@@ -222,13 +222,17 @@ int main(int argc, char *argv[])
std::this_thread::sleep_for(1s);
}
- }).detach();
+ });
const bool &run = game::engine.shouldRun;
while (run) {
game::engine.render(0);
render();
}
+
+ thMain.join();
+ thDebug.join();
+ //game::engine.getSystem<WorldSystem>()->thAmbient.join();
}
// put away the brice for later
@@ -254,7 +258,8 @@ void render() {
const auto SCREEN_WIDTH = game::SCREEN_WIDTH;
const auto SCREEN_HEIGHT = game::SCREEN_HEIGHT;
- offset.x = game::engine.getSystem<PlayerSystem>()->getPosition().x;// + player->width / 2;
+ auto ps = game::engine.getSystem<PlayerSystem>();
+ offset.x = ps->getPosition().x + ps->getWidth() / 2;
const auto& worldWidth = game::engine.getSystem<WorldSystem>()->getWidth();
if (worldWidth < (int)SCREEN_WIDTH)
diff --git a/src/player.cpp b/src/player.cpp
index 2694a54..a88734a 100644
--- a/src/player.cpp
+++ b/src/player.cpp
@@ -1,7 +1,6 @@
#include <player.hpp>
#include <brice.hpp>
-#include <engine.hpp>
#include <ui.hpp>
#include <gametime.hpp>
#include <world.hpp>
@@ -71,10 +70,7 @@ void PlayerSystem::receive(const KeyUpEvent &kue)
p->inv->selected = false;
p->inv->mouseSel = false;
- }
-
- // disable action ui
- ui::action::disable();*/
+ }*/
}
}
@@ -114,23 +110,17 @@ void PlayerSystem::receive(const KeyDownEvent &kde)
} else if (kc == getControl(4)) {
speed = .5;
} else if (kc == getControl(5)) {
- /*static int heyOhLetsGo = 0;
-
+ //static int heyOhLetsGo = 0;
//edown = true;
-
// start hover counter?
- if (!heyOhLetsGo) {
- heyOhLetsGo = game::time::getTickCount();
- p->inv->mouseSel = false;
- }
+ //if (!heyOhLetsGo) {
+ // heyOhLetsGo = game::time::getTickCount();
+ // p->inv->mouseSel = false;
+ //}
// run hover thing
- if (game::time::getTickCount() - heyOhLetsGo >= 2 && !(p->inv->invOpen) && !(p->inv->selected)) {
- p->inv->invHover = true;
-
- // enable action ui
- ui::action::enable();
- }*/
+ //if (game::time::getTickCount() - heyOhLetsGo >= 2 && !(p->inv->invOpen) && !(p->inv->selected))
+ // p->inv->invHover = true;
}
} else if (kc == SDLK_DELETE) {
game::endGame();
diff --git a/src/texture.cpp b/src/texture.cpp
index 3a2f071..a232e0e 100644
--- a/src/texture.cpp
+++ b/src/texture.cpp
@@ -46,7 +46,6 @@ namespace Texture{
GLuint loadTexture(std::string fileName) {
SDL_Surface *image;
- static GLuint object = 0;
// check if texture is already loaded
for(auto &t : LoadedTexture) {
@@ -67,11 +66,13 @@ namespace Texture{
#ifdef DEBUG
DEBUG_printf("Loaded image file: %s\n", fileName.c_str());
#endif // DEBUG
+
/*
* Load texture through OpenGL.
*/
- //glGenTextures(1,&object); // Turns "object" into a texture
- glBindTexture(GL_TEXTURE_2D,++object); // Binds "object" to the top of the stack
+ GLuint object;
+ glGenTextures(1, &object); // Turns "object" into a texture
+ glBindTexture(GL_TEXTURE_2D, object); // Binds "object" to the top of the stack
glPixelStoref(GL_UNPACK_ALIGNMENT,1);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // Sets the "min" filter
diff --git a/src/ui.cpp b/src/ui.cpp
index 94100e4..9439e30 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -9,6 +9,7 @@
#include <engine.hpp>
#include <events.hpp>
#include <window.hpp>
+#include <player.hpp>
#include <chrono>
using namespace std::literals::chrono_literals;
@@ -851,9 +852,6 @@ namespace ui {
auto SCREEN_HEIGHT = static_cast<float>(game::SCREEN_HEIGHT);
// will return if not toggled
- //action::draw(vec2 {player->loc.x + player->width / 2, player->loc.y + player->height + game::HLINE});
-
- // will return if not toggled
quest::draw();
if (pageTexReady) {
diff --git a/src/ui_action.cpp.bak b/src/ui_action.cpp.bak
deleted file mode 100644
index 9029907..0000000
--- a/src/ui_action.cpp.bak
+++ /dev/null
@@ -1,143 +0,0 @@
-#include <ui_action.hpp>
-#include <world.hpp>
-
-#define ACTION_PROLOUGE { actioning = true; }
-#define ACTION_EPILOUGE { actioning = false; actionHover = 0; }
-
-extern World *currentWorld;
-extern Arena *arena;
-extern Player *player;
-extern bool inBattle;
-
-static std::vector<std::pair<std::string, vec3>> actionText = {
- {"Attack", vec3 {0, 0, 0}},
- {"Action", vec3 {0, 0, 0}},
- {"Umm" , vec3 {0, 0, 0}}
-};
-
-void actionAttack(void);
-void actionAction(void);
-
-static std::vector<void (*)(void)> actionFunc = {
- actionAttack,
- actionAction,
- nullptr,
-};
-
-static bool actionToggle = false, actioning = false;
-static unsigned int actionHover = 0;
-static Entity *nearEntity = nullptr, *lastEntity = nullptr;
-
-namespace ui {
- namespace action {
- bool make = false;
-
- // enables action ui
- void enable(void) {
- actionToggle = true;
- }
-
- // disables action ui
- void disable(void) {
- actionToggle = false;
-
- if (lastEntity != nullptr)
- lastEntity->canMove = true;
- }
-
- // draws the action ui
- void draw(vec2 loc) {
- unsigned int i = 1;
- float y = loc.y;
-
- if (!actionToggle)
- return;
-
- nearEntity = currentWorld->getNearInteractable(*player);
-
- if (nearEntity == nullptr) {
- if (lastEntity != nullptr) {
- lastEntity->canMove = true;
- lastEntity = nullptr;
- }
- return;
- } else if (nearEntity != lastEntity) {
- if (lastEntity != nullptr)
- lastEntity->canMove = true;
- lastEntity = nearEntity;
- }
-
- if (make) {
- while(actioning);
-
- if (!actionHover) {
- make = false;
- return;
- }
-
- if (actionFunc[actionHover - 1] != nullptr)
- std::thread(actionFunc[actionHover - 1]).detach();
-
- actionHover = 0;
- } else {
- nearEntity->canMove = false;
- ui::drawBox(vec2 {loc.x - HLINES(11), loc.y}, vec2 {loc.x + HLINES(12), loc.y + actionText.size() * HLINES(8)});
-
- for (auto &s : actionText) {
- s.second.z = ui::putStringCentered((s.second.x = loc.x), (s.second.y = (y += fontSize * 1.15f)), s.first) / 2;
-
- if (ui::mouse.x > s.second.x - s.second.z && ui::mouse.x < s.second.x + s.second.z &&
- ui::mouse.y > s.second.y && ui::mouse.y < s.second.y + ui::fontSize) {
- actionHover = i;
- ui::setFontColor(255, 100, 100, 255);
- ui::putStringCentered(s.second.x, s.second.y, s.first);
- ui::setFontColor(255, 255, 255, 255);
- }
- i++;
- }
-
- ui::putStringCentered(loc.x, y + fontSize * 1.2f, nearEntity->name);
- }
-
- if (i == actionText.size())
- actionHover = 0;
-
- ui::setFontColor(255, 255, 255, 255);
- make = false;
- }
- }
-}
-
-void actionAttack(void)
-{
- ACTION_PROLOUGE;
-
- auto m = currentWorld->getNearInteractable(*player);
-
- if (m->type == MOBT) {
- if (!inBattle && m != nullptr) {
- arena->fight(currentWorld, player, Mobp(m));
-
- ui::toggleWhiteFast();
- ui::waitForCover();
- currentWorld = arena;
- ui::toggleWhiteFast();
- }
- } else {
- ui::dialogBox(player->name, "", false, "%s doesn't appear to be in the mood for fighting...", m->name.c_str());
- }
-
- ACTION_EPILOUGE;
-}
-
-void actionAction(void)
-{
- ACTION_PROLOUGE;
-
- auto e = currentWorld->getNearInteractable(*player);
-
- if (e->type == NPCT)
- e->interact();
-
- ACTION_EPILOUGE;
-}
diff --git a/src/world.cpp b/src/world.cpp
index f4795ac..4ab8af7 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -114,7 +114,7 @@ static const float bgDraw[4][3]={
** Functions section
** --------------------------------------------------------------------------*/
-void WorldSystem::generate(unsigned int width)
+void WorldSystem::generate(int width)
{
float geninc = 0;
@@ -209,7 +209,9 @@ void WorldSystem::load(const std::string& file)
auto file = ixml->Attribute("file");
if (file != nullptr) {
DEBUG_printf("Including file: %s\n", file);
- xmlRaw.append(readFile((xmlFolder + file).c_str()));
+ auto include = readFile((xmlFolder + file).c_str());
+ xmlRaw.append(include);
+ delete[] include;
}
ixml = ixml->NextSiblingElement();
}
@@ -263,7 +265,7 @@ void WorldSystem::load(const std::string& file)
// world generation
else if (tagName == "generation") {
- generate(wxml->UnsignedAttribute("width") / game::HLINE);
+ generate(wxml->IntAttribute("width"));
}
// indoor stuff
@@ -272,7 +274,9 @@ void WorldSystem::load(const std::string& file)
UserError("<house> can only be used inside <IndoorWorld>");
world.indoorWidth = wxml->FloatAttribute("width");
- world.indoorTex = Texture::loadTexture(wxml->Attribute("texture"));
+ auto str = wxml->StrAttribute("texture");
+ auto tex = Texture::loadTexture(str);
+ world.indoorTex = tex;
}
// weather tag
@@ -649,8 +653,9 @@ void WorldSystem::render(void)
static bool ambientUpdaterStarted = false;
if (!ambientUpdaterStarted) {
ambientUpdaterStarted = true;
- std::thread([&](void) {
- while (true) {
+ thAmbient = std::thread([&](void) {
+ const bool &run = game::engine.shouldRun;
+ while (run) {
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);
@@ -659,7 +664,8 @@ void WorldSystem::render(void)
std::this_thread::sleep_for(1ms);
}
- }).detach();
+ });
+ thAmbient.detach();
}
@@ -883,8 +889,8 @@ void WorldSystem::render(void)
// only draw world within player vision
iStart = std::clamp(static_cast<int>(pOffset - (SCREEN_WIDTH / 2 / HLINE) - GROUND_HILLINESS),
0, static_cast<int>(world.data.size()));
- iEnd = std::clamp(static_cast<int>(pOffset + (SCREEN_WIDTH / 2 / HLINE)),
- 0, static_cast<int>(world.data.size())) + 1;
+ iEnd = std::clamp(static_cast<int>(pOffset + (SCREEN_WIDTH / 2 / HLINE) + 2),
+ 0, static_cast<int>(world.data.size()));
// draw the dirt
waitToSwap = true;
@@ -1010,7 +1016,7 @@ void WorldSystem::render(void)
// the starting pixel of the world
float s = -(static_cast<float>(SCREEN_WIDTH)/2.0f);
// the ending pixel of the world
- float e = (static_cast<float>(SCREEN_WIDTH)/2.0f);
+ float e = (static_cast<float>(SCREEN_WIDTH)/2.0f);
if (offset.x + world.startX > s) {
diff --git a/xml/!town.xml b/xml/!town.xml
index 1e193fb..d98e8c6 100644
--- a/xml/!town.xml
+++ b/xml/!town.xml
@@ -3,7 +3,7 @@
<World>
<style background="0" bgm="assets/music/embark.wav" folder="assets/style/classic/"/>
- <generation width="1600"/>
+ <generation width="320"/>
<time>6000</time>
<link right="!town2.xml"/>
<spawnx>-300</spawnx>
@@ -17,7 +17,7 @@
<Dialog name="Bob">
<text id="0" nextid="1" pause="true">
<give id="Dank MayMay" count="10"/>
- <content>
+ <content>
Hey there! The name's Bob. Good to see you've finally woken up from your nap by the cliff there... lol
</content>
</text>
diff --git a/xml/bobshouse.xml b/xml/bobshouse.xml
index 8993a5c..b638ae5 100644
--- a/xml/bobshouse.xml
+++ b/xml/bobshouse.xml
@@ -3,7 +3,7 @@
<IndoorWorld>
<style background="0" bgm="assets/music/theme_jazz.wav" folder="assets/style/classic/"/>
- <!--<house width="800" texture="assets/style/classic/bg/insideWoodHouse.png"/>-->
+ <house width="640" texture="assets/style/classic/bg/insideWoodHouse.png"/>
<generation width="1600"/>
<time>6000</time>
<!--<link outside="town.xml"/>-->