diff --git a/.idea/.idea.Motherload/.idea/workspace.xml b/.idea/.idea.Motherload/.idea/workspace.xml index 98534b4..d4c72e9 100644 --- a/.idea/.idea.Motherload/.idea/workspace.xml +++ b/.idea/.idea.Motherload/.idea/workspace.xml @@ -11,14 +11,23 @@ + + + + - - - - - + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -71,28 +285,28 @@ - { - "keyToString": { - "C++ Project.Game.executor": "Debug", - "RunOnceActivity.OpenProjectViewOnStart": "true", - "RunOnceActivity.ShowReadmeOnStart": "true", - "ignore.virus.scanning.warn.message": "true", - "node.js.detected.package.eslint": "true", - "node.js.detected.package.tslint": "true", - "node.js.selected.package.eslint": "(autodetect)", - "node.js.selected.package.tslint": "(autodetect)", - "nodejs_package_manager_path": "npm", - "settings.editor.selected.configurable": "preferences.pluginManager", - "vue.rearranger.settings.migration": "true" + +}]]> @@ -228,7 +442,11 @@ - + + + + + - @@ -366,7 +592,8 @@ - diff --git a/Assets/Player/PlayerDig.aseprite b/Assets/Player/PlayerDig.aseprite new file mode 100644 index 0000000..efceedd Binary files /dev/null and b/Assets/Player/PlayerDig.aseprite differ diff --git a/Assets/Player/PlayerDigStart.aseprite b/Assets/Player/PlayerDigStart.aseprite index db52475..f45a1ea 100644 Binary files a/Assets/Player/PlayerDigStart.aseprite and b/Assets/Player/PlayerDigStart.aseprite differ diff --git a/Game/Animations/Animation.cpp b/Game/Animations/Animation.cpp index eca8ebb..4fdd482 100644 --- a/Game/Animations/Animation.cpp +++ b/Game/Animations/Animation.cpp @@ -1,6 +1,8 @@ #include "pch.h" #include "Animation.h" +#include + #include "utils.h" Animation::Animation(Texture* pTexture, int frames, float frameDuration, Rectf srcRect, bool isLooping): m_pTexture(pTexture), m_SrcRect(srcRect), m_Frames(frames), m_isLooping(isLooping), m_FrameDuration(frameDuration) { diff --git a/Game/Animations/Animation.h b/Game/Animations/Animation.h index 7c691d6..c9e89ea 100644 --- a/Game/Animations/Animation.h +++ b/Game/Animations/Animation.h @@ -23,6 +23,7 @@ public: m_CurrentFrame = 0; m_hasPlayedOnce = false; m_isPlaying = true; + m_FrameTimer = m_FrameDuration; } bool IsDone() const { return m_hasPlayedOnce && !m_isLooping; diff --git a/Game/Game.vcxproj b/Game/Game.vcxproj index 19f9ab8..f8ad97a 100644 --- a/Game/Game.vcxproj +++ b/Game/Game.vcxproj @@ -308,7 +308,9 @@ true - + + + @@ -477,7 +479,9 @@ - + + + diff --git a/Game/Gui/Button.cpp b/Game/Gui/GuiButton.cpp similarity index 76% rename from Game/Gui/Button.cpp rename to Game/Gui/GuiButton.cpp index 64a1f34..2f47c4e 100644 --- a/Game/Gui/Button.cpp +++ b/Game/Gui/GuiButton.cpp @@ -1,28 +1,28 @@ #include "pch.h" -#include "Button.h" +#include "GuiButton.h" #include #include "colors.h" #include "utils.h" -Button::Button(const std::string& filePath, Vector2f pos, Vector2f size, TextureManager* manager): m_Position(pos), m_Size(size) { +GuiButton::GuiButton(const std::string& filePath, Vector2f pos, Vector2f size, TextureManager* manager): m_Position(pos), m_Size(size) { m_Texture = manager->GetTexture(filePath); if(size.x == 0 && size.y == 0) { m_Size = Vector2f{float(m_Texture->GetWidth()), float(m_Texture->GetHeight())}; } std::cout << "Button created" << '\n'; } -Button::~Button() { +GuiButton::~GuiButton() { std::cout << "Button destroyed" << '\n'; } -void Button::Draw() const { +void GuiButton::Draw() const { Rectf dest = Rectf(m_Position, m_Size); Rectf src = Rectf(0, 0, m_Texture->GetWidth(), m_Texture->GetHeight()); if(m_IsHovered) { m_Texture->Draw(dest, src, false); } } -void Button::Update(float elapsedSec) { +void GuiButton::Update(float elapsedSec) { Vector2f mousePos = utils::GetMousePos(); Rectf buttonRect = Rectf(m_Position, m_Size); diff --git a/Game/Gui/Button.h b/Game/Gui/GuiButton.h similarity index 62% rename from Game/Gui/Button.h rename to Game/Gui/GuiButton.h index 6dc9eaa..999871c 100644 --- a/Game/Gui/Button.h +++ b/Game/Gui/GuiButton.h @@ -2,17 +2,18 @@ #include #include +#include "GuiElement.h" #include "Texture.h" #include "../TextureManager.h" -class Button +class GuiButton : public GuiElement { public: - Button() = default; - Button(const std::string& filePath, Vector2f pos, Vector2f size, TextureManager* manager); - ~Button(); - void Draw() const; - void Update(float elapsedSec); + GuiButton() = default; + GuiButton(const std::string& filePath, Vector2f pos, Vector2f size, TextureManager* manager); + ~GuiButton() override; + virtual void Draw() const override; + virtual void Update(float elapsedSec) override; void SetOnClick(std::function onClick) { m_OnClick = onClick; diff --git a/Game/Gui/GuiElement.cpp b/Game/Gui/GuiElement.cpp new file mode 100644 index 0000000..6b09a53 --- /dev/null +++ b/Game/Gui/GuiElement.cpp @@ -0,0 +1,2 @@ +#include "pch.h" +#include "GuiElement.h" diff --git a/Game/Gui/GuiElement.h b/Game/Gui/GuiElement.h new file mode 100644 index 0000000..3bff5b7 --- /dev/null +++ b/Game/Gui/GuiElement.h @@ -0,0 +1,14 @@ +#pragma once + +class GuiElement +{ +public: + GuiElement() = default; + virtual ~GuiElement() = default; + + virtual void Draw() const = 0; + virtual void Update(float elapsedSec) = 0; + +private: + +}; diff --git a/Game/Gui/GuiMeter.cpp b/Game/Gui/GuiMeter.cpp new file mode 100644 index 0000000..3abba58 --- /dev/null +++ b/Game/Gui/GuiMeter.cpp @@ -0,0 +1,18 @@ +#include "pch.h" +#include "GuiMeter.h" + +#include "TextureManager.h" +GuiMeter::GuiMeter(const std::string& filePath, Vector2f pos, Vector2f frameSize, int frameCount, TextureManager* manager): m_Position(pos), m_FrameCount(frameCount) { + m_Animation = new Animation(manager->GetTexture(filePath),frameCount, 0.0f, Rectf{0, 0, frameSize.x, frameSize.y}, false); + +} +GuiMeter::~GuiMeter() { + delete m_Animation; +} +void GuiMeter::Draw() const { + m_Animation->Draw(m_Position); +} +void GuiMeter::Update(float elapsedSec) { + + +} \ No newline at end of file diff --git a/Game/Gui/GuiMeter.h b/Game/Gui/GuiMeter.h new file mode 100644 index 0000000..221fa1b --- /dev/null +++ b/Game/Gui/GuiMeter.h @@ -0,0 +1,25 @@ +#pragma once +#include "GuiElement.h" +#include "Texture.h" +#include "Animations/Animation.h" + +class TextureManager; + +class GuiMeter : public GuiElement +{ +public: + GuiMeter() = default; + GuiMeter(const std::string& filePath, Vector2f pos, Vector2f frameSize, int frameCount, TextureManager* manager); + virtual ~GuiMeter(); + + virtual void Draw() const override; + virtual void Update(float elapsedSec) override; + +private: + Animation* m_Animation{ nullptr }; + Vector2f m_Position; + + float m_Value{ 0.0f }; + + int m_FrameCount; +}; diff --git a/Game/Gui/Screen.cpp b/Game/Gui/Screen.cpp index e6fca17..05bad80 100644 --- a/Game/Gui/Screen.cpp +++ b/Game/Gui/Screen.cpp @@ -5,12 +5,12 @@ Screen::Screen(const std::string& filePath, Vector2f pos, Vector2f size, Texture m_Background = manager->GetTexture(filePath); } Screen::~Screen() { - for (Button* b : m_Buttons) { + for (GuiElement* b : m_Elements) { delete b; } } void Screen::Update(float elapsedSecs) { - for (Button* b : m_Buttons) { + for (GuiElement* b : m_Elements) { b->Update(elapsedSecs); } } @@ -19,7 +19,7 @@ void Screen::Draw() const { Rectf src = Rectf(0, 0, m_Background->GetWidth(), m_Background->GetHeight()); m_Background->Draw(dest, src, false); - for (Button* b : m_Buttons) { + for (GuiElement* b : m_Elements) { b->Draw(); } } diff --git a/Game/Gui/Screen.h b/Game/Gui/Screen.h index 16a44f5..208a72b 100644 --- a/Game/Gui/Screen.h +++ b/Game/Gui/Screen.h @@ -1,7 +1,7 @@ #pragma once #include -#include "Button.h" +#include "GuiButton.h" #include "structs.h" #include "Texture.h" #include "../TextureManager.h" @@ -14,7 +14,7 @@ public: virtual ~Screen(); - void AddButton(Button* button) { m_Buttons.push_back(button); } + void AddElement(GuiElement* element) { m_Elements.push_back(element); } virtual void Update(float elapsedSecs); virtual void Draw() const; @@ -24,5 +24,5 @@ private: Texture* m_Background{ nullptr }; - std::vector m_Buttons; + std::vector m_Elements; }; diff --git a/Game/Gui/Screens/FuelScreen.cpp b/Game/Gui/Screens/FuelScreen.cpp index 5b72025..4d2b00a 100644 --- a/Game/Gui/Screens/FuelScreen.cpp +++ b/Game/Gui/Screens/FuelScreen.cpp @@ -15,29 +15,29 @@ FuelScreen::FuelScreen(const std::string& filePath, Vector2f pos, Vector2f size, const Vector2f closeButtonOffset = Vector2f { 460, 396 - 14 }; Vector2f closeButtonPos = fuelScreenCenter + closeButtonOffset; closeButtonPos.y -= 18; - Button* closeFuelButton = new Button { "gui/close.png", closeButtonPos, Vector2f{0,0}, TextureManager::GetInstance() }; + GuiButton* closeFuelButton = new GuiButton { "gui/close.png", closeButtonPos, Vector2f{0,0}, TextureManager::GetInstance() }; closeFuelButton->SetOnClick([this]() { ScreenManager::GetInstance()->CloseScreen(); }); - this->AddButton(closeFuelButton); + this->AddElement(closeFuelButton); const Vector2f oneDollarButtonPos = Vector2f { 451, 287 }; - Button* fiveDollarButton = new Button { "gui/fuel/5dollars.png", oneDollarButtonPos , Vector2f{0,0}, TextureManager::GetInstance() }; - this->AddButton(fiveDollarButton); + GuiButton* fiveDollarButton = new GuiButton { "gui/fuel/5dollars.png", oneDollarButtonPos , Vector2f{0,0}, TextureManager::GetInstance() }; + this->AddElement(fiveDollarButton); const Vector2f tenDollarButtonPos = oneDollarButtonPos + Vector2f { 113, -1 }; - Button* tenDollarButton = new Button { "gui/fuel/10dollars.png", tenDollarButtonPos, Vector2f{0,0}, TextureManager::GetInstance() }; - this->AddButton(tenDollarButton); + GuiButton* tenDollarButton = new GuiButton { "gui/fuel/10dollars.png", tenDollarButtonPos, Vector2f{0,0}, TextureManager::GetInstance() }; + this->AddElement(tenDollarButton); const Vector2f twentyFiveDollarButtonPos = oneDollarButtonPos + Vector2f { 0, -89 }; - Button* twentyFiveDollarButton = new Button { "gui/fuel/25dollars.png", twentyFiveDollarButtonPos, Vector2f{0,0}, TextureManager::GetInstance() }; - this->AddButton(twentyFiveDollarButton); + GuiButton* twentyFiveDollarButton = new GuiButton { "gui/fuel/25dollars.png", twentyFiveDollarButtonPos, Vector2f{0,0}, TextureManager::GetInstance() }; + this->AddElement(twentyFiveDollarButton); const Vector2f fiftyDollarButtonPos = twentyFiveDollarButtonPos + Vector2f { 114, 0 }; - Button* fiftyDollarButton = new Button { "gui/fuel/50dollars.png", fiftyDollarButtonPos, Vector2f{0,0}, TextureManager::GetInstance() }; - this->AddButton(fiftyDollarButton); + GuiButton* fiftyDollarButton = new GuiButton { "gui/fuel/50dollars.png", fiftyDollarButtonPos, Vector2f{0,0}, TextureManager::GetInstance() }; + this->AddElement(fiftyDollarButton); const Vector2f fillTankButtonPos = Vector2f { 450, 108 }; - Button* fillTankButton = new Button { "gui/fuel/fillTank.png", fillTankButtonPos, Vector2f{0,0}, TextureManager::GetInstance() }; - this->AddButton(fillTankButton); + GuiButton* fillTankButton = new GuiButton { "gui/fuel/fillTank.png", fillTankButtonPos, Vector2f{0,0}, TextureManager::GetInstance() }; + this->AddElement(fillTankButton); } diff --git a/Game/Player.cpp b/Game/Player.cpp index 12e2763..73e69e0 100644 --- a/Game/Player.cpp +++ b/Game/Player.cpp @@ -25,7 +25,11 @@ Player::Player(const Vector2f& Position, TextureManager* manager) : m_Position(P 5, 0.07f, Rectf { 0, 0, 70, 70 }, false); m_digStartAnimation = new Animation( manager->GetTexture("animations/player/player_dig_start.png"), - 8, 0.1f, Rectf { 0, 0, 70, 70 }, false); + 7, 0.07f, Rectf { 0, 0, 70, 70 }, false); + m_digAnimation = new Animation( + manager->GetTexture("animations/player/player_dig.png"), + 7, 0.05f, Rectf { 0, 0, 70, 70 }, true); + m_currentAnimation = m_walkAnimation; } Player::Player(Player&& other) { @@ -90,6 +94,7 @@ void Player::ProcessImGui() { break; } ImGui::Text("Player State %s", currentState.c_str()); + ImGui::Text("Is digging Primed: %s", m_IsDiggingPrimed ? "true" : "false"); ImGui::Text("Bob counter: %f", m_BobTimer); ImGui::Text("Bob up: %s", m_BobUp ? "true" : "false"); ImGui::Text("Is Grounded: %s", m_Grounded ? "true" : "false"); @@ -165,14 +170,18 @@ void Player::Update(float elapsedTime, WorldLevel& level) { if (m_State != PlayerState::Digging) { if (utils::isKeyDown(SDL_SCANCODE_W)) { // if (m_Grounded) { - m_State = PlayerState::Flying; - m_Vel.y = m_Speed; - m_Grounded = false; + m_State = PlayerState::Flying; + m_Vel.y = m_Speed; + m_Grounded = false; // } } if (utils::isKeyPressed(SDL_SCANCODE_S)) { if (m_Grounded) { if (this->CanDig(Collision::Bottom, level)) { + m_DigDirection = DigDirection::Down; + m_currentAnimation = m_digStartAnimation; + m_currentAnimation->Reset(); + m_IsDiggingPrimed = false; this->Dig(Collision::CollisionDirection::Bottom, level); } } @@ -192,6 +201,7 @@ void Player::Update(float elapsedTime, WorldLevel& level) { if (m_Grounded && !m_DidJustDigLeft) { //Check if the player doesnt come from digging a tile if (this->CanDig(Collision::CollisionDirection::Left, level)) { + m_DigDirection = DigDirection::Left; this->Dig(Collision::CollisionDirection::Left, level); m_DidJustDigLeft = true; } @@ -220,6 +230,7 @@ void Player::Update(float elapsedTime, WorldLevel& level) { if (m_Grounded && !m_DidJustDigRight) { //Check if the player doesnt come from digging a tile if (this->CanDig(Collision::CollisionDirection::Right, level)) { + m_DigDirection = DigDirection::Right; this->Dig(Collision::CollisionDirection::Right, level); m_DidJustDigRight = true; } @@ -245,10 +256,17 @@ void Player::Update(float elapsedTime, WorldLevel& level) { m_currentAnimation->Update(elapsedTime); + if (m_currentAnimation->IsDone() && m_IsTurning) { m_currentAnimation = m_walkAnimation; m_IsTurning = false; } + + + + if(m_currentAnimation == m_digStartAnimation) { + + } #pragma region Collision m_ContactMap[Collision::CollisionDirection::Top] = nullptr; @@ -338,30 +356,39 @@ void Player::Update(float elapsedTime, WorldLevel& level) { m_walkAnimation->SetPlaying(true); break; case PlayerState::Digging: { - m_walkAnimation->SetPlaying(false); + // m_walkAnimation->SetPlaying(false); //Diganimation - - if (!m_Digging) { //TODO: fix for setting the start position - m_Digging = true; - m_DigStart = m_Position; - m_Vel = Vector2f { 0, 0 }; + m_currentAnimation->Update(elapsedTime); + if(m_currentAnimation->IsDone() && m_State == PlayerState::Digging && !m_IsDiggingPrimed) { + m_IsDiggingPrimed = true; + m_currentAnimation = m_digAnimation; } - m_DigProgress += elapsedTime; - //lerp to the destination - float progress = utils::map(m_DigProgress, 0.0f, m_DigTime, 0.0f, 1.0f); - std::cout << progress << '\n'; - m_Position = utils::lerp(m_DigStart, m_DigDestination, progress); - if (progress >= 0.5f && !m_HasDeletedTile) { - m_DigTile->SetTileType(GroundTileTypeManager::GetInstance()->AIR); - m_DigTile = nullptr; - m_HasDeletedTile = true; - } - if (progress >= 1.0f) { - m_State = PlayerState::Idle; - m_HasDeletedTile = false; - m_Digging = false; + if(m_IsDiggingPrimed) { + if (!m_Digging) { //TODO: fix for setting the start position + m_Digging = true; + m_DigStart = m_Position; + m_Vel = Vector2f { 0, 0 }; + } + + m_DigProgress += elapsedTime; + //lerp to the destination + float progress = utils::map(m_DigProgress, 0.0f, m_DigTime, 0.0f, 1.0f); + std::cout << progress << '\n'; + m_Position = utils::lerp(m_DigStart, m_DigDestination, progress); + if (progress >= 0.5f && !m_HasDeletedTile) { + m_DigTile->SetTileType(GroundTileTypeManager::GetInstance()->AIR); + m_DigTile = nullptr; + m_HasDeletedTile = true; + } + if (progress >= 1.0f) { + m_State = PlayerState::Idle; + m_currentAnimation = m_walkAnimation; + m_HasDeletedTile = false; + m_Digging = false; + } } + break; } default: diff --git a/Game/Player.h b/Game/Player.h index ac7deb6..60a6a71 100644 --- a/Game/Player.h +++ b/Game/Player.h @@ -93,6 +93,8 @@ private: bool m_HasDeletedTile{ false }; WorldTile* m_DigTile{ nullptr }; + bool m_IsDiggingPrimed{ false }; + const float m_DigTime{ 0.5f }; bool m_Grounded { false }; diff --git a/Resources/animations/player/player_dig.png b/Resources/animations/player/player_dig.png new file mode 100644 index 0000000..6960908 Binary files /dev/null and b/Resources/animations/player/player_dig.png differ diff --git a/Resources/animations/player/player_dig_start.png b/Resources/animations/player/player_dig_start.png index c2814c7..9584c6a 100644 Binary files a/Resources/animations/player/player_dig_start.png and b/Resources/animations/player/player_dig_start.png differ diff --git a/Resources/gui/main/fuel_guage.png b/Resources/gui/main/fuel_guage.png new file mode 100644 index 0000000..224cd4c Binary files /dev/null and b/Resources/gui/main/fuel_guage.png differ