Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
I
imt2531_assignment2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Andreas Blakli
imt2531_assignment2
Commits
be99bfcf
Commit
be99bfcf
authored
5 years ago
by
iaminadequate
Browse files
Options
Downloads
Patches
Plain Diff
merging
parent
adea66d6
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
README.md
+4
-1
4 additions, 1 deletion
README.md
include/ghost.h
+2
-1
2 additions, 1 deletion
include/ghost.h
src/game.cpp
+1
-1
1 addition, 1 deletion
src/game.cpp
src/ghost.cpp
+41
-5
41 additions, 5 deletions
src/ghost.cpp
with
48 additions
and
8 deletions
README.md
+
4
−
1
View file @
be99bfcf
...
...
@@ -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
This diff is collapsed.
Click to expand it.
include/ghost.h
+
2
−
1
View file @
be99bfcf
...
...
@@ -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
This diff is collapsed.
Click to expand it.
src/game.cpp
+
1
−
1
View file @
be99bfcf
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
src/ghost.cpp
+
41
−
5
View file @
be99bfcf
...
...
@@ -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
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment