diff --git a/.idea/.idea.Motherload/.idea/workspace.xml b/.idea/.idea.Motherload/.idea/workspace.xml
index d241815..9ec5f49 100644
--- a/.idea/.idea.Motherload/.idea/workspace.xml
+++ b/.idea/.idea.Motherload/.idea/workspace.xml
@@ -11,16 +11,30 @@
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
@@ -34,7 +48,191 @@
+ {
+ "lastFilter": {
+ "state": "OPEN",
+ "assignee": "VerhulstBram"
+ }
+}
+ {
+ "selectedUrlAndAccountId": {
+ "url": "https://github.com/HowestDAE/dae16-VerhulstBram",
+ "accountId": "10646dff-e3dc-43df-be50-11b78f56b677"
+ }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -42,6 +240,7 @@
+
@@ -51,7 +250,6 @@
-
@@ -251,6 +449,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -404,7 +616,15 @@
1715817878533
-
+
+
+ 1715856298231
+
+
+
+ 1715856298231
+
+
@@ -432,7 +652,15 @@
-
+
+
+
+
+
+
+
+
+
diff --git a/Assets/Player/PlayerFly.aseprite b/Assets/Player/PlayerFly.aseprite
new file mode 100644
index 0000000..102b7b3
Binary files /dev/null and b/Assets/Player/PlayerFly.aseprite differ
diff --git a/Assets/Player/PlayerFlyStart.aseprite b/Assets/Player/PlayerFlyStart.aseprite
new file mode 100644
index 0000000..a837435
Binary files /dev/null and b/Assets/Player/PlayerFlyStart.aseprite differ
diff --git a/Assets/Player/PlayerFlyTurn.aseprite b/Assets/Player/PlayerFlyTurn.aseprite
new file mode 100644
index 0000000..8d883ff
Binary files /dev/null and b/Assets/Player/PlayerFlyTurn.aseprite differ
diff --git a/Engine/Collision.h b/Engine/Collision.h
index 57fc041..4cb0cf9 100644
--- a/Engine/Collision.h
+++ b/Engine/Collision.h
@@ -29,6 +29,10 @@ namespace Collision
Vector2f vel;
std::map ContactMap{};
+
+ Rectf getRectf() {
+ return Rectf{ pos.x, pos.y, size.x, size.y };
+ }
};
struct TileCollisionRect
diff --git a/Engine/SoundEffect.cpp b/Engine/SoundEffect.cpp
index 1e51b88..4f97c57 100644
--- a/Engine/SoundEffect.cpp
+++ b/Engine/SoundEffect.cpp
@@ -2,76 +2,59 @@
#include
#include "SoundEffect.h"
-SoundEffect::SoundEffect( const std::string& path )
- :m_pMixChunk{ Mix_LoadWAV( path.c_str( ) ) }
-{
- if ( m_pMixChunk == nullptr )
- {
- const std::string errorMsg = "SoundEffect: Failed to load " + path + ",\nSDL_mixer Error: " + Mix_GetError( );
+SoundEffect::SoundEffect(const std::string& path, int channel)
+ : m_pMixChunk { Mix_LoadWAV(path.c_str()) }, m_Channel(channel) {
+ if (m_pMixChunk == nullptr) {
+ const std::string errorMsg = "SoundEffect: Failed to load " + path + ",\nSDL_mixer Error: " + Mix_GetError();
std::cerr << errorMsg;
}
}
-SoundEffect::~SoundEffect( )
-{
- Mix_FreeChunk( m_pMixChunk );
+SoundEffect::~SoundEffect() {
+ Mix_FreeChunk(m_pMixChunk);
m_pMixChunk = nullptr;
}
-bool SoundEffect::IsLoaded( ) const
-{
+bool SoundEffect::IsLoaded() const {
return m_pMixChunk != nullptr;
}
-bool SoundEffect::Play( const int loops ) const
-{
- // Don't save the channel as a data member,
- // because when it stops playing the channel becomes free
- // and available for usage by other effects
- if ( m_pMixChunk != nullptr )
- {
- const int channel{ Mix_PlayChannel( -1, m_pMixChunk, loops ) };
- return channel == -1 ? false : true;
+void SoundEffect::Play(const int loops) const {
+ if (m_pMixChunk != nullptr) {
+ const int channel { Mix_PlayChannel(m_Channel, m_pMixChunk, loops) };
}
- else
- {
- return false;
+ else {
+ std::cout << "SoundEffect::Play() failed, sound effect not loaded\n";
}
}
-void SoundEffect::SetVolume( const int value )
-{
- if ( m_pMixChunk != nullptr )
- {
- Mix_VolumeChunk( m_pMixChunk, value );
+void SoundEffect::SetVolume(const int value) {
+ if (m_pMixChunk != nullptr) {
+ Mix_VolumeChunk(m_pMixChunk, value);
}
}
-int SoundEffect::GetVolume( ) const
-{
- if ( m_pMixChunk != nullptr )
- {
- return Mix_VolumeChunk( m_pMixChunk, -1 );
+int SoundEffect::GetVolume() const {
+ if (m_pMixChunk != nullptr) {
+ return Mix_VolumeChunk(m_pMixChunk, -1);
}
- else
- {
+ else {
return -1;
}
}
-void SoundEffect::StopAll( )
-{
- Mix_HaltChannel(-1 );
+void SoundEffect::Stop() const {
+ Mix_HaltChannel(m_Channel);
}
-void SoundEffect::PauseAll( )
-{
- Mix_Pause( -1 );
-}
-void SoundEffect::ResumeAll( )
-{
- Mix_Resume( -1 );
+void SoundEffect::StopAll() {
+ Mix_HaltChannel(-1);
}
-
+void SoundEffect::PauseAll() {
+ Mix_Pause(-1);
+}
+void SoundEffect::ResumeAll() {
+ Mix_Resume(-1);
+}
diff --git a/Engine/SoundEffect.h b/Engine/SoundEffect.h
index 16be04e..fbd4477 100644
--- a/Engine/SoundEffect.h
+++ b/Engine/SoundEffect.h
@@ -4,7 +4,7 @@ class Mix_Chunk;
class SoundEffect final
{
public:
- explicit SoundEffect( const std::string& path );
+ explicit SoundEffect( const std::string& path, int channel = -1);
~SoundEffect( );
SoundEffect(const SoundEffect& other) = delete;
SoundEffect& operator=(const SoundEffect& rhs) = delete;
@@ -12,13 +12,15 @@ public:
SoundEffect& operator=( SoundEffect&& rhs) = delete;
bool IsLoaded( ) const;
- bool Play( const int loops ) const;
+ void Play( const int loops ) const;
void SetVolume( const int value );
- int GetVolume( ) const;
+ int GetVolume( ) const;
+ void Stop( ) const;
static void StopAll( );
static void PauseAll( );
static void ResumeAll( );
private:
Mix_Chunk* m_pMixChunk;
+ int m_Channel;
};
diff --git a/Engine/Text.cpp b/Engine/Text.cpp
index 5e22aa1..4f073db 100644
--- a/Engine/Text.cpp
+++ b/Engine/Text.cpp
@@ -21,6 +21,9 @@ void Text::Draw(const Vector2f& pos) const {
}
}
void Text::ChangeText(const std::string& text) {
+ if(m_Text == text) {
+ return;
+ }
if(m_IsCreatedOk && m_Texture->IsCreationOk()) {
delete m_Texture;
m_Texture = new Texture(text, m_FontPath, m_Size, m_Color);
diff --git a/Engine/colors.h b/Engine/colors.h
index 28b1afc..4169914 100644
--- a/Engine/colors.h
+++ b/Engine/colors.h
@@ -14,4 +14,5 @@ namespace Colors
const Color4f MAGENTA{ 1.0f, 0.0f, 1.0f, 1.0f };
const Color4f CYAN{ 0.0f, 1.0f, 1.0f, 1.0f };
const Color4f PINK{ 1.0f, 0.0f, 0.5f, 1.0f };
+ const Color4f ORANGE{ 1.0f, 0.5f, 0.0f, 1.0f };
}
diff --git a/Game/GameManager.cpp b/Game/GameManager.cpp
index 276cd67..ca3796b 100644
--- a/Game/GameManager.cpp
+++ b/Game/GameManager.cpp
@@ -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
+}
diff --git a/Game/GameManager.h b/Game/GameManager.h
index c67fedb..cb365b3 100644
--- a/Game/GameManager.h
+++ b/Game/GameManager.h
@@ -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 };
};
diff --git a/Game/GridSystem/WorldTile.cpp b/Game/GridSystem/WorldTile.cpp
index 59575e6..b103a51 100644
--- a/Game/GridSystem/WorldTile.cpp
+++ b/Game/GridSystem/WorldTile.cpp
@@ -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);
}
}
diff --git a/Game/GridSystem/WorldTile.h b/Game/GridSystem/WorldTile.h
index 7a97f70..ae5ac82 100644
--- a/Game/GridSystem/WorldTile.h
+++ b/Game/GridSystem/WorldTile.h
@@ -6,8 +6,7 @@
class Camera;
-enum class GroundTileTypes
-{
+enum class GroundTileTypes {
Air,
Dirt,
Grass,
@@ -38,64 +37,67 @@ static std::map 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 GroundTileWeights {
@@ -128,12 +129,11 @@ public:
// { Tiles::Ores::IRON, 0.1f },
// };
-static std::map GroundTileWeights;
+static std::map 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 m_SideTextures { 8, nullptr };
+ std::vector m_SideTextures { 8, nullptr };
Texture* m_pAllTexture;
};
diff --git a/Game/Gui/GuiMeter.cpp b/Game/Gui/GuiMeter.cpp
index ca11ed4..1dff68e 100644
--- a/Game/Gui/GuiMeter.cpp
+++ b/Game/Gui/GuiMeter.cpp
@@ -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(utils::map(m_Value, 0.0f, m_MaxValue, 0, (float)m_Animation->GetFrameCount()));
m_Animation->SetFrame(frame);
}
diff --git a/Game/Gui/GuiText.cpp b/Game/Gui/GuiText.cpp
index ddb2e56..0e6808c 100644
--- a/Game/Gui/GuiText.cpp
+++ b/Game/Gui/GuiText.cpp
@@ -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;
diff --git a/Game/Gui/Screens/FuelScreen.cpp b/Game/Gui/Screens/FuelScreen.cpp
index 8a1727c..f2b245c 100644
--- a/Game/Gui/Screens/FuelScreen.cpp
+++ b/Game/Gui/Screens/FuelScreen.cpp
@@ -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()));
}
diff --git a/Game/Gui/Screens/FuelScreen.h b/Game/Gui/Screens/FuelScreen.h
index 02f49f2..ca120ba 100644
--- a/Game/Gui/Screens/FuelScreen.h
+++ b/Game/Gui/Screens/FuelScreen.h
@@ -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;
};
diff --git a/Game/Gui/Screens/MainScreen.cpp b/Game/Gui/Screens/MainScreen.cpp
index 166fab5..f2f1bfa 100644
--- a/Game/Gui/Screens/MainScreen.cpp
+++ b/Game/Gui/Screens/MainScreen.cpp
@@ -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) {
diff --git a/Game/Gui/Screens/ScreenManager.cpp b/Game/Gui/Screens/ScreenManager.cpp
index 1cf6de1..4cca990 100644
--- a/Game/Gui/Screens/ScreenManager.cpp
+++ b/Game/Gui/Screens/ScreenManager.cpp
@@ -37,6 +37,9 @@ void ScreenManager::CloseScreen() {
}
}
+bool ScreenManager::IsScreenOpen() {
+ return m_IsScreenOpen;
+}
ScreenManager::~ScreenManager() {
delete m_FuelScreen;
delete m_SellScreen;
diff --git a/Game/Gui/Screens/ScreenManager.h b/Game/Gui/Screens/ScreenManager.h
index 4ca8259..cf7f210 100644
--- a/Game/Gui/Screens/ScreenManager.h
+++ b/Game/Gui/Screens/ScreenManager.h
@@ -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;
diff --git a/Game/Levels/World/Building.cpp b/Game/Levels/World/Building.cpp
index 175782f..a3eb75f 100644
--- a/Game/Levels/World/Building.cpp
+++ b/Game/Levels/World/Building.cpp
@@ -2,14 +2,48 @@
#include "Building.h"
#include
-Building::Building(const std::string& filePath, const Vector2f& position, TextureManager* pTextureManager): m_Position(position) {
+#include
+
+#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 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);
}
diff --git a/Game/Levels/World/Building.h b/Game/Levels/World/Building.h
index 08855b0..9227331 100644
--- a/Game/Levels/World/Building.h
+++ b/Game/Levels/World/Building.h
@@ -1,26 +1,34 @@
#pragma once
+#include
+
#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 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 m_OnEnterHitbox;
+ bool m_IsPlayerInHitbox{ false };
+ bool m_DidPlayerEnterHitbox{ false };
};
diff --git a/Game/Levels/World/WorldLevel.cpp b/Game/Levels/World/WorldLevel.cpp
index fa169c1..e69803a 100644
--- a/Game/Levels/World/WorldLevel.cpp
+++ b/Game/Levels/World/WorldLevel.cpp
@@ -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;
diff --git a/Game/Levels/World/WorldLevel.h b/Game/Levels/World/WorldLevel.h
index 3b2eb55..76546bb 100644
--- a/Game/Levels/World/WorldLevel.h
+++ b/Game/Levels/World/WorldLevel.h
@@ -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 m_Buildings{};
+ std::vector 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 };
};
diff --git a/Game/Player.cpp b/Game/Player.cpp
index ecc686c..82ad169 100644
--- a/Game/Player.cpp
+++ b/Game/Player.cpp
@@ -5,6 +5,7 @@
#include
#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;
}
}
diff --git a/Game/Player.h b/Game/Player.h
index 2b99a46..4445d50 100644
--- a/Game/Player.h
+++ b/Game/Player.h
@@ -94,6 +94,8 @@ private:
bool m_HasDeletedTile{ false };
WorldTile* m_DigTile{ nullptr };
+ int m_ToAddPoints{ 0 };
+
bool m_IsDiggingPrimed{ false };
std::vector 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 };
diff --git a/Resources/animations/player/player_fly.png b/Resources/animations/player/player_fly.png
new file mode 100644
index 0000000..0539d34
Binary files /dev/null and b/Resources/animations/player/player_fly.png differ
diff --git a/Resources/animations/player/player_fly_start.png b/Resources/animations/player/player_fly_start.png
new file mode 100644
index 0000000..acbb7e1
Binary files /dev/null and b/Resources/animations/player/player_fly_start.png differ
diff --git a/Resources/animations/player/player_fly_turn.png b/Resources/animations/player/player_fly_turn.png
new file mode 100644
index 0000000..ddceb0b
Binary files /dev/null and b/Resources/animations/player/player_fly_turn.png differ
diff --git a/Resources/gui/fuel/background.png b/Resources/gui/fuel/background.png
index 13741cb..307f41c 100644
Binary files a/Resources/gui/fuel/background.png and b/Resources/gui/fuel/background.png differ
diff --git a/Resources/smb_gameover.wav b/Resources/smb_gameover.wav
new file mode 100644
index 0000000..daf9bac
Binary files /dev/null and b/Resources/smb_gameover.wav differ