#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.
*/
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.
: scrollDistance(sd) {}
int scrollDistance;
- };
+};
struct KeyDownEvent {
KeyDownEvent(SDL_Keycode kc = 0)
#include <entityx/entityx.h>
#include <events.hpp>
+#include <components.hpp>
#include <common.hpp>
constexpr const float PLAYER_SPEED_CONSTANT = 0.15f;
void receive(const KeyDownEvent&);
vec2 getPosition(void) const;
+ inline void setX(const float& x)
+ { player.component<Position>().get()->x = x; }
};
#endif // PLAYER_HPP_
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
#include <events.hpp>
#include <render.hpp>
+#include <ui.hpp>
#include <engine.hpp>
void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt)
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);
+ });
}
/*
#include <ui.hpp>
#include <gametime.hpp>
#include <world.hpp>
-#include <components.hpp>
void PlayerSystem::create(void)
{
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);
moveLeft = faceLeft = false;
moveRight = true;
- worldSystem.goWorldRight(loc);
+ worldSystem.goWorldRight(loc, *player.component<Solid>().get());
}
} else if (kc == getControl(3)) {
if (game::canSprint)
*/
void setFontSize(unsigned int size) {
- if (size == 16) {
+ (void)size;
+ /*if (size == 16) {
if (!ft16loaded) {
loadFontSize(fontSize = size, ftex16, ftdat16);
ft16loaded = true;
ftex = &ftex24;
ftdat = &ftdat24;
fontSize = 24;
- }
+ }*/
}
/*
}
void waitForCover(void) {
+ fadeIntensity = 0;
while (fadeIntensity < 255);
fadeIntensity = 255;
}
void waitForUncover(void) {
+ fadeIntensity = 255;
while (fadeIntensity > 0);
fadeIntensity = 0;
}
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,
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);
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;
}
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) {
}
entity.assign<Physics>(g);
+ } else if (tname == "Name") {
+ entity.assign<Name>(coalesce(wxml->Attribute("name"), abcd->Attribute("value")));
}
abcd = abcd->NextSiblingElement();
});
}
-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();
}
}
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();
}
}
ui::toggleBlack();
ui::waitForCover();
load(portal.toFile);
- p.x = 0;
ui::toggleBlack();
return;
}
<Direction />
<Solid />
<Physics />
+ <Name value="Daddy" />
</npc>
<structure>