-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphic.cpp
83 lines (67 loc) · 2.32 KB
/
graphic.cpp
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
#include "graphic.h"
#include "SDL2/SDL.h"
void buildView(int row, int col, spacesMap *spaces) {
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Window *window;
window = SDL_CreateWindow("procedural-map-generation", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 900, 900, SDL_WINDOW_RESIZABLE);
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDL_RenderClear(renderer);
SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255);
int leftSpace = 0;
int topSpace = 0;
int height = 40;
int width = 5;
for (int i = 0; i < col; i++) {
for (int j = 0; j < row; j++) {
std::string xyKey = std::to_string(i) + ":" + std::to_string(j);
if ((*spaces)[xyKey][UP] != true) {
SDL_Rect r1;
r1.x = height + leftSpace;
r1.y = height + topSpace;
r1.h = width;
r1.w = height;
SDL_RenderFillRect(renderer, &r1);
}
if ((*spaces)[xyKey][LEFT] != true) {
SDL_Rect r2;
r2.x = height + leftSpace;
r2.y = height + topSpace;
r2.h = height;
r2.w = width;
SDL_RenderFillRect(renderer, &r2);
}
if ((*spaces)[xyKey][DOWN] != true) {
SDL_Rect r3;
r3.x = height + leftSpace;
r3.y = height + topSpace + (height - width);
r3.h = width;
r3.w = height;
SDL_RenderFillRect(renderer, &r3);
}
if ((*spaces)[xyKey][RIGHT] != true) {
SDL_Rect r4;
r4.x = height + leftSpace + (height - width);
r4.y = height + topSpace;
r4.h = height;
r4.w = width;
SDL_RenderFillRect(renderer, &r4);
}
topSpace += (height - width);
}
leftSpace = leftSpace + (height - width);
topSpace = 0;
}
SDL_RenderPresent(renderer);
SDL_Event e;
bool quit = false;
while (!quit){
while (SDL_PollEvent(&e)){
if (e.type == SDL_QUIT){
quit = true;
}
}
}
SDL_DestroyWindow(window);
SDL_Quit();
}