Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 4 additions & 33 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
updateCoinRotation,
updateSceneColors,
updateMovingWalls,
updateChunks,
} from './renderer.js';

import { initTracker, calibrate, detectTilt, detectPitch, detectMouthOpen, resetTilt } from './tracker.js';
Expand Down Expand Up @@ -57,7 +58,6 @@ let score = 0;
let finalScore = 0;
let currentLevel = 1;
let gameStartTime = 0;
let finishTime = 0;

function updateScore(value) {
score = value;
Expand Down Expand Up @@ -140,32 +140,6 @@ function renderLeaderboard() {
function showLeaderboard() { renderLeaderboard(); leaderboardPanel.classList.add('visible'); }
function hideLeaderboard() { leaderboardPanel.classList.remove('visible'); }

// --- Finish state ---

function enterFinished(timestamp) {
finishTime = ((timestamp - gameStartTime) / 1000).toFixed(1);
finalScore = score;
state = 'finished';

gameoverTitle.textContent = 'FINISHED!';
gameoverScore.textContent = 'Score: ' + finalScore + ' | Time: ' + finishTime + 's';

if (scoreQualifies(finalScore)) {
gameoverMessage.textContent = 'New high score!';
nameEntry.classList.add('visible');
nameInput.value = '';
nameInput.focus();
} else {
gameoverMessage.textContent = 'Great run!';
nameEntry.classList.remove('visible');
resetTimer = setTimeout(() => { exitGameOver(); }, NON_QUALIFYING_DELAY);
}

levelEl.style.display = 'none';
timerEl.style.display = 'none';
gameoverOverlay.classList.add('visible');
}

// --- Game over flow ---

function enterGameOver() {
Expand Down Expand Up @@ -303,6 +277,8 @@ function gameLoop(timestamp) {
if (state === 'playing') {
updateLevel(result.distance);
updateTimer(timestamp);
// Generate new track chunks and cull old ones
updateChunks(result.distance);
}

updateBallPosition(result.x, result.y, result.z);
Expand All @@ -326,12 +302,7 @@ function gameLoop(timestamp) {
if (result.boostActive) { boostIndicator.classList.add('visible'); }
else { boostIndicator.classList.remove('visible'); }

// Handle finish
if (result.finished && state === 'playing') {
enterFinished(timestamp);
}

// Handle falling
// Handle falling — game over only when ball falls off track
if (result.falling && state === 'playing') { state = 'falling'; }
if (result.needsReset && state === 'falling') { enterGameOver(); }
}
Expand Down
11 changes: 0 additions & 11 deletions js/physics.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
TRACK_HEIGHT,
BALL_RADIUS,
BALL_START_DISTANCE,
FINISH_LINE_DISTANCE,
getPointAtDistance,
getTangentAtDistance,
getRightAtDistance,
Expand Down Expand Up @@ -108,11 +107,6 @@ function updateOnTrack(dt, tiltAngle, pitch, mouthOpen) {
ball.distance += ball.vForward * dt;
ball.lateral += ball.vLateral * dt;

// Clamp distance to track length
if (ball.distance > getTrackLength()) {
ball.distance = getTrackLength();
}

// Compute world position from track coordinates
const centerPoint = getPointAtDistance(ball.distance);
const right = getRightAtDistance(ball.distance);
Expand Down Expand Up @@ -173,9 +167,6 @@ function updateOnTrack(dt, tiltAngle, pitch, mouthOpen) {
}
}

// Check finish line
const finished = ball.distance >= trackConfig.finishLineDistance;

return {
x: ball.worldX,
y: ball.worldY,
Expand All @@ -185,7 +176,6 @@ function updateOnTrack(dt, tiltAngle, pitch, mouthOpen) {
vz: ball.vForward,
falling: ball.falling,
needsReset: false,
finished,
obstacleHit,
coinsCollected: newlyCollected,
turtleCollected: turtleJustCollected,
Expand Down Expand Up @@ -215,7 +205,6 @@ function updateFalling(dt) {
vz: ball.vForward,
falling: true,
needsReset,
finished: false,
obstacleHit: false,
coinsCollected: [],
turtleCollected: null,
Expand Down
Loading
Loading