-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainGame.cpp
143 lines (110 loc) · 2.65 KB
/
MainGame.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
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
138
139
140
141
142
143
#include "MainGame.h"
#include "GameState.h"
MainGame::MainGame(string title, int w, int h, int bpp, int fps)
{
mWinName = title;
mAppRunning = true;
mWinHeight = h;
mWinWidth = w;
mWinBPP = bpp;
mAppFrameRateLimit = fps;
mFontSize = 15.0f;
mGreen.r = 66;
mGreen.g = 235;
mGreen.b = 14;
mPosX = 10;
mPosY = 10;
mPosX2 = mWinWidth - 10;
mPosY2 = 10;
mScore1s.SetPosition(mPosX, mPosY);
mScore2s.SetPosition(mPosX2, mPosY2);
}
// Initializes the Window
bool MainGame::Init()
{
mAppWindowSettings.DepthBits = 0; // Request a 24 bits depth buffer
mAppWindowSettings.StencilBits = 0; // Request a 8 bits stencil buffer
mAppWindowSettings.AntialiasingLevel = 0; // Request 2 levels of antialiasing
mAppWindow.Create(sf::VideoMode(mWinWidth, mWinHeight, mWinBPP), mWinName, sf::Style::Close, mAppWindowSettings);
mAppWindow.SetFramerateLimit(mAppFrameRateLimit);
if(!mFontType.LoadFromFile("data\\fonts\\visitor2.ttf"))
{
//error
}
mScore1s.SetFont(mFontType);
mScore1s.SetSize(mFontSize);
mScore1s.SetColor(mGreen);
mScore2s.SetFont(mFontType);
mScore2s.SetSize(mFontSize);
mScore2s.SetColor(mGreen);
return true;
}
void MainGame::Cleanup()
{
cout << "[ ] Entering Cleanup" << endl;
}
void MainGame::ChangeState(GameState *newState)
{
// cleans current state first
if( !mGameState.empty() )
{
mGameState.back()->Cleanup();
mGameState.pop_back();
}
// then add out new state
mGameState.push_back(newState);
mGameState.back()->Init(this); // and start it
}
void MainGame::PushState(GameState *newState)
{
// if we want to pause a state
// or if we want to kill the state.
if( !mGameState.empty() )
{
mGameState.back()->Pause();
}
// add new state in back of the line
// and start it.
mGameState.push_back(newState);
mGameState.back()->Init(this);
}
void MainGame::PopState()
{
// clean the current state
// and removes it.
if( !mGameState.empty() )
{
mGameState.back()->Cleanup();
mGameState.pop_back();
}
// after cleanup and deletion if there
// are still other states then
// resume it.
if( !mGameState.empty() )
{
mGameState.back()->Resume();
}
}
void MainGame::Quit()
{
mAppRunning = false;
}
void MainGame::OnEvent()
{
while( mAppWindow.GetEvent(mAppEvent) )
{
mGameState.back()->OnEvent(this, mAppEvent);
}
}
void MainGame::OnUpdate()
{
mGameState.back()->OnUpdate(this);
}
void MainGame::OnDraw()
{
mGameState.back()->Draw(this);
}
bool MainGame::isRunning()
{
return mAppRunning;
}