mirror of
https://gitlab.com/arnekeller/tunnel-racer.git
synced 2024-11-08 16:50:38 +00:00
Random large spheres
This commit is contained in:
parent
608942c365
commit
32c91a6ecd
24
game.js
24
game.js
@ -81,6 +81,8 @@ const vertexShader = `
|
||||
`;
|
||||
|
||||
const diameterOfTunnel = 100;
|
||||
const spawnInterval = 40;
|
||||
let lastSpawned = 0;
|
||||
|
||||
var gn;
|
||||
var headSet = false;
|
||||
@ -193,7 +195,7 @@ init_gn();
|
||||
|
||||
import * as THREE from './three.module.js';
|
||||
let scene, renderer;
|
||||
const camera = new THREE.PerspectiveCamera(70, window.innerWidth / window.innerHeight, 0.1, 1000);
|
||||
const camera = new THREE.PerspectiveCamera(70, window.innerWidth / window.innerHeight, 0.1, 10000);
|
||||
|
||||
const geometrySphere = new THREE.SphereGeometry(11, 32, 32);
|
||||
const materialCube = new THREE.MeshBasicMaterial();
|
||||
@ -318,7 +320,7 @@ function animate() {
|
||||
if (running) {
|
||||
|
||||
for (let i = 0; i < cubes.length; i++) {
|
||||
if (cubes[i].geometry.parameters.radius !== geometrySphere.parameters.radius) {
|
||||
if (cubes[i].material !== materialCube) {
|
||||
continue;
|
||||
}
|
||||
let x1 = cubes[i].position.x;
|
||||
@ -333,7 +335,7 @@ function animate() {
|
||||
z2 = Math.max(z1, z2 - speed);
|
||||
}
|
||||
let dist_squared = (x1 - x2) ** 2 + (y1 - y2) ** 2 + (z1 - z2) ** 2;
|
||||
if (dist_squared <= cubes[i].geometry.parameters.radius ** 2) {
|
||||
if (dist_squared <= (cubes[i].geometry.parameters.radius * cubes[i].scale.x) ** 2) {
|
||||
gameOver();
|
||||
break;
|
||||
}
|
||||
@ -344,14 +346,20 @@ function animate() {
|
||||
camera.position.x += 0.1 * leftRightMove;
|
||||
camera.position.y += 0.1 * upDownMove;
|
||||
|
||||
if (Math.random() < 0.09) {
|
||||
while (camera.position.z < lastSpawned - spawnInterval) {
|
||||
lastSpawned -= spawnInterval;
|
||||
|
||||
// randomly spawn large spheres
|
||||
let scale = Math.random() < 0.1 ? 5.0 : 1.0;
|
||||
|
||||
const meshCube = new THREE.Mesh(geometrySphere, materialCube);
|
||||
meshCube.position.z = camera.position.z - 930;
|
||||
meshCube.position.z = camera.position.z - speed * 210;
|
||||
meshCube.position.x = (2 * Math.random() - 1.0) * diameterOfTunnel;
|
||||
meshCube.position.y = (2 * Math.random() - 1.0) * 0.9 * diameterOfTunnel;
|
||||
meshCube.scale.multiplyScalar(scale);
|
||||
|
||||
const outlineMesh = new THREE.Mesh(geometrySphere, customMaterial);
|
||||
outlineMesh.scale.multiplyScalar(1.17);
|
||||
outlineMesh.scale.multiplyScalar(scale * 1.17);
|
||||
outlineMesh.position.z = meshCube.position.z;
|
||||
outlineMesh.position.x = meshCube.position.x;
|
||||
outlineMesh.position.y = meshCube.position.y;
|
||||
@ -368,7 +376,7 @@ function animate() {
|
||||
|
||||
|
||||
for (let i = 0; i < cubes.length; i++) {
|
||||
if (cubes[i].position.z > camera.position.z + cubes[i].geometry.parameters.radius) {
|
||||
if (cubes[i].position.z > camera.position.z + cubes[i].geometry.parameters.radius * cubes[i].scale.x) {
|
||||
scene.remove(cubes[i]);
|
||||
cubes.splice(i, 1);
|
||||
i--;
|
||||
@ -380,7 +388,7 @@ function animate() {
|
||||
removed = removed % 2;
|
||||
document.getElementById("score").innerText = score;
|
||||
}
|
||||
if (borders.length == 0 || borders[borders.length - 1].position.z - camera.position.z > -600) {
|
||||
if (borders.length == 0 || borders[borders.length - 1].position.z - camera.position.z > -1200) {
|
||||
const newZ = borders.length == 0 ? -200 : borders[borders.length - 1].position.z - diameterOfTunnel * 2;
|
||||
|
||||
let border = new THREE.Mesh(borderGeometry, material);
|
||||
|
Loading…
Reference in New Issue
Block a user