Add fly animations

This commit is contained in:
Bram Verhulst
2024-05-29 00:00:29 +02:00
parent 3c83e566dd
commit e1165fdcb4
31 changed files with 580 additions and 157 deletions

View File

@@ -13,16 +13,19 @@ void GameManager::SetMainScreen(MainScreen* pMainScreen) {
m_pMainScreen = pMainScreen;
//TODO: not the best but ¯\_(ツ)_/¯
}
void GameManager::SetFuel(int fuel) {
void GameManager::SetFuel(float fuel) {
m_Fuel = fuel;
//Limit to 0 - MAXa
}
int GameManager::GetFuel() const {
float GameManager::GetFuel() const {
return m_Fuel;
}
void GameManager::DecreaseFuel(int fuel) {
void GameManager::DecreaseFuel(float fuel) {
m_Fuel -= fuel;
m_Fuel = std::max(0.0f, m_Fuel);
}
void GameManager::AddFuel(int fuel) {
void GameManager::AddFuel(float fuel) {
m_Fuel += fuel;
}
void GameManager::SetHullIntegrity(int hullIntegrity) {
@@ -43,8 +46,20 @@ int GameManager::GetScore() const {
void GameManager::IncreaseScore(int score) {
m_Score += score;
}
void GameManager::SetMoney(int money) {
m_Money = money;
}
int GameManager::GetMoney() const {
return m_Money;
}
void GameManager::IncreaseMoney(int money) {
m_Money += money;
}
void GameManager::Update(float elapsedSecs) {
m_pMainScreen->SetFuelMeterValue(m_Fuel);
m_pMainScreen->SetFuelMeterValue(this->GetMaxFuel() - m_Fuel);
m_pMainScreen->SetHullMeterValue(m_HullIntegrity);
m_pMainScreen->SetScore(std::to_string(m_Score));
}
int GameManager::GetMaxFuel() {
return 100; //TODO: change if i ever add upgrades
}

View File

@@ -10,10 +10,10 @@ public:
void SetMainScreen(MainScreen* pMainScreen);
void SetFuel(int fuel);
int GetFuel() const;
void DecreaseFuel(int fuel);
void AddFuel(int fuel);
void SetFuel(float fuel);
float GetFuel() const;
void DecreaseFuel(float fuel);
void AddFuel(float fuel);
void SetHullIntegrity(int hullIntegrity);
int GetHullIntegrity() const;
@@ -23,7 +23,12 @@ public:
int GetScore() const;
void IncreaseScore(int score);
void SetMoney(int money);
int GetMoney() const;
void IncreaseMoney(int money);
void Update(float elapsedSecs);
int GetMaxFuel();
private:
GameManager() = default;
@@ -31,8 +36,9 @@ private:
float m_Balance{ 0.0f };
int m_HullIntegrity{ 100 };
int m_Fuel{ 100 };
float m_Fuel{ 100.0f };
int m_Score{ 0 };
int m_Money{ 0 };
MainScreen* m_pMainScreen{ nullptr };
};

View File

@@ -36,20 +36,20 @@ GroundTileType * getRandomGroundTile() {
}
void InitializeGroundTiles() {
Tiles tiles {};
GroundTileTypeManager::GetInstance()->AIR = new GroundTileType("", GroundTileTypes::Air);
GroundTileTypeManager::GetInstance()->DIRT = new RandomGroundTile("tiles/dirt/dirt[0].png", GroundTileTypes::Dirt, 5);
GroundTileTypeManager::GetInstance()->AIR = new GroundTileType("", GroundTileTypes::Air, 0);
GroundTileTypeManager::GetInstance()->DIRT = new RandomGroundTile("tiles/dirt/dirt[0].png", GroundTileTypes::Dirt, 5, 250);
GroundTileTypeManager::GetInstance()->STONE = new RandomGroundTile("tiles/ores/Ore_Stone_[0].png", GroundTileTypes::Stone, 3);
GroundTileTypeManager::GetInstance()->LAVA = new RandomGroundTile("tiles/ores/Ore_Lava_[0].png", GroundTileTypes::Lava, 3);
GroundTileTypeManager::GetInstance()->STONE = new RandomGroundTile("tiles/ores/Ore_Stone_[0].png", GroundTileTypes::Stone, 3, 0);
GroundTileTypeManager::GetInstance()->LAVA = new RandomGroundTile("tiles/ores/Ore_Lava_[0].png", GroundTileTypes::Lava, 3, 0);
GroundTileTypeManager::GetInstance()->IRON = new GroundTileType("tiles/ores/Ore_Ironium.png", GroundTileTypes::Iron);
GroundTileTypeManager::GetInstance()->BRONZE = new GroundTileType("tiles/ores/Ore_Bronzium.png", GroundTileTypes::Bronze);
GroundTileTypeManager::GetInstance()->GOLD = new GroundTileType("tiles/ores/Ore_Goldium.png", GroundTileTypes::Gold);
GroundTileTypeManager::GetInstance()->IRON = new GroundTileType("tiles/ores/Ore_Ironium.png", GroundTileTypes::Iron, 1500);
GroundTileTypeManager::GetInstance()->BRONZE = new GroundTileType("tiles/ores/Ore_Bronzium.png", GroundTileTypes::Bronze, 3000);
GroundTileTypeManager::GetInstance()->GOLD = new GroundTileType("tiles/ores/Ore_Goldium.png", GroundTileTypes::Gold, 12500);
GroundTileTypeManager::GetInstance()->GRASS = new RandomGroundTile("tiles/dirt/special/grass[0].png", GroundTileTypes::Grass, 2);
GroundTileTypeManager::GetInstance()->HARD_LEFT = new GroundTileType("tiles/dirt/special/hardLeft.png", GroundTileTypes::Hard);
GroundTileTypeManager::GetInstance()->HARD_RIGHT = new GroundTileType("tiles/dirt/special/hardRight.png", GroundTileTypes::Hard);
GroundTileTypeManager::GetInstance()->HARD_MIDDLE = new GroundTileType("tiles/dirt/special/hardMiddle.png", GroundTileTypes::Hard);
GroundTileTypeManager::GetInstance()->GRASS = new RandomGroundTile("tiles/dirt/special/grass[0].png", GroundTileTypes::Grass, 2, 250);
GroundTileTypeManager::GetInstance()->HARD_LEFT = new GroundTileType("tiles/dirt/special/hardLeft.png", GroundTileTypes::Hard, 0);
GroundTileTypeManager::GetInstance()->HARD_RIGHT = new GroundTileType("tiles/dirt/special/hardRight.png", GroundTileTypes::Hard, 0);
GroundTileTypeManager::GetInstance()->HARD_MIDDLE = new GroundTileType("tiles/dirt/special/hardMiddle.png", GroundTileTypes::Hard, 0);
GroundTileWeights = {
{ GroundTileTypeManager::GetInstance()->AIR, 0.2f },
@@ -70,7 +70,7 @@ WorldTile::WorldTile(const Vector2f& position, GroundTileType* groundTileType, T
m_GroundTileType { groundTileType }, m_pGridManager { pGridManager } {
// const std::string dirtPath = + "tiles/dirt/dirt" + std::to_string(utils::randRange(1, 5)) + ".png";
// m_pTexture = new Texture(dirtPath);
m_pTexture = pTextureManager->GetTexture(groundTileType->getPath());
m_pTexture = pTextureManager->GetTexture(groundTileType->GetPath());
m_SideTextures[TileDirection::TopLeft] = pTextureManager->GetTexture("tiles/dirt/sidepieces/topLeft.png");
m_SideTextures[TileDirection::TopRight] = pTextureManager->GetTexture("tiles/dirt/sidepieces/topRight.png");
@@ -90,7 +90,7 @@ WorldTile::~WorldTile() {
void WorldTile::Draw() {
switch (m_GroundTileType->getType()) {
switch (m_GroundTileType->GetType()) {
case GroundTileTypes::Air: {
//check if it's all around dirt
// bool allDirt = true;
@@ -157,17 +157,17 @@ Collision::TileCollisionRect WorldTile::GetCollisionRect() {
void WorldTile::DrawSide(const TileDirection& direction) {
const WorldTile* tile = m_SurroundingTiles.GetTile(direction);
if (tile != nullptr) {
const GroundTileTypes type = tile->GetTileType()->getType();
const GroundTileTypes type = tile->GetTileType()->GetType();
if (direction == TileDirection::BottomMiddle || direction == TileDirection::BottomLeft || direction == TileDirection::BottomRight) {
if (type == GroundTileTypeManager::GetInstance()->GRASS->getType() || type == GroundTileTypeManager::GetInstance()->HARD_LEFT->getType() || type ==
GroundTileTypeManager::GetInstance()->HARD_MIDDLE->getType() || type == GroundTileTypeManager::GetInstance()->HARD_RIGHT->getType()) {
if (type == GroundTileTypeManager::GetInstance()->GRASS->GetType() || type == GroundTileTypeManager::GetInstance()->HARD_LEFT->GetType() || type ==
GroundTileTypeManager::GetInstance()->HARD_MIDDLE->GetType() || type == GroundTileTypeManager::GetInstance()->HARD_RIGHT->GetType()) {
//Fix for edges being renderd on grass / hard tiles
//TODO: Possible fix if i have time
return;
}
}
if (type != GroundTileTypeManager::GetInstance()->AIR->getType()) {
if (type != GroundTileTypeManager::GetInstance()->AIR->GetType()) {
m_SideTextures[direction]->Draw(m_Position);
}
}

View File

@@ -6,8 +6,7 @@
class Camera;
enum class GroundTileTypes
{
enum class GroundTileTypes {
Air,
Dirt,
Grass,
@@ -38,64 +37,67 @@ static std::map<GroundTileTypes, std::string> GroundTileTypeStrings {
GroundTileType * getRandomGroundTile();
class GroundTileType
{
class GroundTileType {
public:
GroundTileType(const std::string&& filePath, GroundTileTypes type): m_filePath(filePath), m_type(type) {
GroundTileType(const std::string&& filePath, GroundTileTypes type, int value): m_FilePath(filePath), m_Type(type), m_Value(value) {
}
virtual ~GroundTileType() = default;
bool operator==(const GroundTileType& rhs) const {
return m_type == rhs.m_type;
return m_Type == rhs.m_Type;
}
bool operator!=(const GroundTileType& rhs) const {
return m_type != rhs.m_type;
return m_Type != rhs.m_Type;
}
virtual bool operator==(const GroundTileType* rhs) const {
return rhs->m_type == m_type;
return rhs->m_Type == m_Type;
}
virtual bool operator!=(const GroundTileType* rhs) const {
return rhs->m_type != m_type;
return rhs->m_Type != m_Type;
}
virtual std::string getPath() const {
return m_filePath;
virtual std::string GetPath() const {
return m_FilePath;
}
virtual GroundTileTypes getType() const {
return m_type;
virtual GroundTileTypes GetType() const {
return m_Type;
}
virtual int GetValue() const {
return m_Value;
}
protected:
std::string m_filePath;
std::string m_FilePath;
private:
GroundTileTypes m_type;
GroundTileTypes m_Type;
int m_Value;
};
class RandomGroundTile : public GroundTileType
{
class RandomGroundTile : public GroundTileType {
public:
RandomGroundTile(const std::string& filePath, GroundTileTypes type, int maxRandom): GroundTileType(std::move(filePath), type), m_maxRandom(maxRandom) {
RandomGroundTile(const std::string& filePath, GroundTileTypes type, int maxRandom, int value): GroundTileType(std::move(filePath), type, value), m_maxRandom(maxRandom) {
}
~RandomGroundTile() override = default;
bool operator==(const GroundTileType* rhs) const override {
return rhs->getType() == this->getType();
return rhs->GetType() == this->GetType();
}
bool operator!=(const GroundTileType* rhs) const override {
return rhs->getType() != this->getType();
return rhs->GetType() != this->GetType();
}
std::string getPath() const override {
std::string GetPath() const override {
int variant = utils::randRange(1, m_maxRandom);
std::string toReplace { "[0]" };
std::string replacement = std::to_string(utils::randRange(1, m_maxRandom));
size_t found = m_filePath.find(toReplace);
std::string newFilePath { m_filePath };
size_t found = m_FilePath.find(toReplace);
std::string newFilePath { m_FilePath };
if (found != std::string::npos) {
newFilePath.replace(found, 3, replacement);
@@ -108,10 +110,9 @@ private:
int m_maxRandom;
};
class Tiles
{
class Tiles {
public:
};
// static std::map<GroundTileType *, float> GroundTileWeights {
@@ -128,12 +129,11 @@ public:
// { Tiles::Ores::IRON, 0.1f },
// };
static std::map<GroundTileType*, float> GroundTileWeights;
static std::map<GroundTileType *, float> GroundTileWeights;
void InitializeGroundTiles();
class WorldTile
{
class WorldTile {
public:
WorldTile() = default;
WorldTile(const Vector2f& position, GroundTileType* groundTileType, TextureManager* pTextureManager, WorldGridManager* pGridManager);
@@ -158,7 +158,7 @@ public:
}
void SetTileType(GroundTileType* type) {
m_GroundTileType = type;
m_pTexture = TextureManager::GetInstance()->GetTexture(type->getPath()); //Chage the texture when setting a new type
m_pTexture = TextureManager::GetInstance()->GetTexture(type->GetPath()); //Chage the texture when setting a new type
}
Collision::TileCollisionRect GetCollisionRect();
@@ -179,7 +179,7 @@ private:
surroundingTiles m_SurroundingTiles;
std::vector<Texture*> m_SideTextures { 8, nullptr };
std::vector<Texture *> m_SideTextures { 8, nullptr };
Texture* m_pAllTexture;
};

View File

@@ -18,7 +18,6 @@ void GuiMeter::Draw() const {
utils::DrawRect(Rectf { m_Position, m_DrawSize});
}
void GuiMeter::Update(float elapsedSec) {
m_Value += 1;
const int frame = static_cast<int>(utils::map(m_Value, 0.0f, m_MaxValue, 0, (float)m_Animation->GetFrameCount()));
m_Animation->SetFrame(frame);
}

View File

@@ -19,7 +19,6 @@ void GuiText::Update(float elapsedSec) {
void GuiText::ChangeText(const std::string& text) const {
m_Text->ChangeText(text);
}
GuiText::~GuiText() {
delete m_Text;

View File

@@ -1,6 +1,8 @@
#include "pch.h"
#include "FuelScreen.h"
#include "colors.h"
#include "GameManager.h"
#include "ScreenManager.h"
#include "utils.h"
FuelScreen::FuelScreen(const std::string& filePath, Vector2f pos, Vector2f size, TextureManager* manager): Screen(filePath, pos, size, manager)
@@ -38,14 +40,33 @@ FuelScreen::FuelScreen(const std::string& filePath, Vector2f pos, Vector2f size,
const Vector2f fillTankButtonPos = Vector2f { 450, 108 };
GuiButton* fillTankButton = new GuiButton { "gui/fuel/fillTank.png", fillTankButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
this->AddElement(fillTankButton);
Vector2f offset{ 50, 320};
m_MoneyText = new GuiText {fuelScreenCenter + offset, "$ 20", "fonts/Arial.ttf", 20, Colors::YELLOW };
}
FuelScreen::~FuelScreen() = default;
FuelScreen::~FuelScreen() {
delete m_MoneyText;
};
void FuelScreen::Draw() const {
int currentFuel = GameManager::GetInstance().GetFuel();
int maxFuel = GameManager::GetInstance().GetMaxFuel();
utils::SetColor(Colors::ORANGE);
Vector2f fuelBarPos = Vector2f { 275, 135 };
const int MAX_HEIGHT = 210;
Vector2f fuelBarSize = Vector2f { 40, utils::map(currentFuel, 0, maxFuel, 0, MAX_HEIGHT) };
utils::FillRect(Rectf{fuelBarPos, fuelBarSize});
Screen::Draw();
m_MoneyText->Draw();
}
void FuelScreen::Update(float elapsedSecs) {
Screen::Update(elapsedSecs);
m_MoneyText->ChangeText("$ " + std::to_string(GameManager::GetInstance().GetMoney()));
}

View File

@@ -1,5 +1,6 @@
#pragma once
#include "../Screen.h"
#include "Gui/GuiText.h"
class FuelScreen : public Screen
{
@@ -10,5 +11,8 @@ public:
virtual void Draw() const override;
virtual void Update(float elapsedSecs) override;
private:
GuiText* m_MoneyText;
};

View File

@@ -2,6 +2,7 @@
#include "MainScreen.h"
#include "colors.h"
#include "GameManager.h"
#include "utils.h"
#include "Gui/GuiText.h"
MainScreen::MainScreen(TextureManager* manager) : Screen("", Vector2f{0, 0}, Vector2f{900.f, 500.f}, manager) {

View File

@@ -37,6 +37,9 @@ void ScreenManager::CloseScreen() {
}
}
bool ScreenManager::IsScreenOpen() {
return m_IsScreenOpen;
}
ScreenManager::~ScreenManager() {
delete m_FuelScreen;
delete m_SellScreen;

View File

@@ -12,8 +12,9 @@ public:
void OpenScreen(Screen* screen);
void CloseScreen();
Screen* GetCurrentScreen() const { return m_currentScreen; }
Screen* GetCurrentScreen() const { return m_currentScreen; }
bool IsScreenOpen();
static ScreenManager* m_pInstance;

View File

@@ -2,14 +2,48 @@
#include "Building.h"
#include <iostream>
Building::Building(const std::string& filePath, const Vector2f& position, TextureManager* pTextureManager): m_Position(position) {
#include <utility>
#include "colors.h"
#include "utils.h"
Building::Building(const std::string& filePath, const Vector2f& position, const Rectf& boundingBox, TextureManager* pTextureManager): m_Position(position),
m_BoundingBox(boundingBox) {
m_Texture = pTextureManager->GetTexture(filePath);
m_Size = Vector2f(m_Texture->GetWidth(), m_Texture->GetHeight());
std::cout << "i like kids" << std::endl;
}
Building::~Building() = default;
void Building::Draw() const {
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);
}
void Building::Update(float dt) {
void Building::Update(float dt, const Rectf& objectBoundingBox) {
if (IsObjectInHitbox(objectBoundingBox)) {
if (!m_IsPlayerInHitbox) { //TODO: what
m_IsPlayerInHitbox = true;
if (m_OnEnterHitbox != nullptr) {
m_OnEnterHitbox();
}
else {
std::cout << "No function set for onEnterHitbox" << std::endl;
}
}
}
else {
m_IsPlayerInHitbox = false;
}
}
void Building::SetOnEnterHitbox(std::function<void()> onEnterHitbox) {
m_OnEnterHitbox = std::move(onEnterHitbox);
}
bool Building::IsObjectInHitbox(const Rectf& objectBoundingBox) const {
Rectf temp = m_BoundingBox;
temp.left += m_Position.x;
temp.bottom += m_Position.y;
return utils::IsRectInRect(objectBoundingBox, temp);
}

View File

@@ -1,26 +1,34 @@
#pragma once
#include <functional>
#include "Texture.h"
#include "TextureManager.h"
class Building
{
public:
Building(const std::string& filePath, const Vector2f& position, TextureManager* pTextureManager);
Building(const Building& other) = default;
Building(Building&& other) = default;
Building& operator=(const Building& other) = default;
Building& operator=(Building&& other) = default;
Building(const std::string& filePath, const Vector2f& position, const Rectf& boundingBox, TextureManager* pTextureManager);
// Building(const Building& other) = default;
// Building(Building&& other) = default;
// Building& operator=(const Building& other) = default;
// Building& operator=(Building&& other) = default;
~Building();
void Draw() const;
void Update(float dt);
void Update(float dt, const Rectf& objectBoundingBox);
void SetOnEnterHitbox(std::function<void(void)> onEnterHitbox);
private:
bool IsObjectInHitbox(const Rectf& objectBoundingBox) const;
Texture* m_Texture;
Vector2f m_Position;
Vector2f m_Size;
Rectf m_boundingBox;
Rectf m_BoundingBox;
std::function<void(void)> m_OnEnterHitbox;
bool m_IsPlayerInHitbox{ false };
bool m_DidPlayerEnterHitbox{ false };
};

View File

@@ -8,6 +8,7 @@
#include "Collision.h"
#include "colors.h"
#include "GameManager.h"
#include "../../GridSystem/GroundTileTypeManager.h"
#include "utils.h"
#include "GridSystem/WorldTile.h"
@@ -35,44 +36,56 @@ 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);
}
m_Buildings.emplace_back(Building { "buildings/fuelStation.png", Vector2f { -700, -52 }, TextureManager::GetInstance() });
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);
});
m_Buildings.push_back(fuelBuilding);
m_GridManager.GetTileAtWorldPos(Vector2f { -750, -50 })->SetTileType(GroundTileTypeManager::GetInstance()->HARD_LEFT);
m_GridManager.GetTileAtWorldPos(Vector2f { -700, -50 })->SetTileType(GroundTileTypeManager::GetInstance()->HARD_LEFT);
m_GridManager.GetTileAtWorldPos(Vector2f { -700, -50 })->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
m_GridManager.GetTileAtWorldPos(Vector2f { -650, -50 })->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
m_GridManager.GetTileAtWorldPos(Vector2f { -600, -50 })->SetTileType(GroundTileTypeManager::GetInstance()->HARD_RIGHT);
m_Buildings.emplace_back(Building { "buildings/mineralStation.png", Vector2f { -350, -52 }, TextureManager::GetInstance() });
m_Buildings.emplace_back(new Building { "buildings/mineralStation.png", Vector2f { -350, -52 }, Rectf{0 ,0, 100, 100}, TextureManager::GetInstance() });
m_GridManager.GetTileAtWorldPos(Vector2f {-400, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_LEFT);
m_GridManager.GetTileAtWorldPos(Vector2f {-350, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
m_GridManager.GetTileAtWorldPos(Vector2f {-300, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
m_GridManager.GetTileAtWorldPos(Vector2f {-250, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
m_GridManager.GetTileAtWorldPos(Vector2f {-200, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
m_GridManager.GetTileAtWorldPos(Vector2f {-150, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_RIGHT);
m_Buildings.emplace_back(Building { "buildings/junkStation.png", Vector2f { 250, -52 }, TextureManager::GetInstance() });
m_Buildings.emplace_back(new Building { "buildings/junkStation.png", Vector2f { 250, -52 }, Rectf{0 ,0, 100, 100}, TextureManager::GetInstance() });
m_GridManager.GetTileAtWorldPos(Vector2f {200, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_LEFT);
m_GridManager.GetTileAtWorldPos(Vector2f {250, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
m_GridManager.GetTileAtWorldPos(Vector2f {300, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
m_GridManager.GetTileAtWorldPos(Vector2f {350, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
m_GridManager.GetTileAtWorldPos(Vector2f {400, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
m_GridManager.GetTileAtWorldPos(Vector2f {450, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_RIGHT);
m_Buildings.emplace_back(Building { "buildings/repairStation.png", Vector2f { 700, -52 }, TextureManager::GetInstance() });
m_Buildings.emplace_back(new Building { "buildings/repairStation.png", Vector2f { 700, -52 }, Rectf{0 ,0, 100, 100}, TextureManager::GetInstance() });
m_GridManager.GetTileAtWorldPos(Vector2f {650, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_LEFT);
m_GridManager.GetTileAtWorldPos(Vector2f {700, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
m_GridManager.GetTileAtWorldPos(Vector2f {750, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
m_GridManager.GetTileAtWorldPos(Vector2f {800, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_RIGHT);
// Texture* test = new Texture("gui/main/fuel_guage.png");
m_topCover = TextureManager::GetInstance()->GetTexture("topBackground.png");
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);
GameManager::GetInstance().SetFuel(100);
GameManager::GetInstance().SetHullIntegrity(100);
}
WorldLevel::~WorldLevel() {
delete m_MainScreen;
delete m_Sun;
delete m_Moon;
}
void WorldLevel::Update(float elapsedSec) {
m_Fps = 1 / elapsedSec;
@@ -102,8 +115,9 @@ void WorldLevel::Update(float elapsedSec) {
}
}
for (Building building : m_Buildings) {
building.Update(elapsedSec);
for (Building* building : m_Buildings) {
building->Update(elapsedSec, m_Player.GetCollisionRect().getRectf());
// building.IsPlayerInHitbox(Rectf{m_Player.GetCollisionRect().pos, m_Player.GetCollisionRect().size});
}
@@ -112,8 +126,9 @@ void WorldLevel::Update(float elapsedSec) {
m_pSelectedTile->SetTileType(GroundTileTypeManager::GetInstance()->AIR);
}
}
m_Player.Update(elapsedSec, *this);
if(!m_ScreenManager->IsScreenOpen()) {
m_Player.Update(elapsedSec, *this);
}
//Move the camera when the player gets to the edge
if(m_FollowPlayer) {
@@ -139,8 +154,14 @@ void WorldLevel::Update(float elapsedSec) {
screen->Update(elapsedSec);
}
m_MainScreen->Update(elapsedSec);
GameManager::GetInstance().Update(elapsedSec);
m_MainScreen->SetDepth(std::to_string((int)-m_Player.GetPosition().y - 50) + " ft.");
m_MainScreen->SetScore("Score: " + std::to_string(GameManager::GetInstance().GetScore()));
// m_MainScreen->SetFuelMeterValue(GameManager::GetInstance().GetFuel());
// m_MainScreen->SetHullMeterValue(GameManager::GetInstance().GetHullIntegrity());
m_MainScreen->Update(elapsedSec);
//Vector2f playerPos = m_player.GetPosition();
//Vector2f newCameraPos = playerPos;
@@ -152,6 +173,10 @@ void WorldLevel::Update(float elapsedSec) {
void WorldLevel::Draw() const {
m_pCamera->BeginRendering();
m_Sun->Draw();
m_Moon->Draw();
// m_topCover->Draw(Vector2f{-850,-70} );
m_topCover->Draw(Rectf{-850, -70, 850, -70 + 32}, Rectf{0, 0, WORLD_WIDTH * 50, 32});
@@ -175,8 +200,8 @@ void WorldLevel::Draw() const {
m_pSelectedTile->Draw();
}
for(Building building : m_Buildings) {
building.Draw();
for(Building* building : m_Buildings) {
building->Draw();
}
m_Player.Draw();
@@ -184,9 +209,6 @@ void WorldLevel::Draw() const {
utils::SetColor(Colors::GREEN);
utils::DrawArrow(Vector2f{0, 0}, m_MousePos);
m_Sun->Draw();
m_Moon->Draw();
m_pCamera->EndRendering();
utils::FillRect(utils::GetMousePos(), 10, 10);
@@ -209,7 +231,7 @@ void WorldLevel::ProcessImGui() {
ImGui::Begin("Selected Tile");
std::string tileType = "None";
if (m_pSelectedTile != nullptr) {
switch (m_pSelectedTile->GetTileType()->getType()) {
switch (m_pSelectedTile->GetTileType()->GetType()) {
case GroundTileTypes::Air:
tileType = "Air";
break;
@@ -243,6 +265,9 @@ void WorldLevel::ProcessImGui() {
if (ImGui::MenuItem("Player Info")) {
m_ShowPlayerInfo = !m_ShowPlayerInfo;
}
if(ImGui::MenuItem("Game Manager Info")) {
m_ShowGameManagerInfo = !m_ShowGameManagerInfo;
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Screens")) {
@@ -302,6 +327,26 @@ void WorldLevel::ProcessImGui() {
ImGui::End();
m_Player.ProcessImGui();
}
if(m_ShowGameManagerInfo) {
ImGui::Begin("Game Manager", &m_ShowGameManagerInfo, ImGuiWindowFlags_AlwaysAutoResize);
ImGui::Text("Fuel: %f", GameManager::GetInstance().GetFuel());
ImGui::Text("Hull Integrity: %d", GameManager::GetInstance().GetHullIntegrity());
ImGui::Text("Score: %d", GameManager::GetInstance().GetScore());
ImGui::Text("Money: %d", GameManager::GetInstance().GetMoney());
ImGui::Separator();
if(ImGui::Button("Add 1$")) {
GameManager::GetInstance().IncreaseMoney(1);
}
if(ImGui::Button("Add 10$")) {
GameManager::GetInstance().IncreaseMoney(10);
}
ImGui::SameLine();
if(ImGui::Button("Add 100$")) {
GameManager::GetInstance().IncreaseMoney(100);
}
ImGui::End();
}
}
WorldGridManager& WorldLevel::GetGridManager() {
return m_GridManager;

View File

@@ -7,6 +7,7 @@
#include "Gui/Screens/ScreenManager.h"
#include "Camera.h"
#include "OrbitingObject.h"
#include "SoundEffect.h"
#include "Text.h"
#include "Gui/GuiMeter.h"
#include "Gui/Screens/MainScreen.h"
@@ -45,7 +46,7 @@ private:
WorldTile* m_pSelectedTile { nullptr };
std::vector<Building> m_Buildings{};
std::vector<Building*> m_Buildings{};
MainScreen* m_MainScreen{};
@@ -55,10 +56,12 @@ private:
Texture* m_topCover{ nullptr };
// ImGui Vars
bool m_ShowTextureManagerWindow { false };
bool m_ShowCameraWindow { false };
bool m_ShowPlayerInfo { true };
bool m_ShowGameManagerInfo{ true };
bool m_FollowPlayer { true };
};

View File

@@ -5,6 +5,7 @@
#include <algorithm>
#include "colors.h"
#include "GameManager.h"
#include "GridSystem/GroundTileTypeManager.h"
#include "utils.h"
#include "Levels/World/WorldLevel.h"
@@ -30,6 +31,18 @@ Player::Player(const Vector2f& Position, TextureManager* manager) : m_Position(P
manager->GetTexture("animations/player/player_dig.png"),
7, 0.05f, Rectf { 0, 0, 70, 70 }, true);
m_flyStartAnimation = new Animation(
manager->GetTexture("animations/player/player_fly_start.png"),
12, 0.05f, Rectf { 0, 0, 70, 70 }, false);
m_flyAnimation = new Animation(
manager->GetTexture("animations/player/player_fly.png"),
5, 0.01f, Rectf { 0, 0, 70, 70 }, true);
m_flyTurnAnimation = new Animation(
manager->GetTexture("animations/player/player_fly_turn.png"),
3, 0.05f, Rectf { 0, 0, 70, 70 }, false);
m_currentAnimation = m_walkAnimation;
}
Player::Player(Player&& other) {
@@ -41,6 +54,10 @@ Player::~Player() {
delete m_turnAnimation;
delete m_digAnimation;
delete m_digStartAnimation;
delete m_flyStartAnimation;
delete m_flyAnimation;
delete m_flyTurnAnimation;
}
Collision::CollisionRect Player::GetCollisionRect() const {
@@ -59,7 +76,7 @@ void Player::Draw() const {
int halfFrameWidth = frameWidth / 2;
int bobOffset = m_BobUp ? 1 : 0;
float rotateOffset = std::abs(m_Vel.x) / 40;
float rotateOffset = std::abs(m_Vel.x) / 30;
Vector2f drawPos = Vector2f { center.x, center.y + 9 + bobOffset };
glPushMatrix();
glTranslatef(drawPos.x - halfFrameWidth, drawPos.y - halfFrameWidth, 0);
@@ -123,6 +140,12 @@ void Player::ProcessImGui() {
ImGui::Text("Bottom: %s", m_ContactMap[Collision::CollisionDirection::Bottom] != nullptr ? "true" : "false");
ImGui::Text("Left: %s", m_ContactMap[Collision::CollisionDirection::Left] != nullptr ? "true" : "false");
ImGui::Text("Right: %s", m_ContactMap[Collision::CollisionDirection::Right] != nullptr ? "true" : "false");
ImGui::Separator();
ImGui::Text("Values");
ImGui::Text("Current Fuel: %f", GameManager::GetInstance().GetFuel());
ImGui::Text("Current Score: %d", GameManager::GetInstance().GetScore());
ImGui::Text("Current Hull Integrity: %d", GameManager::GetInstance().GetHullIntegrity());
ImGui::End();
}
void Player::Dig(Collision::CollisionDirection dir, WorldLevel& level) {
@@ -131,6 +154,7 @@ void Player::Dig(Collision::CollisionDirection dir, WorldLevel& level) {
m_DigTile = m_ContactMap[dir];
//Set the digging location in the center of the destination tile;
const WorldTile* tile = m_ContactMap[dir];
m_ToAddPoints = tile->GetTileType()->GetValue();
//Add case for bottom because otherwise i clip through the floor
m_DigDestination = tile->GetPosition();
if (dir == Collision::Bottom) {
@@ -183,7 +207,14 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
if (m_State != PlayerState::Digging) {
if (utils::isKeyDown(SDL_SCANCODE_W)) {
m_State = PlayerState::Flying;
m_Vel.y = m_Speed;
// m_Vel.y = m_Speed / 10;
m_Acc.y += m_Speed * 10;
if(!m_IsPropellorDeployed) {
m_currentAnimation = m_flyStartAnimation;
m_flyStartAnimation->SetFlipped(m_Direction == PlayerDirection::Right);
} else {
m_currentAnimation = m_flyAnimation;
}
m_Grounded = false;
}
if (utils::isKeyPressed(SDL_SCANCODE_S)) {
@@ -200,11 +231,12 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
if (utils::isKeyDown(SDL_SCANCODE_A)) {
if (!m_IsTurning) {
m_walkAnimation->SetFlipped(false);
m_flyAnimation->SetFlipped(false);
}
m_Acc.x = -m_Speed;
if (m_Direction == PlayerDirection::Right) {
m_IsTurning = true;
m_currentAnimation = m_turnAnimation;
m_currentAnimation = m_State == PlayerState::Walking ? m_turnAnimation : m_flyTurnAnimation;
m_currentAnimation->SetFlipped(true);
m_currentAnimation->Reset();
}
@@ -227,12 +259,13 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
if (utils::isKeyDown(SDL_SCANCODE_D)) {
if (!m_IsTurning) {
m_walkAnimation->SetFlipped(true);
m_flyAnimation->SetFlipped(true);
}
m_Acc.x = m_Speed;
if (m_Direction == PlayerDirection::Left) {
m_IsTurning = true;
m_currentAnimation = m_turnAnimation;
m_currentAnimation = m_State == PlayerState::Walking ? m_turnAnimation : m_flyTurnAnimation;
m_currentAnimation->SetFlipped(false);
m_currentAnimation->Reset();
}
@@ -268,11 +301,30 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
m_currentAnimation->Update(elapsedTime);
if (m_currentAnimation->IsDone() && m_IsTurning) {
if(m_State == PlayerState::Flying && m_Grounded) {
m_State = PlayerState::Idle;
m_walkAnimation->SetFlipped(m_Direction == PlayerDirection::Right);
m_currentAnimation = m_walkAnimation;
m_IsPropellorDeployed = false;
m_flyStartAnimation->Reset();
}
if (m_currentAnimation->IsDone() && m_IsTurning) {
m_currentAnimation = m_State == PlayerState::Walking ? m_walkAnimation : m_flyAnimation;
m_IsTurning = false;
}
if(m_currentAnimation == m_flyStartAnimation) {
if(m_flyStartAnimation->IsDone()) {
m_IsPropellorDeployed = true;
m_currentAnimation = m_flyAnimation;
} else {
m_currentAnimation = m_flyStartAnimation;
}
}
if (m_currentAnimation == m_digStartAnimation) {
@@ -361,9 +413,11 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
switch (m_State) {
case PlayerState::Idle:
m_walkAnimation->SetPlaying(false);
GameManager::GetInstance().DecreaseFuel(0.02f);
break;
case PlayerState::Walking:
m_walkAnimation->SetPlaying(true);
GameManager::GetInstance().DecreaseFuel(0.04f);
break;
case PlayerState::Digging: {
// m_walkAnimation->SetPlaying(false);
@@ -386,8 +440,8 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
float progress = utils::map(m_DigProgress, 0.0f, m_DigTime, 0.0f, 1.0f);
int particleProgress = (int)utils::map(m_DigProgress, 0.0f, m_DigTime, 0.0f, 100.0f);
std::cout << progress << '\n';
if (particleProgress % 25 == 0) {
m_DigParticles.push_back(new Particle(m_Position, Vector2f { (float)utils::randRange(-200, 200), (float)utils::randRange(-100, -300) }, 5.f,
if (particleProgress % 2 == 0) {
m_DigParticles.push_back(new Particle(m_Position + Vector2f{ 20, 0 }, Vector2f { (float)utils::randRange(-200, 200), (float)utils::randRange(-100, -300) }, 5.f,
TextureManager::GetInstance()->GetTexture("particles/dirt_" + std::to_string(utils::randRange(1, 8)) + ".png")));
}
m_Position = utils::lerp(m_DigStart, m_DigDestination, progress);
@@ -401,6 +455,8 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
m_currentAnimation = m_walkAnimation;
m_HasDeletedTile = false;
m_Digging = false;
GameManager::GetInstance().IncreaseScore(m_ToAddPoints);
m_ToAddPoints = 0;
}
}

View File

@@ -94,6 +94,8 @@ private:
bool m_HasDeletedTile{ false };
WorldTile* m_DigTile{ nullptr };
int m_ToAddPoints{ 0 };
bool m_IsDiggingPrimed{ false };
std::vector<Particle*> m_DigParticles{};
@@ -111,6 +113,11 @@ private:
Animation* m_digStartAnimation{ nullptr };
Animation* m_digAnimation{ nullptr };
Animation* m_flyStartAnimation{ nullptr };
Animation* m_flyAnimation{ nullptr };
Animation* m_flyTurnAnimation{ nullptr };
bool m_IsPropellorDeployed{ false };
PlayerState m_State { PlayerState::Idle };
PlayerDirection m_Direction { PlayerDirection::Left };
DigDirection m_DigDirection { DigDirection::Right };