blob: 4dce6a54ec14f1936ad1c0c26bd83ac2d4972729 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
#include "renderer.h"
#include <random>
#include "simulation.h"
#include "level.h"
int main(int, char**)
{
std::random_device randomEngine;
std::mt19937 rng(randomEngine());
Renderer renderer;
Level level;
Simulation sim(level);
Simulation::id_type player = sim.emplaceEntity();
Entity& entity = sim.getEntity(player);
entity.gridPos.x() = 1;
entity.gridPos.y() = 5;
entity.size = TILE_SIZE;
entity.speed = 3.0;
entity.controllable = true;
entity.colliderType = ColliderType::player;
entity.colorVal = 180;
Simulation::id_type crateId = sim.emplaceEntity();
Entity& crate = sim.getEntity(crateId);
crate.gridPos.x() = 4;
crate.gridPos.y() = 5;
crate.size = TILE_SIZE;
crate.speed = 4.0;
crate.playerCanPush = true;
bool quit = false;
SDL_Event e;
size_t lastTime = SDL_GetTicks();
while (!quit)
{
size_t currentTime = SDL_GetTicks();
size_t frameTime = currentTime - lastTime;
lastTime = currentTime;
while (SDL_PollEvent(&e))
{
if (e.type == SDL_QUIT)
{
quit = true;
} else if (e.type == SDL_KEYDOWN)
{
switch (e.key.keysym.sym)
{
case SDLK_ESCAPE:
{
quit = true;
break;
}
}
}
}
const Uint8* state = SDL_GetKeyboardState(NULL);
sim.tick(frameTime / 1000.0, state);
renderer.render(sim);
}
}
|