]> git.localhorst.tv Git - blobs.git/blobdiff - src/blobs.cpp
primitive collision response
[blobs.git] / src / blobs.cpp
index 918925664f3d66f553685d831363e1e0110b5de0..9a94b96e0f55b87a4855efff5d1d434e0300fa92 100644 (file)
@@ -1,9 +1,9 @@
-#include "const.hpp"
 #include "app/Application.hpp"
 #include "app/Assets.hpp"
 #include "app/init.hpp"
 #include "app/MasterState.hpp"
-#include "world/Creature.hpp"
+#include "creature/Creature.hpp"
+#include "math/const.hpp"
 #include "world/Planet.hpp"
 #include "world/Set.hpp"
 #include "world/Simulation.hpp"
 
 using namespace blobs;
 
+namespace {
+
+struct SwitchPanel {
+       SwitchPanel(world::Planet &p, app::Application &app, app::MasterState &state)
+       : planet(p), app(app), state(state) { }
+
+       void operator ()(creature::Creature &c) {
+               if (planet.Creatures().empty()) {
+                       std::cout << "no more creatures, game over" << std::endl;
+                       state.GetCreaturePanel().Hide();
+                       while (app.HasState()) {
+                               app.PopState();
+                       }
+               } else {
+                       for (auto a : planet.Creatures()) {
+                               if (a != &c) {
+                                       state.GetCreaturePanel().Show(*a);
+                                       a->OnDeath([&](creature::Creature &b) { (*this)(b); });
+                                       break;
+                               }
+                       }
+               }
+       }
+
+       world::Planet &planet;
+       app::Application &app;
+       app::MasterState &state;
+};
+}
+
 int main(int argc, char *argv[]) {
        app::Init init(true, 8);
        app::Assets assets;
@@ -49,28 +79,23 @@ int main(int argc, char *argv[]) {
        second_planet.AxialTilt(glm::dvec2(PI * 0.95, 0.0));
        second_planet.AngularMomentum(1.0e8);
 
-       world::Simulation sim(sun);
+       world::Simulation sim(sun, assets);
        sim.AddSun(sun);
        sim.AddPlanet(planet);
        sim.AddPlanet(second_planet);
        sim.AddPlanet(moon);
 
-       world::GenerateEarthlike(assets.data.tiles, planet);
-       world::GenerateTest(assets.data.tiles, moon);
-       world::GenerateTest(assets.data.tiles, second_planet);
-
-       std::cout << "length of year: " << planet.OrbitalPeriod() << "s" << std::endl;
-       std::cout << "length of moon cycle: " << moon.OrbitalPeriod() << "s" << std::endl;
-       std::cout << "length of day: " << planet.RotationalPeriod() << "s" << std::endl;
-       std::cout << "days per year: " << (planet.OrbitalPeriod() / planet.RotationalPeriod()) << std::endl;
-       std::cout << "moon cycle in days: " << (moon.OrbitalPeriod() / planet.RotationalPeriod()) << std::endl;
-       std::cout << "moon cycles per year: " << (planet.OrbitalPeriod() / moon.OrbitalPeriod()) << std::endl;
+       world::GenerateEarthlike(assets.data.tile_types, planet);
+       planet.Atmosphere(assets.data.resources["air"].id);
+       world::GenerateTest(assets.data.tile_types, moon);
+       world::GenerateTest(assets.data.tile_types, second_planet);
 
-       auto blob = new world::Creature;
+       auto blob = new creature::Creature(sim);
+       blob->Name(assets.name.Sequential());
+       Spawn(*blob, planet);
+       // decrease chances of ur-blob dying without splitting
+       blob->GetProperties().Fertility() = 1.0;
        blob->BuildVAO();
-       planet.AddCreature(blob);
-       blob->Surface(0);
-       blob->Position(glm::dvec3(0.0, 0.0, 0.0));
 
        app::MasterState state(assets, sim);
        state.GetCamera()
@@ -80,17 +105,20 @@ int main(int argc, char *argv[]) {
                // sunset
                //.FirstPerson(3, glm::vec3(0.0f, 0.0f, 0.1f), glm::vec3(1.0f, -0.75f, 0.1f))
                // from afar
-               //.MapView(0, glm::vec3(0.0f, 0.0f, 60.0f), 0.0f)
+               .MapView(0, glm::vec3(0.0f, 0.0f, 30.0f), 0.0f)
                // from afar, rotating
-               .Orbital(glm::vec3(-60.0f, 0.0f, 0.0f))
+               //.Orbital(glm::vec3(-60.0f, 0.0f, 0.0f))
        ;
        // system view
        //state.GetCamera()
        //      .Reference(sun)
        //      .Orbital(glm::vec3(-500.0f, 500.0f, 500.0f))
        //;
+       state.GetCreaturePanel().Show(*blob);
 
        app::Application app(init.window, init.viewport);
+       SwitchPanel swp(planet, app, state);
+       blob->OnDeath([&](creature::Creature &c) { swp(c); });
        app.PushState(&state);
        app.Run();