mirror of
https://github.com/HowestDAE/dae16-VerhulstBram.git
synced 2025-12-16 21:01:48 +01:00
Add player turning (Finally)
This commit is contained in:
@@ -20,8 +20,14 @@ 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 });
|
||||
m_turnAnimation = new Animation(
|
||||
manager->GetTexture("animations/player/player_turn.png"),
|
||||
5, 0.07f, Rectf{ 0, 0, 70, 70 }, false);
|
||||
m_currentAnimation = m_walkAnimation;
|
||||
}
|
||||
Player::Player(Player&& other) {
|
||||
|
||||
}
|
||||
|
||||
Player::~Player() {
|
||||
delete m_walkAnimation;
|
||||
@@ -46,7 +52,7 @@ void Player::Draw() const {
|
||||
float bobOffset = m_BobUp ? 1 : 0;
|
||||
Vector2f drawPos = Vector2f { center.x - halfFrameWidth, center.y - halfFrameWidth + 9 + bobOffset };
|
||||
|
||||
m_walkAnimation->Draw(drawPos, Rectf { drawPos.x, drawPos.y, frameWidth, frameWidth });
|
||||
m_currentAnimation->Draw(drawPos, Rectf { drawPos.x, drawPos.y, frameWidth, frameWidth });
|
||||
utils::DrawEllipse(m_DigDestination, 5, 5);
|
||||
utils::DrawEllipse(m_DigStart, 5, 5);
|
||||
}
|
||||
@@ -69,6 +75,22 @@ void Player::ProcessImGui() {
|
||||
ImGui::Text("Player State %s", currentState.c_str());
|
||||
ImGui::Text("Bob counter: %f", m_BobTimer);
|
||||
ImGui::Text("Bob up: %s", m_BobUp ? "true" : "false");
|
||||
std::string direction {};
|
||||
switch (m_Direction) {
|
||||
case PlayerDirection::Down:
|
||||
direction = "Down";
|
||||
break;
|
||||
case PlayerDirection::Left:
|
||||
direction = "Left";
|
||||
break;
|
||||
case PlayerDirection::Right:
|
||||
direction = "Right";
|
||||
break;
|
||||
case PlayerDirection::Up:
|
||||
direction = "Up";
|
||||
break;
|
||||
}
|
||||
ImGui::Text("Direction: %s", direction.c_str());
|
||||
|
||||
|
||||
//ContactMap
|
||||
@@ -138,8 +160,17 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
|
||||
}
|
||||
}
|
||||
if (utils::isKeyDown(SDL_SCANCODE_A)) {
|
||||
m_walkAnimation->SetFlipped(false);
|
||||
m_Acc.x = -m_Speed;
|
||||
if(!m_IsTurning) {
|
||||
m_walkAnimation->SetFlipped(false);
|
||||
m_Acc.x = -m_Speed;
|
||||
}
|
||||
if(m_Direction == PlayerDirection::Right) {
|
||||
m_IsTurning = true;
|
||||
m_currentAnimation = m_turnAnimation;
|
||||
m_currentAnimation->SetFlipped(true);
|
||||
m_currentAnimation->Reset();
|
||||
}
|
||||
m_Direction = PlayerDirection::Left;
|
||||
if (m_Grounded && !m_DidJustDigLeft) {
|
||||
//Check if the player doesnt come from digging a tile
|
||||
if (this->CanDig(Collision::CollisionDirection::Left, level)) {
|
||||
@@ -155,8 +186,20 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
|
||||
}
|
||||
|
||||
if (utils::isKeyDown(SDL_SCANCODE_D)) {
|
||||
m_Acc.x = m_Speed;
|
||||
m_walkAnimation->SetFlipped(true);
|
||||
|
||||
if(!m_IsTurning) {
|
||||
m_Acc.x = m_Speed;
|
||||
m_walkAnimation->SetFlipped(true);
|
||||
}
|
||||
|
||||
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
|
||||
if (this->CanDig(Collision::CollisionDirection::Right, level)) {
|
||||
@@ -183,7 +226,12 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
|
||||
m_Acc = Vector2f { 0, 0 };
|
||||
|
||||
|
||||
m_walkAnimation->Update(elapsedTime);
|
||||
m_currentAnimation->Update(elapsedTime);
|
||||
if(m_currentAnimation->IsDone()) {
|
||||
m_currentAnimation = m_walkAnimation; //TODO: fix this hack
|
||||
m_IsTurning = false;
|
||||
}
|
||||
#pragma region Collision
|
||||
|
||||
|
||||
m_ContactMap[Collision::CollisionDirection::Top] = nullptr;
|
||||
@@ -192,7 +240,6 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
|
||||
m_ContactMap[Collision::CollisionDirection::Right] = nullptr;
|
||||
m_Grounded = false;
|
||||
|
||||
|
||||
float t = 0, min_t = INFINITY;
|
||||
Vector2f intersectionPoint, normal;
|
||||
|
||||
@@ -254,6 +301,8 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
|
||||
Collision::CollisionRect rect = world_tile->GetCollisionRect().getCollisionRect(); //TODO: fix this mess
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user