- Add Class Map
   - Add plane a bottom
This commit is contained in:
Hugo Bourgeon
2024-08-20 16:36:35 +02:00
parent 240182bb54
commit 75cd958a4f
4 changed files with 68 additions and 8 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
*/.env
*.pyc

View File

@ -0,0 +1,58 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Map.js :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hubourge <hubourge@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/20 14:52:55 by hubourge #+# #+# */
/* Updated: 2024/08/20 16:34:25 by hubourge ### ########.fr */
/* */
/* ************************************************************************** */
import * as THREE from 'three';
class Map
{
scene = null;
arrObject = [];
constructor(scene, length)
{
this.scene = scene;
scene.add(this.#createPlanes(7.5, length, -(Math.PI / 2), "plane1"));
// scene.add(this.#createWalls(0, 0, 0, "wallLeft"));
};
#createPlanes(x, y, rot, name) // passer un materiel
{
for (let i = 0; i < this.arrObject.length; i++)
{
if (this.arrObject[i].name == name)
throw Error("Name already exist.");
}
const geometry = new THREE.PlaneGeometry(x, y);
const material = new THREE.MeshPhysicalMaterial()
const mesh = new THREE.Mesh(geometry, material);
mesh.rotateX(rot);
mesh.position.set(0, 0.15, -6);
this.arrObject.push({mesh: mesh, name: name});
return (mesh);
};
// #createWalls(x, y, z, name)
// {
// const geometry = new THREE.BoxGeometry(20, 20, 20);
// const material = new THREE.MeshPhysicalMaterial();
// const mesh = new THREE.Mesh(geometry, material);
// mesh.position.set(x, y, z);
// this.arrObject.push({mesh: mesh, name: name});
// return (mesh);
// };
};
export { Map };

View File

@ -3,10 +3,10 @@
/* ::: :::::::: */
/* Player.js :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
/* By: hubourge <hubourge@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/18 00:30:31 by edbernar #+# #+# */
/* Updated: 2024/08/20 14:33:51 by edbernar ### ########.fr */
/* Updated: 2024/08/20 16:00:24 by hubourge ### ########.fr */
/* */
/* ************************************************************************** */
@ -51,8 +51,8 @@ let playerExist = false;
const limits = {
up : 3,
down: 0.2,
left: -4,
right: 4,
left: -3,
right: 3,
}
class Player

View File

@ -3,15 +3,17 @@
/* ::: :::::::: */
/* main.js :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
/* By: hubourge <hubourge@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/18 00:53:53 by edbernar #+# #+# */
/* Updated: 2024/08/19 23:08:38 by edbernar ### ########.fr */
/* Updated: 2024/08/20 16:11:26 by hubourge ### ########.fr */
/* */
/* ************************************************************************** */
import * as THREE from 'three';
import { Player } from './class/Player'
import { Map } from './class/Map'
import { OrbitControls } from 'three/examples/jsm/Addons.js';
function createBarPlayer(color)
{
@ -41,18 +43,17 @@ function createMap()
const scene = new THREE.Scene();
const map = new Map(scene, 13);
const bar = createBarPlayer(0xed56ea);
const renderer = new THREE.WebGLRenderer({antialias: true});
const player = new Player(bar);
const spotLight = new THREE.SpotLight(0xffffff, 10000, 0, Math.PI / 4);
const ambiantLight = new THREE.AmbientLight(0xffffff, 1);
const map = createMap();
scene.add(player.object);
scene.add(ambiantLight);
spotLight.position.set(0, 100, 0);
scene.add(spotLight);
scene.add(map);
scene.background = new THREE.Color(0x1a1a1a);
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);