Temp commit

This commit is contained in:
Bram Verhulst
2024-04-25 11:04:40 +02:00
parent 8a1506d42f
commit da8377e7a0
4 changed files with 42 additions and 35 deletions

View File

@@ -122,9 +122,9 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
//check for keys
if (m_State != PlayerState::Digging) {
m_Vel = Vector2f { 0, -100 };
// m_Acc = Vector2f { 0, -100 };
if (utils::isKeyDown(SDL_SCANCODE_W)) {
m_Vel.y = 100;
m_Vel.y = m_Speed;
m_Grounded = false;
}
if (utils::isKeyPressed(SDL_SCANCODE_S)) {
@@ -134,12 +134,12 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
}
}
else {
m_Vel.y = -100;
//m_Acc.y = -100;
}
}
if (utils::isKeyDown(SDL_SCANCODE_A)) {
m_walkAnimation->SetFlipped(false);
m_Vel.x = -100;
m_Acc.x = -m_Speed;
if (m_Grounded && !m_DidJustDigLeft) {
//Check if the player doesnt come from digging a tile
if (this->CanDig(Collision::CollisionDirection::Left, level)) {
@@ -155,7 +155,7 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
}
if (utils::isKeyDown(SDL_SCANCODE_D)) {
m_Vel.x = 100;
m_Acc.x = m_Speed;
m_walkAnimation->SetFlipped(true);
if (m_Grounded && !m_DidJustDigRight) {
//Check if the player doesnt come from digging a tile
@@ -171,6 +171,17 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
}
}
m_Vel = m_Vel + m_Gravity * elapsedTime;
m_Vel = m_Vel + m_Acc * elapsedTime;
//air resistance
//only if not moving
if(abs(m_Acc.x) < 0.1f) {
m_Vel.x = m_Vel.x * 0.85f;
}
m_Acc = Vector2f { 0, 0 };
m_walkAnimation->Update(elapsedTime);
@@ -266,6 +277,7 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
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;