aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/common.hpp6
-rw-r--r--include/components.hpp6
-rw-r--r--include/events.hpp2
-rw-r--r--include/player.hpp3
-rw-r--r--include/world.hpp2
-rw-r--r--src/components.cpp7
-rw-r--r--src/player.cpp29
-rw-r--r--src/ui.cpp24
-rw-r--r--src/world.cpp14
-rw-r--r--xml/entities.xml1
10 files changed, 54 insertions, 40 deletions
diff --git a/include/common.hpp b/include/common.hpp
index d152bb7..d13e397 100644
--- a/include/common.hpp
+++ b/include/common.hpp
@@ -58,6 +58,12 @@ typedef unsigned int uint;
#define BREAKPOINT __asm__("int $3")
+template<typename T>
+inline const T * const& coalesce(const T * const &p1, const T * const &p2)
+{
+ return ((p1 == nullptr) ? p2 : p1);
+}
+
/**
* Creates a coordinate of integers.
*/
diff --git a/include/components.hpp b/include/components.hpp
index c0b7110..1195337 100644
--- a/include/components.hpp
+++ b/include/components.hpp
@@ -81,6 +81,12 @@ struct Portal {
std::string toFile;
};
+struct Name {
+ Name(std::string n = "") : name(n) {}
+
+ std::string name;
+};
+
/**
* @struct Solid
* @brief Allows an entity to collide with other objects.
diff --git a/include/events.hpp b/include/events.hpp
index d98d52a..6a9bd8c 100644
--- a/include/events.hpp
+++ b/include/events.hpp
@@ -16,7 +16,7 @@ struct MouseScrollEvent {
: scrollDistance(sd) {}
int scrollDistance;
- };
+};
struct KeyDownEvent {
KeyDownEvent(SDL_Keycode kc = 0)
diff --git a/include/player.hpp b/include/player.hpp
index e196fa4..187e77e 100644
--- a/include/player.hpp
+++ b/include/player.hpp
@@ -4,6 +4,7 @@
#include <entityx/entityx.h>
#include <events.hpp>
+#include <components.hpp>
#include <common.hpp>
constexpr const float PLAYER_SPEED_CONSTANT = 0.15f;
@@ -31,6 +32,8 @@ public:
void receive(const KeyDownEvent&);
vec2 getPosition(void) const;
+ inline void setX(const float& x)
+ { player.component<Position>().get()->x = x; }
};
#endif // PLAYER_HPP_
diff --git a/include/world.hpp b/include/world.hpp
index fb0a5fa..421031c 100644
--- a/include/world.hpp
+++ b/include/world.hpp
@@ -166,7 +166,7 @@ public:
void detect(entityx::TimeDelta dt);
void goWorldLeft(Position& p);
- void goWorldRight(Position& p);
+ void goWorldRight(Position& p, Solid &d);
void goWorldPortal(Position& p);
// worlddata2 stuff
diff --git a/src/components.cpp b/src/components.cpp
index 45a9315..e00d474 100644
--- a/src/components.cpp
+++ b/src/components.cpp
@@ -4,6 +4,7 @@
#include <events.hpp>
#include <render.hpp>
+#include <ui.hpp>
#include <engine.hpp>
void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt)
@@ -88,6 +89,12 @@ void RenderSystem::update(entityx::EntityManager &en, entityx::EventManager &ev,
Render::worldShader.disable();
Render::worldShader.unuse();
+
+ en.each<Visible, Position, Solid, Name>([](entityx::Entity e, Visible &v, Position &pos, Solid& dim, Name &name) {
+ (void)e;
+ (void)v;
+ ui::putStringCentered(pos.x + dim.width / 2, pos.y - ui::fontSize - HLINES(0.5), name.name);
+ });
}
/*
diff --git a/src/player.cpp b/src/player.cpp
index 37a958d..1bbfaea 100644
--- a/src/player.cpp
+++ b/src/player.cpp
@@ -5,7 +5,6 @@
#include <ui.hpp>
#include <gametime.hpp>
#include <world.hpp>
-#include <components.hpp>
void PlayerSystem::create(void)
{
@@ -85,30 +84,14 @@ void PlayerSystem::receive(const KeyDownEvent &kde)
auto kc = kde.keycode;
auto& loc = *player.component<Position>().get();
+ auto& vel = *player.component<Direction>().get();
auto& faceLeft = player.component<Sprite>().get()->faceLeft;
- /*if ((kc == SDLK_SPACE) && (game::canJump & p->ground)) {
- p->loc.y += HLINES(2);
- p->vel.y = .4;
- p->ground = false;
- }*/
-
- if (!ui::dialogBoxExists || ui::dialogPassive) {
+ if ((kc == SDLK_SPACE) && game::canJump && ((vel.y > -0.01) & (vel.y < 0.01))) {
+ loc.y += HLINES(2);
+ vel.y = .4;
+ } else if (!ui::dialogBoxExists || ui::dialogPassive) {
if (kc == getControl(0)) {
- /*if (inBattle) {
- std::thread([&](void){
- auto thing = dynamic_cast<Arena *>(currentWorld)->exitArena(p);
- if (thing.first != currentWorld)
- worldSwitch(thing);
- }).detach();
- } else if (!ui::fadeIntensity) {
- std::thread([&](void){
- auto thing = currentWorld->goInsideStructure(p);
- if (thing.first != currentWorld)
- worldSwitch(thing);
- }).detach();
- }*/
-
if (!ui::fadeIntensity)
worldSystem.goWorldPortal(loc);
@@ -124,7 +107,7 @@ void PlayerSystem::receive(const KeyDownEvent &kde)
moveLeft = faceLeft = false;
moveRight = true;
- worldSystem.goWorldRight(loc);
+ worldSystem.goWorldRight(loc, *player.component<Solid>().get());
}
} else if (kc == getControl(3)) {
if (game::canSprint)
diff --git a/src/ui.cpp b/src/ui.cpp
index 4731261..3c568d1 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -237,7 +237,8 @@ namespace ui {
*/
void setFontSize(unsigned int size) {
- if (size == 16) {
+ (void)size;
+ /*if (size == 16) {
if (!ft16loaded) {
loadFontSize(fontSize = size, ftex16, ftdat16);
ft16loaded = true;
@@ -253,7 +254,7 @@ namespace ui {
ftex = &ftex24;
ftdat = &ftdat24;
fontSize = 24;
- }
+ }*/
}
/*
@@ -572,11 +573,13 @@ namespace ui {
}
void waitForCover(void) {
+ fadeIntensity = 0;
while (fadeIntensity < 255);
fadeIntensity = 255;
}
void waitForUncover(void) {
+ fadeIntensity = 255;
while (fadeIntensity > 0);
fadeIntensity = 0;
}
@@ -1075,10 +1078,9 @@ EXIT:
return;
}
- if (fadeWhite)
- glBindTexture(GL_TEXTURE_2D, Texture::genColor(Color(255, 255, 255, fadeIntensity)));
- else
- glBindTexture(GL_TEXTURE_2D, Texture::genColor(Color(0, 0, 0, fadeIntensity)));
+ auto fadeTex = Texture::genColor( (fadeWhite ? Color(255, 255, 255, fadeIntensity) :
+ Color(0, 0, 0, fadeIntensity)) );
+
GLfloat tex[] = {0.0, 0.0,
1.0, 0.0,
@@ -1096,6 +1098,7 @@ EXIT:
Render::textShader.use();
Render::textShader.enable();
+ glBindTexture(GL_TEXTURE_2D, fadeTex);
glVertexAttribPointer(Render::textShader.coord, 3, GL_FLOAT, GL_FALSE, 0, backdrop);
glVertexAttribPointer(Render::textShader.tex, 2, GL_FLOAT, GL_FALSE, 0, tex);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
@@ -1105,21 +1108,22 @@ EXIT:
setFontZ(-8.0);
+ glDeleteTextures(1, &fadeTex);
}
void fadeUpdate(void) {
if (fadeEnable) {
if (fadeIntensity < 150)
- fadeIntensity += fadeFast ? 40 : 10;
- else if (fadeIntensity < 255)
fadeIntensity += fadeFast ? 20 : 5;
+ else if (fadeIntensity < 255)
+ fadeIntensity += fadeFast ? 10 : 5;
else
fadeIntensity = 255;
} else {
if (fadeIntensity > 150)
- fadeIntensity -= fadeFast ? 20 : 5;
+ fadeIntensity -= fadeFast ? 10 : 5;
else if (fadeIntensity > 0)
- fadeIntensity -= fadeFast ? 40 : 10;
+ fadeIntensity -= fadeFast ? 20 : 5;
else
fadeIntensity = 0;
}
diff --git a/src/world.cpp b/src/world.cpp
index 8e2d60b..3ff819b 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -260,8 +260,11 @@ void WorldSystem::load(const std::string& file)
world.toLeft = world.toRight = "";
currentXMLFile = file;
+ std::cout << "ka" << std::endl;
game::entities.reset();
+ std::cout << "CHOW!!!" << std::endl;
game::engine.getSystem<PlayerSystem>()->create();
+ std::cout << "chow cow" << std::endl;
// iterate through tags
while (wxml) {
@@ -395,6 +398,8 @@ void WorldSystem::load(const std::string& file)
}
entity.assign<Physics>(g);
+ } else if (tname == "Name") {
+ entity.assign<Name>(coalesce(wxml->Attribute("name"), abcd->Attribute("value")));
}
abcd = abcd->NextSiblingElement();
@@ -1085,14 +1090,14 @@ void WorldSystem::detect(entityx::TimeDelta dt)
});
}
-void WorldSystem::goWorldRight(Position& p)
+void WorldSystem::goWorldRight(Position& p, Solid &d)
{
- if (!(world.toRight.empty()) && (p.x > world.startX * -1 - HLINES(10))) {
+ if (!(world.toRight.empty()) && (p.x + d.width > world.startX * -1 - HLINES(15))) {
ui::toggleBlack();
ui::waitForCover();
auto file = world.toRight;
load(file);
- p.x = world.startX + HLINES(15);
+ game::engine.getSystem<PlayerSystem>()->setX(world.startX + HLINES(15));
ui::toggleBlack();
}
}
@@ -1103,7 +1108,7 @@ void WorldSystem::goWorldLeft(Position& p)
ui::toggleBlack();
ui::waitForCover();
load(world.toLeft);
- p.x = world.startX * -1 - HLINES(15);
+ game::engine.getSystem<PlayerSystem>()->setX(world.startX * -1 - HLINES(15));
ui::toggleBlack();
}
}
@@ -1119,7 +1124,6 @@ void WorldSystem::goWorldPortal(Position& p)
ui::toggleBlack();
ui::waitForCover();
load(portal.toFile);
- p.x = 0;
ui::toggleBlack();
return;
}
diff --git a/xml/entities.xml b/xml/entities.xml
index cf6dbf3..431c067 100644
--- a/xml/entities.xml
+++ b/xml/entities.xml
@@ -7,6 +7,7 @@
<Direction />
<Solid />
<Physics />
+ <Name value="Daddy" />
</npc>
<structure>