diff --git a/grk/project/Bullet.h b/grk/project/Bullet.h index bbfea5b..7e3c2e8 100644 --- a/grk/project/Bullet.h +++ b/grk/project/Bullet.h @@ -62,7 +62,6 @@ public: for (const auto& entity : gameEntities) { glm::mat4 entityModelMatrix = entity->getModelMatrix(); - // Sprawdź kolizję AABB między pociskiem a obiektem z wektora gameEntities if (checkAABBCollision(bulletModelMatrix, entityModelMatrix)) { entity->applyDamage(attackerDmg); return true; @@ -72,12 +71,14 @@ public: return false; } bool checkAABBCollision(const glm::mat4& obj1ModelMatrix, const glm::mat4& obj2ModelMatrix) { - // Pobierz rozmiary obiektów z ich macierzy modelu + glm::vec3 obj1Min = glm::vec3(obj1ModelMatrix * glm::vec4(-0.5f, -0.5f, -0.5f, 1.0f)); glm::vec3 obj1Max = glm::vec3(obj1ModelMatrix * glm::vec4(0.5f, 0.5f, 0.5f, 1.0f)); - glm::vec3 obj2Min = glm::vec3(obj2ModelMatrix * glm::vec4(-0.5f, -0.5f, -0.5f, 1.0f)); - glm::vec3 obj2Max = glm::vec3(obj2ModelMatrix * glm::vec4(0.5f, 0.5f, 0.5f, 1.0f)); + /*glm::vec3 obj2Min = glm::vec3(obj2ModelMatrix * glm::vec4(-0.5f, -0.5f, -0.5f, 1.0f)); + glm::vec3 obj2Max = glm::vec3(obj2ModelMatrix * glm::vec4(0.5f, 0.5f, 0.5f, 1.0f));*/ + glm::vec3 obj2Min = glm::vec3(obj2ModelMatrix * glm::vec4(-0.6f, -0.6f, -0.6f, 1.0f)); + glm::vec3 obj2Max = glm::vec3(obj2ModelMatrix * glm::vec4(0.6f, 0.6f, 0.6f, 1.0f)); // Sprawdź kolizję wzdłuż trzech osi (x, y, z) bool collisionX = obj1Max.x >= obj2Min.x && obj1Min.x <= obj2Max.x; diff --git a/grk/project/Enemy.h b/grk/project/Enemy.h index 6249fc7..2fd7fae 100644 --- a/grk/project/Enemy.h +++ b/grk/project/Enemy.h @@ -12,6 +12,7 @@ private: std::list bullets; float lastShootTime = 0.f; float shootInterval = 0.3f; + glm::mat4 initialModelMatrix; public: glm::mat4 modelMatrix; @@ -21,6 +22,7 @@ public: : aggroRange(initialAggroRange), modelMatrix(initialModelMatrix), + initialModelMatrix(initialModelMatrix), GameEntity(currHp, initialHp, initialDmg) {} @@ -70,7 +72,11 @@ public: { return modelMatrix; } - + void respawn() override { + this->currentHP = this->maxHP; + this->modelMatrix = this->initialModelMatrix; + return; + } private: void requestShoot(float time) { if (canShoot(time)) { @@ -84,7 +90,8 @@ private: void shoot(float time) { Spaceship* spaceship = Spaceship::getInstance(); - glm::vec3 bulletDirection = glm::normalize(spaceship->spaceshipPos - glm::vec3(modelMatrix[3])); + //glm::vec3 bulletDirection = glm::normalize(spaceship->spaceshipPos - glm::vec3(modelMatrix[3])); + glm::vec3 bulletDirection = glm::normalize(glm::vec3(spaceship->getModelMatrix()[3]) - glm::vec3(modelMatrix[3])); //bulletDirection += glm::linearRand(glm::vec3(-0.01f), glm::vec3(0.1f)); // Modyfikacja kierunku o losowy szum this->bullets.push_back(Bullet::createSimpleBullet(bulletDirection, this->modelMatrix[3], time)); this->lastShootTime = time; diff --git a/grk/project/GameEntity.h b/grk/project/GameEntity.h index 7a5c189..c8019f5 100644 --- a/grk/project/GameEntity.h +++ b/grk/project/GameEntity.h @@ -19,5 +19,12 @@ public: }; virtual glm::vec3 getPosition() const = 0; virtual glm::mat4 getModelMatrix() = 0; + virtual bool isAlive() { + if (this->currentHP <= 0) { + return false; + } + return true; + }; + virtual void respawn() = 0; }; diff --git a/grk/project/Spaceship.h b/grk/project/Spaceship.h index 0bc5a56..3d5769b 100644 --- a/grk/project/Spaceship.h +++ b/grk/project/Spaceship.h @@ -386,4 +386,12 @@ public: return cameraMatrix; } + + void respawn() override { + this->currentHP = this->maxHP; + this->turbo = this->turboMAX; + this->spaceshipPos = glm::vec3(4.065808f, 10.250000f, -20.189549f); + return; + } + }; \ No newline at end of file diff --git a/grk/project/src/ex_9_1.hpp b/grk/project/src/ex_9_1.hpp index 0ba59a6..0f90fb4 100644 --- a/grk/project/src/ex_9_1.hpp +++ b/grk/project/src/ex_9_1.hpp @@ -260,6 +260,13 @@ void renderScene(GLFWwindow* window) glm::mat4 viewMatrix = Core::createViewMatrix(spaceship->cameraPos, spaceship->cameraDir, cameraUp); spaceship->renderParticles(programParticle, viewMatrix, Core::createPerspectiveMatrix(), time); + if(!spaceship->isAlive()){ + spaceship->respawn(); + for (const auto& enemy : enemies) { + enemy->respawn(); + } + + } renderHUD(window); renderEnemies(); @@ -322,11 +329,11 @@ bool isFarFromReferencePoints(float x, float y, float z, const std::vector