Space Fighter
A "shmup" game for Computer Programming C++
Loading...
Searching...
No Matches
Game.h
Go to the documentation of this file.
1
2/*
3 ██╗ ██╗ █████╗ ████████╗ █████╗ ███╗ ██╗ █████╗
4 ██║ ██╔╝ ██╔══██╗ ╚══██╔══╝ ██╔══██╗ ████╗ ██║ ██╔══██╗
5 █████╔╝ ███████║ ██║ ███████║ ██╔██╗ ██║ ███████║
6 ██╔═██╗ ██╔══██║ ██║ ██╔══██║ ██║╚██╗██║ ██╔══██║
7 ██║ ██╗ ██║ ██║ ██║ ██║ ██║ ██║ ╚████║ ██║ ██║
8 ╚═╝ ╚═╝ ╚═╝ ╚═╝/\ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝
9 /vvvvvvvvvvvvvvvvvvv \=========================================,
10 `^^^^^^^^^^^^^^^^^^^ /---------------------------------------"
11 Katana Engine \/ © 2012 - Shuriken Studios LLC
12 http://www.shurikenstudios.com
13*/
14
15#pragma once
16
17namespace KatanaEngine
18{
21 class Game
22 {
23
24 public:
25
26 Game();
27 virtual ~Game();
28
31 virtual int Run();
32
33
36 static int GetScreenWidth() { return s_screenWidth; }
37
40 static int GetScreenHeight() { return s_screenHeight; }
41
44 static Vector2 GetScreenCenter() { return (Vector2(s_screenWidth / 2, s_screenHeight / 2)); }
45
48 virtual std::string GetName() const = 0;
49
52 virtual ResourceManager *GetResourceManager() const { return m_pResourceManager; }
53
56 virtual ScreenManager *GetScreenManager() const { return m_pScreenManager; }
57
60 virtual SpriteBatch *GetSpriteBatch() const { return m_pSpriteBatch; }
61
65 virtual void LoadContent(ResourceManager& resourceManager) { }
66
69 virtual void UnloadContent() { }
70
73 virtual void Update(const GameTime& gameTime);
74
77 virtual void Draw(SpriteBatch& spriteBatch);
78
80 virtual void Quit() { m_isRunning = false; }
81
82
83 protected:
84
88 static void SetScreenResolution(int width, int height) { s_screenWidth = width; s_screenHeight = height; }
89
93 static void SetWindowTitle(std::string title) { s_windowTitle = title; }
94
97 virtual void SetResourceDirectory(const std::string &path) { m_pResourceManager->SetContentPath(path); }
98
101 virtual void SetTargetFramesPerSecond(int const frames);
102
105 virtual void SetFrameCounterFont(Font *pFont) { m_pFrameCounterFont = pFont; }
106
108 virtual void InitializeScreenManager() { m_pScreenManager = new ScreenManager(this); }
109
111 virtual void DisplayFrameRate();
112
114 virtual void SetFullScreen(bool isFullScreen) { m_isFullScreen = isFullScreen; }
115
117 virtual void SetOpenGLFlag() { m_requireOpenGL = true; }
118
120 virtual void ResetGameTime() { m_pGameTime = new GameTime(); }
121
122
123 private:
124
125 static int s_screenWidth;
126 static int s_screenHeight;
127
128 static std::string s_windowTitle;
129 static std::string s_contentDirectory;
130
131 bool m_isInitialized = false;
132 bool m_isRunning = false;
133 bool m_isFullScreen = false;
134 bool m_requireOpenGL = false;
135
136 double m_targetFramesPerSecond = 0;
137 double m_inverseTargetFrames = 0;
138 double m_actualFramesPerSec = 0;
139 double m_currentTime = 0;
140 double m_previousTime = 0;
141 float m_frameCounter = 0;
142
143 GameTime *m_pGameTime = nullptr;
144 InputState *m_pInput = nullptr;
145
146 SpriteBatch *m_pSpriteBatch = nullptr;
147
148 ScreenManager *m_pScreenManager = nullptr;
149 ResourceManager *m_pResourceManager = nullptr;
150
151 Font *m_pFrameCounterFont = nullptr;
152
153 bool IsRunning() const { return m_isRunning; }
154 };
155}
Represents a font or true-type font.
Definition Font.h:21
Base class for all games. Provides graphics initialization, game loop, and rendering code....
Definition Game.h:22
virtual std::string GetName() const =0
Gets the name of the game.
virtual void SetResourceDirectory(const std::string &path)
Sets the location of the directory where the game's resources are stored.
Definition Game.h:97
virtual int Run()
Runs the game instance.
Definition Game.cpp:86
virtual void ResetGameTime()
Resets the game's timing values.
Definition Game.h:120
static void SetWindowTitle(std::string title)
Sets the title of the game window.
Definition Game.h:93
virtual void DisplayFrameRate()
Displays the game's current frame rate.
Definition Game.cpp:195
static int GetScreenHeight()
Gets the screen width in pixels.
Definition Game.h:40
static int GetScreenWidth()
Gets the screen width in pixels.
Definition Game.h:36
virtual void SetFrameCounterFont(Font *pFont)
Sets the font for the frame counter.
Definition Game.h:105
virtual void SetTargetFramesPerSecond(int const frames)
Sets the target frame rate for the game.
Definition Game.cpp:243
virtual ScreenManager * GetScreenManager() const
Gets a pointer to the ScreenManager, for managing game screens.
Definition Game.h:56
virtual void UnloadContent()
Called when resources need to be unloaded. Override this method to unload any game-specific resources...
Definition Game.h:69
virtual void SetOpenGLFlag()
Sets the OpenGL flag, which forces OpenGL rendering.
Definition Game.h:117
virtual void Quit()
Quits the game.
Definition Game.h:80
virtual ~Game()
Definition Game.cpp:59
static Vector2 GetScreenCenter()
Gets the screen size in pixels.
Definition Game.h:44
virtual SpriteBatch * GetSpriteBatch() const
Gets a pointer to the SpriteBatch, for rendering.
Definition Game.h:60
virtual void Update(const GameTime &gameTime)
Called when the game has determined that game logic needs to be processed.
Definition Game.cpp:70
static void SetScreenResolution(int width, int height)
Sets the screen resolution.
Definition Game.h:88
virtual void LoadContent(ResourceManager &resourceManager)
Called when resources need to be loaded.
Definition Game.h:65
virtual void InitializeScreenManager()
Initializes the game's ScreenManager.
Definition Game.h:108
virtual void Draw(SpriteBatch &spriteBatch)
Called when the game determines it is time to draw a frame.
Definition Game.cpp:78
virtual ResourceManager * GetResourceManager() const
Gets a pointer to the ResourceManager, for loading and managing resources.
Definition Game.h:52
virtual void SetFullScreen(bool isFullScreen)
Sets the game to display in fullscreen mode.
Definition Game.h:114
Contains timing values for game updates and rendering.
Definition GameTime.h:21
Handles the state of multiple player input devices.
Definition InputState.h:22
Loads and manages the lifespan of objects from external files.
void SetContentPath(const std::string &path)
Sets the location of the folder where game resources are stored.
Updates, renders, and manages transitions between instances of the Screen class.
Enables a group of sprites to be drawn using the same settings.
Definition SpriteBatch.h:48
Defines a vector with 2 components (x and y).
Definition Vector2.h:21
Katana Engine is a library of classes, interfaces, and value types that provides a foundation for dev...
Definition Animation.cpp:18