Space Fighter
A "shmup" game for Computer Programming C++
Loading...
Searching...
No Matches
GameplayScreen.cpp
Go to the documentation of this file.
1
2#include "GameplayScreen.h"
3#include "MainMenuScreen.h"
4#include "Level.h"
5#include "Level01.h"
6
7// Callback function
8
12{
13 pScreen->GetScreenManager()->AddScreen(new MainMenuScreen());
14}
15
16
17GameplayScreen::GameplayScreen(const int levelIndex)
18{
19 m_levelIndex = levelIndex;
20
23
25
26 Show();
27}
28
30{
31 m_pResourceManager = &resourceManager;
32 LoadLevel(m_levelIndex);
33}
34
35void GameplayScreen::LoadLevel(const int levelIndex)
36{
37 if (m_pLevel) delete m_pLevel;
38
39 switch (levelIndex)
40 {
41 case 0: m_pLevel = new Level01(); break;
42 }
43
44 m_pLevel->SetGameplayScreen(this);
45 m_pLevel->LoadContent(*m_pResourceManager);
46}
47
49{
50 m_pLevel->HandleInput(input);
51}
52
53void GameplayScreen::Update(const GameTime& gameTime)
54{
55 m_pLevel->Update(gameTime);
56}
57
59{
60 spriteBatch.Begin();
61
62 m_pLevel->Draw(spriteBatch);
63
64 spriteBatch.End();
65}
void OnGameplayScreenRemoved(Screen *pScreen)
Callback function for when the gameplay screen is removed from the screen manager.
virtual void Draw(SpriteBatch &spriteBatch)
Render the screen.
GameplayScreen(const int levelIndex=0)
Instantiate a gameplay screen object.
virtual void LoadLevel(const int levelIndex)
Load a specific level.
virtual void Update(const GameTime &gameTime)
Update the screen.
virtual void LoadContent(ResourceManager &resourceManager)
Load the content for the screen.
virtual void HandleInput(const InputState &input)
Handle input for the screen.
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.
Base class for all game screens and menus.
Definition Screen.h:40
virtual ScreenManager * GetScreenManager()
Gets a pointer to the ScreenManager, for managing game screens.
Definition Screen.h:83
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 void SetTransitionOutTime(double seconds)
Set the time in seconds that the screen should transition out.
Definition Screen.h:149
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 void AddScreen(Screen *pScreen)
Add a screen to be managed.
Enables a group of sprites to be drawn using the same settings.
Definition SpriteBatch.h:48
void Begin(const SpriteSortMode sortMode=SpriteSortMode::Deferred, const BlendState blendState=BlendState::Alpha, ALLEGRO_TRANSFORM *pTransformation=NULL)
Begins a sprite batch operation.
void End()
Flushes the sprite batch and restores the device state to how it was before Begin was called.
The first level of the game.
Definition Level01.h:7
virtual void Draw(SpriteBatch &spriteBatch)
Render the level, and all of the game objects within it.
Definition Level.cpp:243
virtual void LoadContent(ResourceManager &resourceManager)
Load the content for the level, including game objects and resources.
Definition Level.cpp:88
virtual void SetGameplayScreen(GameplayScreen *pGameplayScreen)
Set a reference to the gameplay screen.
Definition Level.h:55
virtual void Update(const GameTime &gameTime)
Update the level.
Definition Level.cpp:118
virtual void HandleInput(const InputState &input)
Handle input for the level.
Definition Level.cpp:110
The main menu screen for the game.