]> git.localhorst.tv Git - blobs.git/blob - src/blobs.cpp
primitive collision response
[blobs.git] / src / blobs.cpp
1 #include "app/Application.hpp"
2 #include "app/Assets.hpp"
3 #include "app/init.hpp"
4 #include "app/MasterState.hpp"
5 #include "creature/Creature.hpp"
6 #include "math/const.hpp"
7 #include "world/Planet.hpp"
8 #include "world/Set.hpp"
9 #include "world/Simulation.hpp"
10 #include "world/Sun.hpp"
11 #include "world/TileType.hpp"
12
13 #include <cstdint>
14 #include <iostream>
15
16
17 using namespace blobs;
18
19 namespace {
20
21 struct SwitchPanel {
22         SwitchPanel(world::Planet &p, app::Application &app, app::MasterState &state)
23         : planet(p), app(app), state(state) { }
24
25         void operator ()(creature::Creature &c) {
26                 if (planet.Creatures().empty()) {
27                         std::cout << "no more creatures, game over" << std::endl;
28                         state.GetCreaturePanel().Hide();
29                         while (app.HasState()) {
30                                 app.PopState();
31                         }
32                 } else {
33                         for (auto a : planet.Creatures()) {
34                                 if (a != &c) {
35                                         state.GetCreaturePanel().Show(*a);
36                                         a->OnDeath([&](creature::Creature &b) { (*this)(b); });
37                                         break;
38                                 }
39                         }
40                 }
41         }
42
43         world::Planet &planet;
44         app::Application &app;
45         app::MasterState &state;
46 };
47 }
48
49 int main(int argc, char *argv[]) {
50         app::Init init(true, 8);
51         app::Assets assets;
52
53         world::Sun sun;
54         sun.Mass(1.0e14);
55         sun.Radius(20.0);
56         sun.SurfaceTilt(glm::dvec2(PI * 0.25, PI * 0.25));
57         sun.AngularMomentum(1.0e13);
58
59         world::Planet planet(25);
60         planet.SetParent(sun);
61         planet.Mass(1.0e10);
62         planet.GetOrbit().SemiMajorAxis(941.7);
63         planet.SurfaceTilt(glm::dvec2(PI * 0.25, PI * 0.25));
64         planet.AxialTilt(glm::dvec2(PI * 0.127, 0.0));
65         planet.AngularMomentum(6.0e10);
66
67         world::Planet moon(3);
68         moon.SetParent(planet);
69         moon.Mass(1.0e6);
70         moon.GetOrbit().SemiMajorAxis(37.0);
71         moon.Rotation(PI * 0.25);
72         moon.AngularMomentum(1.0e4);
73
74         world::Planet second_planet(9);
75         second_planet.SetParent(sun);
76         second_planet.Mass(1.0e9);
77         second_planet.GetOrbit().SemiMajorAxis(350.0);
78         second_planet.SurfaceTilt(glm::dvec2(PI * 0.125, PI * 0.25));
79         second_planet.AxialTilt(glm::dvec2(PI * 0.95, 0.0));
80         second_planet.AngularMomentum(1.0e8);
81
82         world::Simulation sim(sun, assets);
83         sim.AddSun(sun);
84         sim.AddPlanet(planet);
85         sim.AddPlanet(second_planet);
86         sim.AddPlanet(moon);
87
88         world::GenerateEarthlike(assets.data.tile_types, planet);
89         planet.Atmosphere(assets.data.resources["air"].id);
90         world::GenerateTest(assets.data.tile_types, moon);
91         world::GenerateTest(assets.data.tile_types, second_planet);
92
93         auto blob = new creature::Creature(sim);
94         blob->Name(assets.name.Sequential());
95         Spawn(*blob, planet);
96         // decrease chances of ur-blob dying without splitting
97         blob->GetProperties().Fertility() = 1.0;
98         blob->BuildVAO();
99
100         app::MasterState state(assets, sim);
101         state.GetCamera()
102                 .Reference(planet)
103                 // sunrise
104                 //.FirstPerson(0, glm::vec3(0.0f, 0.0f, 0.1f), glm::vec3(1.0f, -0.75f, 0.1f))
105                 // sunset
106                 //.FirstPerson(3, glm::vec3(0.0f, 0.0f, 0.1f), glm::vec3(1.0f, -0.75f, 0.1f))
107                 // from afar
108                 .MapView(0, glm::vec3(0.0f, 0.0f, 30.0f), 0.0f)
109                 // from afar, rotating
110                 //.Orbital(glm::vec3(-60.0f, 0.0f, 0.0f))
111         ;
112         // system view
113         //state.GetCamera()
114         //      .Reference(sun)
115         //      .Orbital(glm::vec3(-500.0f, 500.0f, 500.0f))
116         //;
117         state.GetCreaturePanel().Show(*blob);
118
119         app::Application app(init.window, init.viewport);
120         SwitchPanel swp(planet, app, state);
121         blob->OnDeath([&](creature::Creature &c) { swp(c); });
122         app.PushState(&state);
123         app.Run();
124
125         return 0;
126 }