/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* multiOnlineGamePage.js :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: edbernar { if (e.key == 'g') { player.pointAnimation(map); map.handleAnimation(ball, player.playerGoalAnimation); // map.animationGoal1(0, 0.30, 6.3); // Le serv envoie la position de la balle pour faire l'explosion la ou il y a but } if (e.key == 'h') { player.pointOpponentAnimation(map, opponent.object); map.handleAnimation(ball, opponent.playerGoalAnimation); // map.animationGoal1(0, 0.30, -6.3); } if (e.key == 'c') debug = !debug; if (e.key == 'p') map.putVideoOnCanvas(0, null); if (e.key == 'o') { map.putVideoOnCanvas(3, 'goal'); } if (e.key == 'i') map.putVideoOnCanvas(3, 'outstanding'); if (e.key == 'u') map.putVideoOnCanvas(3, 3); if (e.key == 'y') map.putVideoOnCanvas(2, 3); if (e.key == 't') map.putVideoOnCanvas(1, 3); if (e.key == 'l') map.reCreate("player"); if (e.key == 'k') map.reCreate("opponent"); }) renderer.setAnimationLoop(loop) sendRequest('game', {action: 1}); let lastPosition = player.object.position.x; let lastUp = player.isUp; interval = setInterval(() => { if (player && player.object.position.x != lastPosition || player.isUp != lastUp) { lastPosition = player.object.position.x; lastUp = player.isUp; sendRequest('game', {action: 3, pos: player.object.position.x, up: player.isUp}); } }, 1000 / 20); } static dispose() { if (interval) clearInterval(interval); interval = null; if (renderer) renderer.dispose(); renderer = null; if (map) map.dispose(); map = null; if (ball) ball.dispose(); ball = null; if (player) player.dispose(); player = null; if (opponent) opponent.dispose(); opponent = null; if (scene) { scene.children.forEach(child => { if (child.geometry) child.geometry.dispose(); if (child.material) child.material.dispose(); if (child.texture) child.texture.dispose(); scene.remove(child); }); } scene = null; } static opponentDisconnect() { pageRenderer.changePage('lobbyPage'); } } function createBarPlayer(color) { const geometry = new THREE.BoxGeometry(1, 0.1, 0.1); const material = new THREE.MeshPhysicalMaterial({color: color}); const mesh = new THREE.Mesh(geometry, material); mesh.castShadow = true; return (mesh); } function changeBarColor(bar, color) { bar.material.color.set(color); } function loop() { ///////////// stats.begin(); ///////////// player.update(); opponent.update(); ball.update(); map.update(ball); if (debug) { controls.update(); renderer.render(scene, cameraTmp); } else renderer.render(scene, player.camera); ///////////// stats.end(); //////////// } export { MultiOnlineGamePage, player, opponent, ball, map};