game over

This commit is contained in:
Kamil Ryżek 2024-03-01 18:19:41 +01:00
parent 9884610edc
commit 84061f9577

View File

@ -70,13 +70,16 @@ Core::RenderContext cylinderContext;
glm::vec3 cameraPos = glm::vec3(-4.f, 0, 0);
glm::vec3 cameraDir = glm::vec3(1.f, 0, 0.f);
glm::vec3 spaceshipPos = glm::vec3(-4.f, 0, 0);
glm::vec3 spaceshipPos = glm::vec3(-22.f, 0, 0);
glm::vec3 spaceshipDir = glm::vec3(1.f, 0.f, 0.f);
GLuint VAO, VBO;
float aspectRatio = 1.f;
unsigned int textureID;
bool gameOver = false;
bool gameWon = false;
const int maxSize = 30;
int numberOfCollectedCoins = 0;
@ -95,7 +98,7 @@ float xCordinatesOfCollectedCoin[maxSize] = {};
float zCordinatesOfCollectedCoin[maxSize] = {};
float angleSpeed = 0.005f;
float moveSpeed = 0.0025f;
float moveSpeed = 0.0035f;
struct Planet {
glm::vec3 currentPos;
@ -554,18 +557,11 @@ void renderScene(GLFWwindow* window)
drawSun(sphereContext, glm::mat4(), texture::sun);
//rendering all the planets
//renderPlanets();
/*glm::mat4 modelMatrix = glm::eulerAngleY(time / planet.rotationSpeed)
* glm::translate(glm::vec3(planet.orbitRadius, 0, 0))
* glm::eulerAngleY(time)
* glm::scale(planet.modelScale);*/
for (auto& planet : planets) {
glm::mat4 modelMatrix = glm::rotate(glm::mat4(1.0f), time * planet.orbitSpeed, glm::vec3(0, 1, 0)) // orbitowanie dooko³a s³oñca
glm::mat4 modelMatrix = glm::rotate(glm::mat4(1.0f), 5*time * planet.orbitSpeed, glm::vec3(0, 1, 0)) // orbitowanie dooko³a s³oñca
* glm::translate(glm::vec3(planet.orbitRadius, 0, 0)) // translacja na odp. odleg³oœæ
* glm::rotate(glm::mat4(1.0f), time * planet.rotationSpeed, glm::vec3(0, 1, 0)) //obrót planety wokó³ w³asnej osi
* glm::scale(glm::vec3(planet.modelScale)); //skalowanie planety
@ -576,7 +572,7 @@ void renderScene(GLFWwindow* window)
}
for (auto& satellite : satellites) {
glm::mat4 modelMatrix = glm::eulerAngleY(time * satellite.parentPlanet.orbitSpeed)
glm::mat4 modelMatrix = glm::eulerAngleY(2*time * satellite.parentPlanet.orbitSpeed)
* glm::translate(glm::vec3(satellite.parentPlanet.orbitRadius, 0, 0))
* glm::eulerAngleY(time * satellite.rotationSpeed)
* glm::translate(glm::vec3(satellite.orbitRadius, 0, 0))
@ -585,13 +581,6 @@ void renderScene(GLFWwindow* window)
satellite.currentPos = glm::vec3(modelMatrix * glm::vec4(0, 0, 0, 1.0f));
}
/*drawObjectTexture(sphereContext,
glm::eulerAngleY(time * planets[2].orbitSpeed) * glm::translate(glm::vec3(planets[2].orbitRadius, 0, 0)) * glm::eulerAngleY(time * 0.5f) * glm::translate(glm::vec3(0.8f, 0, 0)) * glm::scale(glm::vec3(0.055f)),
texture::moon,
texture::asteroidNormal);*/
//renderPlanets();
renderCoins();
// obliczanie orientacji statku
glm::vec3 spaceshipSide = glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.f, 1.f, 0.f)));
@ -734,6 +723,13 @@ void init(GLFWwindow* window)
void gameOverScreen(GLFWwindow* window) {
if (gameWon) {
std::cout << "Congratulations!" << std::endl;
}
else if (gameOver) {
std::cout << "GAME OVER. Number of collected coins: " << numberOfCollectedCoins << std::endl;
}
glfwSetWindowShouldClose(window, GLFW_TRUE);
moveSpeed = 0;
angleSpeed = 0;
}
@ -787,23 +783,26 @@ void renderLoop(GLFWwindow* window) {
{
processInput(window);
renderScene(window);
int index = 0;
if (numberOfCollectedCoins == 30) {
gameWon = true;
}
for (auto& planet : planets) {
if (checkCollision(spaceshipPos, planet.currentPos, planet.modelScale)) {
//placeholder
gameOver = true;
std::cout << "Kolizja statku z planeta " << index << std::endl;
//std::cout << "Kolizja statku z planeta " << index << std::endl;
}
++index;
}
for (auto& satellite : satellites) {
if (checkCollision(spaceshipPos, satellite.currentPos, satellite.modelScale)) {
//placeholder
gameOver = true;
std::cout << "Kolizja statku z satelita " << index << std::endl;
//std::cout << "Kolizja statku z satelita " << index << std::endl;
}
++index;
}
@ -812,13 +811,14 @@ void renderLoop(GLFWwindow* window) {
loopCount++;
if (loopCount >= interval) {
printPlanetPos();
std::cout << "Pozycja statku " << glm::to_string(spaceshipPos) << std::endl;
//printPlanetPos();
//std::cout << "Pozycja statku " << glm::to_string(spaceshipPos) << std::endl;
std::cout << "Coins collected " << numberOfCollectedCoins << std::endl;
loopCount = 0;
timeOfLastUpdate = glfwGetTime();
}
if (gameOver) {
if (gameOver || gameWon) {
gameOverScreen(window);
}