-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSource.cpp
More file actions
77 lines (63 loc) · 2.61 KB
/
Source.cpp
File metadata and controls
77 lines (63 loc) · 2.61 KB
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
71
72
73
74
75
76
77
#include "Game.h"
#define xGridSize 20
#define yGridSize 20
#define FOV 90
#define xResolution 1200
#define yResolution 800
#define xResolutionMap 800
#define yResolutionMap 800
#define planeDistance 50
using namespace std;
Game *game = nullptr;
const float fovRads = FOV * (M_PI / 180);
const int perspectivePlane = 2 * tan(fovRads / 2)*planeDistance;
int map[xGridSize][yGridSize] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3,
3, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 3,
3, 0, 0, 2, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3,
3, 0, 0, 2, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3,
3, 0, 0, 3, 3, 3, 3, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 3,
3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 3,
3, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 3,
3, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 3,
3, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 3,
3, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3,
3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 3,
3, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 3,
3, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 3,
3, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 3,
3, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 0, 2, 2, 0, 0, 0, 0, 3,
3, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2, 2, 0, 0, 0, 3,
3, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 2, 2, 0, 0, 3,
3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
int main(int argc, char * argv[])
{
//Keep track of the current frame
int frame = 0;
//Whether or not to cap the frame rate
bool cap = true;
//The frame rate regulator
const int FPS = 30;
const int frameDelay = 1000 / FPS;
Uint32 frameStart;
int frameTime;
game = new Game();
game->init("Map View", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, xResolutionMap,yResolutionMap, false);
const float fovRads = FOV * (M_PI / 180);
const int perspectivePlane = 2 * tan(fovRads/2)*planeDistance;
while(game->running())
{
frameStart = SDL_GetTicks();
game->handleEvents(map);
game->update(map);
game->render(map, xGridSize, yGridSize);
frameTime = SDL_GetTicks() - frameStart;
if (frameDelay > frameTime)
{
SDL_Delay(frameDelay - frameTime);
}
};
game->clean();
return 0;
}