Space Fighter
A "shmup" game for Computer Programming C++
Loading...
Searching...
No Matches
Screen.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{
19 class ScreenManager;
20 class Screen;
21
27 typedef void(*OnExit)(Screen *pScreen);
28
36 typedef void(*OnRemove)(Screen *pScreen);
37
39 class Screen
40 {
41 friend class ScreenManager;
42
43 public:
44
45 Screen();
46 virtual ~Screen() { }
47
48
52 virtual void LoadContent(ResourceManager& resourceManager) { }
53
56 virtual void UnloadContent() { }
57
60 virtual void HandleInput(const InputState& input) { }
61
64 virtual void Update(const GameTime& gameTime) = 0;
65
68 virtual void Draw(SpriteBatch& spriteBatch) = 0;
69
72 virtual bool IsExiting() const { return m_isExiting; }
73
79 float GetAlpha() const { return m_transitionValue; }
80
83 virtual ScreenManager *GetScreenManager() { return m_pScreenManager; }
84
87 virtual Game *GetGame() const;
88
91 virtual void SetScreenManager(ScreenManager& screenManager);
92
94 virtual void Show();
95
101 virtual void Exit();
102
105 virtual void SetExitCallback(OnExit callback) { m_onExit = callback; }
106
110 virtual void SetRemoveCallback(OnRemove callback) { m_onRemove = callback; }
111
114 virtual double GetTransitionOutTime() const { return m_transitionOutTime; }
115
116
117 protected:
118
121 {
122 None,
123 In,
124 Out
125 };
126
130 virtual bool ShouldHandleInputBelow() { return false; }
131
136 virtual bool ShouldUpdateBelow() { return false; }
137
141 virtual bool ShouldDrawBelow() { return false; }
142
145 virtual void SetTransitionInTime(double seconds) { m_transitionInTime = seconds; }
146
149 virtual void SetTransitionOutTime(double seconds) { m_transitionOutTime = seconds; }
150
153 virtual double GetTransitionInTime() const { return m_transitionInTime; }
154
157 virtual ScreenTransition GetTransition() const { return m_transition; }
158
162 virtual float GetTransitionValue() const { return m_transitionValue; }
163
167 virtual bool NeedsToBeRemoved() const { return m_needsToBeRemoved; }
168
170 virtual void UseRenderTarget();
171
175 virtual RenderTarget *GetRenderTarget() const { return m_pRenderTarget; }
176
179 virtual Color GetRenderTargetColor() const { return Color::White * GetAlpha(); }
180
181
182 private:
183
184 void *m_onExit;
185 void *m_onRemove;
186
187 bool m_isExiting = false;
188
189 bool m_needsToBeRemoved;
190
191 double m_transitionInTime = 0;
192 double m_transitionOutTime = 0;
193
195
196 float m_transitionValue = 0;
197 double m_transitionTime = 0;
198
199 ScreenManager *m_pScreenManager = nullptr;
200
201 RenderTarget *m_pRenderTarget = nullptr;
202
203 void TransitionIn();
204 void TransitionOut();
205
206 void UpdateTransition(const GameTime& gameTime);
207 };
208}
Represents a four-component color using red, green, blue, and alpha data.
Definition Color.h:21
static const Color White
White.
Definition Color.h:201
Base class for all games. Provides graphics initialization, game loop, and rendering code....
Definition Game.h:22
Contains timing values for game updates and rendering.
Definition GameTime.h:21
Handles the state of multiple player input devices.
Definition InputState.h:22
Contains a 2D texture that can be used as a render target.
Loads and manages the lifespan of objects from external files.
Base class for all game screens and menus.
Definition Screen.h:40
virtual bool ShouldUpdateBelow()
Checks if the screen manager should call Update on the screen below this one.
Definition Screen.h:136
virtual ScreenManager * GetScreenManager()
Gets a pointer to the ScreenManager, for managing game screens.
Definition Screen.h:83
virtual void Draw(SpriteBatch &spriteBatch)=0
Called when the game determines it is time to draw a frame.
virtual bool ShouldDrawBelow()
Checks if the screen manager should call Draw on the screen below this one.
Definition Screen.h:141
virtual void LoadContent(ResourceManager &resourceManager)
Called when resources need to be loaded.
Definition Screen.h:52
virtual void Update(const GameTime &gameTime)=0
Called when the game has determined that screen logic needs to be processed.
virtual bool NeedsToBeRemoved() const
Determines if the screen has completely faded out and needs to be removed by the ScreenManager.
Definition Screen.h:167
virtual void UnloadContent()
Called when resources need to be unloaded. Override this method to unload any screen-specific resourc...
Definition Screen.h:56
virtual ~Screen()
Definition Screen.h:46
virtual double GetTransitionInTime() const
Get the time in seconds that the screen will transition in.
Definition Screen.h:153
virtual void SetExitCallback(OnExit callback)
Sets the callback function for when the Exit() is called.
Definition Screen.h:105
virtual void UseRenderTarget()
Forces all screen rendering to a render target.
Definition Screen.cpp:127
virtual Color GetRenderTargetColor() const
Get the color that will be used to tint the render target.
Definition Screen.h:179
virtual ScreenTransition GetTransition() const
Get the current transition state of the screen.
Definition Screen.h:157
virtual float GetTransitionValue() const
Get the interpolated value (between zero and one) of the screen transition.
Definition Screen.h:162
virtual Game * GetGame() const
Gets a pointer to the Game.
Definition Screen.cpp:122
virtual RenderTarget * GetRenderTarget() const
Get screen's render target.
Definition Screen.h:175
virtual void HandleInput(const InputState &input)
Called when the game has determined that player input needs to be processed.
Definition Screen.h:60
float GetAlpha() const
Gets the overall screen transition alpha value (or opacity). This is handy for fading screens in and ...
Definition Screen.h:79
virtual void SetTransitionInTime(double seconds)
Set the time in seconds that the screen should transition in.
Definition Screen.h:145
virtual void Show()
Tells the screen to transition in.
Definition Screen.cpp:90
virtual double GetTransitionOutTime() const
Get the time in seconds that the screen will transition out.
Definition Screen.h:114
virtual void Exit()
Tells the screen to transition out. When the screen has completed its transition, UnloadContent() wil...
Definition Screen.cpp:95
virtual void SetTransitionOutTime(double seconds)
Set the time in seconds that the screen should transition out.
Definition Screen.h:149
virtual bool IsExiting() const
Determines if the screen is currently exiting.
Definition Screen.h:72
ScreenTransition
Defines the state of the transition between screens.
Definition Screen.h:121
@ None
The screen is not transitioning.
@ Out
The screen is transitioning out.
@ In
The screen is transitioning in.
virtual void SetScreenManager(ScreenManager &screenManager)
Gets a pointer to the ScreenManager, for managing game screens.
Definition Screen.cpp:85
virtual void SetRemoveCallback(OnRemove callback)
Sets the callback function for when the screen is about to be removed by the screen manager.
Definition Screen.h:110
virtual bool ShouldHandleInputBelow()
Checks if the screen manager should call HandleInput on the screen below this one.
Definition Screen.h:130
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
Katana Engine is a library of classes, interfaces, and value types that provides a foundation for dev...
Definition Animation.cpp:18
void(* OnRemove)(Screen *pScreen)
Callback function for when a screen has completely exited and is about to be removed by the screen ma...
Definition Screen.h:36
void(* OnExit)(Screen *pScreen)
Callback function for when Exit() is called on a screen and it begins to transition out.
Definition Screen.h:27