Add window icon,

Add digging animation (Non functional)
This commit is contained in:
Bram Verhulst
2024-05-02 12:28:03 +02:00
parent 64915567dc
commit b6be73019f
16 changed files with 140 additions and 101 deletions

View File

@@ -10,14 +10,21 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="26a0623a-44d5-441c-8048-32ff1dab3479" name="Changes" comment="Add fps">
<list default="true" id="26a0623a-44d5-441c-8048-32ff1dab3479" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.idea/.idea.Motherload/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.Motherload/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Player/PlayerWalk.aseprite" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Player/PlayerWalk.aseprite" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Game/Animations/Animation.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Animations/Animation.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Game/Animations/Animation.h" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Animations/Animation.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/.idea.Prog2Engine/.idea/.gitignore" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/.idea.Prog2Engine/.idea/.name" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/.idea.Prog2Engine/.idea/encodings.xml" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/.idea.Prog2Engine/.idea/indexLayout.xml" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/.idea.Prog2Engine/.idea/vcs.xml" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/Engine/BaseGame.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Engine/BaseGame.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Engine/BaseGame.h" beforeDir="false" afterPath="$PROJECT_DIR$/Engine/BaseGame.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Engine/utils.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Engine/utils.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Engine/utils.h" beforeDir="false" afterPath="$PROJECT_DIR$/Engine/utils.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Game/Levels/World/WorldLevel.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Levels/World/WorldLevel.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Game/Player.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Player.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Game/Player.h" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Player.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Resources/animations/player/player_walk.png" beforeDir="false" afterPath="$PROJECT_DIR$/Resources/animations/player/player_walk.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Resources/test.png" beforeDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -82,10 +89,19 @@
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/../../../../../../Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.37.32822/include/algorithm" root0="SKIP_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/../../../../../../Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.37.32822/include/type_traits" root0="SKIP_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/../../../../../../Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.37.32822/include/vector" root0="SKIP_HIGHLIGHTING" />
<setting file="mock://C:/Users/Bram/Desktop/Programming 2/Exam/dae16-VerhulstBram/Engine/BaseGame.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock://C:/Users/Bram/Desktop/Programming 2/Exam/dae16-VerhulstBram/Game/Animations/Animation.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/Game/Animations/Animation.h" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/Game/Camera.cpp" root0="FORCE_HIGHLIGHTING" />
<setting file="mock://C:/Users/Bram/Desktop/Programming 2/Exam/dae16-VerhulstBram/Game/Game.cpp" root0="SKIP_HIGHLIGHTING" />
@@ -270,7 +286,9 @@
<workItem from="1714026889126" duration="4211000" />
<workItem from="1714046400732" duration="2462000" />
<workItem from="1714372163827" duration="2962000" />
<workItem from="1714459066696" duration="11199000" />
<workItem from="1714459066696" duration="21789000" />
<workItem from="1714640485259" duration="321000" />
<workItem from="1714641751956" duration="3705000" />
</task>
<task id="LOCAL-00001" summary="Rework Tile detection system">
<option name="closed" value="true" />
@@ -368,7 +386,23 @@
<option name="project" value="LOCAL" />
<updated>1714460546894</updated>
</task>
<option name="localTasksCounter" value="13" />
<task id="LOCAL-00013" summary="Add player turning (Finally)">
<option name="closed" value="true" />
<created>1714471045905</created>
<option name="number" value="00013" />
<option name="presentableId" value="LOCAL-00013" />
<option name="project" value="LOCAL" />
<updated>1714471045905</updated>
</task>
<task id="LOCAL-00014" summary="Update gitignore">
<option name="closed" value="true" />
<created>1714471502013</created>
<option name="number" value="00014" />
<option name="presentableId" value="LOCAL-00014" />
<option name="project" value="LOCAL" />
<updated>1714471502013</updated>
</task>
<option name="localTasksCounter" value="15" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
@@ -390,7 +424,9 @@
<MESSAGE value="Added Buildings&#10;Fixed rendering bugs with edges" />
<MESSAGE value="Add alot of memory leak fixes" />
<MESSAGE value="Add fps" />
<option name="LAST_COMMIT_MESSAGE" value="Add fps" />
<MESSAGE value="Add player turning (Finally)" />
<MESSAGE value="Update gitignore" />
<option name="LAST_COMMIT_MESSAGE" value="Update gitignore" />
</component>
<component name="XSLT-Support.FileAssociations.UIState">
<expand />

View File

@@ -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

View File

@@ -1 +0,0 @@
Prog2Engine

View File

@@ -1,4 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>

View File

@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

View File

@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

Binary file not shown.

View File

@@ -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);

View File

@@ -59,6 +59,8 @@ private:
SDL_GameController* m_pGameController;
SDL_Surface* m_pIcon;
// FUNCTIONS
void InitializeGameEngine();
void CleanupGameEngine();

View File

@@ -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) {

View File

@@ -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);

View File

@@ -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<TileDirection, 8> 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<TileDirection, 8> 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);

View File

@@ -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<int, float>& a, const std::pair<int, float>& b) {
std::sort(contactTimes.begin(), contactTimes.end(), [](const std::pair<int, float>& a, const std::pair<int, float>& 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;
}
}
}

View File

@@ -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 };

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB