Skip to content

Commit

Permalink
feat: Add IntroStage
Browse files Browse the repository at this point in the history
Added a stage which can be used to display a logo or some
introduction text.
  • Loading branch information
ThePythonator committed Sep 16, 2024
1 parent c05fb43 commit e00ece0
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 4 deletions.
4 changes: 2 additions & 2 deletions include/game/Constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ namespace COLOURS {
}

namespace TIMINGS {

const float INTRO_OPEN_TIME = 4.0f;
}

namespace TRANSITIONS {
Expand Down Expand Up @@ -152,4 +152,4 @@ namespace BUTTONS {

namespace GAME {

}
}
14 changes: 14 additions & 0 deletions include/game/MenuStages.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
#pragma once

#include "BaseStage.hpp"
#include "Font.hpp"
#include "Timer.hpp"

#include "Constants.hpp"

#include "GameStages.hpp"

class IntroStage : public Framework::BaseStage {
public:
void start();

bool update(float dt);
void render();

private:
Framework::Timer intro_timer;
Framework::Text intro_text;
};

class TitleStage : public Framework::BaseStage {
public:
void start();
Expand Down
4 changes: 2 additions & 2 deletions src/game/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Game::Game() : BaseGame() {
}

void Game::start() {
stage = new TitleStage();
stage = new IntroStage();
}

void Game::end() {
Expand Down Expand Up @@ -64,4 +64,4 @@ void Game::clear_data() {
// Don't need to clear up graphics objects items - it's done for us in BaseGame

// Clear up anything else we need to
}
}
44 changes: 44 additions & 0 deletions src/game/MenuStages.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,49 @@
#include "MenuStages.hpp"

// IntroStage

void IntroStage::start() {
intro_text = Framework::Text(graphics_objects->font_ptrs[GRAPHICS_OBJECTS::FONTS::MAIN_FONT], "Some intro text", COLOURS::BLACK);

intro_timer.stop();

// Start transition
set_transition(graphics_objects->transition_ptrs[GRAPHICS_OBJECTS::TRANSITIONS::FADE_TRANSITION]);
transition->open();
}

bool IntroStage::update(float dt) {
transition->update(dt);
intro_timer.update(dt);

if (transition->is_open()) {
if (intro_timer.running()) {
if (intro_timer.time() >= TIMINGS::INTRO_OPEN_TIME) {
transition->close();
}
}
else {
intro_timer.reset();
intro_timer.start();
}
}
else if (transition->is_closed()) {
// Finish intro
finish(new TitleStage());
}

return true;
}

void IntroStage::render() {
graphics_objects->graphics_ptr->fill(COLOURS::BLUE);

// Display some intro text in the centre of the display
intro_text.render(WINDOW::SIZE_HALF);

transition->render();
}

// TitleStage

void TitleStage::start() {
Expand Down

0 comments on commit e00ece0

Please sign in to comment.