X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fblobs.cpp;h=836c51d335845b0f79e74caf891c6bc3f9ae4732;hb=e0180e01f4c659c97973f585fea5eb3344254ce0;hp=23ab012fed3a0d31aaca785e327074da2dde6e41;hpb=2025d49798b93180237b6ce62d3ff5d6ee8ebc6e;p=blobs.git diff --git a/src/blobs.cpp b/src/blobs.cpp index 23ab012..836c51d 100644 --- a/src/blobs.cpp +++ b/src/blobs.cpp @@ -1,9 +1,9 @@ -#include "const.hpp" #include "app/Application.hpp" #include "app/Assets.hpp" #include "app/init.hpp" #include "app/MasterState.hpp" #include "creature/Creature.hpp" +#include "math/const.hpp" #include "world/Planet.hpp" #include "world/Set.hpp" #include "world/Simulation.hpp" @@ -16,6 +16,35 @@ 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; + 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,7 +78,7 @@ 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, assets.data.resources, assets.data.tile_types); + world::Simulation sim(sun, assets); sim.AddSun(sun); sim.AddPlanet(planet); sim.AddPlanet(second_planet); @@ -67,10 +96,10 @@ int main(int argc, char *argv[]) { std::cout << "moon cycle in days: " << (moon.OrbitalPeriod() / planet.RotationalPeriod()) << std::endl; std::cout << "moon cycles per year: " << (planet.OrbitalPeriod() / moon.OrbitalPeriod()) << std::endl; - auto blob = new creature::Creature; - Spawn(*blob, planet, assets); + auto blob = new creature::Creature(sim); + blob->Name(assets.name.Sequential()); + Spawn(*blob, planet); blob->BuildVAO(); - blob->Name("Blob"); app::MasterState state(assets, sim); state.GetCamera() @@ -80,9 +109,9 @@ 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() @@ -92,6 +121,8 @@ int main(int argc, char *argv[]) { 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();