Add fly animations
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include <algorithm>
|
||||
|
||||
#include "colors.h"
|
||||
#include "GameManager.h"
|
||||
#include "GridSystem/GroundTileTypeManager.h"
|
||||
#include "utils.h"
|
||||
#include "Levels/World/WorldLevel.h"
|
||||
@@ -30,6 +31,18 @@ Player::Player(const Vector2f& Position, TextureManager* manager) : m_Position(P
|
||||
manager->GetTexture("animations/player/player_dig.png"),
|
||||
7, 0.05f, Rectf { 0, 0, 70, 70 }, true);
|
||||
|
||||
m_flyStartAnimation = new Animation(
|
||||
manager->GetTexture("animations/player/player_fly_start.png"),
|
||||
12, 0.05f, Rectf { 0, 0, 70, 70 }, false);
|
||||
|
||||
m_flyAnimation = new Animation(
|
||||
manager->GetTexture("animations/player/player_fly.png"),
|
||||
5, 0.01f, Rectf { 0, 0, 70, 70 }, true);
|
||||
|
||||
m_flyTurnAnimation = new Animation(
|
||||
manager->GetTexture("animations/player/player_fly_turn.png"),
|
||||
3, 0.05f, Rectf { 0, 0, 70, 70 }, false);
|
||||
|
||||
m_currentAnimation = m_walkAnimation;
|
||||
}
|
||||
Player::Player(Player&& other) {
|
||||
@@ -41,6 +54,10 @@ Player::~Player() {
|
||||
delete m_turnAnimation;
|
||||
delete m_digAnimation;
|
||||
delete m_digStartAnimation;
|
||||
|
||||
delete m_flyStartAnimation;
|
||||
delete m_flyAnimation;
|
||||
delete m_flyTurnAnimation;
|
||||
}
|
||||
|
||||
Collision::CollisionRect Player::GetCollisionRect() const {
|
||||
@@ -59,7 +76,7 @@ void Player::Draw() const {
|
||||
int halfFrameWidth = frameWidth / 2;
|
||||
int bobOffset = m_BobUp ? 1 : 0;
|
||||
|
||||
float rotateOffset = std::abs(m_Vel.x) / 40;
|
||||
float rotateOffset = std::abs(m_Vel.x) / 30;
|
||||
Vector2f drawPos = Vector2f { center.x, center.y + 9 + bobOffset };
|
||||
glPushMatrix();
|
||||
glTranslatef(drawPos.x - halfFrameWidth, drawPos.y - halfFrameWidth, 0);
|
||||
@@ -123,6 +140,12 @@ void Player::ProcessImGui() {
|
||||
ImGui::Text("Bottom: %s", m_ContactMap[Collision::CollisionDirection::Bottom] != nullptr ? "true" : "false");
|
||||
ImGui::Text("Left: %s", m_ContactMap[Collision::CollisionDirection::Left] != nullptr ? "true" : "false");
|
||||
ImGui::Text("Right: %s", m_ContactMap[Collision::CollisionDirection::Right] != nullptr ? "true" : "false");
|
||||
|
||||
ImGui::Separator();
|
||||
ImGui::Text("Values");
|
||||
ImGui::Text("Current Fuel: %f", GameManager::GetInstance().GetFuel());
|
||||
ImGui::Text("Current Score: %d", GameManager::GetInstance().GetScore());
|
||||
ImGui::Text("Current Hull Integrity: %d", GameManager::GetInstance().GetHullIntegrity());
|
||||
ImGui::End();
|
||||
}
|
||||
void Player::Dig(Collision::CollisionDirection dir, WorldLevel& level) {
|
||||
@@ -131,6 +154,7 @@ void Player::Dig(Collision::CollisionDirection dir, WorldLevel& level) {
|
||||
m_DigTile = m_ContactMap[dir];
|
||||
//Set the digging location in the center of the destination tile;
|
||||
const WorldTile* tile = m_ContactMap[dir];
|
||||
m_ToAddPoints = tile->GetTileType()->GetValue();
|
||||
//Add case for bottom because otherwise i clip through the floor
|
||||
m_DigDestination = tile->GetPosition();
|
||||
if (dir == Collision::Bottom) {
|
||||
@@ -183,7 +207,14 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
|
||||
if (m_State != PlayerState::Digging) {
|
||||
if (utils::isKeyDown(SDL_SCANCODE_W)) {
|
||||
m_State = PlayerState::Flying;
|
||||
m_Vel.y = m_Speed;
|
||||
// m_Vel.y = m_Speed / 10;
|
||||
m_Acc.y += m_Speed * 10;
|
||||
if(!m_IsPropellorDeployed) {
|
||||
m_currentAnimation = m_flyStartAnimation;
|
||||
m_flyStartAnimation->SetFlipped(m_Direction == PlayerDirection::Right);
|
||||
} else {
|
||||
m_currentAnimation = m_flyAnimation;
|
||||
}
|
||||
m_Grounded = false;
|
||||
}
|
||||
if (utils::isKeyPressed(SDL_SCANCODE_S)) {
|
||||
@@ -200,11 +231,12 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
|
||||
if (utils::isKeyDown(SDL_SCANCODE_A)) {
|
||||
if (!m_IsTurning) {
|
||||
m_walkAnimation->SetFlipped(false);
|
||||
m_flyAnimation->SetFlipped(false);
|
||||
}
|
||||
m_Acc.x = -m_Speed;
|
||||
if (m_Direction == PlayerDirection::Right) {
|
||||
m_IsTurning = true;
|
||||
m_currentAnimation = m_turnAnimation;
|
||||
m_currentAnimation = m_State == PlayerState::Walking ? m_turnAnimation : m_flyTurnAnimation;
|
||||
m_currentAnimation->SetFlipped(true);
|
||||
m_currentAnimation->Reset();
|
||||
}
|
||||
@@ -227,12 +259,13 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
|
||||
if (utils::isKeyDown(SDL_SCANCODE_D)) {
|
||||
if (!m_IsTurning) {
|
||||
m_walkAnimation->SetFlipped(true);
|
||||
m_flyAnimation->SetFlipped(true);
|
||||
}
|
||||
m_Acc.x = m_Speed;
|
||||
|
||||
if (m_Direction == PlayerDirection::Left) {
|
||||
m_IsTurning = true;
|
||||
m_currentAnimation = m_turnAnimation;
|
||||
m_currentAnimation = m_State == PlayerState::Walking ? m_turnAnimation : m_flyTurnAnimation;
|
||||
m_currentAnimation->SetFlipped(false);
|
||||
m_currentAnimation->Reset();
|
||||
}
|
||||
@@ -268,11 +301,30 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
|
||||
|
||||
m_currentAnimation->Update(elapsedTime);
|
||||
|
||||
if (m_currentAnimation->IsDone() && m_IsTurning) {
|
||||
if(m_State == PlayerState::Flying && m_Grounded) {
|
||||
m_State = PlayerState::Idle;
|
||||
m_walkAnimation->SetFlipped(m_Direction == PlayerDirection::Right);
|
||||
m_currentAnimation = m_walkAnimation;
|
||||
m_IsPropellorDeployed = false;
|
||||
m_flyStartAnimation->Reset();
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (m_currentAnimation->IsDone() && m_IsTurning) {
|
||||
m_currentAnimation = m_State == PlayerState::Walking ? m_walkAnimation : m_flyAnimation;
|
||||
m_IsTurning = false;
|
||||
}
|
||||
|
||||
if(m_currentAnimation == m_flyStartAnimation) {
|
||||
if(m_flyStartAnimation->IsDone()) {
|
||||
m_IsPropellorDeployed = true;
|
||||
m_currentAnimation = m_flyAnimation;
|
||||
} else {
|
||||
m_currentAnimation = m_flyStartAnimation;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (m_currentAnimation == m_digStartAnimation) {
|
||||
|
||||
@@ -361,9 +413,11 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
|
||||
switch (m_State) {
|
||||
case PlayerState::Idle:
|
||||
m_walkAnimation->SetPlaying(false);
|
||||
GameManager::GetInstance().DecreaseFuel(0.02f);
|
||||
break;
|
||||
case PlayerState::Walking:
|
||||
m_walkAnimation->SetPlaying(true);
|
||||
GameManager::GetInstance().DecreaseFuel(0.04f);
|
||||
break;
|
||||
case PlayerState::Digging: {
|
||||
// m_walkAnimation->SetPlaying(false);
|
||||
@@ -386,8 +440,8 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
|
||||
float progress = utils::map(m_DigProgress, 0.0f, m_DigTime, 0.0f, 1.0f);
|
||||
int particleProgress = (int)utils::map(m_DigProgress, 0.0f, m_DigTime, 0.0f, 100.0f);
|
||||
std::cout << progress << '\n';
|
||||
if (particleProgress % 25 == 0) {
|
||||
m_DigParticles.push_back(new Particle(m_Position, Vector2f { (float)utils::randRange(-200, 200), (float)utils::randRange(-100, -300) }, 5.f,
|
||||
if (particleProgress % 2 == 0) {
|
||||
m_DigParticles.push_back(new Particle(m_Position + Vector2f{ 20, 0 }, Vector2f { (float)utils::randRange(-200, 200), (float)utils::randRange(-100, -300) }, 5.f,
|
||||
TextureManager::GetInstance()->GetTexture("particles/dirt_" + std::to_string(utils::randRange(1, 8)) + ".png")));
|
||||
}
|
||||
m_Position = utils::lerp(m_DigStart, m_DigDestination, progress);
|
||||
@@ -401,6 +455,8 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
|
||||
m_currentAnimation = m_walkAnimation;
|
||||
m_HasDeletedTile = false;
|
||||
m_Digging = false;
|
||||
GameManager::GetInstance().IncreaseScore(m_ToAddPoints);
|
||||
m_ToAddPoints = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user