From 2fdba63def5204672cdf35c935db9d4ef9a6650a Mon Sep 17 00:00:00 2001 From: Kum1ta Date: Wed, 28 Aug 2024 17:30:46 +0200 Subject: [PATCH] Game - Starting solo game --- site/real_game/class/SoloGame.js | 33 ++++--- site/real_game/class/soloClass/Ball.js | 105 ++++++++++++++++++++++ site/real_game/class/soloClass/Map.js | 48 ++++++++-- site/real_game/class/soloClass/Players.js | 95 ++++++++++++++++++++ site/real_game/main.js | 2 +- 5 files changed, 265 insertions(+), 18 deletions(-) create mode 100644 site/real_game/class/soloClass/Ball.js create mode 100644 site/real_game/class/soloClass/Players.js diff --git a/site/real_game/class/SoloGame.js b/site/real_game/class/SoloGame.js index 1790500..d6730a3 100644 --- a/site/real_game/class/SoloGame.js +++ b/site/real_game/class/SoloGame.js @@ -6,18 +6,23 @@ /* By: edbernar 0) + { + console.log("Distance du rayon à l'objet : ", intersects[0].distance); + if (intersects[0].distance <= 0.5) + { + ball.rotation.y = Math.PI - ball.rotation.y + } + } +} + +function bounceWallTBottom() +{ + const origin = new THREE.Vector3(ball.position.x, ball.position.y, ball.position.z); + const direction = new THREE.Vector3(ball.position.x, ball.position.y, ball.position.z + 1); + + direction.normalize(); + const raycaster = new THREE.Raycaster(origin, direction); + const objects = [ wallBottom ]; + const intersects = raycaster.intersectObjects(objects); + + if (intersects.length > 0) + { + console.log("Distance du rayon à l'objet : ", intersects[0].distance); + if (intersects[0].distance <= 0.5) + { + ball.rotation.y = Math.PI - ball.rotation.y; + } + } +} + +export { Ball }; \ No newline at end of file diff --git a/site/real_game/class/soloClass/Map.js b/site/real_game/class/soloClass/Map.js index 2679a30..0e221c8 100644 --- a/site/real_game/class/soloClass/Map.js +++ b/site/real_game/class/soloClass/Map.js @@ -6,32 +6,66 @@ /* By: edbernar -5.05) + player1.position.z -= speed; + else if (pressedButton[i] == 's' && player1.position.z < 5.05) + player1.position.z += speed; + else if (pressedButton[i] == 'ArrowUp' && player2.position.z > -5.05) + player2.position.z -= speed; + else if (pressedButton[i] == 'ArrowDown' && player2.position.z < 5.05) + player2.position.z += speed; + i++; + } + } +} + +function newBarPlayer(nbPlayer) +{ + const geometry = new THREE.BoxGeometry(0.1, 0.2, 2); + const material = new THREE.MeshPhysicalMaterial({color: 0xffffff}); + const mesh = new THREE.Mesh(geometry, material); + + if (nbPlayer == 1) + mesh.position.set(-12, 0.2, 0); + else + mesh.position.set(12, 0.2, 0); + return (mesh); +} + +function addKeyInArr(e) +{ + let i; + + i = 0; + while (i < pressedButton.length && e.key != pressedButton[i]) + i++; + if (i == pressedButton.length) + pressedButton.push(e.key); +} + +function remKeyInArr(e) +{ + let i; + + i = 0; + while (i < pressedButton.length && e.key != pressedButton[i]) + i++; + if (i != pressedButton.length) + pressedButton.splice(i, 1); +} + +export { Players }; \ No newline at end of file diff --git a/site/real_game/main.js b/site/real_game/main.js index ec7a0ec..878b993 100644 --- a/site/real_game/main.js +++ b/site/real_game/main.js @@ -6,7 +6,7 @@ /* By: edbernar