From 773d9966271938692fe9f4e3b32d88b7055e01f7 Mon Sep 17 00:00:00 2001 From: Kum1ta Date: Thu, 29 Aug 2024 18:43:23 +0200 Subject: [PATCH] Game - Starting solo game with physics --- site/real_game/class/SoloGame.js | 11 ++-- site/real_game/class/soloClass/Ball.js | 87 ++------------------------ site/real_game/class/soloClass/Map.js | 77 +++++++++++++++++++---- site/real_game/package-lock.json | 43 +++++++++++++ site/real_game/package.json | 4 ++ 5 files changed, 121 insertions(+), 101 deletions(-) diff --git a/site/real_game/class/SoloGame.js b/site/real_game/class/SoloGame.js index a61d1e2..377c2df 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() @@ -78,6 +75,8 @@ function loop() { stats.begin(); controls.update(); + Ball.update(); + Map.update(); Players.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 5bab16d..a5de6ff 100644 --- a/site/real_game/class/soloClass/Ball.js +++ b/site/real_game/class/soloClass/Ball.js @@ -6,7 +6,7 @@ /* By: edbernar { - console.log(ball.position); - moveForward(); - bounceWallTop(); - bounceWallTBottom(); - bouncePlayer1(); - }, 16); -} - -function moveForward() -{ - const direction = new THREE.Vector3(0, 0, dir); - direction.applyQuaternion(ball.quaternion); - - ball.position.add(direction.multiplyScalar(speed)); } function createBall() @@ -81,55 +53,4 @@ function createBall() return (mesh); } -function bounceWallTop() -{ - 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 = [ wallTop ]; - const intersects = raycaster.intersectObjects(objects); - - if (intersects.length > 0) - { - 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) - { - 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; - } -} - -export { Ball }; \ No newline at end of file +export { Ball, 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 0e221c8..dc1aa74 100644 --- a/site/real_game/class/soloClass/Map.js +++ b/site/real_game/class/soloClass/Map.js @@ -6,23 +6,35 @@ /* By: edbernar = 0.4.x" + } + }, "node_modules/esbuild": { "version": "0.21.5", "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.21.5.tgz", @@ -740,6 +758,31 @@ "node": ">=0.10.0" } }, + "node_modules/stats": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/stats/-/stats-1.0.0.tgz", + "integrity": "sha512-YmKiMSrDaYA8Iu8/mPbZQmQLfzUrCstea60zPLkBMjpUveRh89GLipU/7AuMRAAX3aMmnseSuJtkgpPv29VoqA==", + "dependencies": { + "commander": "0.5.2" + }, + "bin": { + "stats": "bin/stats" + }, + "engines": { + "node": ">=0.4.x" + } + }, + "node_modules/stats-js": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/stats-js/-/stats-js-1.0.1.tgz", + "integrity": "sha512-EAwEFghGNv8mlYC4CZzI5kWghsnP8uBKXw6VLRHtXkOk5xySfUKLTqTkjgJFfDluIkf/O7eZwi5MXP50VeTbUg==", + "license": "MIT" + }, + "node_modules/statsjs": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/statsjs/-/statsjs-1.0.7.tgz", + "integrity": "sha512-fch+88pDPk8y4BwFwStMQR52vgJnrTHPtY15UBSkR8QAAjVBkntrFIiuDTRdknoIabfMEF7qaGhOBI+V4RtMkA==" + }, "node_modules/three": { "version": "0.167.1", "resolved": "https://registry.npmjs.org/three/-/three-0.167.1.tgz", diff --git a/site/real_game/package.json b/site/real_game/package.json index fe9ee82..63c0882 100644 --- a/site/real_game/package.json +++ b/site/real_game/package.json @@ -4,7 +4,11 @@ }, "dependencies": { "@rollup/rollup-darwin-arm64": "^4.21.0", + "cannon-es": "^0.20.0", "rollup": "^4.21.0", + "stats": "^1.0.0", + "stats-js": "^1.0.1", + "statsjs": "^1.0.7", "three": "^0.167.1", "vite": "^5.4.1" }