]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
explosions (crashes)
authorClyne Sullivan <tullivan99@gmail.com>
Fri, 6 Jan 2017 20:57:35 +0000 (15:57 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Fri, 6 Jan 2017 20:57:35 +0000 (15:57 -0500)
include/particle.hpp
include/weather.hpp
main.cpp
src/particle.cpp
src/player.cpp
src/ui.cpp
xml/!town.xml

index d9aa29f1df68fd9c8022068d8f537dcc534ae825..4d42b39c934c05c9f0f0fefab40e6cce823dcc40 100644 (file)
@@ -9,7 +9,8 @@
 
 enum class ParticleType : char {
        Drop,
-       Confetti
+       Confetti,
+       SmallBlast
 };
 
 struct Particle {
@@ -18,8 +19,8 @@ struct Particle {
        ParticleType type;
        int timeLeft;
 
-       Particle(vec2 p, ParticleType t = ParticleType::Drop)
-               : location(p), type(t), timeLeft(3000) {} // TODO times
+       Particle(vec2 p, ParticleType t = ParticleType::Drop, int tl = 3000)
+               : location(p), type(t), timeLeft(tl) {} // TODO times
 } __attribute__ ((packed));
 
 class ParticleSystem : public entityx::System<ParticleSystem> {
@@ -28,10 +29,10 @@ private:
        bool max;
 
 public:
-       ParticleSystem(int count = 1024, bool m = false);
+       ParticleSystem(int count = 2048, bool m = false);
 
-       void add(const vec2& pos, const ParticleType& type);
-       void addMultiple(const int& count, const ParticleType& type, std::function<vec2(void)> f);
+       void add(const vec2& pos, const ParticleType& type, const int& timeleft = 3000);
+       void addMultiple(const int& count, const ParticleType& type, std::function<vec2(void)> f, const int& timeleft = 3000);
 
        void render(void) const; 
        void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override;
index 3aac2e651b522dcdd907da0ae69536762eb05e6b..c348c15d3eb2f4fa3896d4779023f8343261f92f 100644 (file)
@@ -52,6 +52,12 @@ public:
                        }
                        break; // TODO
                case Weather::Snowy:
+                       if (newPartDelay++ == 4) {
+                               newPartDelay = 0;
+                               partSystem.add(vec2(offset.x - game::SCREEN_WIDTH / 2 + randGet() % game::SCREEN_WIDTH,
+                                       offset.y + game::SCREEN_HEIGHT / 2 + 100),
+                                       ParticleType::Confetti, 6000);
+                       }
                        break; // TODO
                default:
                        break;
index 2e33a83ff513fc252a4ba67566bae08639d3edc5..0c5a6f204e8557a61b2d8be7a43f793757c7a10f 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -208,11 +208,13 @@ int main(int argc, char *argv[])
                        }
                });
 
+               static float fpsInternal = 0;
+
                // the debug loop, gets debug screen values
                std::thread thDebug ([&] {
                        const bool &run = game::engine.shouldRun;
                        while (run) {
-                               fps = 1000 / game::time::getDeltaTime(); // TODO really?
+                               fps = fpsInternal, fpsInternal = 0;
                                std::this_thread::sleep_for(1s);
                        }
                });
@@ -220,6 +222,7 @@ int main(int argc, char *argv[])
                // thre render loop, renders
                const bool &run = game::engine.shouldRun;
                while (run) {
+                       fpsInternal++;
                        render();
                        game::engine.resetRender(0);
                }
index 3e140ae88616ba98a9b0550c351f7cbaccde65eb..52a563521b77ce13c5116a40de8955d39df75459 100644 (file)
@@ -10,20 +10,20 @@ ParticleSystem::ParticleSystem(int count, bool m)
        parts.reserve(count);
 }
 
