Skip to content
Snippets Groups Projects
Commit aafcd568 authored by Dos Reis Cedric's avatar Dos Reis Cedric
Browse files

doc + finalisation

parent d9e0ea22
No related branches found
No related tags found
No related merge requests found
Cedric Dos Reis Cedric Dos Reis
IHM
# lab5 - IHM # lab5 - IHM
Read `./src/README.md` for installation guide Read `./src/README.md` for installation guide
...@@ -28,12 +30,12 @@ Read `./src/README.md` for installation guide ...@@ -28,12 +30,12 @@ Read `./src/README.md` for installation guide
#### Routes #### Routes
`/get/map/<id>` : get an 1D array of string defining the map strcuture. `<id>` : file name of the map (without extension). `/get/map/<id>` : get an 1D array of string defining the map structure. `<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). `/get/maps/` : get a 2D array of string which contains the list of maps in `./src/maps/` (This route is not used).
## Features to be added ## Features to be added
* Let the user choose which map he wants to play in. This can actually be done by changing an argument in the code : at line 71 of `./src/static/js/GameManager.js`, change the first argument with one of these values : `map1`, `map2` or `map3`. You will need to reload the cache to see the new map `CTRL+F5`. * Let the user choose which map he wants to play in. This can actually be done by changing an argument in the code : at line 73 of `./src/static/js/GameManager.js`, change the first argument with one of these values : `map1`, `map2` or `map3`. You will need to reload the cache to see the new map `CTRL+F5`.
* Score. * Manage & display the score.
\ No newline at end of file \ No newline at end of file
...@@ -20,13 +20,13 @@ python -m virtualenv env ...@@ -20,13 +20,13 @@ python -m virtualenv env
2. Activate the virtual environment with : 2. Activate the virtual environment with :
On Linux and macOS : On Linux and macOS :
``` ```
source env/bin/activate source env/bin/activate
``` ```
On Windows : On Windows :
``` ```
.\env\Scripts\activate .\env\Scripts\activate
...@@ -34,7 +34,7 @@ source env/bin/activate ...@@ -34,7 +34,7 @@ source env/bin/activate
3. Then install all packages dependencies in `requirements.txt` : 3. Then install all packages dependencies in `requirements.txt` :
```python ```
pip install -r requirements.txt pip install -r requirements.txt
``` ```
...@@ -47,7 +47,7 @@ pip install -r requirements.txt ...@@ -47,7 +47,7 @@ pip install -r requirements.txt
export FLASK_APP=app.py export FLASK_APP=app.py
``` ```
On Windows : On Windows :
``` ```
set FLASK_ENV=development set FLASK_ENV=development
...@@ -60,10 +60,15 @@ set FLASK_APP=app.py ...@@ -60,10 +60,15 @@ set FLASK_APP=app.py
python -m flask run python -m flask run
``` ```
## Starting the web client ## Starting the web client
http://localhost:5000/ http://localhost:5000/
or or
127.0.0.1:5000 127.0.0.1:5000
......
...@@ -70,7 +70,7 @@ function main() { ...@@ -70,7 +70,7 @@ function main() {
//create objects //create objects
// load map from image // load map from image
[plane, walls, foods, playerObj, path, enemies_spawns] = mapGenerator.generateMap("map1", scene); [playing, plane, walls, foods, playerObj, path, enemies_spawns] = mapGenerator.generateMap("map1", scene);
player = new Player(playerObj); player = new Player(playerObj);
// spawn enemies // spawn enemies
...@@ -114,6 +114,7 @@ function spawnEnemy(){ ...@@ -114,6 +114,7 @@ function spawnEnemy(){
enemies.push(new Enemy(enemy)); enemies.push(new Enemy(enemy));
} }
// check if there is any enemy in the same box of the player
function checkCollision() { function checkCollision() {
let[playerX, playerY] = player.getCoordinates(); let[playerX, playerY] = player.getCoordinates();
enemies.forEach(enemy => { enemies.forEach(enemy => {
......
...@@ -2,6 +2,10 @@ function convert2Dto1D(x, y, sz){ ...@@ -2,6 +2,10 @@ function convert2Dto1D(x, y, sz){
return (y * sz) + x; return (y * sz) + x;
} }
function convertCoordToPos(c,sz){
return -c + (sz - 1)/2;
}
class MapGenerator { class MapGenerator {
constructor() {} constructor() {}
...@@ -35,6 +39,7 @@ class MapGenerator { ...@@ -35,6 +39,7 @@ class MapGenerator {
map_content = JSON.parse(request.responseText); map_content = JSON.parse(request.responseText);
}else { }else {
alert(request.responseText); alert(request.responseText);
return false;
} }
...@@ -47,6 +52,7 @@ class MapGenerator { ...@@ -47,6 +52,7 @@ class MapGenerator {
i = convert2Dto1D(x,y,SIZE); i = convert2Dto1D(x,y,SIZE);
switch (map_content[i]){ // switch (map_content[i]){ //
// ******** Walls ********
case "WALL": case "WALL":
offsetX = 1; offsetX = 1;
offsetY = 1; offsetY = 1;
...@@ -85,13 +91,14 @@ class MapGenerator { ...@@ -85,13 +91,14 @@ class MapGenerator {
walls.push(wall); walls.push(wall);
break; break;
// ******** Food ********
case "FOOD": case "FOOD":
var geometry = new THREE.SphereGeometry(0.1); var geometry = new THREE.SphereGeometry(0.1);
var material = new THREE.MeshBasicMaterial( {color: 0xffffff} ); var material = new THREE.MeshBasicMaterial( {color: 0xffffff} );
var food = new THREE.Mesh( geometry, material ); var food = new THREE.Mesh( geometry, material );
food.name = "food" + foods.length; food.name = "food" + foods.length;
food.position.x = -x + (SIZE - 1)/2; food.position.x = convertCoordToPos(x,SIZE);//-x + (SIZE - 1)/2;
food.position.y = -y + (SIZE - 1)/2; food.position.y = convertCoordToPos(y,SIZE);;
scene.add(food); scene.add(food);
foods.push(food); foods.push(food);
...@@ -99,43 +106,48 @@ class MapGenerator { ...@@ -99,43 +106,48 @@ class MapGenerator {
path[y].push(1); //define path path[y].push(1); //define path
break; break;
// ******** Special Food ********
case "S_FOOD": case "S_FOOD":
// special foo object spawn
var geometry = new THREE.SphereGeometry(0.2); var geometry = new THREE.SphereGeometry(0.2);
var material = new THREE.MeshBasicMaterial( {color: 0x00ff00} ); var material = new THREE.MeshBasicMaterial( {color: 0x00ff00} );
var food = new THREE.Mesh( geometry, material ); var food = new THREE.Mesh( geometry, material );
food.name = "s_food" + foods.length; food.name = "sfood" + foods.length;
food.position.x = -x + (SIZE - 1)/2; food.position.x = convertCoordToPos(x,SIZE);
food.position.y = -y + (SIZE - 1)/2; food.position.y = convertCoordToPos(y,SIZE);
scene.add(food); scene.add(food);
foods.push(food); foods.push(food);
path[y].push(1); //define path path[y].push(1); //define path
break; break;
// ******** Path ********
case "": case "":
path[y].push(1); path[y].push(1);
break; break;
// ******** Enemy Spawn ********
case "SPAWN_E": case "SPAWN_E":
var spawnX = (-x + (SIZE - 1)/2); var spawnX = convertCoordToPos(x,SIZE);
var spawnY = (-y + (SIZE - 1)/2); var spawnY = convertCoordToPos(y,SIZE);;
enemies_spawn_zones.push({"x":spawnX, "y": spawnY}); enemies_spawn_zones.push({"x":spawnX, "y": spawnY});
path[y].push(1); path[y].push(1);
break; break;
// ******** Player Spawn ********
case "SPAWN_P": case "SPAWN_P":
// Player spawn zone // Player spawn zone
var geometry = new THREE.SphereGeometry(0.4); var geometry = new THREE.SphereGeometry(0.4);
var material = new THREE.MeshBasicMaterial( {color: 0xffff00} ); var material = new THREE.MeshBasicMaterial( {color: 0xffff00} );
player = new THREE.Mesh( geometry, material ); player = new THREE.Mesh( geometry, material );
player.position.x = -x + (SIZE - 1)/2; player.position.x = convertCoordToPos(x,SIZE);
player.position.y = -y + (SIZE - 1)/2; player.position.y = convertCoordToPos(y,SIZE);;
player.name = "Player"; player.name = "Player";
scene.add(player); scene.add(player);
path[y].push(1); //define path path[y].push(1); //define path
break; break;
// ******** Walls done ********
case "WALL_DONE": case "WALL_DONE":
path[y].push(0); path[y].push(0);
break; break;
...@@ -144,6 +156,6 @@ class MapGenerator { ...@@ -144,6 +156,6 @@ class MapGenerator {
} }
} }
return [plane, walls, foods, player, path, enemies_spawn_zones]; return [true, plane, walls, foods, player, path, enemies_spawn_zones];
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment