Skip to content

Commit

Permalink
Merge pull request #8 from ThePythonator/chore/merge-changes-from-ssbr
Browse files Browse the repository at this point in the history
Chore: Merge changes from SSB:R
  • Loading branch information
ThePythonator authored Sep 16, 2024
2 parents 25c557a + e291f43 commit 8b12447
Show file tree
Hide file tree
Showing 12 changed files with 199 additions and 118 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ set(GAME_SOURCES
"Application.cpp"
"Game.cpp"

"Stages.cpp"
"MenuStages.cpp"
"GameStages.cpp"
)

# To be used instead of set(GAME_SOURCES ...)
Expand Down
1 change: 1 addition & 0 deletions include/framework/BaseStage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace Framework {
// Called when stage stops being the current stage
virtual void end();

// Returns false if the application should close
virtual bool update(float dt) = 0;
virtual void render() = 0;

Expand Down
2 changes: 1 addition & 1 deletion include/framework/File.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace Framework {
// This shouldn't ever be needed, so it isn't implemented
//void write(std::string filepath, TMX data, TMXFormat file_format = TMXFormat::AUTO);

/// Determines the Tiled level file format from the file name
// Determines the Tiled level file format from the file name
TMXFormat get_format(std::string filepath);

// Changes the null tile index from 0 to the value specified, reducing all other indices by 1
Expand Down
3 changes: 3 additions & 0 deletions include/framework/Maths.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ namespace Framework {
vec2 size;
};

Rect operator*(const Rect& r, const float s);
Rect operator*(const float s, const Rect& r);

extern const Rect RECT_NULL;

bool colliding(Rect a, vec2 b);
Expand Down
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 {

}
}
2 changes: 1 addition & 1 deletion include/game/Game.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "BaseGame.hpp"

#include "Stages.hpp"
#include "MenuStages.hpp"

#include "FadeTransition.hpp"

Expand Down
13 changes: 2 additions & 11 deletions include/game/Stages.hpp → include/game/GameStages.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,7 @@

#include "Constants.hpp"

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

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

private:
Framework::Timer _timer;
};
#include "MenuStages.hpp"

class GameStage : public Framework::BaseStage {
public:
Expand All @@ -34,4 +25,4 @@ class PausedStage : public Framework::BaseStage {

private:
BaseStage* _background_stage;
};
};
32 changes: 32 additions & 0 deletions include/game/MenuStages.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#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();

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

private:
Framework::Timer _timer;
};
8 changes: 8 additions & 0 deletions src/framework/Maths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ namespace Framework {
return position + size;
}

Rect operator*(const Rect& r, const float s) {
return Rect(r.position * s, r.size * s);
}

Rect operator*(const float s, const Rect & r) {
return r * s;
}

bool colliding(Rect a, vec2 b) {
return b.x >= a.position.x && b.x <= a.position.x + a.size.x &&
b.y >= a.position.y && b.y <= a.position.y + a.size.y;
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
}
}
100 changes: 100 additions & 0 deletions src/game/GameStages.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#include "GameStages.hpp"

// GameStage

void GameStage::start() {
// Set transition
set_transition(graphics_objects->transition_ptrs[GRAPHICS_OBJECTS::TRANSITIONS::FADE_TRANSITION]);

// Start transition
transition->open();
}

bool GameStage::update(float dt) {
transition->update(dt);

if (input->just_down(Framework::KeyHandler::Key::ESCAPE) || input->just_down(Framework::KeyHandler::Key::P)) {
finish(new PausedStage(this), false);
}

return true;
}

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

graphics_objects->spritesheet_ptrs[GRAPHICS_OBJECTS::SPRITESHEETS::MAIN_SPRITESHEET]->sprite(0, Framework::Vec(128, 64));

transition->render();
}

// PausedStage

PausedStage::PausedStage(BaseStage* background_stage) : BaseStage() {
// Save the background stage so we can still render it, and then go back to it when done
_background_stage = background_stage;
}

void PausedStage::start() {
// Create buttons
buttons.clear();
buttons.emplace_back(
Framework::Rect(WINDOW::SIZE_HALF - Framework::Vec(128, 32), Framework::Vec(256, 64)),
graphics_objects->button_image_groups[GRAPHICS_OBJECTS::BUTTON_IMAGE_GROUPS::STANDARD],
Framework::Text(graphics_objects->font_ptrs[GRAPHICS_OBJECTS::FONTS::MAIN_FONT], "Resume", COLOURS::BLACK, 4.0f),
BUTTONS::PAUSED::RESUME
);
buttons.emplace_back(
Framework::Rect(WINDOW::SIZE_HALF - Framework::Vec(128, -64), Framework::Vec(256, 64)),
graphics_objects->button_image_groups[GRAPHICS_OBJECTS::BUTTON_IMAGE_GROUPS::STANDARD],
Framework::Text(graphics_objects->font_ptrs[GRAPHICS_OBJECTS::FONTS::MAIN_FONT], "Exit", COLOURS::BLACK, 4.0f),
BUTTONS::PAUSED::EXIT
);

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

bool PausedStage::update(float dt) {
transition->update(dt);

if (input->just_down(Framework::KeyHandler::Key::ESCAPE) || input->just_down(Framework::KeyHandler::Key::P)) {
transition->close();
}

// Update buttons
for (Framework::Button& button : buttons) {
button.update(input);

if (button.pressed() && transition->is_open()) {
button_selected = button.get_id();
transition->close();
}
}

if (transition->is_closed()) {
if (button_selected == BUTTONS::PAUSED::EXIT) {
finish(new TitleStage());
}
else {
// Return to game (exit pause)
finish(_background_stage);
}
}

return true;
}

void PausedStage::render() {
// Render background stage
_background_stage->render();

// Render pause menu
graphics_objects->graphics_ptr->fill(COLOURS::BLACK, 0x7f);

for (const Framework::Button& button : buttons) {
button.render();
}

transition->render();
}
Loading

0 comments on commit 8b12447

Please sign in to comment.