Add respawn for spaceship and enemies
This commit is contained in:
parent
91c2dca35b
commit
6737f14356
@ -62,7 +62,6 @@ public:
|
|||||||
for (const auto& entity : gameEntities) {
|
for (const auto& entity : gameEntities) {
|
||||||
glm::mat4 entityModelMatrix = entity->getModelMatrix();
|
glm::mat4 entityModelMatrix = entity->getModelMatrix();
|
||||||
|
|
||||||
// Sprawdź kolizję AABB między pociskiem a obiektem z wektora gameEntities
|
|
||||||
if (checkAABBCollision(bulletModelMatrix, entityModelMatrix)) {
|
if (checkAABBCollision(bulletModelMatrix, entityModelMatrix)) {
|
||||||
entity->applyDamage(attackerDmg);
|
entity->applyDamage(attackerDmg);
|
||||||
return true;
|
return true;
|
||||||
@ -72,12 +71,14 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool checkAABBCollision(const glm::mat4& obj1ModelMatrix, const glm::mat4& obj2ModelMatrix) {
|
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 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 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 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 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)
|
// SprawdŸ kolizjê wzd³u¿ trzech osi (x, y, z)
|
||||||
bool collisionX = obj1Max.x >= obj2Min.x && obj1Min.x <= obj2Max.x;
|
bool collisionX = obj1Max.x >= obj2Min.x && obj1Min.x <= obj2Max.x;
|
||||||
|
@ -12,6 +12,7 @@ private:
|
|||||||
std::list<Bullet*> bullets;
|
std::list<Bullet*> bullets;
|
||||||
float lastShootTime = 0.f;
|
float lastShootTime = 0.f;
|
||||||
float shootInterval = 0.3f;
|
float shootInterval = 0.3f;
|
||||||
|
glm::mat4 initialModelMatrix;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
glm::mat4 modelMatrix;
|
glm::mat4 modelMatrix;
|
||||||
@ -21,6 +22,7 @@ public:
|
|||||||
:
|
:
|
||||||
aggroRange(initialAggroRange),
|
aggroRange(initialAggroRange),
|
||||||
modelMatrix(initialModelMatrix),
|
modelMatrix(initialModelMatrix),
|
||||||
|
initialModelMatrix(initialModelMatrix),
|
||||||
GameEntity(currHp, initialHp, initialDmg)
|
GameEntity(currHp, initialHp, initialDmg)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
@ -70,7 +72,11 @@ public:
|
|||||||
{
|
{
|
||||||
return modelMatrix;
|
return modelMatrix;
|
||||||
}
|
}
|
||||||
|
void respawn() override {
|
||||||
|
this->currentHP = this->maxHP;
|
||||||
|
this->modelMatrix = this->initialModelMatrix;
|
||||||
|
return;
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
void requestShoot(float time) {
|
void requestShoot(float time) {
|
||||||
if (canShoot(time)) {
|
if (canShoot(time)) {
|
||||||
@ -84,7 +90,8 @@ private:
|
|||||||
|
|
||||||
void shoot(float time) {
|
void shoot(float time) {
|
||||||
Spaceship* spaceship = Spaceship::getInstance();
|
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
|
//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->bullets.push_back(Bullet::createSimpleBullet(bulletDirection, this->modelMatrix[3], time));
|
||||||
this->lastShootTime = time;
|
this->lastShootTime = time;
|
||||||
|
@ -19,5 +19,12 @@ public:
|
|||||||
};
|
};
|
||||||
virtual glm::vec3 getPosition() const = 0;
|
virtual glm::vec3 getPosition() const = 0;
|
||||||
virtual glm::mat4 getModelMatrix() = 0;
|
virtual glm::mat4 getModelMatrix() = 0;
|
||||||
|
virtual bool isAlive() {
|
||||||
|
if (this->currentHP <= 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
virtual void respawn() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -386,4 +386,12 @@ public:
|
|||||||
|
|
||||||
return cameraMatrix;
|
return cameraMatrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void respawn() override {
|
||||||
|
this->currentHP = this->maxHP;
|
||||||
|
this->turbo = this->turboMAX;
|
||||||
|
this->spaceshipPos = glm::vec3(4.065808f, 10.250000f, -20.189549f);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
@ -260,6 +260,13 @@ void renderScene(GLFWwindow* window)
|
|||||||
glm::mat4 viewMatrix = Core::createViewMatrix(spaceship->cameraPos, spaceship->cameraDir, cameraUp);
|
glm::mat4 viewMatrix = Core::createViewMatrix(spaceship->cameraPos, spaceship->cameraDir, cameraUp);
|
||||||
spaceship->renderParticles(programParticle, viewMatrix, Core::createPerspectiveMatrix(), time);
|
spaceship->renderParticles(programParticle, viewMatrix, Core::createPerspectiveMatrix(), time);
|
||||||
|
|
||||||
|
if(!spaceship->isAlive()){
|
||||||
|
spaceship->respawn();
|
||||||
|
for (const auto& enemy : enemies) {
|
||||||
|
enemy->respawn();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
renderHUD(window);
|
renderHUD(window);
|
||||||
renderEnemies();
|
renderEnemies();
|
||||||
@ -322,11 +329,11 @@ bool isFarFromReferencePoints(float x, float y, float z, const std::vector<glm::
|
|||||||
|
|
||||||
for (const auto& referencePoint : referencePoints) {
|
for (const auto& referencePoint : referencePoints) {
|
||||||
if (!checkDistance(referencePoint)) {
|
if (!checkDistance(referencePoint)) {
|
||||||
return false; // Jeśli choć jeden punkt jest zbyt blisko, zwracamy false
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true; // Jeśli wszystkie punkty są wystarczająco daleko, zwracamy true
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void createEnemies() {
|
void createEnemies() {
|
||||||
@ -363,7 +370,7 @@ void createEnemies() {
|
|||||||
|
|
||||||
glm::mat4 randomModelMatrix = glm::translate(glm::mat4(1.0f), glm::vec3(randomX, randomY, randomZ));
|
glm::mat4 randomModelMatrix = glm::translate(glm::mat4(1.0f), glm::vec3(randomX, randomY, randomZ));
|
||||||
|
|
||||||
enemies.push_back(new Enemy(100.0f, 100.0f, randomModelMatrix, 1.0f, 5.0f));
|
enemies.push_back(new Enemy(100.0f, 100.0f, randomModelMatrix, 1.0f, 8.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user