]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
something...
authorClyne Sullivan <tullivan99@gmail.com>
Fri, 21 Oct 2016 11:59:01 +0000 (06:59 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Fri, 21 Oct 2016 11:59:01 +0000 (06:59 -0500)
include/components.hpp
src/components.cpp
src/player.cpp
src/world.cpp

index 31ff2838b94abf24e14c6e56773449f54788714b..d2655c985344b861aed379c67b05b7a79058aabb 100644 (file)
@@ -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;
 };
 
index a1e3e45b1795aadde84909b25afb35c39cb6db7f..32d0f7976db82b7cd9e4386afc740cb514b4a60f 100644 (file)
@@ -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);
index 912027ff434aa2ab2922161e8f0e82361cc9ad9f..95a9c081f8b6aacc2581982add47dee71303cae0 100644 (file)
@@ -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) {
index 4b5bb2dad53f8602d2ffdc405ce4e89629242661..5f696b549d5302ad5bc71e94bb8e6eb6aee60076 100644 (file)
@@ -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),