diff --git a/site/game/elements.js b/site/game/elements.js new file mode 100644 index 0000000..37cdeb6 --- /dev/null +++ b/site/game/elements.js @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* elements.js :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hubourge +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/08/07 16:07:51 by hubourge #+# #+# */ +/* Updated: 2024/08/07 16:12:33 by hubourge ### ########.fr */ +/* */ +/* ************************************************************************** */ + +import * as THREE from 'three'; + +/* --- Box items --- */ +let BoxWidth = 1; +let BoxHeight = 0.1; +let BoxThickness = 0.1; + +function createBox(scene, x, y, z) +{ + const geometryBox = new THREE.BoxGeometry(BoxWidth, BoxHeight, BoxThickness); + const materialBox = new THREE.MeshLambertMaterial({ + color: 0xff0000, + }); + const box = new THREE.Mesh(geometryBox, materialBox); + box.position.set(x, y, z); + box.rotateY(Math.PI / 2); + box.receiveShadow = true; + scene.add(box); + return box; +} + +export { createBox }; \ No newline at end of file diff --git a/site/game/main.js b/site/game/main.js index 78ccede..b549b08 100644 --- a/site/game/main.js +++ b/site/game/main.js @@ -3,15 +3,16 @@ /* ::: :::::::: */ /* main.js :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: edbernar +#+ +:+ +#+ */ +/* By: hubourge +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/30 13:50:49 by edbernar #+# #+# */ -/* Updated: 2024/08/07 16:21:01 by edbernar ### ########.fr */ +/* Updated: 2024/08/07 16:26:11 by hubourge ### ########.fr */ /* */ /* ************************************************************************** */ import { sendRequest } from './websocket.js'; import { MoveObject } from './controls.js'; +import { createBox } from './elements.js'; import * as THREE from 'three'; import Stats from 'stats.js'; import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js'; @@ -52,7 +53,11 @@ ball.castShadow = true; scene.add(ball); const controlBall = new MoveObject(ball); - +// --------------- Box Constrols -------------- // +const boxLeft = createBox(scene, -4.45, 0.1 / 2, 0); +const boxRight = createBox(scene, 4.45, 0.1 / 2, 0); +const controlBoxLeft = new MoveObject(boxLeft); +const controlBoxRight = new MoveObject(boxRight); let spotLight = createSpotLight(0xffffff, ball, scene); let lightAmbient = createLightAmbient(scene); diff --git a/site/game/map.js b/site/game/map.js index cd2c71b..2ac089e 100644 --- a/site/game/map.js +++ b/site/game/map.js @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* map.js :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: edbernar +#+ +:+ +#+ */ +/* By: hubourge +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/30 13:50:51 by edbernar #+# #+# */ -/* Updated: 2024/08/07 16:20:08 by edbernar ### ########.fr */ +/* Updated: 2024/08/07 16:26:17 by hubourge ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,8 +21,6 @@ function createMap(scene) { wallUp = createWall(scene, 0, 0.25, -2.3, 0.1); wallDown = createWall(scene, 0, 0.25, 2.3, 0.1); - boxLeft = createBox(scene, 0, 0.25, 0); - // boxRight = createBox(scene, 0, 0.25, 0); ground = createGround(scene); } @@ -50,18 +48,4 @@ function createGround(scene) { return plane; } -function createBox(scene, x, y, z) -{ - const geometryBox = new THREE.BoxGeometry(1, 0.5, 0.1); - const materialBox = new THREE.MeshLambertMaterial({ - color: 0xff0000, - }); - const box = new THREE.Mesh(geometryBox, materialBox); - box.position.set(x, y, z); - box.rotateY(Math.PI / 2); - box.receiveShadow = true; - scene.add(box); - return box; -} - export { createMap };