diff --git a/.idea/.idea.Motherload/.idea/workspace.xml b/.idea/.idea.Motherload/.idea/workspace.xml
index 22e23ff..2f7cf3c 100644
--- a/.idea/.idea.Motherload/.idea/workspace.xml
+++ b/.idea/.idea.Motherload/.idea/workspace.xml
@@ -10,14 +10,21 @@
-
+
-
-
-
+
+
+
+
+
+
+
+
+
+
-
+
@@ -82,10 +89,19 @@
+
+
+
+
+
+
+
+
+
@@ -270,7 +286,9 @@
-
+
+
+
@@ -368,7 +386,23 @@
1714460546894
-
+
+
+ 1714471045905
+
+
+
+ 1714471045905
+
+
+
+ 1714471502013
+
+
+
+ 1714471502013
+
+
@@ -390,7 +424,9 @@
-
+
+
+
diff --git a/.idea/.idea.Prog2Engine/.idea/.gitignore b/.idea/.idea.Prog2Engine/.idea/.gitignore
deleted file mode 100644
index 0d12fee..0000000
--- a/.idea/.idea.Prog2Engine/.idea/.gitignore
+++ /dev/null
@@ -1,15 +0,0 @@
-# Default ignored files
-/shelf/
-/workspace.xml
-# Rider ignored files
-/modules.xml
-/projectSettingsUpdater.xml
-/contentModel.xml
-/.idea.Prog2Engine.iml
-# Editor-based HTTP Client requests
-/httpRequests/
-# Datasource local storage ignored files
-/dataSources/
-/dataSources.local.xml
-# GitHub Copilot persisted chat sessions
-/copilot/chatSessions
diff --git a/.idea/.idea.Prog2Engine/.idea/.name b/.idea/.idea.Prog2Engine/.idea/.name
deleted file mode 100644
index 988920a..0000000
--- a/.idea/.idea.Prog2Engine/.idea/.name
+++ /dev/null
@@ -1 +0,0 @@
-Prog2Engine
\ No newline at end of file
diff --git a/.idea/.idea.Prog2Engine/.idea/encodings.xml b/.idea/.idea.Prog2Engine/.idea/encodings.xml
deleted file mode 100644
index df87cf9..0000000
--- a/.idea/.idea.Prog2Engine/.idea/encodings.xml
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/.idea/.idea.Prog2Engine/.idea/indexLayout.xml b/.idea/.idea.Prog2Engine/.idea/indexLayout.xml
deleted file mode 100644
index 7b08163..0000000
--- a/.idea/.idea.Prog2Engine/.idea/indexLayout.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/.idea.Prog2Engine/.idea/vcs.xml b/.idea/.idea.Prog2Engine/.idea/vcs.xml
deleted file mode 100644
index 35eb1dd..0000000
--- a/.idea/.idea.Prog2Engine/.idea/vcs.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Assets/Player/PlayerDigStart.aseprite b/Assets/Player/PlayerDigStart.aseprite
new file mode 100644
index 0000000..db52475
Binary files /dev/null and b/Assets/Player/PlayerDigStart.aseprite differ
diff --git a/Engine/BaseGame.cpp b/Engine/BaseGame.cpp
index 09d2d66..d257b78 100644
--- a/Engine/BaseGame.cpp
+++ b/Engine/BaseGame.cpp
@@ -107,7 +107,7 @@ void BaseGame::InitializeGameEngine()
// Setup Dear ImGui style
ImGui::StyleColorsDark();
- //ImGui::StyleColorsLight();
+ // ImGui::StyleColorsLight();
// Setup Platform/Renderer backends
ImGui_ImplSDL2_InitForOpenGL(m_pWindow, m_pContext);
@@ -146,6 +146,10 @@ void BaseGame::InitializeGameEngine()
return;
}
+ m_pIcon = IMG_Load("icon.png");
+ SDL_SetWindowIcon(m_pWindow, m_pIcon);
+
+ // delete icon;
//Initialize controller
m_pGameController = nullptr;
@@ -270,6 +274,9 @@ void BaseGame::CleanupGameEngine()
ImGui_ImplSDL2_Shutdown();
ImGui::DestroyContext();
+ SDL_FreeSurface(m_pIcon);
+ delete m_pIcon;
+
SDL_GL_DeleteContext(m_pContext);
SDL_DestroyWindow(m_pWindow);
diff --git a/Engine/BaseGame.h b/Engine/BaseGame.h
index b80a0f7..7d42795 100644
--- a/Engine/BaseGame.h
+++ b/Engine/BaseGame.h
@@ -59,6 +59,8 @@ private:
SDL_GameController* m_pGameController;
+ SDL_Surface* m_pIcon;
+
// FUNCTIONS
void InitializeGameEngine();
void CleanupGameEngine();
diff --git a/Engine/utils.cpp b/Engine/utils.cpp
index ccb2680..4bb970b 100644
--- a/Engine/utils.cpp
+++ b/Engine/utils.cpp
@@ -692,6 +692,12 @@ float utils::map(float value, float start1, float stop1, float start2, float sto
float newVal = (value - start1) / (stop1 - start1) * (stop2 - start2) + start2;
return newVal;
}
+float utils::clamp(float value, float min, float max) {
+ return std::max(min, std::min(value, max));
+}
+Vector2f utils::clamp(const Vector2f& value, const Vector2f& min, const Vector2f& max) {
+ return Vector2f { clamp(value.x, min.x, max.x), clamp(value.y, min.y, max.y) };
+}
bool utils::isKeyDown(int keycode) {
const Uint8* pStates = SDL_GetKeyboardState(nullptr);
if (pStates != nullptr) {
diff --git a/Engine/utils.h b/Engine/utils.h
index 50670ad..0e9ca9b 100644
--- a/Engine/utils.h
+++ b/Engine/utils.h
@@ -111,6 +111,9 @@ namespace utils
Vector2f lerp(const Vector2f& a, const Vector2f& b, float t);
float map(float value, float start1, float stop1, float start2, float stop2);
+
+ float clamp(float value, float min, float max);
+ Vector2f clamp(const Vector2f& value, const Vector2f& min, const Vector2f& max);
#pragma endregion CollisionFunctionality
bool isKeyDown(SDL_Keycode keycode);
diff --git a/Game/Levels/World/WorldLevel.cpp b/Game/Levels/World/WorldLevel.cpp
index 7a22797..0346d61 100644
--- a/Game/Levels/World/WorldLevel.cpp
+++ b/Game/Levels/World/WorldLevel.cpp
@@ -79,12 +79,12 @@ void WorldLevel::Update(float elapsedSec) {
m_mousePos = Vector2f { float(mouseX), float(mouseY) };
m_mousePos = m_pCamera->TransformMouse(m_mousePos);
-
- for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
- for (size_t y { 0 }; y < WORLD_HEIGHT; ++y) {
- m_gridManager.GetTileAtIndex(x, y)->m_Hightlight = false;
- }
- }
+ // for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
+ // for (size_t y { 0 }; y < WORLD_HEIGHT; ++y) {
+ // m_gridManager.GetTileAtIndex(x, y)->m_Hightlight = false;
+ // }
+ // }
+
for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
for (size_t y { 0 }; y < WORLD_HEIGHT; ++y) {
m_gridManager.GetTileAtIndex(x, y)->Update(m_pCamera);
@@ -101,21 +101,21 @@ void WorldLevel::Update(float elapsedSec) {
}
//Get the diogonal tiles of the selected tile
- if (m_pSelectedTile != nullptr) {
- surroundingTiles surroundingTiles = m_gridManager.GetSurroundingTiles(m_pSelectedTile);
- TileDirection direction = TileDirection::TopMiddle;
- const std::array directions = { TileDirection::TopLeft, TileDirection::TopMiddle, TileDirection::TopRight, TileDirection::MiddleLeft,
- TileDirection::MiddleRight, TileDirection::BottomLeft, TileDirection::BottomMiddle, TileDirection::BottomRight };
-
- for (int i = 0; i < 8; i++) {
- direction = directions[i];
- if (surroundingTiles.GetTile(direction) != nullptr) {
- if (surroundingTiles.GetTile(direction)->GetTileType() != GroundTileTypeManager::GetInstance()->AIR) {
- //surroundingTiles.GetTile(direction)->m_Hightlight = true;
- }
- }
- }
- }
+ // if (m_pSelectedTile != nullptr) {
+ // surroundingTiles surroundingTiles = m_gridManager.GetSurroundingTiles(m_pSelectedTile);
+ // TileDirection direction = TileDirection::TopMiddle;
+ // const std::array directions = { TileDirection::TopLeft, TileDirection::TopMiddle, TileDirection::TopRight, TileDirection::MiddleLeft,
+ // TileDirection::MiddleRight, TileDirection::BottomLeft, TileDirection::BottomMiddle, TileDirection::BottomRight };
+ //
+ // for (int i = 0; i < 8; i++) {
+ // direction = directions[i];
+ // if (surroundingTiles.GetTile(direction) != nullptr) {
+ // if (surroundingTiles.GetTile(direction)->GetTileType() != GroundTileTypeManager::GetInstance()->AIR) {
+ // //surroundingTiles.GetTile(direction)->m_Hightlight = true;
+ // }
+ // }
+ // }
+ // }
m_player.Update(elapsedSec, *this);
diff --git a/Game/Player.cpp b/Game/Player.cpp
index a937c68..259b916 100644
--- a/Game/Player.cpp
+++ b/Game/Player.cpp
@@ -19,14 +19,17 @@ Player::Player(const Vector2f& Position, TextureManager* manager) : m_Position(P
m_walkAnimation = new Animation(
manager->GetTexture("animations/player/player_walk.png"),
- 8, 0.1f, Rectf { 0, 0, 70, 70 });
+ 8, 0.1f, Rectf { 0, 0, 70, 70 }, true);
m_turnAnimation = new Animation(
manager->GetTexture("animations/player/player_turn.png"),
- 5, 0.07f, Rectf{ 0, 0, 70, 70 }, false);
+ 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);
m_currentAnimation = m_walkAnimation;
}
Player::Player(Player&& other) {
-
+
}
Player::~Player() {
@@ -50,9 +53,19 @@ void Player::Draw() const {
const int frameWidth = 70; //TODO: fix this
int halfFrameWidth = frameWidth / 2;
float bobOffset = m_BobUp ? 1 : 0;
- Vector2f drawPos = Vector2f { center.x - halfFrameWidth, center.y - halfFrameWidth + 9 + bobOffset };
- m_currentAnimation->Draw(drawPos, Rectf { drawPos.x, drawPos.y, frameWidth, frameWidth });
+ float rotateOffset = std::abs(m_Vel.x) / 40;
+ Vector2f drawPos = Vector2f { center.x, center.y + 9 + bobOffset };
+ glPushMatrix();
+ glTranslatef(drawPos.x - halfFrameWidth, drawPos.y - halfFrameWidth, 0);
+ if (!m_Grounded && std::abs(m_Vel.y) > 0.1f) {
+ glRotatef(m_Direction == PlayerDirection::Left ? rotateOffset : -rotateOffset, 0, 0, 1);
+ }
+ {
+ m_currentAnimation->Draw(Vector2f { 0, 0 }, Rectf { 0, 0, frameWidth, frameWidth });
+
+ }
+ glPopMatrix();
utils::DrawEllipse(m_DigDestination, 5, 5);
utils::DrawEllipse(m_DigStart, 5, 5);
}
@@ -60,7 +73,7 @@ void Player::ProcessImGui() {
ImGui::Begin("Collision Info", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
ImGui::Text("is Grounded: %s", m_Grounded ? "true" : "false");
ImGui::Checkbox("Draw Collision Rect", &m_DrawCollisionRect);
- std::string currentState {};
+ std::string currentState { "No idea" };
switch (m_State) {
case PlayerState::Idle:
currentState = "Idle";
@@ -71,10 +84,14 @@ void Player::ProcessImGui() {
case PlayerState::Walking:
currentState = "Walking";
break;
+ case PlayerState::Flying:
+ currentState = "Flying";
+ break;
}
ImGui::Text("Player State %s", currentState.c_str());
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");
std::string direction {};
switch (m_Direction) {
case PlayerDirection::Down:
@@ -114,8 +131,8 @@ void Player::Dig(Collision::CollisionDirection dir, WorldLevel& level) {
//Center
m_DigDestination.x += tile->GetSize().x / 2 - m_Size.x / 2;
}
- if(dir == Collision::Left) {
- m_DigDestination += Vector2f{ 2, 0};
+ if (dir == Collision::Left) {
+ m_DigDestination += Vector2f { 2, 0 };
}
m_ContactMap[dir] = nullptr;
}
@@ -128,7 +145,8 @@ bool Player::CanDig(Collision::CollisionDirection dir, WorldLevel& level) {
GroundTileType type = *tile->GetTileType();
//TODO: Add a list of non diggable tiles
- if (type == GroundTileTypeManager::GetInstance()->HARD_LEFT || type == GroundTileTypeManager::GetInstance()->HARD_MIDDLE || type == GroundTileTypeManager::GetInstance()->HARD_RIGHT) {
+ if (type == GroundTileTypeManager::GetInstance()->HARD_LEFT || type == GroundTileTypeManager::GetInstance()->HARD_MIDDLE || type == GroundTileTypeManager::GetInstance()->
+ HARD_RIGHT) {
return false;
}
@@ -144,10 +162,12 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
//check for keys
if (m_State != PlayerState::Digging) {
- // m_Acc = Vector2f { 0, -100 };
if (utils::isKeyDown(SDL_SCANCODE_W)) {
- m_Vel.y = m_Speed;
- m_Grounded = false;
+ // if (m_Grounded) {
+ m_State = PlayerState::Flying;
+ m_Vel.y = m_Speed;
+ m_Grounded = false;
+ // }
}
if (utils::isKeyPressed(SDL_SCANCODE_S)) {
if (m_Grounded) {
@@ -155,16 +175,13 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
this->Dig(Collision::CollisionDirection::Bottom, level);
}
}
- else {
- //m_Acc.y = -100;
- }
}
if (utils::isKeyDown(SDL_SCANCODE_A)) {
- if(!m_IsTurning) {
+ if (!m_IsTurning) {
m_walkAnimation->SetFlipped(false);
- m_Acc.x = -m_Speed;
}
- if(m_Direction == PlayerDirection::Right) {
+ m_Acc.x = -m_Speed;
+ if (m_Direction == PlayerDirection::Right) {
m_IsTurning = true;
m_currentAnimation = m_turnAnimation;
m_currentAnimation->SetFlipped(true);
@@ -186,19 +203,18 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
}
if (utils::isKeyDown(SDL_SCANCODE_D)) {
-
- if(!m_IsTurning) {
- m_Acc.x = m_Speed;
+ if (!m_IsTurning) {
m_walkAnimation->SetFlipped(true);
}
+ m_Acc.x = m_Speed;
- if(m_Direction == PlayerDirection::Left) {
+ if (m_Direction == PlayerDirection::Left) {
m_IsTurning = true;
m_currentAnimation = m_turnAnimation;
m_currentAnimation->SetFlipped(false);
m_currentAnimation->Reset();
}
-
+
m_Direction = PlayerDirection::Right;
if (m_Grounded && !m_DidJustDigRight) {
//Check if the player doesnt come from digging a tile
@@ -216,24 +232,24 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
m_Vel = m_Vel + m_Gravity * elapsedTime;
m_Vel = m_Vel + m_Acc * elapsedTime;
+ m_Vel = utils::clamp(m_Vel, Vector2f { -m_Speed, -m_Speed }, Vector2f { m_Speed, m_Speed });
//air resistance
//only if not moving
- if(abs(m_Acc.x) < 0.1f) {
- m_Vel.x = m_Vel.x * 0.85f;
+ if (abs(m_Acc.x) < 0.1f) {
+ m_Vel.x = m_Vel.x * 0.90f;
}
m_Acc = Vector2f { 0, 0 };
-
+
m_currentAnimation->Update(elapsedTime);
- if(m_currentAnimation->IsDone()) {
- m_currentAnimation = m_walkAnimation; //TODO: fix this hack
+ if (m_currentAnimation->IsDone() && m_IsTurning) {
+ m_currentAnimation = m_walkAnimation;
m_IsTurning = false;
}
+
#pragma region Collision
-
-
m_ContactMap[Collision::CollisionDirection::Top] = nullptr;
m_ContactMap[Collision::CollisionDirection::Bottom] = nullptr;
m_ContactMap[Collision::CollisionDirection::Left] = nullptr;
@@ -259,7 +275,8 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
}
}
- std::sort(contactTimes.begin(), contactTimes.end(), [](const std::pair& a, const std::pair& b) {
+ std::sort(contactTimes.begin(), contactTimes.end(), [](const std::pair& a, const std::pair& b)
+ {
return a.second < b.second;
});
@@ -302,13 +319,13 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
Collision::ResolvePlayerVsRect(*this, elapsedTime, &rect);
}
#pragma endregion
-
- if (m_State != PlayerState::Digging) { //Fix for when the state is JUST set to digging
- if (m_Vel.x != 0.0f) {
- m_State = PlayerState::Walking;
+
+ if (m_State == PlayerState::Walking || m_State == PlayerState::Idle) { //Fix for when the state is JUST set to digging
+ if (std::abs(m_Vel.x) < 0.1f) {
+ m_State = PlayerState::Idle;
}
else {
- m_State = PlayerState::Idle;
+ m_State = PlayerState::Walking;
}
}
}
diff --git a/Game/Player.h b/Game/Player.h
index 521e3ea..ac7deb6 100644
--- a/Game/Player.h
+++ b/Game/Player.h
@@ -10,7 +10,8 @@ enum class PlayerState
Idle,
Walking,
Digging,
- Turning
+ Turning,
+ Flying
};
enum class PlayerDirection
@@ -102,6 +103,7 @@ private:
Animation* m_currentAnimation{ nullptr };
Animation* m_walkAnimation;
Animation* m_turnAnimation{ nullptr };
+ Animation* m_digStartAnimation{ nullptr };
Animation* m_digAnimation{ nullptr };
PlayerState m_State { PlayerState::Idle };
diff --git a/Resources/animations/player/player_dig_start.png b/Resources/animations/player/player_dig_start.png
new file mode 100644
index 0000000..c2814c7
Binary files /dev/null and b/Resources/animations/player/player_dig_start.png differ
diff --git a/Resources/test.png b/Resources/icon.png
similarity index 100%
rename from Resources/test.png
rename to Resources/icon.png