diff --git a/Opis_Projektu.pdf b/Opis_Projektu.pdf new file mode 100644 index 0000000..d0cb45f Binary files /dev/null and b/Opis_Projektu.pdf differ diff --git a/grk/project/Bullet.h b/grk/project/Bullet.h index 0d92cec..bfa5306 100644 --- a/grk/project/Bullet.h +++ b/grk/project/Bullet.h @@ -61,7 +61,6 @@ public: bool checkCollisionWithGameEntities(std::vector& gameEntities, glm::mat4 bulletModelMatrix, float attackerDmg) { for (const auto& entity : gameEntities) { glm::mat4 entityModelMatrix = entity->getModelMatrix(); - if (checkAABBCollision(bulletModelMatrix, entityModelMatrix)) { entity->applyDamage(attackerDmg); return true; diff --git a/grk/project/Enemy.h b/grk/project/Enemy.h index 8d0eda4..6e8a288 100644 --- a/grk/project/Enemy.h +++ b/grk/project/Enemy.h @@ -82,6 +82,9 @@ public: this->dmg = this->initDMG; return; } + void heal() override { + this->currentHP = this->currentHP + 5.0f; + } private: void requestShoot(float time) { if (canShoot(time)) { diff --git a/grk/project/GameEntity.h b/grk/project/GameEntity.h index 0715193..79feb55 100644 --- a/grk/project/GameEntity.h +++ b/grk/project/GameEntity.h @@ -10,11 +10,12 @@ public: float initDMG; GameEntity(float currentHP, float maxHP, float initialDmg) - : currentHP(currentHP), maxHP(maxHP), dmg(initialDmg),initDMG(initialDmg) + : currentHP(currentHP), maxHP(maxHP), dmg(initialDmg), initDMG(initialDmg) { } + virtual void applyDamage(float attackerDmg) { currentHP = currentHP - attackerDmg; }; @@ -27,5 +28,6 @@ public: return true; }; virtual void respawn() = 0; + virtual void heal() = 0; }; diff --git a/grk/project/Heart.h b/grk/project/Heart.h new file mode 100644 index 0000000..9d4bb02 --- /dev/null +++ b/grk/project/Heart.h @@ -0,0 +1,55 @@ +#include "glm.hpp" +#include "ext.hpp" +#include "src/Render_Utils.h" +#include "./GameEntity.h" +#include "Spaceship.h" + +#pragma once +class Heart : public GameEntity +{ +public: + glm::mat4 modelMatrix; + glm::mat4 initialModelMatrix; + float healAmount = 10; + bool isCollected; + + + Heart(glm::mat4 initialModelMatrix, float healAmount) + : + modelMatrix(initialModelMatrix), + initialModelMatrix(initialModelMatrix), + healAmount(healAmount), + isCollected(false), + GameEntity(1, 1, 0) + {} + + + virtual ~Heart() = default; + + virtual bool isAlive() { + if (this->currentHP <= 0) { + isCollected = true; + return false; + } + return true; + } + + glm::vec3 getPosition() const override + { + return modelMatrix[3]; + } + glm::mat4 getModelMatrix() override + { + return modelMatrix; + } + void respawn() override { + this->currentHP = this->maxHP; + this->modelMatrix = this->initialModelMatrix; + return; + } + void heal() override { + this->currentHP = this->currentHP + 5.0f; + } + +}; + diff --git a/grk/project/Nitro.h b/grk/project/Nitro.h new file mode 100644 index 0000000..720a809 --- /dev/null +++ b/grk/project/Nitro.h @@ -0,0 +1,55 @@ +#include "glm.hpp" +#include "ext.hpp" +#include "src/Render_Utils.h" +#include "./GameEntity.h" +#include "Spaceship.h" + +#pragma once +class Nitro : public GameEntity +{ +public: + glm::mat4 modelMatrix; + glm::mat4 initialModelMatrix; + float healAmount = 10; + bool isCollected; + + + Nitro(glm::mat4 initialModelMatrix, float healAmount) + : + modelMatrix(initialModelMatrix), + initialModelMatrix(initialModelMatrix), + healAmount(healAmount), + isCollected(false), + GameEntity(1, 1, 0) + {} + + + virtual ~Nitro() = default; + + virtual bool isAlive() { + if (this->currentHP <= 0) { + isCollected = true; + return false; + } + return true; + } + + glm::vec3 getPosition() const override + { + return modelMatrix[3]; + } + glm::mat4 getModelMatrix() override + { + return modelMatrix; + } + void respawn() override { + this->currentHP = this->maxHP; + this->modelMatrix = this->initialModelMatrix; + return; + } + void heal() override { + this->currentHP = this->currentHP + 5.0f; + } + +}; + diff --git a/grk/project/Spaceship.h b/grk/project/Spaceship.h index 28d5653..81204ae 100644 --- a/grk/project/Spaceship.h +++ b/grk/project/Spaceship.h @@ -394,4 +394,12 @@ public: return; } + + void heal() override { + this->currentHP = this->currentHP + 3.f; + } + + void turboBoost() { + this->turbo = this->turboMAX; + } }; \ No newline at end of file diff --git a/grk/project/grk-project.vcxproj b/grk/project/grk-project.vcxproj index e1e7e9f..7479210 100644 --- a/grk/project/grk-project.vcxproj +++ b/grk/project/grk-project.vcxproj @@ -32,6 +32,8 @@ + + diff --git a/grk/project/grk-project.vcxproj.filters b/grk/project/grk-project.vcxproj.filters index d489eb7..6fb47a3 100644 --- a/grk/project/grk-project.vcxproj.filters +++ b/grk/project/grk-project.vcxproj.filters @@ -59,7 +59,7 @@ Source Files - + Shader Files @@ -123,14 +123,20 @@ Header Files - Header Files - + Header Files + Header Files Header Files + + Header Files + + + Header Files + @@ -163,14 +169,14 @@ Shader Files - Shader Files - - - Shader Files - - - Shader Files - + Shader Files + + + Shader Files + + + Shader Files + Shader Files diff --git a/grk/project/src/ex_9_1.hpp b/grk/project/src/ex_9_1.hpp index 04864bb..d3c60a3 100644 --- a/grk/project/src/ex_9_1.hpp +++ b/grk/project/src/ex_9_1.hpp @@ -22,6 +22,8 @@ #include "../GameUtils.h" #include "../SpriteRenderer.h" #include "../Enemy.h" +#include "../Heart.h" +#include "../Nitro.h" #include "../ParticleSystem.h" #include "Camera.h" @@ -54,6 +56,8 @@ namespace texture { GLuint earthTexture; GLuint asteroidTexture; GLuint asteroidNormal; + GLuint heartTexture; + GLuint boosterTexture; } struct TextureTuple { @@ -82,6 +86,8 @@ std::list planets; Sun* sun; GLuint VAO,VBO; +std::vector nitros; +std::vector hearts; std::vector enemies; std::vector gameEntities; @@ -236,6 +242,46 @@ void renderEnemies() { } } + +void renderHeartsAndNitro() { + //if (heart->isAlive()) { + //spriteRenderer->DrawSprite(texture::heartTexture, heart->modelMatrix, programSprite); + //} + + glUseProgram(programSprite); + for (auto it = hearts.begin(); it != hearts.end();) { + Heart* heart = *it; + if (heart->isAlive()) { + spriteRenderer->DrawSprite(texture::heartTexture, heart->modelMatrix, programSprite); + } + + if (heart->isCollected) { + spaceship->heal(); + it = hearts.erase(it); + } + else { + ++it; + } + } + + for (auto it = nitros.begin(); it != nitros.end();) { + Nitro* nitro = *it; + if (nitro->isAlive()) { + spriteRenderer->DrawSprite(texture::boosterTexture, nitro->modelMatrix, programSprite); + } + + if (nitro->isCollected) { + spaceship->turboBoost(); + it = nitros.erase(it); + } + else { + ++it; + } + } +} + + + TextureTuple getRandomPlanetTexture() { int textureIndex = rand() % planetTextures.size(); TextureTuple selectedTextures = planetTextures[textureIndex]; @@ -280,8 +326,13 @@ void renderScene(GLFWwindow* window) glUseProgram(program); std::vector gameEntities(enemies.begin(), enemies.end()); + //spaceship->renderBullets(glfwGetTime(), program, gameEntities); + + gameEntities.insert(gameEntities.end(), hearts.begin(), hearts.end()); + gameEntities.insert(gameEntities.end(), nitros.begin(), nitros.end()); spaceship->renderBullets(glfwGetTime(), program, gameEntities); + drawObjectPBR(models::sphereContext, glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::eulerAngleY(time) * glm::translate(glm::vec3(1.f, 0, 0)) * glm::scale(glm::vec3(0.1f)), glm::vec3(0.5, 0.5, 0.5), 0.7, 0.0, program); @@ -333,7 +384,7 @@ void renderScene(GLFWwindow* window) renderHUD(window); renderEnemies(); - + renderHeartsAndNitro(); //drawObjectPBR(sphereContext, glm::translate(pointlightPos) * glm::scale(glm::vec3(1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(10.f, 0, 0)) * glm::scale(glm::vec3(0.3f)), glm::vec3(0.2, 0.7, 0.3), 0.3, 0.0, program); @@ -365,7 +416,7 @@ void createAsteroids() { float maxDistanceFromCenter = 26.f; float rotationSpeed = 0.05f; float scale = 0.002f; - int numAsteroids = 160; + int numAsteroids = 80; float distanceIncrement = 2.f / (minDistanceFromCenter + 1); for (int j = -1; j < 2; j++) { @@ -413,20 +464,31 @@ void createEnemies() { //enemies.push_back(new Enemy(100.0f,100.0f, glm::mat4(1.0f), 1.0f, 5.0f)); //enemies.push_back(new Enemy(100.0f,100.0f, glm::translate(glm::mat4(1.0f) , glm::vec3(1.f,1.f,1.f)), 1.0f, 5.0f)); //enemies.push_back(new Enemy(100.0f,100.0f, glm::translate(glm::mat4(1.0f), glm::vec3(-1.f, 2.f, -0.9f)), 1.0f, 5.0f)); - + int j = 0; enemies.push_back(new Enemy(100.0f, 100.0f, glm::translate(glm::translate(glm::mat4(1.0f), spaceship->getPosition()), glm::vec3(1.f, 1.f, 2.f)), 1.0f, 5.0f)); for (int i = 0; i < ENEMY_COUNT; ++i) { glm::mat4 randomModelMatrix = generateRandomMatrix(glm::mat4(1.0f)); enemies.push_back(new Enemy(100.0f, 100.0f, randomModelMatrix, 1.0f, 8.0f)); + + if (j % 4 == 0) { + hearts.push_back(new Heart(glm::translate(randomModelMatrix, glm::vec3(6.f, 5.f, 8.f)), -5.0f)); + nitros.push_back(new Nitro(glm::translate(randomModelMatrix, glm::vec3(2.f, -9.f, 3.f)), 10.0f)); + } + j = j + 1; } + hearts.push_back(new Heart(glm::translate(glm::mat4(1.0f), glm::vec3(25.f, 20.f, 25.f)), 10.0f)); + nitros.push_back(new Nitro(glm::translate(glm::mat4(1.0f), glm::vec3(20.f, 20.f, 25.f)), 10.0f)); //obiekty do ktorych bedzie sprawdzana kolizja dla pociskow enemy gameEntities.push_back(spaceship); } + + + void loadPlanetsAndSunTextures() { planetTextures.clear(); @@ -504,6 +566,8 @@ void init(GLFWwindow* window) texture::earthTexture = Core::LoadTexture("./textures/planets/8k_earth_daymap.jpg"); texture::asteroidTexture = Core::LoadTexture("./textures/asteroids/asteroidtx.jpg"); texture::asteroidNormal = Core::LoadTexture("./textures/asteroids/asteroidnn.png"); + texture::heartTexture = Core::LoadTexture("textures/heart.png"); + texture::boosterTexture = Core::LoadTexture("textures/boooster.png"); spaceship->createParticles(); createSuns(); diff --git a/grk/project/textures/boooster.png b/grk/project/textures/boooster.png new file mode 100644 index 0000000..4d697c9 Binary files /dev/null and b/grk/project/textures/boooster.png differ diff --git a/grk/project/textures/heart.png b/grk/project/textures/heart.png new file mode 100644 index 0000000..2f68f4a Binary files /dev/null and b/grk/project/textures/heart.png differ