-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.cpp
More file actions
105 lines (89 loc) · 2.37 KB
/
Copy pathapp.cpp
File metadata and controls
105 lines (89 loc) · 2.37 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
#include "App.hpp"
App::App()
: window(nullptr),
renderer(nullptr)
{
running = true;
init();
// Main Grid
int mainGridXPos = screenWidth / 10;
int mainGridYPos = screenHeight / 10;
int mainGridWidth = screenWidth / 2;
int mainGridHeight = screenHeight / 2;
int mainGridRows = 30;
int mainGridCols = 20;
mainGrid = new Grid(mainGridXPos, mainGridYPos, mainGridWidth, mainGridHeight,
mainGridRows, mainGridCols);
}
void App::init()
{
// Initialize SDL, Window, and Renderer
SDL_Log("Initializing SDL...");
if (SDL_Init(SDL_INIT_VIDEO) != 0)
{
std::cerr << "Could not Initialize SDL. Error: " << SDL_GetError() << std::endl;
return;
}
SDL_Log("SDL Initialized Successfully!");
SDL_Log("Creating a Window...");
window = SDL_CreateWindow("2D Tile Map Editor", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
screenWidth, screenHeight, SDL_WINDOW_SHOWN);
if (!window)
{
std::cerr << "Could not Create Window. Error: " << SDL_GetError() << std::endl;
SDL_Quit();
return;
}
SDL_Log("Window Created Successfully!");
SDL_Log("Creating a Renderer...");
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if (!renderer)
{
std::cerr << "Could not Create Renderer. Error: " << SDL_GetError() << std::endl;
SDL_DestroyWindow(window);
SDL_Quit();
return;
}
SDL_Log("Renderer Created Successfully!");
}
bool App::isRunning()
{
return running;
}
void App::run()
{
SDL_Event event;
while(SDL_PollEvent(&event))
{
if(event.type == SDL_QUIT)
{
running = false;
}
}
update();
render();
}
void App::update()
{
}
void App::render()
{
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
SDL_RenderClear(renderer);
// Render Objects here
mainGrid->render(renderer);
SDL_RenderPresent(renderer);
}
void App::shutdown()
{
// Cleanup
SDL_Log("Destroying Renderer...");
SDL_DestroyRenderer(renderer);
SDL_Log("Destroyed Renderer!");
SDL_Log("Destroying Window...");
SDL_DestroyWindow(window);
SDL_Log("Destroyed Window!");
SDL_Log("Quitting SDL...");
SDL_Quit();
SDL_Log("SDL Quit!");
}