-
Notifications
You must be signed in to change notification settings - Fork 0
/
TitleMenuState.cpp
109 lines (86 loc) · 2.11 KB
/
TitleMenuState.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
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
#include "TitleMenuState.h"
TitleMenuState::TitleMenuState()
{
stateName = "TitleMenu";
}
void TitleMenuState::Enter()
{
stateManager = this->GetStateManager();
resManager = stateManager->GetResourceManager();
screen = stateManager->GetGpuTarget();
//
// Load resources
//
// Font
fontSharedBig = resManager->GetSharedFontResourceIdByName("Data\\Fonts\\OpenSans-Regular-64.fnt");
// Button
buttonNewGame = new Button(stateManager, fontSharedBig, "New Game", 500.0f, 300.0f, true);
buttonOptions = new Button(stateManager, fontSharedBig, "Options", 500.0f, 400.0f, true);
buttonExit = new Button(stateManager, fontSharedBig, "Exit", 500.0f, 500.0f, true);
//
// Inputs
//
//keyEsc = false;
}
void TitleMenuState::Exit()
{
resManager->FreeResources();
fontSharedBig = 0;
if (buttonNewGame)
delete buttonNewGame;
buttonNewGame = nullptr;
if (buttonOptions)
delete buttonOptions;
buttonOptions = nullptr;
if (buttonExit)
delete buttonExit;
buttonExit = nullptr;
resManager = nullptr;
stateManager = nullptr;
screen = nullptr;
}
GotoState TitleMenuState::Update()
{
// **** INPUT ****
while (SDL_PollEvent(&e)) // e for event
{
if (e.type == SDL_QUIT)
{
return ToState::Quit;
}
// Check "New Game"
buttonNewGame->Event(e);
if (buttonNewGame->GetClick())
{
//menuSelection = 0;
return ToState::GameLoad;
}
// Check "Options"
buttonOptions->Event(e);
if (buttonOptions->GetClick())
{
//menuSelection = 0;
return ToState::Options;
}
// Check "Exit"
buttonExit->Event(e);
if (buttonExit->GetClick())
{
//menuSelection = 0;
return ToState::Quit;
}
}
// **** RENDER ****
// Clear the screen
GPU_Clear(screen);
//
resManager->GetSharedFontResource(fontSharedBig)->SetColor(160, 160, 160, 255);
resManager->GetSharedFontResource(fontSharedBig)->DrawText("TITLE MENU", 500.0f, 200.0f);
// Buttons
buttonNewGame->Draw();
buttonOptions->Draw();
buttonExit->Draw();
// Show the result in the window
GPU_Flip(screen);
return ToState::Run;
}