Add Main UI, Fuel meter. Add particles to player digging

This commit is contained in:
Bram Verhulst
2024-05-14 12:28:37 +02:00
parent d5c002c2b2
commit 600050c198
39 changed files with 251 additions and 108 deletions

View File

@@ -29,7 +29,7 @@ Player::Player(const Vector2f& Position, TextureManager* manager) : m_Position(P
m_digAnimation = new Animation(
manager->GetTexture("animations/player/player_dig.png"),
7, 0.05f, Rectf { 0, 0, 70, 70 }, true);
m_currentAnimation = m_walkAnimation;
}
Player::Player(Player&& other) {
@@ -71,8 +71,9 @@ void Player::Draw() const {
}
glPopMatrix();
utils::DrawEllipse(m_DigDestination, 5, 5);
utils::DrawEllipse(m_DigStart, 5, 5);
for (Particle* particle : m_DigParticles) {
particle->Draw();
}
}
void Player::ProcessImGui() {
ImGui::Begin("Collision Info", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
@@ -166,17 +167,24 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
m_BobTimer = 0.0f;
}
std::vector<Particle *> particlesToDelete {};
for (Particle* particle : m_DigParticles) {
particle->Update(elapsedTime);
if (particle->IsDead()) {
particlesToDelete.push_back(particle);
}
}
for (Particle* particle : particlesToDelete) {
m_DigParticles.erase(std::remove(m_DigParticles.begin(), m_DigParticles.end(), particle), m_DigParticles.end());
delete particle;
}
//check for keys
if (m_State != PlayerState::Digging) {
if (utils::isKeyDown(SDL_SCANCODE_W)) {
// if (m_Grounded) {
m_State = PlayerState::Flying;
m_Vel.y = m_Speed;
m_Grounded = false;
// }
}
if (utils::isKeyPressed(SDL_SCANCODE_S)) {
if (m_Grounded) {
@@ -259,16 +267,15 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
m_currentAnimation->Update(elapsedTime);
if (m_currentAnimation->IsDone() && m_IsTurning) {
m_currentAnimation = m_walkAnimation;
m_IsTurning = false;
}
if(m_currentAnimation == m_digStartAnimation) {
if (m_currentAnimation == m_digStartAnimation) {
}
#pragma region Collision
@@ -362,12 +369,12 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
// m_walkAnimation->SetPlaying(false);
//Diganimation
m_currentAnimation->Update(elapsedTime);
if(m_currentAnimation->IsDone() && m_State == PlayerState::Digging && !m_IsDiggingPrimed) {
if (m_currentAnimation->IsDone() && m_State == PlayerState::Digging && !m_IsDiggingPrimed) {
m_IsDiggingPrimed = true;
m_currentAnimation = m_digAnimation;
}
if(m_IsDiggingPrimed) {
if (m_IsDiggingPrimed) {
if (!m_Digging) { //TODO: fix for setting the start position
m_Digging = true;
m_DigStart = m_Position;
@@ -377,7 +384,12 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
m_DigProgress += elapsedTime;
//lerp to the destination
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,
TextureManager::GetInstance()->GetTexture("particles/dirt_" + std::to_string(utils::randRange(1, 8)) + ".png")));
}
m_Position = utils::lerp(m_DigStart, m_DigDestination, progress);
if (progress >= 0.5f && !m_HasDeletedTile) {
m_DigTile->SetTileType(GroundTileTypeManager::GetInstance()->AIR);