-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.h
106 lines (81 loc) · 2.95 KB
/
game.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
// Programming 2D Games
// Copyright (c) 2011 by:
// Charles Kelly
// Chapter 7 game.h v1.0
#ifndef _GAME_H // Prevent multiple definitions if this
#define _GAME_H // file is included in more than one place
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <Mmsystem.h>
#include "graphics.h"
#include "input.h"
#include "audio.h"
#include "constants.h"
#include "gameError.h"
class Game
{
protected:
// common game properties
Graphics *graphics; // pointer to Graphics
Input *input; // pointer to Input
Audio *audio; // pointer to Audio
HWND hwnd; // window handle
HRESULT hr; // standard return type
LARGE_INTEGER timeStart; // Performance Counter start value
LARGE_INTEGER timeEnd; // Performance Counter end value
LARGE_INTEGER timerFreq; // Performance Counter frequency
float frameTime; // time required for last frame
float fps; // frames per second
DWORD sleepTime; // number of milli-seconds to sleep between frames
bool paused; // true if game is paused
bool initialized;
public:
// Constructor
Game();
// Destructor
virtual ~Game();
// Member functions
// Window message handler
LRESULT messageHandler( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );
// Initialize the game
// Pre: hwnd is handle to window
virtual void initialize(HWND hwnd);
// Call run repeatedly by the main message loop in WinMain
virtual void run(HWND);
// Call when the graphics device was lost.
// Release all reserved video memory so graphics device may be reset.
virtual void releaseAll();
// Recreate all surfaces and reset all entities.
virtual void resetAll();
// Delete all reserved memory.
virtual void deleteAll();
// Render game items.
virtual void renderGame();
// Handle lost graphics device
virtual void handleLostGraphicsDevice();
// Set display mode (fullscreen, window or toggle)
void setDisplayMode(graphicsNS::DISPLAY_MODE mode = graphicsNS::TOGGLE);
// Return pointer to Graphics.
Graphics* getGraphics() {return graphics;}
// Return pointer to Input.
Input* getInput() {return input;}
// Exit the game
void exitGame() {PostMessage(hwnd, WM_DESTROY, 0, 0);}
// Return pointer to Audio.
Audio* getAudio() {return audio;}
// Pure virtual function declarations
// These functions MUST be written in any class that inherits from Game
// Update game items.
virtual void update() = 0;
// Perform AI calculations.
virtual void ai() = 0;
// Check for collisions.
virtual void collisions() = 0;
// Render graphics.
// Call graphics->spriteBegin();
// draw sprites
// Call graphics->spriteEnd();
// draw non-sprites
virtual void render() = 0;
};
#endif