-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameScene.h
140 lines (112 loc) · 2.94 KB
/
GameScene.h
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
#pragma once
#include <iostream>
#include <string>
#include "Window.h"
#include "FrameTimer.h"
#include "KeyboardInput.h"
#include "MusicPlayer.h"
#include "ScreenBuffer.h"
class GameObject;
class GameScene
{
public:
GameScene()
: m_stdWindow(GetStdHandle(STD_OUTPUT_HANDLE))
{ };
virtual ~GameScene()
{
delete m_backBuffer;
delete m_frontBuffer;
// restore the screen buffer to the standard output.
SetConsoleActiveScreenBuffer(GetStdHandle(STD_OUTPUT_HANDLE));
}
virtual void initaliseGame ( int lastGameSceneResponse );
void gameLoop ( );
virtual int loadNextScene ( std::shared_ptr<GameScene> & newScene, bool & loadAdditively ) = 0;
void quit ( );
KeyboardInput m_keyboardInput;
/// <summary>
/// The length of time in seconds that the game has been running for.
/// </summary>
inline const float getGameTime() const
{
return m_gameTime;
}
/// <summary>
/// The length of time in seconds that the previous frame took to be completed.
/// </summary>
inline const float getDeltaTime() const
{
return m_deltaTime;
}
/// <summary>
/// The length of time in milliseconds that the previous frame took to be completed.
/// </summary>
inline const float getDeltaTimeMs() const
{
return m_deltaTimeMs;
}
inline const int getScreenWidth ( ) const
{
return m_stdWindow.getWidth ( );
}
inline const int getScreenHeight ( ) const
{
return m_stdWindow.getHeight ( );
}
inline const int getFrameCount() const
{
return m_frameCount;
}
protected:
virtual void initaliseLevel() = 0;
virtual void processInput ( );
virtual void updateGame ( );
virtual void drawGame ( ) = 0;
/// <summary>
/// Helper method that takes in the pointer to an array of GameObjects
/// and the number of objects in the array.
/// Each active object is then rendered to the back buffer.
/// </summary>
template< class GameObject >
void drawObjectsInArray ( GameObject * objects, size_t count )
{
for ( int i = 0; i < count; i++ )
{
GameObject & gObject = objects [ i ];
if ( !gObject.getActive ( ) )
{
continue;
}
drawGameObject ( gObject );
}
}
void drawGameObject ( const GameObject & object );
bool m_runLoop = false;
FrameTimer m_frameTimer;
MusicPlayer m_musicPlayer;
/// <summary>
/// This screen buffer pointed to by m_backBuffer
/// will never be the active console buffer.
/// </summary>
ScreenBuffer* m_backBuffer = nullptr;
private:
void renderFrame ( );
void quitKeyPressed ( );
/// <summary>
/// The length of time in seconds that the game has been running for.
/// </summary>
float m_gameTime = 0;
/// <summary>
/// The length of time in seconds that the previous frame took to be completed.
/// </summary>
float m_deltaTime = 0;
/// <summary>
/// The length of time in milliseconds that the previous frame took to be completed.
/// </summary>
float m_deltaTimeMs = 0;
int m_frameCount = 0;
bool isInitialised = false;
ScreenBuffer* m_frontBuffer = nullptr;
Window m_stdWindow;
};