/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* multiOnlineGamePage.js :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: edbernar { if (e.key == 'g') player.pointAnimation(map); if (e.key == 'h') player.pointOpponentAnimation(map, opponent.object); 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); }) 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() { player.update(); opponent.update(); ball.update(); map.update(ball); renderer.render(scene, player.camera); } export { MultiOnlineGamePage, opponent, ball };