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