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

doc + finalisation

parent d9e0ea22
Branches
No related tags found
No related merge requests found
Cedric Dos Reis
IHM
# lab5 - IHM
Read `./src/README.md` for installation guide
## Features
* User move the caracter within a path using arrow key.
......@@ -25,15 +27,15 @@ Read `./src/README.md` for installation guide
### Flask server with 2 routes
Read `./src/README.md` for installation guide
#### 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).
## 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.
\ No newline at end of file
* Manage & display the score.
\ No newline at end of file
......@@ -6,37 +6,37 @@
1. Install `virtualenv` package and create a new environment in the `./src` folder project
On Linux and macOS :
On Linux and macOS :
```
python3 -m virtualenv env
```
On Windows :
```
python -m virtualenv env
```
On Windows :
```
python -m virtualenv env
```
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
```
3. Then install all packages dependencies in `requirements.txt` :
```python
pip install -r requirements.txt
```
```
pip install -r requirements.txt
```
4. Define environment variables
......@@ -46,13 +46,13 @@ pip install -r requirements.txt
export FLASK_ENV=development
export FLASK_APP=app.py
```
On Windows :
```
set FLASK_ENV=development
set FLASK_APP=app.py
```
On Windows :
```
set FLASK_ENV=development
set FLASK_APP=app.py
```
## Starting the web server (REST API)
......@@ -60,10 +60,15 @@ set FLASK_APP=app.py
python -m flask run
```
## Starting the web client
http://localhost:5000/
or
or
127.0.0.1:5000
......
......@@ -70,7 +70,7 @@ function main() {
//create objects
// 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);
// spawn enemies
......@@ -114,6 +114,7 @@ function spawnEnemy(){
enemies.push(new Enemy(enemy));
}
// check if there is any enemy in the same box of the player
function checkCollision() {
let[playerX, playerY] = player.getCoordinates();
enemies.forEach(enemy => {
......
......@@ -2,6 +2,10 @@ function convert2Dto1D(x, y, sz){
return (y * sz) + x;
}
function convertCoordToPos(c,sz){
return -c + (sz - 1)/2;
}
class MapGenerator {
constructor() {}
......@@ -35,6 +39,7 @@ class MapGenerator {
map_content = JSON.parse(request.responseText);
}else {
alert(request.responseText);
return false;
}
......@@ -47,6 +52,7 @@ class MapGenerator {
i = convert2Dto1D(x,y,SIZE);
switch (map_content[i]){ //
// ******** Walls ********
case "WALL":
offsetX = 1;
offsetY = 1;
......@@ -84,14 +90,15 @@ class MapGenerator {
scene.add(wall);
walls.push(wall);
break;
// ******** Food ********
case "FOOD":
var geometry = new THREE.SphereGeometry(0.1);
var material = new THREE.MeshBasicMaterial( {color: 0xffffff} );
var food = new THREE.Mesh( geometry, material );
food.name = "food" + foods.length;
food.position.x = -x + (SIZE - 1)/2;
food.position.y = -y + (SIZE - 1)/2;
food.position.x = convertCoordToPos(x,SIZE);//-x + (SIZE - 1)/2;
food.position.y = convertCoordToPos(y,SIZE);;
scene.add(food);
foods.push(food);
......@@ -99,43 +106,48 @@ class MapGenerator {
path[y].push(1); //define path
break;
// ******** Special Food ********
case "S_FOOD":
// special foo object spawn
var geometry = new THREE.SphereGeometry(0.2);
var material = new THREE.MeshBasicMaterial( {color: 0x00ff00} );
var food = new THREE.Mesh( geometry, material );
food.name = "s_food" + foods.length;
food.position.x = -x + (SIZE - 1)/2;
food.position.y = -y + (SIZE - 1)/2;
food.name = "sfood" + foods.length;
food.position.x = convertCoordToPos(x,SIZE);
food.position.y = convertCoordToPos(y,SIZE);
scene.add(food);
foods.push(food);
path[y].push(1); //define path
break;
// ******** Path ********
case "":
path[y].push(1);
break;
// ******** Enemy Spawn ********
case "SPAWN_E":
var spawnX = (-x + (SIZE - 1)/2);
var spawnY = (-y + (SIZE - 1)/2);
var spawnX = convertCoordToPos(x,SIZE);
var spawnY = convertCoordToPos(y,SIZE);;
enemies_spawn_zones.push({"x":spawnX, "y": spawnY});
path[y].push(1);
break;
// ******** Player Spawn ********
case "SPAWN_P":
// Player spawn zone
var geometry = new THREE.SphereGeometry(0.4);
var material = new THREE.MeshBasicMaterial( {color: 0xffff00} );
player = new THREE.Mesh( geometry, material );
player.position.x = -x + (SIZE - 1)/2;
player.position.y = -y + (SIZE - 1)/2;
player.position.x = convertCoordToPos(x,SIZE);
player.position.y = convertCoordToPos(y,SIZE);;
player.name = "Player";
scene.add(player);
path[y].push(1); //define path
break;
// ******** Walls done ********
case "WALL_DONE":
path[y].push(0);
break;
......@@ -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