diff options
| author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2019-02-03 16:10:44 -0500 |
|---|---|---|
| committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2019-02-03 16:10:44 -0500 |
| commit | 8ffb27ab09ff567a159e5be5a243fd3967084977 (patch) | |
| tree | c7c1be31a4074a0d58191b9cc5ed880271c65b91 /src/main.cpp | |
| download | dispatcher-8ffb27ab09ff567a159e5be5a243fd3967084977.tar.gz dispatcher-8ffb27ab09ff567a159e5be5a243fd3967084977.tar.bz2 dispatcher-8ffb27ab09ff567a159e5be5a243fd3967084977.zip | |
Very basic ECS
Diffstat (limited to 'src/main.cpp')
| -rw-r--r-- | src/main.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
| diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..1b74143 --- /dev/null +++ b/src/main.cpp | |||
| @@ -0,0 +1,60 @@ | |||
| 1 | #include "renderer.h" | ||
| 2 | |||
| 3 | #include <random> | ||
| 4 | #include "simulation.h" | ||
| 5 | #include "level.h" | ||
| 6 | |||
| 7 | int main(int, char**) | ||
| 8 | { | ||
| 9 | std::random_device randomEngine; | ||
| 10 | std::mt19937 rng(randomEngine()); | ||
| 11 | |||
| 12 | Renderer renderer; | ||
| 13 | Level level; | ||
| 14 | Simulation sim(level); | ||
| 15 | |||
| 16 | Simulation::id_type player = sim.emplaceEntity(); | ||
| 17 | Entity& entity = sim.getEntity(player); | ||
| 18 | entity.gridPos.x() = 1; | ||
| 19 | entity.gridPos.y() = 5; | ||
| 20 | entity.size = TILE_SIZE; | ||
| 21 | entity.speed = 3.0; | ||
| 22 | entity.player = true; | ||
| 23 | |||
| 24 | bool quit = false; | ||
| 25 | |||
| 26 | SDL_Event e; | ||
| 27 | size_t lastTime = SDL_GetTicks(); | ||
| 28 | |||
| 29 | while (!quit) | ||
| 30 | { | ||
| 31 | size_t currentTime = SDL_GetTicks(); | ||
| 32 | size_t frameTime = currentTime - lastTime; | ||
| 33 | lastTime = currentTime; | ||
| 34 | |||
| 35 | while (SDL_PollEvent(&e)) | ||
| 36 | { | ||
| 37 | if (e.type == SDL_QUIT) | ||
| 38 | { | ||
| 39 | quit = true; | ||
| 40 | } else if (e.type == SDL_KEYDOWN) | ||
| 41 | { | ||
| 42 | switch (e.key.keysym.sym) | ||
| 43 | { | ||
| 44 | case SDLK_ESCAPE: | ||
| 45 | { | ||
| 46 | quit = true; | ||
| 47 | |||
| 48 | break; | ||
| 49 | } | ||
| 50 | } | ||
| 51 | } | ||
| 52 | } | ||
| 53 | |||
| 54 | const Uint8* state = SDL_GetKeyboardState(NULL); | ||
| 55 | |||
| 56 | sim.tick(frameTime / 1000.0, state); | ||
| 57 | |||
| 58 | renderer.render(sim); | ||
| 59 | } | ||
| 60 | } | ||
