/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* Map.js :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: edbernar 0.3) break; if (Math.random() > 0.5) vec3.z -= 0.1; if (Math.random() < 0.5) vec3.z += 0.1; break; } }); ground.position.copy(groundBody.position); ground.quaternion.copy(groundBody.quaternion); wallBottom.position.copy(wallBottomBody.position); wallBottom.quaternion.copy(wallBottomBody.quaternion); wallTop.position.copy(wallTopBody.position); wallTop.quaternion.copy(wallTopBody.quaternion); speed = 3; if (Math.random() > 0.5) { vec3.x = -3; vec3.y = 0; vec3.z = Math.random() * 10 % 4 - 2; } else { vec3.x = 3; vec3.y = 0; vec3.z = Math.random() * 10 % 4 - 2; } initialZ = vec3.z; ballBody.velocity.set(vec3.x, vec3.y, vec3.z); } static dispose() { if (spotLight) spotLight.dispose(); spotLight = null; } static update() { if (onUpdate) return ; world.step(timeStep); if (ballBody.position.x > 20) return (Map.reCreate(false)); if (ballBody.position.x < -20) return (Map.reCreate(true)); ball.position.copy(ballBody.position); player1Body.position.copy(player1.position); player2Body.position.copy(player2.position); if (speed < 10) speed += 0.003; ballBody.velocity.set(vec3.x * speed, vec3.y * speed, vec3.z * speed); } static reCreate(dirLeft) { onUpdate = true; document.getElementsByTagName('canvas')[3].style.animation = 'fadeIn 0.199s'; document.getElementsByTagName('canvas')[3].style.filter = 'brightness(0)'; scoreElement.style.animation = 'fadeInText 0.199s'; scoreElement.style.color = 'rgb(255, 255, 255, 1)'; setTimeout(() => { if (dirLeft) score.player2++; else score.player1++; scoreElement.innerHTML = score.player1 + '-' +score.player2; }, 300); setTimeout(() => { speed = 3; if (dirLeft) { vec3.x = -3; vec3.y = 0; vec3.z = Math.random() * 10 % 4 - 2; } else { vec3.x = 3; vec3.y = 0; vec3.z = Math.random() * 10 % 4 - 2; } initialZ = vec3.z; onUpdate = false; }, 1500); setTimeout(() => { ballBody.velocity.set(0,0,0); ballBody.position.set(0, 0.15, 0); ball.position.copy(ballBody.position); player1Body.position.set(-12, 0.4, 0); player1.position.copy(player1Body.position); player2Body.position.set(12, 0.4, 0); player2.position.copy(player2Body.position); scoreElement.style.animation = 'fadeOut 0.199s'; document.getElementsByTagName('canvas')[3].style.filter = 'brightness(1)'; scoreElement.style.animation = 'fadeOutText 0.399s'; scoreElement.style.color = 'rgb(255, 255, 255, 0.1)'; }, 1000); } } function createGround(scene) { const geometry = new THREE.PlaneGeometry(width, height); const material = new THREE.MeshPhysicalMaterial({color: 0x222222}); const mesh = new THREE.Mesh(geometry, material); mesh.rotateX(-Math.PI / 2); mesh.position.set(0, 0, 0); scene.add(mesh); return (mesh); } function createWall(onTop) { const geometry = new THREE.BoxGeometry(width, 0.7, 0.2); const material = new THREE.MeshPhysicalMaterial({color: 0x333333}); const mesh = new THREE.Mesh(geometry, material); return (mesh); } export { Map, wallBottom, wallTop };