diff --git a/site/real_game/class/Map.js b/site/real_game/class/Map.js index f16c756..44bd5cb 100644 --- a/site/real_game/class/Map.js +++ b/site/real_game/class/Map.js @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* Map.js :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: edbernar +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/08/20 14:52:55 by hubourge #+# #+# */ -/* Updated: 2024/08/21 14:56:10 by edbernar ### ########.fr */ +/* Updated: 2024/08/21 17:03:56 by hubourge ### ########.fr */ /* */ /* ************************************************************************** */ @@ -43,14 +43,15 @@ class Map constructor(scene, length) { this.scene = scene; - scene.add(this.#createPlanes(7.5, length, -(Math.PI / 2), "planeBottom", true, 0xaaffff)); - scene.add(this.#createPlanes(7.5, length, (Math.PI / 2), "planeTop", false, '/textures/testTmp.jpg')); - scene.add(this.#createWall(-3.5, 0.4, -length/2, "wallLeft")); - scene.add(this.#createWall(3.5, 0.4, -length/2, "wallRight")); this.centerPos.x = 0; this.centerPos.y = 0.15; this.centerPos.z = -length / 2 + length / 2; this.mapLength = length; + scene.add(this.#createPlanes(7.5, length, -(Math.PI / 2), "planeBottom", true, 0xaaffff)); + scene.add(this.#createPlanes(7.5, length, (Math.PI / 2), "planeTop", false, '/textures/testTmp.jpg')); + scene.add(this.#createWall(-3.5, 0.4, -length/2, "wallLeft")); + scene.add(this.#createWall(3.5, 0.4, -length/2, "wallRight")); + this.#createGravityChanger(0, 0.2, 4, "gravityChangerGroup1"); }; #createPlanes(x, y, rot, name, isBottom, visual) @@ -97,18 +98,84 @@ class Map const mesh = new THREE.Mesh(geometry, material); mesh.position.set(x, y, z); - mesh.material.transparent = true; - mesh.material.opacity = 0.5; + material.transparent = true; + material.opacity = 0.5; this.arrObject.push({mesh: mesh, name: name}); return (mesh); }; - createGravityChanger(ball, x, z, onTop) + #createGravityChanger(x, y, z, name) { - if (this.ballObject == null) - throw Error("Ball is not init"); + for (let i = 0; i < this.arrObject.length; i++) + { + if (this.arrObject[i].name == name + "1") + throw Error("Name already exist."); + } + const geometry0 = new THREE.CircleGeometry(0.2, 24); + const material0 = new THREE.MeshPhysicalMaterial({color: 0xaaffaa}); + const mesh0 = new THREE.Mesh(geometry0, material0); + mesh0.rotateX(-Math.PI / 2); + mesh0.position.set(x, y - 0.048, z); - } + const geometry = new THREE.CircleGeometry(0.24, 24); + const material = new THREE.MeshPhysicalMaterial({color: 0x00ff00}); + const mesh = new THREE.Mesh(geometry, material); + mesh.rotateX(-Math.PI / 2); + mesh.position.set(x, y - 0.049, z); + + const geometry1 = new THREE.TorusGeometry(1, 0.1, 12, 24); + const material1 = new THREE.MeshPhysicalMaterial({color: 0x00ff00}); + const mesh1 = new THREE.Mesh(geometry1, material1); + mesh1.rotateX(-Math.PI / 2); + mesh1.position.set(x, y, z); + mesh1.scale.set(0.2, 0.2, 0.2); + material1.transparent = true; + material1.opacity = 0.75; + + const geometry2 = new THREE.TorusGeometry(1, 0.1, 12, 24); + const material2 = new THREE.MeshPhysicalMaterial({color: 0x00ff00}); + const mesh2 = new THREE.Mesh(geometry2, material2); + mesh2.rotateX(-Math.PI / 2); + mesh2.position.set(x, y + 0.1, z); + mesh2.scale.set(0.18, 0.18, 0.18); + material2.transparent = true; + material2.opacity = 0.65; + + const geometry3 = new THREE.TorusGeometry(1, 0.1, 12, 24); + const material3 = new THREE.MeshPhysicalMaterial({color: 0x00ff00}); + const mesh3 = new THREE.Mesh(geometry3, material3); + mesh3.rotateX(-Math.PI / 2); + mesh3.position.set(x, y + 0.2, z); + mesh3.scale.set(0.16, 0.16, 0.16); + material3.transparent = true; + material3.opacity = 0.35; + + // collider + const geometry4 = new THREE.CylinderGeometry(0.15, 0.15, 0.5); + const material4 = new THREE.MeshPhysicalMaterial({color: 0x00ff00}); + const mesh4 = new THREE.Mesh(geometry4, material4); + mesh4.position.set(x, y + 0.2, z); + material4.transparent = true; + material4.opacity = 0.1; + + const group = new THREE.Group(); + group.add(mesh0); + group.add(mesh); + group.add(mesh1); + group.add(mesh2); + group.add(mesh3); + group.add(mesh4); + this.arrObject.push({mesh: group, name: name}); + + this.scene.add(group); + }; + + // createGravityChanger(ball, x, z, onTop) + // { + // if (this.ballObject == null) + // throw Error("Ball is not init"); + + // } update(ball) { @@ -136,14 +203,24 @@ class Map this.arrObject[i].mesh.material.opacity = 1 - (diff / 2); } if (this.arrObject[i].name == "wallRight") + { + let diff = this.arrObject[i].mesh.position.x - ball.position.x - 0.1; + + if (diff > 2) + this.arrObject[i].mesh.material.opacity = 0; + else + this.arrObject[i].mesh.material.opacity = 1 - (diff / 2); + } + if (this.arrObject[i].name == "gravityChangerGroup1") + { + for (let j = 2; j < this.arrObject[i].mesh.children.length - 1; j++) { - let diff = this.arrObject[i].mesh.position.x - ball.position.x - 0.1; - - if (diff > 2) - this.arrObject[i].mesh.material.opacity = 0; - else - this.arrObject[i].mesh.material.opacity = 1 - (diff / 2); + + this.arrObject[i].mesh.children[j].rotation.x = Math.sin(Date.now() * 0.001 + (j - 2) * 5) * 0.1 + Math.PI / 2; + this.arrObject[i].mesh.children[j].rotation.y = Math.sin(Date.now() * 0.001 + (j - 2) * 5) * 0.1 + Math.cos(Date.now() * 0.001) * 0.1;; + this.arrObject[i].mesh.children[j].position.y = Math.sin(Date.now() * 0.001 + (j - 2) * 5) * 0.03 + ( 0.25 * (j - 2) / 2) + 0.25; } + } } }; }; diff --git a/site/real_game/class/Player.js b/site/real_game/class/Player.js index 9e54500..20afd84 100644 --- a/site/real_game/class/Player.js +++ b/site/real_game/class/Player.js @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* Player.js :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: edbernar +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/08/18 00:30:31 by edbernar #+# #+# */ -/* Updated: 2024/08/21 14:42:20 by edbernar ### ########.fr */ +/* Updated: 2024/08/21 16:54:36 by hubourge ### ########.fr */ /* */ /* ************************************************************************** */ @@ -64,7 +64,7 @@ class Player this.object = object; this.limits = map.playerLimits; this.camera = new THREE.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 0.1, 10000); - this.object.position.set(0, 0.32, map.mapLength / 2 - 0.2); + this.object.position.set(0, this.limits.down, map.mapLength / 2 - 0.2); this.setCameraPosition( this.object.position.x, this.object.position.y + 0.7, @@ -251,6 +251,7 @@ class Player { clearInterval(this.interval); this.interval = null; + this.object.position.y = this.limits.down; } }, 5); } diff --git a/site/real_game/main.js b/site/real_game/main.js index 9ee3742..11bc50b 100644 --- a/site/real_game/main.js +++ b/site/real_game/main.js @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* main.js :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: edbernar +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/08/18 00:53:53 by edbernar #+# #+# */ -/* Updated: 2024/08/21 14:51:31 by edbernar ### ########.fr */ +/* Updated: 2024/08/21 16:39:17 by hubourge ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,25 @@ import { Ball } from './class/Ball' import { Opponent } from './class/Opponent' import { OrbitControls } from 'three/examples/jsm/Addons.js'; -let debug = false; +/* +Controls : + - w : monter + - s : descendre + - a : gauche + - d : droite + + - g : animation de point + - h : animation de point pour l'adversaire + - c : switch entre la vue du joueur et la vue de la caméra + + - 8 : avance la balle + - 2 : recule la balle + - 4 : balle vers la gauche + - 6 : balle vers ladroite + - 9 : inversion gravite +*/ + +let debug = true; function createBarPlayer(color) { @@ -72,14 +90,14 @@ ball.initMoveBallTmp(); map.ballObject = ball.object; // map.addDecor('blender/exported/map1.glb') -map.createGravityChanger(1, 1, false); +// map.createGravityChanger(1, 1, false); /*---------------DEBUG----------------*/ const cameraTmp = new THREE.PerspectiveCamera(90, window.innerWidth / window.innerHeight); const controls = new OrbitControls(cameraTmp, renderer.domElement); -cameraTmp.position.set(15, 0, 15); +cameraTmp.position.set(5, 3, 5); controls.target = new THREE.Vector3(map.centerPos.x, 0, map.centerPos.z); /*------------------------------------*/ diff --git a/site/real_game/node_modules/.vite/deps/_metadata.json b/site/real_game/node_modules/.vite/deps/_metadata.json index 6675190..ccd4dee 100644 --- a/site/real_game/node_modules/.vite/deps/_metadata.json +++ b/site/real_game/node_modules/.vite/deps/_metadata.json @@ -1,25 +1,25 @@ { - "hash": "b5ed7c4e", - "configHash": "4027b9ee", + "hash": "fba7eca6", + "configHash": "345fb419", "lockfileHash": "cd36b699", - "browserHash": "02ec5995", + "browserHash": "e2576fb7", "optimized": { "three": { "src": "../../three/build/three.module.js", "file": "three.js", - "fileHash": "b8c4b79b", - "needsInterop": false - }, - "three/addons/loaders/GLTFLoader.js": { - "src": "../../three/examples/jsm/loaders/GLTFLoader.js", - "file": "three_addons_loaders_GLTFLoader__js.js", - "fileHash": "605336b1", + "fileHash": "692a1237", "needsInterop": false }, "three/examples/jsm/Addons.js": { "src": "../../three/examples/jsm/Addons.js", "file": "three_examples_jsm_Addons__js.js", - "fileHash": "cc6bff05", + "fileHash": "f47f44f4", + "needsInterop": false + }, + "three/addons/loaders/GLTFLoader.js": { + "src": "../../three/examples/jsm/loaders/GLTFLoader.js", + "file": "three_addons_loaders_GLTFLoader__js.js", + "fileHash": "23466596", "needsInterop": false } },