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
f5b14b5c
Commit
f5b14b5c
authored
5 years ago
by
Cedric.dosreis
Browse files
Options
Downloads
Patches
Plain Diff
Generate map wall from image
parent
ebd4efb3
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lab5/src/static/js/GameManager.js
+15
-17
15 additions, 17 deletions
lab5/src/static/js/GameManager.js
lab5/src/static/js/MapGenerator.js
+95
-18
95 additions, 18 deletions
lab5/src/static/js/MapGenerator.js
with
110 additions
and
35 deletions
lab5/src/static/js/GameManager.js
+
15
−
17
View file @
f5b14b5c
...
...
@@ -27,6 +27,7 @@ var camera;
var
renderer
;
var
player
;
var
enemies
=
[];
var
foods
=
[]
var
walls
=
[];
var
mapGenerator
...
...
@@ -44,24 +45,17 @@ function main() {
document
.
body
.
appendChild
(
renderer
.
domElement
);
//create objects
var
geometry
=
new
THREE
.
BoxGeometry
(
1
,
1
,
1
);
var
material
=
new
THREE
.
MeshBasicMaterial
({
color
:
0x00ff00
});
var
cube
=
new
THREE
.
Mesh
(
geometry
,
material
);
var
cube2
=
new
THREE
.
Mesh
(
geometry
,
material
);
walls
.
push
(
cube
);
walls
.
push
(
cube2
);
var
plane
;
scene
.
add
(
camera
);
scene
.
add
(
cube
);
scene
.
add
(
cube2
);
scene
.
add
(
mapGenerator
.
generateMap
(
1
));
camera
.
position
.
z
=
10
;
[
plane
,
walls
,
[
x
,
y
],
foods
]
=
mapGenerator
.
generateMap
(
1
,
scene
);
// get all wall object from scene
camera
.
position
.
z
=
12
;
camera
.
position
.
x
=
0
;
/*camera.position.y = -10;
camera.rotation.x = 0.5;*/
cube
.
position
.
x
=
0
;
cube
.
position
.
x
=
2
;
camera.rotation.x = 0.5;*/
// player
...
...
@@ -70,9 +64,8 @@ function main() {
var
sphere
=
new
THREE
.
Mesh
(
geometry
,
material
);
sphere
.
name
=
'
player
'
;
scene
.
add
(
sphere
);
player
=
new
Player
(
0
,
2
,
sphere
);
player
=
new
Player
(
x
,
y
,
sphere
);
//console.log(sphere.position);
function
render
(){
checkCollision
();
...
...
@@ -121,6 +114,11 @@ function checkCollision() {
/*collisionResults[0].object.material.transparent = true;
collisionResults[0].object.material.opacity = 0.4;*/
}
/*collisionResults = ray.intersectObjects(foods);
if (collisionResults.length > 0 && collisionResults[0].distance < directionVector.length()) {
console.log('Miam');
}*/
}
}
...
...
This diff is collapsed.
Click to expand it.
lab5/src/static/js/MapGenerator.js
+
95
−
18
View file @
f5b14b5c
function
convert2Dto1D
(
x
,
y
,
size
){
return
(
y
*
size
)
+
x
;
}
class
MapGenerator
{
constructor
()
{
this
.
size
=
21
;
}
generateMap
(
id
)
{
var
map
;
//
fetch
(
"
/get/map/
"
+
id
+
"
/
"
,
{
headers
:
{
"
Content-Type
"
:
"
text/plain; charset=utf-8
"
}})
.
then
(
res
=>
res
.
json
())
// parse response as JSON
.
then
(
response
=>
{
//// 2 dimension coordinates to 1 dimension
console
.
log
(
"
RESPONSE !!!!!!!!!!!!!!!!
"
);
console
.
log
(
response
);
})
.
catch
(
err
=>
{
// hide the modal
console
.
log
(
err
);
alert
(
"
Sorry, there are no results for your search
"
);
});
generateMap
(
id
,
scene
)
{
var
map
;
var
walls
=
[];
// create ground
var
map_content
=
[];
let
playerSpawnX
=
0
,
playerSpawnY
=
0
;
// create ground
var
geometry
=
new
THREE
.
PlaneGeometry
(
this
.
size
,
this
.
size
);
var
material
=
new
THREE
.
MeshBasicMaterial
(
{
color
:
0x000000
,
side
:
THREE
.
DoubleSide
}
);
var
plane
=
new
THREE
.
Mesh
(
geometry
,
material
);
scene
.
add
(
plane
);
plane
.
position
.
z
-=
0.5
;
// send http request
fetch
(
"
/get/map/
"
+
id
+
"
/
"
,
{
headers
:
{
"
Content-Type
"
:
"
text/plain; charset=utf-8
"
}})
.
then
(
res
=>
res
.
json
())
// parse response as JSON
.
then
(
response
=>
{
// copy response to array
for
(
let
i
=
0
;
i
<
this
.
size
*
this
.
size
;
i
++
)
{
map_content
.
push
(
response
[
i
]);
}
// loop through map content in 2 dimension to prepare to position walls in ground
let
i
=
0
;
let
offsetX
,
offsetY
,
wallWidth
,
wallHeight
,
wallPosX
,
wallPosY
;
for
(
let
y
=
0
;
y
<
this
.
size
;
y
++
)
{
for
(
let
x
=
0
;
x
<
this
.
size
;
x
++
)
{
i
=
convert2Dto1D
(
x
,
y
,
this
.
size
);
switch
(
map_content
[
i
]){
//
case
"
WALL
"
:
offsetX
=
1
;
offsetY
=
1
;
wallWidth
=
1
;
wallHeight
=
1
;
wallPosX
=
x
;
wallPosY
=
y
;
map_content
[
i
]
=
''
;
//empty the box to prevent from creating 2 walls at the same spot
// check for a horizontal line of wall
while
(
map_content
[
convert2Dto1D
(
x
+
offsetX
,
y
,
this
.
size
)]
==
'
WALL
'
&
x
+
offsetX
<
this
.
size
){
map_content
[
convert2Dto1D
(
x
+
offsetX
,
y
,
this
.
size
)]
=
''
;
wallWidth
++
;
offsetX
++
;
}
//check for a vertical line of wall only if it was not a horizonatl wall
while
(
wallWidth
<=
1
&
map_content
[
convert2Dto1D
(
x
,
y
+
offsetY
,
this
.
size
)]
==
'
WALL
'
&
y
+
offsetY
<
this
.
size
){
map_content
[
convert2Dto1D
(
x
,
y
+
offsetY
,
this
.
size
)]
=
''
wallHeight
++
;
offsetY
++
;
}
//create wall object
var
geometry
=
new
THREE
.
BoxGeometry
(
wallWidth
,
wallHeight
,
0.6
);
var
material
=
new
THREE
.
MeshBasicMaterial
(
{
color
:
0x0000FF
}
);
var
wall
=
new
THREE
.
Mesh
(
geometry
,
material
);
// re-position coreectly
wall
.
position
.
x
=
wallPosX
-
(
this
.
size
)
/
2
+
wallWidth
/
2
;
wall
.
position
.
y
=
wallPosY
-
(
this
.
size
)
/
2
+
wallHeight
/
2
;
// add to scene
scene
.
add
(
wall
);
walls
.
push
(
wall
);
break
;
case
"
FOOD
"
:
break
;
case
"
S_FOOD
"
:
break
;
case
"
FOOD
"
:
break
;
case
"
SPAWN_P
"
:
playerSpawnX
=
x
;
playerSpawnY
=
y
;
break
;
}
}
}
})
.
catch
(
err
=>
{
alert
(
err
);
});
return
plane
;
return
[
plane
,
walls
,
[
playerSpawnX
,
playerSpawnY
]]
;
}
}
}
\ 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