Space Fighter
A "shmup" game for Computer Programming C++
Loading...
Searching...
No Matches
Screen.cpp
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#include "KatanaEngine.h"
16
17namespace KatanaEngine
18{
20 {
21 m_isExiting = false;
22 m_needsToBeRemoved = false;
23
24 m_transitionInTime = 0.0;
25 m_transitionOutTime = 0.0;
26
27 m_pScreenManager = nullptr;
28
29 m_transition = ScreenTransition::None;
30
31 m_pRenderTarget = nullptr;
32
33 m_transitionValue = 0.0f;
34
35 m_onExit = nullptr;
36 m_onRemove = nullptr;
37 }
38
39 void Screen::UpdateTransition(const GameTime& gameTime)
40 {
41 if (m_transition != ScreenTransition::None)
42 {
43 m_transitionTime -= gameTime.GetElapsedTime();
44
45 if (m_transition == ScreenTransition::In)
46 {
47 if (m_transitionInTime > 0)
48 {
49 m_transitionValue = 1 - (float)m_transitionTime / (float)m_transitionInTime;
50 }
51 else
52 {
53 m_transitionValue = 1;
54 }
55 }
56
57 if (m_transition == ScreenTransition::Out)
58 {
59 if (m_transitionOutTime > 0)
60 {
61 m_transitionValue = (float)m_transitionTime / (float)m_transitionOutTime;
62 }
63 else
64 {
65 m_transitionValue = 0;
66 }
67 }
68
69 if (m_transitionValue < 0) m_transitionValue = 0;
70 if (m_transitionValue > 1) m_transitionValue = 1;
71
72 if (m_transitionTime <= 0)
73 {
74 m_transitionTime = 0;
75 m_transition = ScreenTransition::None;
76
77 if (m_isExiting)
78 {
79 m_needsToBeRemoved = true;
80 }
81 }
82 }
83 }
84
86 {
87 m_pScreenManager = &screenManager;
88 }
89
91 {
92 TransitionIn();
93 }
94
96 {
97 m_isExiting = true;
98
99 TransitionOut();
100
101 if (m_onExit) ((OnExit)m_onExit)(this);
102 }
103
104 void Screen::TransitionIn()
105 {
106 if (m_transition == ScreenTransition::None)
107 {
108 m_transitionTime = m_transitionInTime;
109 m_transition = ScreenTransition::In;
110 }
111 }
112
113 void Screen::TransitionOut()
114 {
115 if (m_transition == ScreenTransition::None)
116 {
117 m_transitionTime = m_transitionOutTime;
118 m_transition = ScreenTransition::Out;
119 }
120 }
121
123 {
124 return m_pScreenManager->GetGame();
125 }
126
128 {
129 m_pRenderTarget = new RenderTarget(Game::GetScreenWidth(), Game::GetScreenHeight());
130 }
131}
Base class for all games. Provides graphics initialization, game loop, and rendering code....
Definition Game.h:22
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
Contains timing values for game updates and rendering.
Definition GameTime.h:21
double GetElapsedTime() const
Gets the time in seconds since last frame.
Definition GameTime.h:30
Contains a 2D texture that can be used as a render target.
virtual void UseRenderTarget()
Forces all screen rendering to a render target.
Definition Screen.cpp:127
virtual Game * GetGame() const
Gets a pointer to the Game.
Definition Screen.cpp:122
virtual void Show()
Tells the screen to transition in.
Definition Screen.cpp:90
virtual void Exit()
Tells the screen to transition out. When the screen has completed its transition, UnloadContent() wil...
Definition Screen.cpp:95
@ 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
Updates, renders, and manages transitions between instances of the Screen class.
Game * GetGame() const
Gets a pointer to the Game.
Katana Engine is a library of classes, interfaces, and value types that provides a foundation for dev...
Definition Animation.cpp:18
void(* OnExit)(Screen *pScreen)
Callback function for when Exit() is called on a screen and it begins to transition out.
Definition Screen.h:27