Skip to content
Snippets Groups Projects
Commit be99bfcf authored by iaminadequate's avatar iaminadequate
Browse files

merging

parent adea66d6
No related branches found
No related tags found
No related merge requests found
......@@ -7,3 +7,6 @@ Group members:
Vegard Opktivtne Årnes vegardoa vegardoa@stud.ntnu.no
Andreas Blakli andrbl andrbl@stud.ntnu.no
Theo Camille Gascogne theocg theocg@stud.ntnu.no
......@@ -20,6 +20,7 @@ public:
ghost(){}
ghost(const char* filepath_obj, const char* diffuse_path);
void move(float deltaTime, levelLoader* mapObjects);
void move(float deltaTime, levelLoader* mapObjects, glm::vec3 pacmanPosition);
bool ghost::collisionDetection(mapObj mapObject, glm::vec3 tempCamPos, float distFromSrc);
int checknear(glm::vec3 pacmanPosition);
};
\ No newline at end of file
......@@ -44,7 +44,7 @@ void game::run(renderer* renderer, pacman* pacman, ghost* ghostOne, levelLoader*
pacman->move(&myWindow, deltaTime, loader, ghostOne, animationTimer);
pacman->mouseMove(xoffset1, yoffset1, deltaTime);
ghostOne->move(deltaTime, loader);
ghostOne->move(deltaTime, loader, pacman->cameraPos);
renderer->loadMap(loader->mapObjects, pacman, ghostOne);
renderer->updatePellet(loader->floorObjects, pacman);
renderer->updateGhost(ghostOne, pacman); // Called before map
......
......@@ -11,18 +11,19 @@ ghost::ghost(const char* filepath_obj, const char* diffuse_path)
void ghost::move(float deltaTime, levelLoader* mapObjects){
void ghost::move(float deltaTime, levelLoader* mapObjects, glm::vec3 pacmanPosition){
glm::vec3 tempCamPos = ghostPos; // Temporary posisiton used to check the position input before actually performing the repositioning.
float cameraSpeed = 2.5 * deltaTime; // Sets movement speed.
canMove = true;
// Based on random INT: Move in 1 of 4 directions. (Initially value is 2, new random values are generated when ghost collides with a wall.)
switch (movementDir) {
case 1: tempCamPos += cameraSpeed * ghostFront;
case 1: tempCamPos += cameraSpeed * ghostFront; //z+
directionRadian = 0.0f; // Radians are used in rendering function for ghost, it rotates the ghost so that it will face the direction its walking.
break;
case 2: tempCamPos -= cameraSpeed * ghostFront;
case 2: tempCamPos -= cameraSpeed * ghostFront; //z-
directionRadian = 3.141592f;
break;
case 3: tempCamPos -= glm::normalize(glm::cross(ghostFront, positionUp)) * cameraSpeed;
......@@ -37,7 +38,11 @@ void ghost::move(float deltaTime, levelLoader* mapObjects){
if (collisionDetection(*iter, tempCamPos, 0.99f)) { // Runs the collision checking function for the iterated wall object
canMove = false; // Sets move bool to false if collision is detected
movementDir = rand() % 4 + 1; // On collision: Get new direction.
movementDir = checknear(pacmanPosition);
// On collision: Get new direction.
}
if (canMove == false) { break; } // Breaks are a no-no, but i wont let this loop run more than necessary.
}
......@@ -53,6 +58,37 @@ void ghost::move(float deltaTime, levelLoader* mapObjects){
}
int ghost::checknear(glm::vec3 pacmanPosition) {
glm::vec3 tempCamPos = ghostPos;
int choosex = abs(pacmanPosition.x - tempCamPos.x);
int choosez = abs(pacmanPosition.z - tempCamPos.z);
int picdirx = (pacmanPosition.x - tempCamPos.x);
int picdirz = (pacmanPosition.z - tempCamPos.z);
if (choosex > choosez) {
if (picdirx < 0) {
return 3;
}
else if (picdirx > 0) {
return 4;
}
}
else if (choosex < choosez) {
if (picdirz < 0) {
return 1;
}
else if (picdirz > 0) {
return 2;
}
}
}
bool ghost::collisionDetection(mapObj mapObject, glm::vec3 tempCamPos, float distFromSrc) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment