]> git.tdb.fi Git - libs/game.git/blob - examples/bassteroids/source/gamecontroller.cpp
f32f04b3716908fffec8438537ab2bcf275d4269
[libs/game.git] / examples / bassteroids / source / gamecontroller.cpp
1 #include "gamecontroller.h"
2 #include <stdexcept>
3 #include <msp/game/root.h>
4 #include <msp/game/transform.h>
5
6 using namespace std;
7 using namespace Msp;
8
9 GameController::GameController(Game::Stage &s):
10         System(s),
11         asteroid_setup{ .mesh = { .object_name = "Asteroid 1.object" }}
12 { }
13
14 void GameController::tick(Time::TimeDelta)
15 {
16         switch(state)
17         {
18         case LEVEL_START:
19                 defer([this]{
20                         uniform_real_distribution<float> sdist(-1, 1);
21                         for(unsigned i=0; i<level+2; ++i)
22                         {
23                                 asteroids.emplace_back(stage.get_root(), asteroid_setup);
24                                 asteroids.back()->get_transform()->set_position({ sdist(rng)*32, sdist(rng)*18, 0.0f });
25                         }
26                         state = PLAYING;
27                 });
28                 break;
29         case PLAYING:
30                 break;
31         default:
32                 throw logic_error("Unimplemented state");
33         }
34 }