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
2c9630ce
Commit
2c9630ce
authored
5 years ago
by
Cedric.dosreis
Browse files
Options
Downloads
Patches
Plain Diff
player movement on a defined path array (no more collision with three.js for walls)
parent
8c75bf46
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/src/maps/map1.png
+0
-0
0 additions, 0 deletions
lab5/src/maps/map1.png
lab5/src/static/js/GameManager.js
+2
-2
2 additions, 2 deletions
lab5/src/static/js/GameManager.js
lab5/src/static/js/Player.js
+55
-17
55 additions, 17 deletions
lab5/src/static/js/Player.js
with
57 additions
and
19 deletions
lab5/src/maps/map1.png
+
0
−
0
View replaced file @
8c75bf46
View file @
2c9630ce
285 B
|
W:
|
H:
360 B
|
W:
|
H:
2-up
Swipe
Onion skin
This diff is collapsed.
Click to expand it.
lab5/src/static/js/GameManager.js
+
2
−
2
View file @
2c9630ce
...
...
@@ -52,7 +52,7 @@ function main() {
//create objects
var
plane
;
scene
.
add
(
camera
);
[
plane
,
walls
,
foods
,
playerObj
,
path
]
=
mapGenerator
.
generateMap
(
2
,
scene
);
[
plane
,
walls
,
foods
,
playerObj
,
path
]
=
mapGenerator
.
generateMap
(
1
,
scene
);
// get all wall object from scene
...
...
@@ -64,7 +64,7 @@ function main() {
// player
player
=
new
Player
(
playerObj
,
);
player
=
new
Player
(
playerObj
);
function
render
(){
...
...
This diff is collapsed.
Click to expand it.
lab5/src/static/js/Player.js
+
55
−
17
View file @
2c9630ce
class
Player
{
constructor
(
obj
,
)
{
constructor
(
obj
)
{
this
.
object
=
obj
;
this
.
direction
=
DIRECTION
.
NONE
;
this
.
newDirection
=
DIRECTION
.
NONE
;
...
...
@@ -12,38 +12,80 @@ class Player {
this
.
object
.
position
.
y
+=
y
;
var
posX
=
this
.
object
.
position
.
x
;
var
posY
=
this
.
object
.
position
.
y
;
// check for edge -> loop
if
(
this
.
object
.
position
.
x
>
SIZE
/
2
|
this
.
object
.
position
.
x
<
SIZE
/
2
*
(
-
1
)){
if
(
posX
>
SIZE
/
2
|
posX
<
SIZE
/
2
*
(
-
1
)){
this
.
object
.
position
.
x
*=
-
1
;
}
if
(
this
.
object
.
position
.
y
>
SIZE
/
2
|
this
.
object
.
position
.
y
<
SIZE
/
2
*
(
-
1
)){
if
(
posY
>
SIZE
/
2
|
posY
<
SIZE
/
2
*
(
-
1
)){
this
.
object
.
position
.
y
*=
-
1
;
}
// TODO
//autoriser les movement uniquement lorsque la position x ou y est sur .5
// x % 1 == 0.5 -> change direction
//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
))
{
if
(
this
.
newDirection
!=
this
.
direction
&
x
%
1
<
0.2
&
y
%
1
<
0.2
){
// postion to coordinates
x
=
Math
.
round
(
this
.
object
.
position
.
x
+
SIZE
/
2
-
0.5
);
y
=
(
Math
.
round
(
this
.
object
.
position
.
y
-
SIZE
/
2
-
0.5
)
*
-
1
)
-
1
;
let
x
=
Math
.
round
(
posX
+
SIZE
/
2
-
0.5
);
let
y
=
(
Math
.
round
(
posY
-
SIZE
/
2
-
0.5
)
*
-
1
)
-
1
;
// check if direction can be changed according to path
if
(
this
.
newDirection
!=
this
.
direction
){
var
nextBox
;
// check if a path is available (not a wall) in the new direction
switch
(
this
.
newDirection
){
case
DIRECTION
.
DOWN
:
nextBox
=
path
[(
y
+
1
)
%
SIZE
][
x
];
break
;
case
DIRECTION
.
UP
:
nextBox
=
path
[(
y
-
1
)
%
SIZE
][
x
];
break
;
case
DIRECTION
.
LEFT
:
nextBox
=
path
[
y
][(
x
-
1
)
%
SIZE
];
break
;
case
DIRECTION
.
RIGHT
:
nextBox
=
path
[
y
][(
x
+
1
)
%
SIZE
]
break
;
}
this
.
direction
=
this
.
newDirection
;
/*switch(this.newDirection){
if
(
nextBox
==
1
){
//change direction
this
.
direction
=
this
.
newDirection
;
}
}
var
nextBox
;
// check collision with wall
switch
(
this
.
direction
){
case
DIRECTION
.
DOWN
:
nextBox
=
path
[(
y
+
1
)
%
SIZE
][
x
];
break
;
case
DIRECTION
.
UP
:
break;
nextBox
=
path
[(
y
-
1
)
%
SIZE
][
x
];
break
;
case
DIRECTION
.
LEFT
:
nextBox
=
path
[
y
][(
x
-
1
)
%
SIZE
];
break
;
case
DIRECTION
.
RIGHT
:
nextBox
=
path
[
y
][(
x
+
1
)
%
SIZE
]
break
;
}*/
}
if
(
nextBox
==
0
){
//change direction
this
.
direction
=
DIRECTION
.
NONE
;
}
}
//console.log (this.object.position.x + " " + this.object.position.y);
...
...
@@ -60,8 +102,4 @@ class Player {
return
this
.
direction
;
}
getObject
(){
return
this
.
object
;
}
}
\ No newline at end of file
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