]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
help fix the particles please
authorClyne Sullivan <tullivan99@gmail.com>
Tue, 10 Jan 2017 16:18:50 +0000 (11:18 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Tue, 10 Jan 2017 16:18:50 +0000 (11:18 -0500)
src/particle.cpp
src/player.cpp
src/world.cpp

index 3a286c4a2f3646b8b8ef9cb42e39f477071e632c..a8fab9da30496982c145a1ebeb0763dc40e540a4 100644 (file)
@@ -46,8 +46,8 @@ void ParticleSystem::render(void)
        // copy data into VBO
        glBindBuffer(GL_ARRAY_BUFFER, particleVBO);
 
-       int offset = 0;
-       for (const auto& p : parts) {
+       for (unsigned int i = 0, offset = 0; i < parts.size() - 1; i++, offset += entrySize) {
+               const auto& p = parts[i];
                static const auto& hl = game::HLINE;
                GLfloat coords[30] = {
                        p.location.x,      p.location.y,      -1, p.color.x, p.color.y,
@@ -59,7 +59,6 @@ void ParticleSystem::render(void)
                };
 
                glBufferSubData(GL_ARRAY_BUFFER, offset, entrySize, coords);
-               offset += entrySize;
        }
 
        // begin actual rendering
@@ -128,7 +127,7 @@ void ParticleSystem::update(entityx::EntityManager &en, entityx::EventManager &e
                case ParticleType::SmallPoof:
                        if (p.velocity.x == 0) {
                                p.velocity.y = 0.1f;
-                               p.velocity.x = randGet() % 12 / 30.0f - 0.2f;
+                               p.velocity.x = randGet() % 10 / 20.0f - 0.25f;
                        } else {
                                p.velocity.x += (p.velocity.x > 0) ? -0.001f : 0.001f;
                                p.velocity.y -= 0.0015f;
index 62ff6fea982d8bbca332cb570950580d612b0802..e83616dac5e1e04b7857efbefa9c56d16ab3795e 100644 (file)
@@ -6,6 +6,13 @@
 #include <world.hpp>
 #include <particle.hpp>
 
+static const char *spriteXML =
+       "<Sprite> \
+               <frame> \
+                       <src limb='0' offset='0,0' size='19,15' drawOffset='0,0'>assets/cat.png</src> \
+               </frame> \
+       </Sprite>";
+
 void PlayerSystem::create(void)
 {
        player = game::entities.create();
@@ -17,9 +24,12 @@ void PlayerSystem::create(void)
        player.assign<Visible>(-0.2f);
 
        auto sprite = player.assign<Sprite>();
-       sprite->addSpriteSegment(SpriteData("assets/cat.png",
-                                                                               vec2(0, 0)),
-                                                        vec2(0, 0));
+       XMLDocument xmld;
+       xmld.Parse(spriteXML);
+       auto frame = developFrame(xmld.FirstChildElement("Sprite"));
+       if (frame.size() > 0)
+               sprite->sprite = frame.at(0);
+
        vec2 dim = player.component<Sprite>().get()->getSpriteSize();
        float cdat[2] = {dim.x, dim.y};
        player.assign<Solid>(cdat[0], cdat[1]);
index b6149e881eb631042ba277544bf6243178f355c5..c882256dbe16c5e4a30d375fd220a38e14491083 100644 (file)
@@ -338,7 +338,7 @@ void WorldSystem::load(const std::string& file)
                                                auto sprite = entity.assign<Sprite>();
                                                auto sprx = abcd;
                                                auto frames = developFrame(sprx);
-                                               if (frames.size())
+                                               if (frames.size() > 0)
                                                        sprite->sprite = frames.at(0);
                                        } else if (tname == "Portal") {
                                                entity.assign<Portal>(wxml->StrAttribute("inside"));
@@ -401,8 +401,8 @@ void WorldSystem::load(const std::string& file)
                                                                                idtc = 0;
                                                                        else 
                                                                                idtc = limbx->UnsignedAttribute("changeID");
-                                                                       for (uint i = 0; i < frames.size(); i++) {
-                                                                               entan->frame.push_back(std::make_pair(idtc, frames[i]));
+                                                                       for (const auto& f : frames) {
+                                                                               entan->frame.emplace_back(idtc, f);
                                                                        }
                                                                limbx = limbx->NextSiblingElement();
                                                                }