-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_window.cpp
More file actions
55 lines (41 loc) · 1.34 KB
/
Copy pathmain_window.cpp
File metadata and controls
55 lines (41 loc) · 1.34 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
#include "main_window.h"
main_window::main_window(const char* main_window_title, int main_window_width, int mainwindow_height, SDL_Event *main_event) :
mainWin_width(main_window_width), mainWin_height(mainwindow_height), mainWin_event(main_event)
{
// ===== window and renderer init =====
mainWin_window = SDL_CreateWindow(main_window_title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, mainWin_width, mainWin_height, SDL_WINDOW_SHOWN);
mainWin_renderer = SDL_CreateRenderer(mainWin_window, -1, SDL_RENDERER_ACCELERATED);
SDL_SetRenderDrawColor(mainWin_renderer, 255, 255, 255, 255);
// ===== isRun =====
win_isRun = true;
// ===== game obj =====
gSm = new game_state_machine(mainWin_renderer, mainWin_event, &win_isRun, mainWin_width, mainWin_height);
}
main_window::~main_window()
{
// ===== clean thing in class main_window =====
SDL_DestroyRenderer(mainWin_renderer);
SDL_DestroyWindow(mainWin_window);
mainWin_event = NULL;
// ===== clean obj =====
delete gSm;
}
void main_window::render(){
gSm->render();
}
void main_window::handle(){
// ===== check States =====
gSm->changeState();
// ===== event procs =====
if (SDL_PollEvent(mainWin_event)){
gSm->handle();
}
}
void main_window::update(){
gSm->update();
}
void main_window::RUN(){
render();
handle();
update();
}