From 7c410aee096bdbd229600da57d1ecab56388d77f Mon Sep 17 00:00:00 2001 From: s473577 Date: Wed, 7 Feb 2024 16:23:09 +0100 Subject: [PATCH] Add turbo bar --- grk/project/Spaceship.h | 21 ++++++++++++++++++--- grk/project/src/ex_9_1.hpp | 12 ++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/grk/project/Spaceship.h b/grk/project/Spaceship.h index 8876620..6b615f2 100644 --- a/grk/project/Spaceship.h +++ b/grk/project/Spaceship.h @@ -38,6 +38,8 @@ public: glm::vec3 color = glm::vec3(0.3, 0.3, 0.5); float roughness = 0.5; float metallic = 0.6; + float turbo = 1.0f; + float turboMAX = 1.0f; glm::vec3 spaceshipPos /*= glm::vec3(0.065808f, 1.250000f, -2.189549f)*/; glm::vec3 spaceshipDir = glm::vec3(-0.490263f, 0.000000f, 0.871578f); @@ -49,7 +51,7 @@ public: glm::vec3 cameraPos = glm::vec3(0.479490f, 1.250000f, -2.124680f); glm::vec3 cameraDir = glm::vec3(-0.354510f, 0.000000f, 0.935054f); - glm::vec3 cameraPosHUDBar = glm::vec3(0.479490f, 1.250000f, -2.124680f); + glm::vec3 cameraPosHUDBar = cameraPos; glm::mat4 additionalHorRotationMatrix; glm::mat4 additionalVerRotationMatrix; @@ -222,15 +224,28 @@ public: if (w == GLFW_PRESS) { if (shiftState == GLFW_PRESS) { - moveSpeed *= 2; - setPerticlesParameters(200.f, 0.00005f); + + turbo = glm::max(0.0f, turbo - 0.004f * deltaTime * 60); + if (turbo == 0.0f) { + shiftState = GLFW_RELEASE; + moveSpeed = 0.05f * deltaTime * 60; + setPerticlesParameters(100.f, 0.0001f); + } + else { + moveSpeed *= 2; + setPerticlesParameters(200.f, 0.00005f); + } + + } else { setPerticlesParameters(100.f, 0.0001f); + turbo = glm::min(turboMAX, turbo + 0.001f * deltaTime * 60); } } else { setPerticlesParameters(50.f, 0.0002f); + turbo = glm::min(turboMAX, turbo + 0.005f * deltaTime * 60); } if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) { diff --git a/grk/project/src/ex_9_1.hpp b/grk/project/src/ex_9_1.hpp index 930397d..4505308 100644 --- a/grk/project/src/ex_9_1.hpp +++ b/grk/project/src/ex_9_1.hpp @@ -107,16 +107,28 @@ void renderHUD(GLFWwindow* window) { glm::mat4 modelMatrixHUD = spaceship->calculateModelMatrixForHUDBar(); glm::mat4 healthBarPosition; glm::vec3 healthBarScale; + glm::mat4 turboBarPosition; + glm::vec3 turboBarScale; + if (glfwGetWindowAttrib(window, GLFW_MAXIMIZED)) { healthBarPosition = glm::translate(modelMatrixHUD, glm::vec3(38.0f, -11.0f, 0.0f)); healthBarScale = glm::vec3(22.0f, 2.f, 1.0f); + turboBarScale = healthBarScale; + turboBarPosition = glm::translate(healthBarPosition, glm::vec3(0.0f, 3.5f, 0.0f)); } else { healthBarScale = glm::vec3(22.0f, 4.f, 1.0f); healthBarPosition = glm::translate(modelMatrixHUD, glm::vec3(38.0f, -30.0f, 0.0f)); + turboBarScale = healthBarScale; + turboBarPosition = glm::translate(healthBarPosition, glm::vec3(0.0f, 5.0f, 0.0f)); } glUseProgram(programSpriteBar); glDisable(GL_DEPTH_TEST); + spriteRenderer->DrawHUDBar( + glm::vec3(0.0824f, 0.5725f, 0.9765f), + glm::scale(turboBarPosition, turboBarScale), + spaceship->turbo / spaceship->turboMAX, + programSpriteBar); spriteRenderer->DrawHUDBar( glm::vec3(0.0f, 1.0f, 0.0f),