Game
- Add Class Map - Add plane a bottom
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
||||
*/.env
|
||||
*.pyc
|
58
site/real_game/class/Map.js
Normal file
58
site/real_game/class/Map.js
Normal 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 };
|
@ -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
|
||||
|
@ -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);
|
||||
|
Reference in New Issue
Block a user