-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
137 lines (122 loc) · 4.28 KB
/
Copy pathmain.cpp
File metadata and controls
137 lines (122 loc) · 4.28 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include <SDL2/SDL.h>
#include <vector>
#include <string>
const int TILE_SIZE = 15;
const int MAP_WIDTH = 28;
const int MAP_HEIGHT = 31;
const int SCREEN_WIDTH = MAP_WIDTH * TILE_SIZE;
const int SCREEN_HEIGHT = MAP_HEIGHT * TILE_SIZE;
// Инициализация карты
std::vector<std::string> maze = {
"############################",
"#............##............#",
"#.####.#####.##.#####.####.#",
"#o####.#####.##.#####.####o#",
"#.####.#####.##.#####.####.#",
"#..........................#",
"#.####.##.########.##.####.#",
"#.####.##.########.##.####.#",
"#......##....##....##......#",
"######.##### ## #####.######",
"######.##### ## #####.######",
"######.## ##.######",
"######.## ###DD### ##.######",
"######.## # # ##.######",
" . # # . ",
"######.## # # ##.######",
"######.## ######## ##.######",
"######.## ##.######",
"######.## ######## ##.######",
"######.## ######## ##.######",
"#............##............#",
"#.####.#####.##.#####.####.#",
"#.####.#####.##.#####.####.#",
"#o..##....... .......##..o#",
"###.##.##.########.##.##.###",
"###.##.##.########.##.##.###",
"#......##....##....##......#",
"#.##########.##.##########.#",
"#.##########.##.##########.#",
"#..........................#",
"############################"
};
SDL_Window* window = nullptr;
SDL_Renderer* renderer = nullptr;
bool doorOpened = false;
Uint32 doorTimer = 0;
void initializeSDL() {
SDL_Init(SDL_INIT_VIDEO);
window = SDL_CreateWindow("Pacman Maze", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH, SCREEN_HEIGHT, 0);
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
}
void closeSDL() {
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
}
void renderMaze() {
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer);
// Отрисовка лабиринта
for (int y = 0; y < MAP_HEIGHT; y++) {
for (int x = 0; x < MAP_WIDTH; x++) {
SDL_Rect rect = { x * TILE_SIZE, y * TILE_SIZE, TILE_SIZE, TILE_SIZE };
switch (maze[y][x]) {
case '#': // Стена
SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255);
SDL_RenderFillRect(renderer, &rect);
break;
case '.': // Точка
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDL_RenderFillRect(renderer, &rect);
break;
case 'o': // Энерджайзер
SDL_SetRenderDrawColor(renderer, 255, 255, 0, 255);
SDL_RenderFillRect(renderer, &rect);
break;
case 'D': // Дверь
if (doorOpened) {
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
} else {
SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255);
}
SDL_RenderFillRect(renderer, &rect);
break;
case ' ': // Туннели
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderFillRect(renderer, &rect);
break;
}
}
}
SDL_RenderPresent(renderer);
}
int main(int argc, char* argv[]) {
initializeSDL();
bool running = true;
SDL_Event event;
doorTimer = SDL_GetTicks();
while (running) {
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
running = false;
}
}
// Открытие двери через 10 секунд
if (!doorOpened && SDL_GetTicks() - doorTimer > 10000) {
doorOpened = true;
// Заменяем дверь на проход
for (int y = 0; y < MAP_HEIGHT; y++) {
for (int x = 0; x < MAP_WIDTH; x++) {
if (maze[y][x] == 'D') {
maze[y][x] = ' ';
}
}
}
}
renderMaze();
SDL_Delay(16);
}
closeSDL();
return 0;
}