aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/components.hpp22
-rw-r--r--src/components.cpp14
-rw-r--r--src/player.cpp5
-rw-r--r--src/world.cpp26
4 files changed, 44 insertions, 23 deletions
diff --git a/include/components.hpp b/include/components.hpp
index 31ff283..d2655c9 100644
--- a/include/components.hpp
+++ b/include/components.hpp
@@ -92,10 +92,10 @@ struct Solid {
};
struct SpriteData {
-
- SpriteData(uint64_t sid = 0, vec2 offset = 0.0f, vec2 size = 0.0f):
+
+ SpriteData(uint64_t sid = 0, vec2 offset = 0.0f, vec2 size = 0.0f):
sheetID(sid), offset(offset), size(size) {}
-
+
uint64_t sheetID;
vec2 offset;
vec2 size;
@@ -108,18 +108,21 @@ struct SpriteData {
* Each entity is given a sprite, a sprite can consist of manu frames or pieces to make one.
*/
struct Sprite {
+ Sprite(bool left = false)
+ : faceLeft(left) {}
+
std::vector<std::pair<SpriteData, vec2>> getSprite() {
return sprite;
}
-
+
int clearSprite() {
if (sprite.empty())
return 0;
sprite.clear();
- return 1;
+ return 1;
}
-
+
int addSpriteSegment(SpriteData data, vec2 loc) {
//TODO if sprite is in this spot, do something
sprite.push_back(std::make_pair(data, loc));
@@ -130,7 +133,7 @@ struct Sprite {
for (auto &s : sprite) {
if (s.second == loc) {
s.first = data;
-
+
return 1;
}
}
@@ -139,6 +142,7 @@ struct Sprite {
}
std::vector<std::pair<SpriteData, vec2>> sprite;
+ bool faceLeft;
};
//TODO
@@ -150,7 +154,7 @@ struct Animate {
//TODO
struct Input {
-
+
};
/**
@@ -180,7 +184,7 @@ public:
class RenderSystem : public entityx::System<RenderSystem> {
private:
-public:
+public:
void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override;
};
diff --git a/src/components.cpp b/src/components.cpp
index a1e3e45..32d0f79 100644
--- a/src/components.cpp
+++ b/src/components.cpp
@@ -13,17 +13,17 @@ void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &e
(void)entity;
position.x += direction.x * dt;
position.y += direction.y * dt;
- });
+ });
}
void RenderSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt)
{
(void)ev;
Render::worldShader.use();
-
+
en.each<Visible, Sprite, Position>([dt](entityx::Entity entity, Visible &visible, Sprite &sprite, Position &pos) {
(void)entity;
- // Verticies and shit
+ // Verticies and shit
GLfloat tex_coord[] = {0.0, 0.0,
1.0, 0.0,
1.0, 1.0,
@@ -43,7 +43,7 @@ void RenderSystem::update(entityx::EntityManager &en, entityx::EventManager &ev,
for (auto &S : sprite.sprite) {
float width = S.first.size.x;
float height = S.first.size.y;
-
+
vec2 loc = vec2(pos.x + S.first.offset.x, pos.y + S.first.offset.y);
GLfloat coords[] = {loc.x, loc.y, visible.z,
@@ -53,8 +53,8 @@ void RenderSystem::update(entityx::EntityManager &en, entityx::EventManager &ev,
loc.x + width, loc.y + height, visible.z,
loc.x, loc.y + height, visible.z,
loc.x, loc.y, visible.z};
-
-
+
+
// make the entity hit flash red
// TODO
/*if (maxHitDuration-hitDuration) {
@@ -66,7 +66,7 @@ void RenderSystem::update(entityx::EntityManager &en, entityx::EventManager &ev,
Render::worldShader.enable();
glVertexAttribPointer(Render::worldShader.coord, 3, GL_FLOAT, GL_FALSE, 0, coords);
- if (false)
+ if (sprite.faceLeft)
glVertexAttribPointer(Render::worldShader.tex, 2, GL_FLOAT, GL_FALSE, 0 ,tex_coordL);
else
glVertexAttribPointer(Render::worldShader.tex, 2, GL_FLOAT, GL_FALSE, 0 ,tex_coord);
diff --git a/src/player.cpp b/src/player.cpp
index 912027f..95a9c08 100644
--- a/src/player.cpp
+++ b/src/player.cpp
@@ -62,6 +62,7 @@ void PlayerSystem::receive(const KeyUpEvent &kue)
void PlayerSystem::receive(const KeyDownEvent &kde)
{
auto kc = kde.keycode;
+ auto& faceLeft = game::entities.get(pid).component<Sprite>().get()->faceLeft;
/*auto worldSwitch = [&](const WorldSwitchInfo& wsi){
player->canMove = false;
@@ -98,7 +99,7 @@ void PlayerSystem::receive(const KeyDownEvent &kde)
}*/
} else if (kc == getControl(1)) {
if (!ui::fadeEnable) {
- moveLeft = true;
+ moveLeft = faceLeft = true;
moveRight = false;
/*if (currentWorldToLeft) {
@@ -111,7 +112,7 @@ void PlayerSystem::receive(const KeyDownEvent &kde)
}
} else if (kc == getControl(2)) {
if (!ui::fadeEnable) {
- moveLeft = false;
+ moveLeft = faceLeft = false;
moveRight = true;
/*if (currentWorldToRight) {
diff --git a/src/world.cpp b/src/world.cpp
index 4b5bb2d..5f696b5 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -299,6 +299,23 @@ void WorldSystem::load(const std::string& file)
game::time::setTickCount(std::stoi(wxml->GetText()));
}
+ else if (tagName == "entity") {
+ auto str2coord = [](std::string s) -> vec2 {
+ auto cpos = s.find(',');
+ s[cpos] = '\0';
+ return vec2 (std::stof(s), std::stof(s.substr(cpos + 1)));
+ };
+
+ auto entity = game::entities.create();
+
+ auto loc = wxml->Attribute("loc");
+ if (loc != nullptr) {
+ auto locVec = str2coord(loc);
+ float locDat[2] = {locVec.x, locVec.y};
+ entity.assign<Position>(locVec.x, locVec.y);
+ }
+ }
+
// hill creation
/*else if (tagName == "hill") {
addHill(ivec2 { wxml->IntAttribute("peakx"), wxml->IntAttribute("peaky") }, wxml->UnsignedAttribute("width"));
@@ -930,13 +947,12 @@ void WorldSystem::update(entityx::EntityManager &en, entityx::EventManager &ev,
void WorldSystem::detect(entityx::TimeDelta dt)
{
- game::entities.each<Position, Direction, Health, Solid>(
- [&](entityx::Entity e, Position &loc, Direction &vel, Health &health, Solid &dim) {
-
+ game::entities.each<Position, Direction, Solid>(
+ [&](entityx::Entity e, Position &loc, Direction &vel, Solid &dim) {
(void)e;
- if (health.health <= 0)
- UserError("die mofo");
+ //if (health.health <= 0)
+ // UserError("die mofo");
// get the line the entity is on
int line = std::clamp(static_cast<int>((loc.x + dim.width / 2 - world.startX) / game::HLINE),