-void ParticleSystem::add(const vec2& pos, const ParticleType& type)
+void ParticleSystem::add(const vec2& pos, const ParticleType& type, const int& timeleft)
 {
        // TODO not enforce max
        if (/*max &&*/ parts.size() + 1 >= parts.capacity())
                return;
 
-       parts.emplace_back(pos, type);
+       parts.emplace_back(pos, type, timeleft);
 }
 
-void ParticleSystem::addMultiple(const int& count, const ParticleType& type, std::function<vec2(void)> f)
+void ParticleSystem::addMultiple(const int& count, const ParticleType& type, std::function<vec2(void)> f, const int& timeleft)
 {
        int togo = count;
        while (togo-- > 0)
-               parts.emplace_back(f(), type);
+               parts.emplace_back(f(), type, timeleft);
 }
 
 void ParticleSystem::render(void) const
@@ -113,6 +113,29 @@ void ParticleSystem::update(entityx::EntityManager &en, entityx::EventManager &e
                                p.velocity.y -= 0.001f;
                        break;
                case ParticleType::Confetti:
+                       if (p.velocity.x > -0.01 && p.velocity.x < 0.01) {
+                               p.velocity.x = randGet() % 12 / 30.0f - 0.2f;
+                       } else {
+                               p.velocity.x += (p.velocity.x > 0) ? -0.002f : 0.002f;
+                       }
+                       p.velocity.y = -0.15f;
+                       break;
+               case ParticleType::SmallBlast:
+                       if (p.velocity.x == 0) {
+                               int degree = randGet() % 100;
+                               p.velocity.x = cos(degree) / 4.0f;
+                               p.velocity.y = sin(degree) / 4.0f;
+                       } else {
+                               p.velocity.x += (p.velocity.x > 0) ? -0.001f : 0.001f;
+                               p.velocity.x += (p.velocity.y > 0) ? -0.001f : 0.001f;
+                               if ((p.velocity.x > -0.01 && p.velocity.x < 0.01) &&
+                                       (p.velocity.y > -0.01 && p.velocity.y < 0.01)) {
+                                       p.timeLeft = 0;
+                                       if (p.timeLeft <= 0)
+                                               parts.erase(part);
+                               }
+                       }
+                       
                        break;
                }
 
index a88734a343234f13b84078cad8b7e0ad973cf0c4..0e75e05da1eae63267c4b463c4d406831611b9fa 100644 (file)
@@ -4,6 +4,7 @@
 #include <ui.hpp>
 #include <gametime.hpp>
 #include <world.hpp>
+#include <particle.hpp>
 
 void PlayerSystem::create(void)
 {
@@ -107,6 +108,9 @@ void PlayerSystem::receive(const KeyDownEvent &kde)
                } else if (kc == getControl(3)) {
                        if (game::canSprint)
                                speed = 2.0f;
+
+                       game::engine.getSystem<ParticleSystem>()->addMultiple(10, ParticleType::SmallBlast,
+                               [&](){ return vec2(loc.x, loc.y); }, 1000);
                } else if (kc == getControl(4)) {
                        speed = .5;
                } else if (kc == getControl(5)) {
index 6383cca2cd27224c425a1ebea11b9ca11190ca67..09a87bf7faac93b17bed152c5765d03049403fbb 100644 (file)
@@ -1284,7 +1284,6 @@ void InputSystem::update(entityx::EntityManager &en, entityx::EventManager &ev,
                        case SDLK_b:
                                if (debug)
                                        posFlag ^= true;
-
                                break;
                        case SDLK_F12:
                                // Make the BYTE array, factor of 3 because it's RBG.
index c197d8df6f627c7b59460cc1713a0b2a70cc8428..230cbdc9083caa751507ec4f0bb2ccacfa4b7467 100644 (file)
@@ -4,7 +4,7 @@
 <World>
     <style background="0" bgm="assets/music/embark.wav" folder="assets/style/classic/"/>
     <generation width="320"/>
-       <weather>Rainy</weather>
+       <weather>Sunny</weather>
     <time>6000</time>
     <link right="!town2.xml"/>
     <spawnx>-300</spawnx>