Arcade Shooter
Screen.h
1 /* --------------------------------------------------------------- /
2 
3  ██╗ ██╗ █████╗ ████████╗ █████╗ ███╗ ██╗ █████╗
4  ██║ ██╔╝ ██╔══██╗ ╚══██╔══╝ ██╔══██╗ ████╗ ██║ ██╔══██╗
5  █████╔╝ ███████║ ██║ ███████║ ██╔██╗ ██║ ███████║
6  ██╔═██╗ ██╔══██║ ██║ ██╔══██║ ██║╚██╗██║ ██╔══██║
7  ██║ ██╗ ██║ ██║ ██║ ██║ ██║ ██║ ╚████║ ██║ ██║
8  ╚═╝ ╚═╝ ╚═╝ ╚═╝/\ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝
9  /vvvvvvvvvvvvvvvvvvv \=========================================,
10  `^^^^^^^^^^^^^^^^^^^ /---------------------------------------"
11  Katana Engine \/ © 2012 - Shuriken Studios LLC
12 
13 / --------------------------------------------------------------- */
14 
15 #pragma once
16 
17 namespace 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 *pResourceManager) { }
53 
56  virtual void UnloadContent() { }
57 
60  virtual void HandleInput(const InputState *pInput) { }
61 
64  virtual void Update(const GameTime *pGameTime) = 0;
65 
68  virtual void Draw(SpriteBatch *pSpriteBatch) = 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 ParticleManager *GetParticleManager() const;
92 
95  virtual void SetScreenManager(ScreenManager *pScreenManager);
96 
98  virtual void Show();
99 
105  virtual void Exit();
106 
109  virtual void SetExitCallback(OnExit callback) { m_onExit = callback; }
110 
114  virtual void SetRemoveCallback(OnRemove callback) { m_onRemove = callback; }
115 
118  virtual double GetTransitionOutTime() const { return m_transitionOutTime; }
119 
120 
121  protected:
122 
124  enum class ScreenTransition
125  {
126  NONE,
127  IN,
128  OUT
129  };
130 
131 
137  virtual void SetPassthroughFlags(const bool draw = false, const bool update = false, const bool handleInput = false);
138 
141  virtual void SetTransitionInTime(double seconds) { m_transitionInTime = seconds; }
142 
145  virtual void SetTransitionOutTime(double seconds) { m_transitionOutTime = seconds; }
146 
149  virtual double GetTransitionInTime() const { return m_transitionInTime; }
150 
153  virtual ScreenTransition GetTransition() const { return m_transition; }
154 
158  virtual float GetTransitionValue() const { return m_transitionValue; }
159 
163  virtual bool NeedsToBeRemoved() const { return m_needsToBeRemoved; }
164 
166  virtual void UseRenderTarget();
167 
171  virtual RenderTarget *GetRenderTarget() const { return m_pRenderTarget; }
172 
175  virtual Color GetRenderTargetColor() const { return Color::White * GetAlpha(); }
176 
177 
178  private:
179 
180  void *m_onExit;
181  void *m_onRemove;
182 
183  bool m_handleInputBelow;
184  bool m_updateBelow;
185  bool m_drawBelow;
186  bool m_isExiting;
187 
188  bool m_needsToBeRemoved;
189 
190  double m_transitionInTime;
191  double m_transitionOutTime;
192 
193  ScreenTransition m_transition;
194 
195  float m_transitionValue;
196  double m_transitionTime;
197 
198  ScreenManager *m_pScreenManager;
199 
200  RenderTarget *m_pRenderTarget;
201 
202  void TransitionIn();
203  void TransitionOut();
204 
205  void UpdateTransition(const GameTime *pGameTime);
206 
207  bool UpdateBelow() const { return m_updateBelow; }
208  bool DrawBelow() const { return m_drawBelow; }
209  bool HandleInputBelow() const { return m_handleInputBelow; }
210 
211  };
212 }
virtual RenderTarget * GetRenderTarget() const
Get screen's render target.
Definition: Screen.h:171
The screen is not transitioning.
virtual ScreenManager * GetScreenManager()
Gets a pointer to the ScreenManager, for managing game screens.
Definition: Screen.h:83
Updates, renders, and manages transitions between instances of the Screen class.
Definition: ScreenManager.h:22
ScreenTransition
Defines the state of the transition between screens.
Definition: Screen.h:124
virtual void UnloadContent()
Called when resources need to be unloaded. Override this method to unload any screen-specific resourc...
Definition: Screen.h:56
Contains a 2D texture that can be used as a render target.
Definition: RenderTarget.h:17
Base class for all game screens and menus.
Definition: Screen.h:39
virtual void Exit()
Tells the screen to transition out. When the screen has completed its transition, UnloadContent() wil...
Definition: Screen.cpp:97
void(* OnExit)(Screen *pScreen)
Callback function for when Exit() is called on a screen and it begins to transition out...
Definition: Screen.h:27
static const Color White
White.
Definition: Color.h:198
Contains timing values for game updates and rendering.
Definition: GameTime.h:17
Handles the state of multiple player input devices.
Definition: InputState.h:18
virtual void LoadContent(ResourceManager *pResourceManager)
Called when resources need to be loaded.
Definition: Screen.h:52
Manages the active particles in a particle system.
Definition: ParticleManager.h:18
virtual bool IsExiting() const
Determines if the screen is currently exiting.
Definition: Screen.h:72
virtual void Show()
Tells the screen to transition in.
Definition: Screen.cpp:92
virtual double GetTransitionInTime() const
Get the time in seconds that the screen will transition in.
Definition: Screen.h:149
virtual void Update(const GameTime *pGameTime)=0
Called when the game has determined that screen logic needs to be processed.
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
Represents a four-component color using red, green, blue, and alpha data.
Definition: Color.h:17
virtual Color GetRenderTargetColor() const
Get the color that will be used to tint the render target.
Definition: Screen.h:175
virtual Game * GetGame() const
Gets a pointer to the Game.
Definition: Screen.cpp:124
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:114
virtual void SetExitCallback(OnExit callback)
Sets the callback function for when the Exit() is called.
Definition: Screen.h:109
virtual void SetTransitionInTime(double seconds)
Set the time in seconds that the screen should transition in.
Definition: Screen.h:141
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 SetPassthroughFlags(const bool draw=false, const bool update=false, const bool handleInput=false)
Sets the flags that determine if the underlaying screen should handle input, update, and/or render.
Definition: Screen.cpp:134
Base class for all games. Provides graphics initialization, game loop, and rendering code...
Definition: Game.h:18
virtual void SetScreenManager(ScreenManager *pScreenManager)
Gets a pointer to the ScreenManager, for managing game screens.
Definition: Screen.cpp:87
virtual void HandleInput(const InputState *pInput)
Called when the game has determined that player input needs to be processed.
Definition: Screen.h:60
virtual void Draw(SpriteBatch *pSpriteBatch)=0
Called when the game determines it is time to draw a frame.
virtual ParticleManager * GetParticleManager() const
Gets a pointer to the ParticleManager, for creating and managing particles.
Definition: Screen.cpp:129
virtual double GetTransitionOutTime() const
Get the time in seconds that the screen will transition out.
Definition: Screen.h:118
Enables a group of sprites to be drawn using the same settings.
Definition: SpriteBatch.h:44
The screen is transitioning out.
The screen is transitioning in.
virtual void SetTransitionOutTime(double seconds)
Set the time in seconds that the screen should transition out.
Definition: Screen.h:145
Loads and manages the lifespan of objects from external files.
Definition: ResourceManager.h:17
virtual bool NeedsToBeRemoved() const
Determines if the screen has completely faded out and needs to be removed by the ScreenManager.
Definition: Screen.h:163
virtual void UseRenderTarget()
Forces all screen rendering to a render target.
Definition: Screen.cpp:141
virtual ScreenTransition GetTransition() const
Get the current transition state of the screen.
Definition: Screen.h:153
virtual float GetTransitionValue() const
Get the interpolated value (between zero and one) of the screen transition.
Definition: Screen.h:158
Katana Engine is a library of classes, interfaces, and value types that provides a foundation for dev...
Definition: Animation.cpp:14