Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
labs_IHM_2019
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cedric.dosreis
labs_IHM_2019
Commits
1498a047
Commit
1498a047
authored
5 years ago
by
Cedric.dosreis
Browse files
Options
Downloads
Patches
Plain Diff
moving enemies
parent
5830f3d3
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lab5/README.md
+24
-0
24 additions, 0 deletions
lab5/README.md
lab5/src/static/js/Enemy.js
+46
-9
46 additions, 9 deletions
lab5/src/static/js/Enemy.js
lab5/src/static/js/GameManager.js
+9
-11
9 additions, 11 deletions
lab5/src/static/js/GameManager.js
with
79 additions
and
20 deletions
lab5/README.md
+
24
−
0
View file @
1498a047
Cedric Dos Reis
# lab5 - IHM
READ
`./src/README.md`
for installation guide
## Features
User move the caracter within a path using arrow key.
Enemies spawn.
Caracter eats food on collision.
Caracter dies if he colides with an enemy.
Enemies move randomly in available direction within a path.
Loading map structure from an image file. Read
`./src/maps/README.md`
for more informations
### Flask server with 2 routes
`/get/map/<id>`
: get an 1D array of string defining the map strcuture.
`<id>`
: file name of the map (without extension).
`/get/maps/`
: get a 2D array of string which contains the list of maps in
`./src/maps/`
(This route is not used).
## Features to ba added
Let the user choose which map he wants to play in.
This diff is collapsed.
Click to expand it.
lab5/src/static/js/Enemy.js
+
46
−
9
View file @
1498a047
...
...
@@ -26,15 +26,29 @@ class Enemy {
//autoriser les movement uniquement lorsque la position x et y est très proche de nombre entier
if
((
Math
.
abs
(
posX
)
%
1
<
0.05
|
Math
.
abs
(
posX
)
%
1
>
0.95
)
&
(
Math
.
abs
(
posY
)
%
1
<
0.05
|
Math
.
abs
(
posY
)
%
1
>
0.95
))
{
&
(
Math
.
abs
(
posY
)
%
1
<
0.05
|
Math
.
abs
(
posY
)
%
1
>
0.95
))
{
// postion to coordinates
let
x
=
Math
.
round
(
posX
+
SIZE
/
2
-
0.5
);
let
y
=
(
Math
.
round
(
posY
-
SIZE
/
2
-
0.5
)
*
-
1
)
-
1
;
var
directions
=
this
.
getPossibleDirections
(
x
,
y
,
path
);
// 10% chance to change direction if 2 direction available
if
(
directions
.
length
==
2
&
Math
.
floor
(
Math
.
random
()
*
10
)
==
0
){
this
.
direction
=
directions
[
Math
.
floor
(
Math
.
random
()
*
directions
.
length
)
];
}
// 25% chance to change direction if 3 directions available
if
(
directions
.
length
==
3
&
Math
.
floor
(
Math
.
random
()
*
3
)
==
0
){
this
.
direction
=
directions
[
Math
.
floor
(
Math
.
random
()
*
directions
.
length
)
];
}
// 50% chance to change direction if 3 directions available
if
(
directions
.
length
==
4
&
Math
.
floor
(
Math
.
random
())
==
0
){
this
.
direction
=
directions
[
Math
.
floor
(
Math
.
random
()
*
directions
.
length
)
];
}
// check if direction can be changed according to path
var
nextBox
;
// check collision with wall
...
...
@@ -51,23 +65,46 @@ class Enemy {
case
DIRECTION
.
RIGHT
:
nextBox
=
path
[
y
][(
x
+
1
)
%
SIZE
]
break
;
case
DIRECTION
.
NONE
:
nextBox
=
0
;
break
;
}
if
(
nextBox
==
0
){
//change direction
this
.
direction
=
DIRECTION
.
NONE
;
this
.
direction
=
directions
[
Math
.
floor
(
Math
.
random
()
*
directions
.
length
)
];
}
}
}
setDirection
(
dir
){
// postion to coordinates
this
.
newDirection
=
dir
;
//this.direction = dir;
getPossibleDirections
(
x
,
y
,
path
){
// look for possible directions from actual position
var
possibleDirections
=
[]
if
(
path
[(
y
+
1
)
%
SIZE
][
x
]
==
1
){
possibleDirections
.
push
(
DIRECTION
.
DOWN
);
}
if
(
path
[(
y
-
1
)
%
SIZE
][
x
]
==
1
){
possibleDirections
.
push
(
DIRECTION
.
UP
);
}
if
(
path
[
y
][(
x
-
1
)
%
SIZE
]
==
1
){
possibleDirections
.
push
(
DIRECTION
.
LEFT
);
}
if
(
path
[
y
][(
x
+
1
)
%
SIZE
]
==
1
){
possibleDirections
.
push
(
DIRECTION
.
RIGHT
);
}
// choose random direction
//this.direction = possibleDirection[ Math.floor(Math.random()*possibleDirection.length) ];
return
possibleDirections
;
}
getDirection
(){
return
this
.
direction
;
}
getObject
(){
return
this
.
object
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
lab5/src/static/js/GameManager.js
+
9
−
11
View file @
1498a047
...
...
@@ -29,13 +29,13 @@ var camera;
var
renderer
;
var
player
;
var
enemies
=
[];
var
foods
=
[]
var
foods
=
[]
;
var
walls
=
[];
var
plane
;
var
mapGenerator
var
score
=
0
;
var
enemies_spawns
=
[]
const
MAX_ENEMIES
=
4
;
var
enemies_spawns
=
[]
const
MAX_ENEMIES
=
5
;
const
SIZE
=
21
...
...
@@ -74,8 +74,9 @@ function main() {
//create objects
LoadMap
(
'
map1
'
);
// laod map from image
[
plane
,
walls
,
foods
,
playerObj
,
path
,
enemies_spawns
]
=
mapGenerator
.
generateMap
(
"
map1
"
,
scene
);
player
=
new
Player
(
playerObj
);
// spawn enemey
for
(
let
i
=
0
;
i
<
MAX_ENEMIES
;
i
++
)
{
...
...
@@ -92,6 +93,8 @@ function main() {
enemies
.
forEach
(
enemy
=>
{
enemy
.
move
(
path
);
});
//checkCollision();
requestAnimationFrame
(
render
);
renderer
.
render
(
scene
,
camera
);
...
...
@@ -112,11 +115,6 @@ function spawnEnemy(){
}
function
LoadMap
(
id
){
[
plane
,
walls
,
foods
,
playerObj
,
path
,
enemies_spawns
]
=
mapGenerator
.
generateMap
(
id
,
scene
);
player
=
new
Player
(
playerObj
);
}
// check player collision with food/specail food and enemies
function
checkCollision
()
{
...
...
@@ -139,7 +137,7 @@ function checkCollision() {
}*/
ray
=
new
THREE
.
Raycaster
(
originPoint
,
directionVector
.
clone
().
normalize
());
collisionResults
=
ray
.
intersectObjects
(
enemies
);
collisionResults
=
ray
.
intersectObjects
(
enemies
.
getObject
()
);
if
(
collisionResults
.
length
>
0
&&
collisionResults
[
0
].
distance
<
directionVector
.
length
())
{
alert
(
'
Game Over
'
);
player
.
setDirection
(
DIRECTION
.
NONE
);
...
...
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