From 24704b849314842396d8ecbe7fc8ff1ffd9177ed Mon Sep 17 00:00:00 2001 From: Kum1ta Date: Thu, 29 Aug 2024 00:45:13 +0200 Subject: [PATCH] Gane - Continuing solo game --- site/real_game/class/SoloGame.js | 13 ++-- site/real_game/class/soloClass/Ball.js | 70 +++++++++++++------ site/real_game/class/soloClass/Players.js | 23 +++--- .../node_modules/.vite/deps/_metadata.json | 30 ++++---- .../deps/three_examples_jsm_Addons__js.js | 6 +- 5 files changed, 86 insertions(+), 56 deletions(-) diff --git a/site/real_game/class/SoloGame.js b/site/real_game/class/SoloGame.js index d6730a3..a61d1e2 100644 --- a/site/real_game/class/SoloGame.js +++ b/site/real_game/class/SoloGame.js @@ -6,7 +6,7 @@ /* By: edbernar { + Ball.moveBall(); + }, 1000); } static dispose() @@ -75,7 +79,6 @@ function loop() stats.begin(); controls.update(); Players.update(); - Ball.update(); renderer.render(scene, camera); stats.end(); } diff --git a/site/real_game/class/soloClass/Ball.js b/site/real_game/class/soloClass/Ball.js index ab0982a..5bab16d 100644 --- a/site/real_game/class/soloClass/Ball.js +++ b/site/real_game/class/soloClass/Ball.js @@ -6,17 +6,18 @@ /* By: edbernar { + console.log(ball.position); + moveForward(); + bounceWallTop(); + bounceWallTBottom(); + bouncePlayer1(); + }, 16); +} + +function moveForward() { const direction = new THREE.Vector3(0, 0, dir); - direction.applyQuaternion(object.quaternion); - object.position.add(direction.multiplyScalar(speed)); + direction.applyQuaternion(ball.quaternion); + + ball.position.add(direction.multiplyScalar(speed)); } function createBall() @@ -57,7 +75,8 @@ function createBall() const mesh = new THREE.Mesh(geometry, material); mesh.position.y += 0.3; - + mesh.castShadow = true; + mesh.receiveShadow = true; mesh.position.set (0, mesh.position.y, 0); return (mesh); } @@ -74,11 +93,8 @@ function bounceWallTop() 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 - } } } @@ -94,11 +110,25 @@ function bounceWallTBottom() if (intersects.length > 0) { - console.log("Distance du rayon à l'objet : ", intersects[0].distance); - if (intersects[0].distance <= 0.5) - { + if (intersects[0].distance <= 0.4) + ball.rotation.y = Math.PI - ball.rotation.y; + } +} + +function bouncePlayer1() +{ + const origin = new THREE.Vector3(ball.position.x, ball.position.y, ball.position.z); + const direction = new THREE.Vector3(ball.position.x - 1, ball.position.y, ball.position.z); + + direction.normalize(); + const raycaster = new THREE.Raycaster(origin, direction); + const objects = [ player1 ]; + const intersects = raycaster.intersectObjects(objects); + + if (intersects.length > 0) + { + if (intersects[0].distance <= 0.4) ball.rotation.y = Math.PI - ball.rotation.y; - } } } diff --git a/site/real_game/class/soloClass/Players.js b/site/real_game/class/soloClass/Players.js index 63f7ac2..7ed5177 100644 --- a/site/real_game/class/soloClass/Players.js +++ b/site/real_game/class/soloClass/Players.js @@ -6,7 +6,7 @@ /* By: edbernar -5.05) + if (pressedButton[i] == 'w' && player1.position.z > -limits) player1.position.z -= speed; - else if (pressedButton[i] == 's' && player1.position.z < 5.05) + else if (pressedButton[i] == 's' && player1.position.z < limits) player1.position.z += speed; - else if (pressedButton[i] == 'ArrowUp' && player2.position.z > -5.05) + else if (pressedButton[i] == 'ArrowUp' && player2.position.z > -limits) player2.position.z -= speed; - else if (pressedButton[i] == 'ArrowDown' && player2.position.z < 5.05) + else if (pressedButton[i] == 'ArrowDown' && player2.position.z < limits) player2.position.z += speed; i++; } @@ -59,14 +60,16 @@ class Players function newBarPlayer(nbPlayer) { - const geometry = new THREE.BoxGeometry(0.1, 0.2, 2); + const geometry = new THREE.BoxGeometry(0.3, 0.4, 2.5); const material = new THREE.MeshPhysicalMaterial({color: 0xffffff}); const mesh = new THREE.Mesh(geometry, material); + mesh.castShadow = true; + mesh.receiveShadow = true; if (nbPlayer == 1) - mesh.position.set(-12, 0.2, 0); + mesh.position.set(-12, 0.4, 0); else - mesh.position.set(12, 0.2, 0); + mesh.position.set(12, 0.4, 0); return (mesh); } @@ -92,4 +95,4 @@ function remKeyInArr(e) pressedButton.splice(i, 1); } -export { Players }; \ No newline at end of file +export { Players, player1, player2 }; \ No newline at end of file diff --git a/site/real_game/node_modules/.vite/deps/_metadata.json b/site/real_game/node_modules/.vite/deps/_metadata.json index d0946df..dba50ea 100644 --- a/site/real_game/node_modules/.vite/deps/_metadata.json +++ b/site/real_game/node_modules/.vite/deps/_metadata.json @@ -1,53 +1,47 @@ { - "hash": "7e76cfec", - "configHash": "5fafa2f5", + "hash": "aeb97021", + "configHash": "0b4c6e74", "lockfileHash": "cd36b699", - "browserHash": "93d0ec79", + "browserHash": "19562a0a", "optimized": { "stats.js": { "src": "../../stats.js/build/stats.min.js", "file": "stats__js.js", - "fileHash": "05a619eb", + "fileHash": "02cf6dab", "needsInterop": true }, "three": { "src": "../../three/build/three.module.js", "file": "three.js", - "fileHash": "de5334d8", + "fileHash": "b84c2f0c", "needsInterop": false }, "three/addons/loaders/GLTFLoader.js": { "src": "../../three/examples/jsm/loaders/GLTFLoader.js", "file": "three_addons_loaders_GLTFLoader__js.js", - "fileHash": "748f8d46", + "fileHash": "c571cff0", "needsInterop": false }, "three/examples/jsm/Addons.js": { "src": "../../three/examples/jsm/Addons.js", "file": "three_examples_jsm_Addons__js.js", - "fileHash": "61a49f6c", - "needsInterop": false - }, - "three": { - "src": "../../three/build/three.module.js", - "file": "three.js", - "fileHash": "9f980d32", + "fileHash": "b1ac92b5", "needsInterop": false }, "three/examples/jsm/controls/OrbitControls.js": { "src": "../../three/examples/jsm/controls/OrbitControls.js", "file": "three_examples_jsm_controls_OrbitControls__js.js", - "fileHash": "7f2e8493", + "fileHash": "470fb7a7", "needsInterop": false } }, "chunks": { - "chunk-X4PC2K6Q": { - "file": "chunk-X4PC2K6Q.js" - }, "chunk-PJQOQ23Z": { "file": "chunk-PJQOQ23Z.js" }, + "chunk-X4PC2K6Q": { + "file": "chunk-X4PC2K6Q.js" + }, "chunk-IS2ZBFBB": { "file": "chunk-IS2ZBFBB.js" }, @@ -55,4 +49,4 @@ "file": "chunk-HKJ2B2AA.js" } } -} +} \ No newline at end of file diff --git a/site/real_game/node_modules/.vite/deps/three_examples_jsm_Addons__js.js b/site/real_game/node_modules/.vite/deps/three_examples_jsm_Addons__js.js index 79ac639..9ca9dd9 100644 --- a/site/real_game/node_modules/.vite/deps/three_examples_jsm_Addons__js.js +++ b/site/real_game/node_modules/.vite/deps/three_examples_jsm_Addons__js.js @@ -1,6 +1,3 @@ -import { - OrbitControls -} from "./chunk-X4PC2K6Q.js"; import { BufferGeometryUtils_exports, GLTFLoader, @@ -9,6 +6,9 @@ import { mergeGroups, mergeVertices } from "./chunk-PJQOQ23Z.js"; +import { + OrbitControls +} from "./chunk-X4PC2K6Q.js"; import { ACESFilmicToneMapping, AddEquation,