-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
86 lines (73 loc) · 3.71 KB
/
main.cpp
File metadata and controls
86 lines (73 loc) · 3.71 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
78
79
80
81
82
83
84
85
86
#include <SDL2/SDL.h>
#include "raycaster.h"
#include "gameMap.h"
int worldMap[MAP_WIDTH][MAP_HEIGHT] = {
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,2,2,2,2,0,0,4,4,4,4,4,0,0,0,5,5,5,5,5,0,0,0,3,3,3,3,3,0,0,1},
{1,0,2,0,0,2,0,0,4,0,0,0,4,0,0,0,5,0,0,0,5,0,0,0,3,0,0,0,3,0,0,1},
{1,0,2,0,0,0,0,0,4,0,0,0,4,0,0,0,0,0,0,0,5,0,0,0,0,0,0,0,3,0,0,1},
{1,0,2,0,0,2,0,0,4,0,0,0,4,0,0,0,5,0,0,0,5,0,0,0,3,0,0,0,3,0,0,1},
{1,0,2,2,0,2,0,0,4,4,0,4,4,0,0,0,5,5,0,5,5,0,0,0,3,3,0,3,3,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,1},
{1,0,1,0,0,0,0,0,2,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5,0,1,0,0,1},
{1,0,4,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,5,0,5,0,1,0,0,1},
{1,0,4,4,0,4,4,0,0,0,3,3,3,3,0,3,3,3,3,0,0,0,1,0,5,5,5,0,1,0,0,1},
{1,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,3,3,3,3,0,3,3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,1,1,1,1,1,1,1,1,1,1,1,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[]) {
if (SDL_Init(SDL_INIT_VIDEO) < 0) return -1;
int w = 800, h = 600;
SDL_Window* window = SDL_CreateWindow("Raycaster",
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
w, h, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1,
SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
SDL_SetRelativeMouseMode(SDL_TRUE);
Raycaster game(w, h);
Uint32 lastTime = SDL_GetTicks();
bool running = true;
SDL_Event e;
while (running) {
while (SDL_PollEvent(&e)) {
if (e.type == SDL_QUIT)
running = false;
}
const Uint8* state = SDL_GetKeyboardState(NULL);
if (state[SDL_SCANCODE_ESCAPE]) running = false;
Uint32 currentTime = SDL_GetTicks();
double frameTime = (currentTime - lastTime) / 1000.0;
lastTime = currentTime;
if (frameTime > 0.1) frameTime = 0.016;
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer);
game.handleInput(SDL_GetKeyboardState(NULL), frameTime * 5.0, frameTime * 3.0);
SDL_GetWindowSize(window, &w, &h);
game.render(renderer, w, h);
SDL_RenderPresent(renderer);
}
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}