Skip to content
Snippets Groups Projects
Commit fdbb4c15 authored by Vegardoa's avatar Vegardoa
Browse files

Fixed pellet rendering bug caused by menu functionality

parent f572f048
Branches
No related tags found
No related merge requests found
...@@ -46,6 +46,9 @@ target_sources( ...@@ -46,6 +46,9 @@ target_sources(
${CMAKE_CURRENT_LIST_DIR}/include/ui.h ${CMAKE_CURRENT_LIST_DIR}/include/ui.h
${CMAKE_CURRENT_LIST_DIR}/src/ui.cpp ${CMAKE_CURRENT_LIST_DIR}/src/ui.cpp
${CMAKE_CURRENT_LIST_DIR}/include/minimap.h
${CMAKE_CURRENT_LIST_DIR}/src/minimap.cpp
# ${CMAKE_CURRENT_LIST_DIR}/src/imgui/imgui.h # ${CMAKE_CURRENT_LIST_DIR}/src/imgui/imgui.h
# ${CMAKE_CURRENT_LIST_DIR}/src/imgui/imgui.cpp # ${CMAKE_CURRENT_LIST_DIR}/src/imgui/imgui.cpp
...@@ -70,7 +73,7 @@ target_sources( ...@@ -70,7 +73,7 @@ target_sources(
) "src/minimap.cpp")
# Set include directories # Set include directories
target_include_directories( target_include_directories(
......
...@@ -17,7 +17,6 @@ public: ...@@ -17,7 +17,6 @@ public:
game(int w = 1024, int h = 768); // Constructor that initialises game window and defaults game(int w = 1024, int h = 768); // Constructor that initialises game window and defaults
~game() { glfwTerminate(); } // Deconstructor ~game() { glfwTerminate(); } // Deconstructor
void run(); // Gameloop void run(renderer* renderer, pacman* pacman, ghost* ghostOne, levelLoader* loader, ui* ui, float deltaTime); // Gameloop
void drawMainMenu(); // Main menu
void loopHandler(); void loopHandler();
}; };
\ No newline at end of file
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "levelLoader.h" #include "levelLoader.h"
#include "ui.h" #include "ui.h"
#include "ghost.h" #include "ghost.h"
#include "window.h"
class pacman { class pacman {
...@@ -22,7 +23,7 @@ public: ...@@ -22,7 +23,7 @@ public:
glm::mat4 view; // Variables public to be used easily in renderer (cheating ;) ) glm::mat4 view; // Variables public to be used easily in renderer (cheating ;) )
glm::vec3 cameraPos = glm::vec3(0.0f, 0.0f, 3.5f); glm::vec3 cameraPos = glm::vec3(0.0f, 0.0f, 3.5f);
pacman() { } pacman() { }
void move(GLFWwindow* window, float deltaTime, levelLoader* mapObjects, ghost* ghost); void move(Window* window, float deltaTime, levelLoader* mapObjects, ghost* ghost);
bool collisionDetection(mapObj mapObject, glm::vec3 tempCamPos, float distFromSrc); bool collisionDetection(mapObj mapObject, glm::vec3 tempCamPos, float distFromSrc);
void mouseMove(double xoffset, double yoffset, float deltaTime); void mouseMove(double xoffset, double yoffset, float deltaTime);
void updateVecPos(); void updateVecPos();
......
...@@ -9,7 +9,7 @@ private: ...@@ -9,7 +9,7 @@ private:
std::vector<int> renderIDList; // MIGHT be used for a layered render in the future. std::vector<int> renderIDList; // MIGHT be used for a layered render in the future.
public: public:
renderer() {} renderer() {}
void loadMap(std::vector<mapObj> mapObjects, pacman pacman, ghost ghost); // Loads and updates the map. void loadMap(std::vector<mapObj> mapObjects, pacman* pacman, ghost* ghost); // Loads and updates the map.
void updatePellet(std::vector<mapObj> pelletObj, pacman pacman); void updatePellet(std::vector<mapObj> pelletObj, pacman* pacman);
void updateGhost(ghost* ghostModel, pacman pacman); void updateGhost(ghost* ghostModel, pacman* pacman);
}; };
\ No newline at end of file
resources/assets/NuPac.png

55.4 KiB

...@@ -36,25 +36,30 @@ game::game(int w, int h) { ...@@ -36,25 +36,30 @@ game::game(int w, int h) {
/* /*
* Where the actual gameloop is located. * All rendering of game.
*/ */
void game::run() { void game::run(renderer* renderer, pacman* pacman, ghost* ghostOne, levelLoader* loader, ui* ui, float deltaTime) {
pacman->move(&myWindow, deltaTime, loader, ghostOne);
pacman->mouseMove(xoffset1, yoffset1, deltaTime);
ghostOne->move(deltaTime, loader);
renderer->loadMap(loader->mapObjects, pacman, ghostOne);
renderer->updatePellet(loader->floorObjects, pacman);
renderer->updateGhost(ghostOne, pacman);
ui->inGameStats(pacman->returnPoints(), pacman->returnLives());
}
void game::loopHandler() { // Dont use this yet, pellets don't render with this func
GFX_INFO("starting app..."); GFX_INFO("starting app...");
ui ui;
renderer renderer; // Gives access to rendering functions renderer renderer; // Gives access to rendering functions
pacman pacman; // Gives access to pacman functions pacman pacman; // Gives access to pacman functions
ui ui; // Gives acsess to ui functions
levelLoader loader; // Gives access to loader levelLoader loader; // Gives access to loader
loader.loadLevel("resources/levels/level0"); // Loads the file and generates objects for each cube loader.loadLevel("resources/levels/level0"); // Loads the file and generates objects for each cube
ghost ghostOne("resources/obj/ghost.obj", "resources/obj/nuGhostTex.png"); ghost ghostOne("resources/obj/ghost.obj", "resources/obj/nuGhostTex.png");
//model ghost; //makes "model" into the weird Model class with that namespace they use, ofc nabbed from lab07
//ghost.load("resources/obj/axe.obj", "resources/obj/axe_color.png");
float deltaTime = 0.0f;
float lastFrame = 0.0f;
// GUI // GUI
ImGui::CreateContext(); ImGui::CreateContext();
...@@ -62,67 +67,36 @@ void game::run() { ...@@ -62,67 +67,36 @@ void game::run() {
ImGui_ImplOpenGL3_Init("#version 430 core"); ImGui_ImplOpenGL3_Init("#version 430 core");
// Actual gameloop. float deltaTime = 0.0f;
while (!myWindow.shouldClose()) { // should be startGame && float lastFrame = 0.0f;
// Loop that that has all the other game loops
do {
myWindow.setViewport(); myWindow.setViewport();
/*
* Gets deltattime data
*/
float currentFrame = glfwGetTime(); float currentFrame = glfwGetTime();
deltaTime = currentFrame - lastFrame; deltaTime = currentFrame - lastFrame;
lastFrame = currentFrame; lastFrame = currentFrame;
/*
* Reset every frame
*/
glClearColor(0, 0, 0, 1); glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
/* // If the game hasnt started, enable cursor and draw menu
* Following section runs the game code if (startGame == false) {
* pacman.move is before renderer.loadMap because the pacman object contains the "view" camera angle DATA and renderer.loadMap() uses it to portray the actual angle in shader glfwSetInputMode(myWindow.window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
*/ ui.mainMenu();
pacman.move(myWindow.window, deltaTime, &loader, &ghostOne);
pacman.mouseMove(xoffset1, yoffset1, deltaTime);
ghostOne.move(deltaTime, &loader);
renderer.loadMap(loader.mapObjects, pacman, ghostOne);
renderer.updatePellet(loader.floorObjects, pacman);
renderer.updateGhost(&ghostOne, pacman);
ui.inGameStats(pacman.returnPoints(), pacman.returnLives());
myWindow.swapBuffers(); //<-- SWAP BUFFERS
glfwPollEvents(); //<-- LISTEN FOR WINDOW EVENTS
} }
// Otherwise, if game is running, disable cursor and run the game code.
else if (startGame) {
glfwSetInputMode(myWindow.window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); // REMBER TO ENABLE THIS, Lock cursor inside game window and hides it.
run(&renderer, &pacman, &ghostOne, &loader, &ui, deltaTime);
} }
void game::drawMainMenu() {
ui ui;
while (exitMenu == false && !myWindow.shouldClose()) { //(exitMenu == 0 && glfwWindowShouldClose(window) == 0)
myWindow.setViewport();
glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
ui.mainMenu(); // Calls main menu func, displays the main menu
myWindow.swapBuffers(); //<-- SWAP BUFFERS myWindow.swapBuffers(); //<-- SWAP BUFFERS
glfwPollEvents(); //<-- LISTEN FOR WINDOW EVENTS glfwPollEvents(); //<-- LISTEN FOR WINDOW EVENTS
}
}
void game::loopHandler() { // Dont use this yet, pellets don't render with this func
GFX_INFO("starting app...");
ui ui;
// GUI
ImGui::CreateContext();
ImGui_ImplGlfw_InitForOpenGL(myWindow.window, true);
ImGui_ImplOpenGL3_Init("#version 430 core");
// Loop that that has all the other game loops
do {
glfwSetInputMode(myWindow.window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
drawMainMenu();
glfwSetInputMode(myWindow.window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); // REMBER TO ENABLE THIS, Lock cursor inside game window and hides it.
run();
} while (quitGameComf == false && !myWindow.shouldClose()); } while (quitGameComf == false && !myWindow.shouldClose());
// Closing imgui // Closing imgui
......
...@@ -8,8 +8,8 @@ int main() ...@@ -8,8 +8,8 @@ int main()
game PacMan; game PacMan;
PacMan.run(); //PacMan.run();
//PacMan.loopHandler(); PacMan.loopHandler();
return 0; return 0;
......
...@@ -2,21 +2,24 @@ ...@@ -2,21 +2,24 @@
#include <iostream> #include <iostream>
void pacman::move(GLFWwindow* window, float deltaTime, levelLoader* mapObjects, ghost* ghost){ void pacman::move(Window* window, float deltaTime, levelLoader* mapObjects, ghost* ghost){
glm::vec3 tempCamPos = cameraPos; // Temporary posisiton used to check the position input before actually performing the repositioning. glm::vec3 tempCamPos = cameraPos; // Temporary posisiton used to check the position input before actually performing the repositioning.
float cameraSpeed = 2.5 * deltaTime; // Sets movement speed. float cameraSpeed = 2.5 * deltaTime; // Sets movement speed.
bool move = true; bool move = true;
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) // If you press W if (glfwGetKey(window->window, GLFW_KEY_W) == GLFW_PRESS) // If you press W
tempCamPos += cameraSpeed * cameraFront; tempCamPos += cameraSpeed * cameraFront;
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) // If you press S if (glfwGetKey(window->window, GLFW_KEY_S) == GLFW_PRESS) // If you press S
tempCamPos -= cameraSpeed * cameraFront; tempCamPos -= cameraSpeed * cameraFront;
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) // If you press A if (glfwGetKey(window->window, GLFW_KEY_A) == GLFW_PRESS) // If you press A
tempCamPos -= glm::normalize(glm::cross(cameraFront, cameraUp)) * cameraSpeed; // Normalize and multiply tempCamPos -= glm::normalize(glm::cross(cameraFront, cameraUp)) * cameraSpeed; // Normalize and multiply
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) { // If you press D if (glfwGetKey(window->window, GLFW_KEY_D) == GLFW_PRESS) { // If you press D
tempCamPos += glm::normalize(glm::cross(cameraFront, cameraUp)) * cameraSpeed; tempCamPos += glm::normalize(glm::cross(cameraFront, cameraUp)) * cameraSpeed;
} }
if (glfwGetKey(window->window, GLFW_KEY_ESCAPE) == GLFW_PRESS) { // Close if you press ESC
window->shouldClose();
}
for (auto iter = begin(mapObjects->mapObjects); iter != end(mapObjects->mapObjects); ++iter) { // For every wall for (auto iter = begin(mapObjects->mapObjects); iter != end(mapObjects->mapObjects); ++iter) { // For every wall
if(collisionDetection(*iter, tempCamPos, 0.6f)){ // Runs the collision checking function for the iterated wall object if(collisionDetection(*iter, tempCamPos, 0.6f)){ // Runs the collision checking function for the iterated wall object
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
void renderer::loadMap(std::vector<mapObj> mapObjects, pacman pacman, ghost ghost){ void renderer::loadMap(std::vector<mapObj> mapObjects, pacman* pacman, ghost* ghost){
for (auto iter = begin(mapObjects); iter != end(mapObjects); ++iter) { // For every wall cube for (auto iter = begin(mapObjects); iter != end(mapObjects); ++iter) { // For every wall cube
glUseProgram(iter->textureProgramID->id()); glUseProgram(iter->textureProgramID->id());
...@@ -38,9 +38,9 @@ void renderer::loadMap(std::vector<mapObj> mapObjects, pacman pacman, ghost ghos ...@@ -38,9 +38,9 @@ void renderer::loadMap(std::vector<mapObj> mapObjects, pacman pacman, ghost ghos
//glUniformMatrix3fv(normalMatrixID, 1, GL_FALSE, glm::value_ptr(normalMatrix)); // Might get some use out of this one in the future //glUniformMatrix3fv(normalMatrixID, 1, GL_FALSE, glm::value_ptr(normalMatrix)); // Might get some use out of this one in the future
glUniformMatrix4fv(viewID, 1, GL_FALSE, glm::value_ptr(pacman.view)); glUniformMatrix4fv(viewID, 1, GL_FALSE, glm::value_ptr(pacman->view));
glUniform3f(lightPositionOneID, pacman.cameraPos.x, pacman.cameraPos.y, pacman.cameraPos.z); glUniform3f(lightPositionOneID, pacman->cameraPos.x, pacman->cameraPos.y, pacman->cameraPos.z);
glUniform3f(lightPositionTwoID, ghost.ghostPos.x, ghost.ghostPos.y, ghost.ghostPos.z); glUniform3f(lightPositionTwoID, ghost->ghostPos.x, ghost->ghostPos.y, ghost->ghostPos.z);
/* /*
* Draws the cube * Draws the cube
*/ */
...@@ -49,7 +49,7 @@ void renderer::loadMap(std::vector<mapObj> mapObjects, pacman pacman, ghost ghos ...@@ -49,7 +49,7 @@ void renderer::loadMap(std::vector<mapObj> mapObjects, pacman pacman, ghost ghos
} }
} }
void renderer::updatePellet(std::vector<mapObj> pelletObj, pacman pacman){ void renderer::updatePellet(std::vector<mapObj> pelletObj, pacman* pacman){
for (auto iter = begin(pelletObj); iter != end(pelletObj); ++iter) { // For every wall cube for (auto iter = begin(pelletObj); iter != end(pelletObj); ++iter) { // For every wall cube
if(iter->visible){ if(iter->visible){
...@@ -82,8 +82,8 @@ void renderer::updatePellet(std::vector<mapObj> pelletObj, pacman pacman){ ...@@ -82,8 +82,8 @@ void renderer::updatePellet(std::vector<mapObj> pelletObj, pacman pacman){
glUniformMatrix4fv(modelID, 1, GL_FALSE, glm::value_ptr(model)); glUniformMatrix4fv(modelID, 1, GL_FALSE, glm::value_ptr(model));
glUniformMatrix4fv(viewID, 1, GL_FALSE, glm::value_ptr(pacman.view)); glUniformMatrix4fv(viewID, 1, GL_FALSE, glm::value_ptr(pacman->view));
glUniform3f(lightPositionID, pacman.cameraPos.x, pacman.cameraPos.y, pacman.cameraPos.z); glUniform3f(lightPositionID, pacman->cameraPos.x, pacman->cameraPos.y, pacman->cameraPos.z);
/* /*
* Draws the cube * Draws the cube
*/ */
...@@ -96,7 +96,7 @@ void renderer::updatePellet(std::vector<mapObj> pelletObj, pacman pacman){ ...@@ -96,7 +96,7 @@ void renderer::updatePellet(std::vector<mapObj> pelletObj, pacman pacman){
void renderer::updateGhost(ghost* ghostModel, pacman pacman){ void renderer::updateGhost(ghost* ghostModel, pacman* pacman){
glUseProgram(ghostModel->ghostModel.ShaderID->id()); glUseProgram(ghostModel->ghostModel.ShaderID->id());
GLint modelID = glGetUniformLocation(ghostModel->ghostModel.ShaderID->id(), "model"); GLint modelID = glGetUniformLocation(ghostModel->ghostModel.ShaderID->id(), "model");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment