Deux Ex Machina
This commit is contained in:
@@ -47,6 +47,6 @@ private:
|
||||
bool m_IsRightMouseDown {};
|
||||
|
||||
|
||||
bool m_ImGui{ true };
|
||||
bool m_ImGui{ false };
|
||||
|
||||
};
|
||||
|
||||
@@ -533,6 +533,7 @@
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<LinkCompiled>true</LinkCompiled>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Gui\Screens\GameOver\GameOverScreen.cpp" />
|
||||
<ClCompile Include="Gui\Screens\MainScreen.cpp" />
|
||||
<ClCompile Include="Gui\Screens\ScreenManager.cpp" />
|
||||
<ClCompile Include="Gui\Screens\SellScreen\SellScreen.cpp">
|
||||
@@ -784,6 +785,7 @@
|
||||
<ClInclude Include="Gui\GuiText.h" />
|
||||
<ClInclude Include="Gui\Screen.h" />
|
||||
<ClInclude Include="Gui\Screens\FuelScreen\FuelScreen.h" />
|
||||
<ClInclude Include="Gui\Screens\GameOver\GameOverScreen.h" />
|
||||
<ClInclude Include="Gui\Screens\MainScreen.h" />
|
||||
<ClInclude Include="Gui\Screens\ScreenManager.h" />
|
||||
<ClInclude Include="Gui\Screens\SellScreen\SellScreen.h" />
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "pch.h"
|
||||
#include "GameManager.h"
|
||||
|
||||
#include "Gui/Screens/ScreenManager.h"
|
||||
|
||||
GameManager* GameManager::m_pInstance = nullptr;
|
||||
|
||||
|
||||
@@ -36,6 +38,9 @@ void GameManager::DecreaseFuel(float fuel) {
|
||||
}
|
||||
void GameManager::AddFuel(float fuel) {
|
||||
m_Fuel += fuel;
|
||||
if(m_Fuel > this->GetMaxFuel()) {
|
||||
m_Fuel = this->GetMaxFuel();
|
||||
}
|
||||
}
|
||||
void GameManager::SetHullIntegrity(int hullIntegrity) {
|
||||
m_HullIntegrity = hullIntegrity;
|
||||
@@ -72,11 +77,14 @@ void GameManager::Update(float elapsedSecs) {
|
||||
|
||||
if (m_HullIntegrity <= 0 or m_Fuel <= 0) {
|
||||
m_pPlayer->Die();
|
||||
m_GameOver = true;
|
||||
ScreenManager::GetInstance()->OpenScreen(ScreenManager::m_GameOverScreen);
|
||||
}
|
||||
|
||||
if(m_Fuel <= 20) {
|
||||
if(m_FuelLowSound->IsPlaying() == false) {
|
||||
m_FuelLowSound->Play(1);
|
||||
if(!m_GameOver) {
|
||||
if(m_Fuel <= 20) {
|
||||
if(m_FuelLowSound->IsPlaying() == false) {
|
||||
m_FuelLowSound->Play(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ private:
|
||||
Player* m_pPlayer{ nullptr };
|
||||
|
||||
SoundEffect* m_FuelLowSound{ nullptr };
|
||||
bool m_GameOver{ false };
|
||||
};
|
||||
|
||||
|
||||
|
||||
31
Game/Gui/Screens/GameOver/GameOverScreen.cpp
Normal file
31
Game/Gui/Screens/GameOver/GameOverScreen.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include "pch.h"
|
||||
#include "GameOverScreen.h"
|
||||
|
||||
#include "colors.h"
|
||||
#include "utils.h"
|
||||
GameOverScreen::GameOverScreen(const std::string& filePath, Vector2f pos, Vector2f size, TextureManager* manager): Screen(filePath, pos, size, manager){
|
||||
m_SkullTexture = manager->GetTexture("gui/gameover/skull.png");
|
||||
|
||||
GuiText* text = new GuiText(Vector2f{360, 150}, "Press Space To Quit", "fonts/Arial.ttf", 20, Colors::YELLOW);
|
||||
AddElement(text);
|
||||
}
|
||||
GameOverScreen::~GameOverScreen() {
|
||||
}
|
||||
void GameOverScreen::Draw() const {
|
||||
Screen::Draw();
|
||||
//1230 x 1087
|
||||
m_SkullTexture->Draw(Rectf{ 350, 200, 1230 / 5, 1087 / 5 });
|
||||
|
||||
}
|
||||
void GameOverScreen::Update(float elapsedSecs) {
|
||||
Screen::Update(elapsedSecs);
|
||||
if(utils::isKeyDown(SDL_SCANCODE_SPACE)){
|
||||
SDL_Event quitEvent;
|
||||
quitEvent.type = SDL_QUIT;
|
||||
SDL_PushEvent(&quitEvent);
|
||||
}
|
||||
}
|
||||
void GameOverScreen::MarkDirty() {
|
||||
}
|
||||
void GameOverScreen::SellAll() {
|
||||
}
|
||||
19
Game/Gui/Screens/GameOver/GameOverScreen.h
Normal file
19
Game/Gui/Screens/GameOver/GameOverScreen.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
#include "../../Screen.h"
|
||||
#include "Gui/GuiText.h"
|
||||
|
||||
class GameOverScreen final : public Screen {
|
||||
public:
|
||||
GameOverScreen(const std::string& filePath, Vector2f pos, Vector2f size, TextureManager* manager);
|
||||
virtual ~GameOverScreen() override;
|
||||
|
||||
virtual void Draw() const override;
|
||||
virtual void Update(float elapsedSecs) override;
|
||||
|
||||
void MarkDirty();
|
||||
void SellAll();
|
||||
|
||||
private:
|
||||
Texture* m_SkullTexture{ nullptr };
|
||||
|
||||
};
|
||||
@@ -4,10 +4,12 @@
|
||||
#include "FuelScreen/FuelScreen.h"
|
||||
#include "SellScreen/SellScreen.h"
|
||||
#include "utils.h"
|
||||
#include "GameOver/GameOverScreen.h"
|
||||
ScreenManager* ScreenManager::m_pInstance = nullptr;
|
||||
|
||||
Screen* ScreenManager::m_FuelScreen { nullptr };
|
||||
Screen* ScreenManager::m_SellScreen { nullptr };
|
||||
Screen* ScreenManager::m_GameOverScreen { nullptr };
|
||||
|
||||
ScreenManager * ScreenManager::GetInstance() {
|
||||
|
||||
@@ -44,6 +46,7 @@ bool ScreenManager::IsScreenOpen() const {
|
||||
ScreenManager::~ScreenManager() {
|
||||
delete m_FuelScreen;
|
||||
delete m_SellScreen;
|
||||
delete m_GameOverScreen;
|
||||
}
|
||||
void ScreenManager::InitializeScreens() {
|
||||
Vector2f fuelScreenSize = Vector2f { 492, 396 };
|
||||
@@ -54,5 +57,9 @@ void ScreenManager::InitializeScreens() {
|
||||
Vector2f sellScreenCenter = Vector2f { utils::GetViewport().x / 2 - sellScreenSize.x / 2, utils::GetViewport().y / 2 - sellScreenSize.y / 2 };
|
||||
m_SellScreen = new SellScreen { "gui/sell/background.png", sellScreenCenter, sellScreenSize, TextureManager::GetInstance() };
|
||||
|
||||
Vector2f gameOverScreenSize = Vector2f { 533, 398 };
|
||||
Vector2f gameOverScreenCenter = Vector2f { utils::GetViewport().x / 2 - gameOverScreenSize.x / 2, utils::GetViewport().y / 2 - gameOverScreenSize.y / 2 };
|
||||
m_GameOverScreen = new GameOverScreen { "", gameOverScreenCenter, gameOverScreenSize, TextureManager::GetInstance() };
|
||||
|
||||
//m_Button = Button { "gui/close.png", closeButtonPos, closeButtonSize, TextureManager::GetInstance() };
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ public:
|
||||
|
||||
static Screen* m_FuelScreen;
|
||||
static Screen* m_SellScreen;
|
||||
static Screen* m_GameOverScreen;
|
||||
|
||||
private:
|
||||
ScreenManager() = default;
|
||||
|
||||
@@ -12,6 +12,7 @@ SellScreen::SellScreen(const std::string& filePath, Vector2f pos, Vector2f size,
|
||||
const Vector2f ScreenCenter = Vector2f { utils::GetViewport().x / 2, utils::GetViewport().y / 2 };
|
||||
|
||||
const Vector2f sellScreenCenter = ScreenCenter - sellScreenSize / 2;
|
||||
m_BuySound = new SoundEffect { "sound/buy.wav" };
|
||||
|
||||
const Vector2f closeButtonOffset = Vector2f { 460, 396 - 14 };
|
||||
Vector2f closeButtonPos = sellScreenCenter + closeButtonOffset;
|
||||
@@ -36,6 +37,7 @@ SellScreen::SellScreen(const std::string& filePath, Vector2f pos, Vector2f size,
|
||||
sellAllButton->SetOnClick([this]()
|
||||
{
|
||||
this->SellAll();
|
||||
m_BuySound->Play(0);
|
||||
});
|
||||
this->AddElement(sellAllButton);
|
||||
|
||||
@@ -48,6 +50,7 @@ SellScreen::~SellScreen() {
|
||||
for (SellSreenRow* row : m_Rows) {
|
||||
delete row;
|
||||
}
|
||||
delete m_BuySound;
|
||||
}
|
||||
void SellScreen::Draw() const {
|
||||
Screen::Draw();
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
#include "../../Screen.h"
|
||||
#include "Gui/GuiText.h"
|
||||
|
||||
class SoundEffect;
|
||||
|
||||
class SellScreen final : public Screen {
|
||||
public:
|
||||
SellScreen(const std::string& filePath, Vector2f pos, Vector2f size, TextureManager* manager);
|
||||
@@ -20,4 +22,7 @@ private:
|
||||
std::vector<SellSreenRow *> m_Rows;
|
||||
|
||||
bool m_AreRowsDirty { true };
|
||||
|
||||
SoundEffect* m_BuySound { nullptr };
|
||||
|
||||
};
|
||||
|
||||
@@ -26,8 +26,8 @@ void SellSreenRow::Draw() const {
|
||||
Vector2f amountPos { namePos.x + 100, m_Pos.y + 8 };
|
||||
m_CalculationText->Draw(amountPos);
|
||||
|
||||
utils::SetColor(Colors::GREEN);
|
||||
utils::DrawRect(Rectf { m_Pos, m_Size });
|
||||
// utils::SetColor(Colors::GREEN);
|
||||
// utils::DrawRect(Rectf { m_Pos, m_Size });
|
||||
}
|
||||
void SellSreenRow::Update(float elapsedSecs) {
|
||||
// m_NameText->ChangeText("EXAMPLE");
|
||||
|
||||
@@ -16,11 +16,11 @@ Building::Building(const std::string& filePath, const Vector2f& position, const
|
||||
void Building::Draw() const {
|
||||
utils::SetColor(Colors::WHITE);
|
||||
m_Texture->Draw(m_Position);
|
||||
utils::SetColor(Colors::GREEN);
|
||||
Rectf temp = m_BoundingBox;
|
||||
temp.left += m_Position.x;
|
||||
temp.bottom += m_Position.y;
|
||||
utils::DrawRect(temp);
|
||||
// utils::SetColor(Colors::GREEN);
|
||||
// Rectf temp = m_BoundingBox;
|
||||
// temp.left += m_Position.x;
|
||||
// temp.bottom += m_Position.y;
|
||||
// utils::DrawRect(temp);
|
||||
}
|
||||
void Building::Update(float dt, const Rectf& objectBoundingBox) {
|
||||
if (IsObjectInHitbox(objectBoundingBox)) {
|
||||
|
||||
@@ -36,6 +36,13 @@ WorldLevel::WorldLevel(Camera* camera, Rectf viewport): Level(camera),
|
||||
m_GridManager.GetTileAtIndex(x, 0)->SetTileType(GroundTileTypeManager::GetInstance()->AIR);
|
||||
m_GridManager.GetTileAtIndex(x, 1)->SetTileType(GroundTileTypeManager::GetInstance()->GRASS);
|
||||
}
|
||||
|
||||
//Add to walls to the side of stone
|
||||
for (int y { 0 }; y < WORLD_HEIGHT - 1; ++y) {
|
||||
m_GridManager.GetTileAtIndex(0, y)->SetTileType(GroundTileTypeManager::GetInstance()->STONE);
|
||||
m_GridManager.GetTileAtIndex(WORLD_WIDTH - 1, y)->SetTileType(GroundTileTypeManager::GetInstance()->STONE);
|
||||
}
|
||||
|
||||
Building* fuelBuilding = new Building { "buildings/fuelStation.png", Vector2f { -700, -52 }, Rectf{0 ,0, 50, 50}, TextureManager::GetInstance() };
|
||||
fuelBuilding->SetOnEnterHitbox([]() {
|
||||
ScreenManager::GetInstance()->OpenScreen(ScreenManager::m_FuelScreen);
|
||||
@@ -78,8 +85,8 @@ WorldLevel::WorldLevel(Camera* camera, Rectf viewport): Level(camera),
|
||||
m_MainScreen = new MainScreen(TextureManager::GetInstance());
|
||||
GameManager::GetInstance().SetMainScreen(m_MainScreen);
|
||||
|
||||
m_Sun = new OrbitingObject(Vector2f{0, -1000}, 1200, 0.5f, TextureManager::GetInstance()->GetTexture("sun.png"));
|
||||
m_Moon = new OrbitingObject(Vector2f{0, -1000}, 1200, 0.5f, TextureManager::GetInstance()->GetTexture("moon.png"), M_PI);
|
||||
m_Sun = new OrbitingObject(Vector2f{0, -1000}, 1200, 0.1f, TextureManager::GetInstance()->GetTexture("sun.png"));
|
||||
m_Moon = new OrbitingObject(Vector2f{0, -1000}, 1200, 0.1f, TextureManager::GetInstance()->GetTexture("moon.png"), M_PI);
|
||||
|
||||
GameManager::GetInstance().SetFuel(100);
|
||||
GameManager::GetInstance().SetHullIntegrity(100);
|
||||
@@ -87,7 +94,10 @@ WorldLevel::WorldLevel(Camera* camera, Rectf viewport): Level(camera),
|
||||
GameManager::GetInstance().SetPlayer(&m_Player);
|
||||
|
||||
m_BackgroundMusic = new SoundStream("sound/bgm.wav");
|
||||
m_BackgroundMusic->Play(0);
|
||||
m_BackgroundMusic->Play(-1);
|
||||
|
||||
GameManager::GetInstance().SetMoney(100);
|
||||
|
||||
}
|
||||
WorldLevel::~WorldLevel() {
|
||||
delete m_MainScreen;
|
||||
@@ -149,6 +159,7 @@ void WorldLevel::Update(float elapsedSec) {
|
||||
}
|
||||
|
||||
//Move the camera when the player gets to the edge
|
||||
//Also lock the camera from going below -800 and above -100
|
||||
if(m_FollowPlayer) {
|
||||
Vector2f playerPos = m_Player.GetPosition();
|
||||
Vector2f newCameraPos = m_pCamera->GetPosition();
|
||||
@@ -158,12 +169,13 @@ void WorldLevel::Update(float elapsedSec) {
|
||||
if (playerPos.x > newCameraPos.x + m_Viewport.width - 100) {
|
||||
newCameraPos.x = playerPos.x - m_Viewport.width + 100;
|
||||
}
|
||||
if (playerPos.y < newCameraPos.y + 50) {
|
||||
newCameraPos.y = playerPos.y - 50;
|
||||
if (playerPos.y < newCameraPos.y + 100) {
|
||||
newCameraPos.y = playerPos.y - 100;
|
||||
}
|
||||
if (playerPos.y > newCameraPos.y + m_Viewport.height - 100) {
|
||||
newCameraPos.y = playerPos.y - m_Viewport.height + 100;
|
||||
if (playerPos.y > newCameraPos.y + m_Viewport.height - 150) {
|
||||
newCameraPos.y = playerPos.y - m_Viewport.height + 150;
|
||||
}
|
||||
newCameraPos.x = utils::clamp(newCameraPos.x, -800, -100);
|
||||
m_pCamera->SetPosition(newCameraPos);
|
||||
}
|
||||
|
||||
@@ -199,11 +211,11 @@ void WorldLevel::Draw() const {
|
||||
m_TopCover->Draw(Rectf{-850, -70, 850, -70 + 32}, Rectf{0, 0, WORLD_WIDTH * 50, 32});
|
||||
|
||||
for (Collision::CollisionRect rect : m_Rects) {
|
||||
utils::DrawRect(rect.pos, rect.size.x, rect.size.y);
|
||||
// utils::DrawRect(rect.pos, rect.size.x, rect.size.y);
|
||||
}
|
||||
|
||||
utils::SetColor(Colors::WHITE);
|
||||
utils::FillEllipse(m_MousePos, 2, 2);
|
||||
// utils::SetColor(Colors::WHITE);
|
||||
// utils::FillEllipse(m_MousePos, 2, 2);
|
||||
|
||||
for (int x { 0 }; x < WORLD_WIDTH; ++x) {
|
||||
for (int y { 0 }; y < WORLD_HEIGHT; ++y) {
|
||||
@@ -211,12 +223,12 @@ void WorldLevel::Draw() const {
|
||||
}
|
||||
}
|
||||
|
||||
utils::SetColor(Colors::MAGENTA);
|
||||
utils::FillEllipse(-5, -5, 5, 5);
|
||||
// utils::SetColor(Colors::MAGENTA);
|
||||
// utils::FillEllipse(-5, -5, 5, 5);
|
||||
|
||||
if (m_pSelectedTile != nullptr) {
|
||||
m_pSelectedTile->Draw();
|
||||
}
|
||||
// if (m_pSelectedTile != nullptr) {
|
||||
// m_pSelectedTile->Draw();
|
||||
// }
|
||||
|
||||
for(Building* building : m_Buildings) {
|
||||
building->Draw();
|
||||
@@ -224,14 +236,14 @@ void WorldLevel::Draw() const {
|
||||
|
||||
m_Player.Draw();
|
||||
|
||||
utils::SetColor(Colors::GREEN);
|
||||
utils::DrawArrow(Vector2f{0, 0}, m_MousePos);
|
||||
// utils::SetColor(Colors::GREEN);
|
||||
// utils::DrawArrow(Vector2f{0, 0}, m_MousePos);
|
||||
|
||||
m_pCamera->EndRendering();
|
||||
|
||||
utils::FillRect(utils::GetMousePos(), 10, 10);
|
||||
// utils::FillRect(utils::GetMousePos(), 10, 10);
|
||||
|
||||
utils::DrawRect(50, 50, m_Viewport.width - 100, m_Viewport.height - 100);
|
||||
// utils::DrawRect(50, 50, m_Viewport.width - 100, m_Viewport.height - 100);
|
||||
|
||||
const Screen* screen = m_ScreenManager->GetCurrentScreen();
|
||||
if (screen != nullptr) {
|
||||
|
||||
@@ -84,6 +84,10 @@ Player::~Player() {
|
||||
for (Particle* particle : m_DigParticles) {
|
||||
delete particle;
|
||||
}
|
||||
|
||||
for (Particle* particle : m_SmokeParticles) {
|
||||
delete particle;
|
||||
}
|
||||
}
|
||||
|
||||
Collision::CollisionRect Player::GetCollisionRect() const {
|
||||
@@ -112,12 +116,10 @@ void Player::Draw() const {
|
||||
{
|
||||
utils::SetColor(Colors::WHITE);
|
||||
m_CurrentAnimation->Draw(Vector2f { 0, 0 }, Rectf { 0, 0, frameWidth, frameWidth });
|
||||
utils::SetColor(Colors::GREEN);
|
||||
|
||||
|
||||
}
|
||||
glPopMatrix();
|
||||
utils::FillEllipse(m_OutletPos + m_Position, 5, 5);
|
||||
for (Particle* particle : m_DigParticles) {
|
||||
utils::SetColor(Colors::WHITE);
|
||||
particle->Draw();
|
||||
@@ -271,8 +273,8 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
|
||||
m_SmokeTimer += elapsedTime;
|
||||
if (m_SmokeTimer >= m_SmokeTime) {
|
||||
m_SmokeTimer = 0.0f;
|
||||
Vector2f Dir { static_cast<float>(m_Direction == PlayerDirection::Left ? 30 : -30), 20 };
|
||||
Particle* NewSmokeParticle = new Particle(m_OutletPos + m_Position, Dir, Vector2f { 0.0f, 9.81f * 30}, 5.f, TextureManager::GetInstance()->GetTexture("particles/smoke.png"));
|
||||
Vector2f Dir { static_cast<float>(m_Direction == PlayerDirection::Left ? 60 : -60), 20 };
|
||||
Particle* NewSmokeParticle = new Particle(m_OutletPos + m_Position, Dir, Vector2f { 0.0f, 9.81f * 5}, 1.f, TextureManager::GetInstance()->GetTexture("particles/smoke.png"));
|
||||
NewSmokeParticle->SetFlipped(m_Direction == PlayerDirection::Left);
|
||||
m_SmokeParticles.push_back(NewSmokeParticle);
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ private:
|
||||
|
||||
Vector2f m_OutletPos;
|
||||
Vector2f m_OutLeftPos{ 55, 45};
|
||||
Vector2f m_OutRightPos{ 0, 45 };
|
||||
Vector2f m_OutRightPos{ -40, 45 };
|
||||
|
||||
Vector2f m_Vel;
|
||||
|
||||
@@ -154,5 +154,5 @@ private:
|
||||
bool m_DidSoundChange{ false };
|
||||
|
||||
//Testing
|
||||
bool m_DrawCollisionRect { true };
|
||||
bool m_DrawCollisionRect { false };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user