Compare commits

..

No commits in common. "962466a0a3820866552915aa829f5c7922064aab" and "cf646282a0d9a41b0a76f1593b9d6aeb4b57913d" have entirely different histories.

6 changed files with 19 additions and 147 deletions

View File

@ -51,8 +51,6 @@
"bumpImpulse": 190,
"respawnMs": 1600,
"offroadRescueMs": 6000,
"checkpointMissSkip": 2,
"checkpointMissMs": 2500,
"gridSpacing": 46,
"itemBoxRespawnMs": 2200,
"itemBoxRadius": 20,

View File

@ -644,8 +644,6 @@ export default class SuperKartGame extends Phaser.Scene {
return l;
});
this.hudGo = t(GAME_WIDTH / 2, 200, '', 90, '#38b048');
// Missed-checkpoint banner (text driven from the player's cpMissMs timer).
this.hudMiss = t(GAME_WIDTH / 2, GAME_HEIGHT / 2 - 60, '', 76, '#e06c75');
this.countTicked = new Set();
this.hud.add(this.add.text(GAME_WIDTH - 24, 12, 'ESC QUITS', { fontFamily: FONT, fontSize: '16px', color: COLORS.mutedHex }).setOrigin(1, 0));
@ -893,7 +891,7 @@ export default class SuperKartGame extends Phaser.Scene {
else s.setScale(scale);
s.setPosition(p.x, p.y - s.displayHeight * 0.42);
s.setDepth(D.world + Math.max(0, 800 - p.z));
s.setAlpha(kart.invulnMs > 0 || kart.cpMissMs > 0 ? (Math.floor(this.raceState.timeMs / 80) % 2 ? 0.35 : 1) : 1);
s.setAlpha(kart.invulnMs > 0 ? (Math.floor(this.raceState.timeMs / 80) % 2 ? 0.35 : 1) : 1);
if (kart.starMs > 0) s.setTint(starTint(this.raceState.timeMs));
else s.clearTint();
}
@ -923,8 +921,7 @@ export default class SuperKartGame extends Phaser.Scene {
else s.setScale(scale);
const hopH = kart.airborne ? Math.sin((1 - kart.hopMs / this.rules.physics.hopMs) * Math.PI) * 46 : 0;
s.setPosition(GAME_WIDTH / 2, GAME_HEIGHT * 0.75 - hopH);
s.setAlpha(kart.rescueMs > 0 ? 0.25
: kart.invulnMs > 0 || kart.cpMissMs > 0 ? (Math.floor(this.raceState.timeMs / 80) % 2 ? 0.35 : 1) : 1);
s.setAlpha(kart.rescueMs > 0 ? 0.25 : kart.invulnMs > 0 ? (Math.floor(this.raceState.timeMs / 80) % 2 ? 0.35 : 1) : 1);
if (kart.starMs > 0) s.setTint(starTint(this.raceState.timeMs));
else s.clearTint();
}
@ -970,12 +967,6 @@ export default class SuperKartGame extends Phaser.Scene {
});
}
if (this.hudMiss) {
const missing = player.cpMissMs > 0;
this.hudMiss.setText(missing ? 'CHECKPOINT MISSED' : '');
if (missing) this.hudMiss.setAlpha(0.55 + 0.45 * Math.abs(Math.sin(state.timeMs / 140)));
}
if (state.phase !== 'countdown' && this.hudLights) {
if (state.timeMs - COUNTDOWN_MS < 900) {
this.hudLights.forEach((l) => l.setFillStyle(0x38b048));
@ -1072,7 +1063,6 @@ export default class SuperKartGame extends Phaser.Scene {
case 'bump': if (ev.a === pIdx || ev.b === pIdx) playSound(this, SFX.KART_THUMP); break;
case 'coin': if (ev.kart === pIdx) playSound(this, SFX.KART_COIN); break;
case 'lap': if (ev.kart === pIdx) playSound(this, SFX.UI_CHIME); break;
case 'checkpoint-miss': if (ev.kart === pIdx) playSound(this, SFX.KART_HIT); break;
case 'splash': if (ev.kart === pIdx) playSound(this, 'sfx-water-splash'); break;
case 'shatter': playSound(this, SFX.EIGHTBIT_EXPLODE); break;
case 'finish':

View File

@ -123,7 +123,6 @@ function makeKart(index, racer, isPlayer, slot, physics) {
lapStartMs: 0,
bestLapMs: 0,
rescueMs: 0,
cpMissMs: 0, // blink/banner window after a missed-checkpoint correction
stuckMs: 0,
reverseMs: 0,
deepMs: 0,
@ -355,7 +354,7 @@ function nextKartAhead(state, kart) {
function stepKart(state, kart, inputs, dt) {
const { physics, model } = state;
for (const key of ['spinMs', 'squashMs', 'invulnMs', 'boostMs', 'starMs', 'empMs', 'hopCooldown', 'wallHitCooldown', 'cpMissMs']) {
for (const key of ['spinMs', 'squashMs', 'invulnMs', 'boostMs', 'starMs', 'empMs', 'hopCooldown', 'wallHitCooldown']) {
if (kart[key] > 0) kart[key] = Math.max(0, kart[key] - STEP_MS);
}
@ -528,36 +527,12 @@ function stepKart(state, kart, inputs, dt) {
const proj = projectToSplineNear(model, kart.x, kart.y, kart.splineS);
kart.splineS = proj.s;
const L = model.totalLength;
let sRel = ((proj.s - model.startS) % L + L) % L;
const sRel = ((proj.s - model.startS) % L + L) % L;
kart.sRel = sRel;
const cps = model.checkpoints.length;
const cpSize = L / cps;
const cp = Math.floor(sRel / cpSize) % cps;
// How far ahead of the last validated gate we are, going forward round the
// ring. 0 = same gate, 1 = the normal advance. A big forward jump means the
// kart shortcut across geometry and the spline projection snapped branches;
// anything past the halfway mark is the kart *behind* its own cpIndex
// (driving backwards, or sitting on the pre-start grid) and is left alone.
const delta = (cp - kart.cpIndex + cps) % cps;
if (delta >= physics.checkpointMissSkip && delta < cps / 2) {
// Missed checkpoint: stop the player dead and put them back on the last
// gate they legitimately crossed — i.e. just behind the one they skipped —
// instead of leaving the lap chain silently stalled until they guess which
// gate it was and drive backwards to it. cpIndex is deliberately untouched,
// so the next step reads delta 0 and this can't retrigger in a loop; a miss
// straddling the start line still owes the player the line crossing.
if (kart.isPlayer && state.phase === 'racing' && !kart.finished
&& kart.cpMissMs <= 0 && kart.rescueMs <= 0) {
const missed = (kart.cpIndex + 1) % cps;
respawnAtCheckpoint(state, kart);
kart.cpMissMs = physics.checkpointMissMs;
// Re-derive arc-length from the teleported anchor so this frame's
// progress reflects where the kart actually is, not the skipped-to spot.
sRel = ((kart.splineS - model.startS) % L + L) % L;
kart.sRel = sRel;
emit(state, 'checkpoint-miss', { kart: kart.index, checkpoint: missed });
}
} else if (delta === 1) {
if (cp === (kart.cpIndex + 1) % cps) {
kart.cpIndex = cp;
if (cp === 0) {
kart.lap += 1;

View File

@ -20,7 +20,6 @@ const BOARD_LEFT = 744;
const BOARD_TOP = 116;
const STEP_MS = 1000 / 60; // logic tick rate
const POSE_HOLD_MS = 5000; // how long a reaction pose holds before resting
export const D = { bg: -10, boardBg: 0, panels: 5, incoming: 4, cursor: 12, fx: 16, hud: 24, portrait: 20, overlay: 60, overlayUI: 62 };
@ -289,8 +288,8 @@ export default class TetrisAttackGame extends Phaser.Scene {
fontFamily: FONT, fontSize: '34px', color, stroke: '#101018', strokeThickness: 6,
}).setOrigin(0.5).setDepth(D.fx);
this.tweens.add({ targets: t, y: t.y - 70, alpha: 0, duration: 900, ease: 'Cubic.easeOut', onComplete: () => t.destroy() });
// host reacts: player doing well → worried for a beat, then back to rest
this.hostPortrait?.setPose('worried', POSE_HOLD_MS);
// host reacts: player doing well → worried
this.hostPortrait?.setPose('worried');
}
// floating score
if (n && e.score) {
@ -420,7 +419,7 @@ export default class TetrisAttackGame extends Phaser.Scene {
stroke: '#3a2a00', strokeThickness: 9, lineSpacing: 10,
}).setOrigin(0.5).setDepth(D.fx);
this.tweens.add({ targets: banner, scale: { from: 0.4, to: 1 }, duration: 340, ease: 'Back.easeOut' });
this.hostPortrait?.setPose('worried', POSE_HOLD_MS);
this.hostPortrait?.setPose('worried');
this.time.delayedCall(1400, () => {
this.tweens.add({

View File

@ -284,41 +284,22 @@ export function showResult(scene, { title, lines = [], buttons = [], round = nul
// ── Host portrait (in-game HUD) ───────────────────────────────────────────────
export function createHostPortrait(scene, x, y, round, index = scene.roundIndex) {
// half-transparent fill so the stage background reads through the portrait box
const frameBg = scene.add.rectangle(x, y, 300, 380, 0x0e1526, 0.5).setStrokeStyle(5, 0x4a6ea8).setDepth(20);
const frameBg = scene.add.rectangle(x, y, 300, 380, 0x0e1526, 1).setStrokeStyle(5, 0x4a6ea8).setDepth(20);
const img = buildPortraitImage(scene, round, index, 'neutral', x, y, 1.0);
img.setDepth(21);
const apply = (pose) => {
if (scene.textures.exists('tetrisattack-characters')) {
img.setFrame(index * 3 + (POSE_OFFSET[pose] ?? 0));
} else {
// opponents fallback has no poses — pulse instead
const tint = pose === 'happy' ? 0xffd0d0 : pose === 'worried' ? 0xd0ffe0 : 0xffffff;
img.setTint(tint);
scene.tweens.add({ targets: img, scale: img.scaleX * 1.06, duration: 120, yoyo: true });
}
};
// basePose is the pose the host rests in (driven by the danger flag); a held
// pose is a momentary reaction that reverts to it once holdMs elapses.
let basePose = 'neutral';
let holdTimer = null;
const clearHold = () => { if (holdTimer) { holdTimer.remove(false); holdTimer = null; } };
return {
sprite: img,
setPose(pose, holdMs = 0) {
clearHold();
if (holdMs > 0) {
apply(pose);
holdTimer = scene.time.delayedCall(holdMs, () => { holdTimer = null; apply(basePose); });
setPose(pose) {
if (scene.textures.exists('tetrisattack-characters')) {
img.setFrame(index * 3 + (POSE_OFFSET[pose] ?? 0));
} else {
basePose = pose;
apply(pose);
// opponents fallback has no poses — pulse instead
const tint = pose === 'happy' ? 0xffd0d0 : pose === 'worried' ? 0xd0ffe0 : 0xffffff;
img.setTint(tint);
scene.tweens.add({ targets: img, scale: img.scaleX * 1.06, duration: 120, yoyo: true });
}
},
destroy() { clearHold(); frameBg.destroy(); img.destroy(); },
destroy() { frameBg.destroy(); img.destroy(); },
};
}

View File

@ -10,7 +10,7 @@ import { readFileSync, existsSync } from 'fs';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
import {
buildTrackModel, validateTrack, surfaceAt, SURFACE, normAngle,
buildTrackModel, validateTrack, surfaceAt, SURFACE,
} from '../src/games/superkart/SuperKartTrack.js';
import {
createRace, step, finalizeRace, kartInputsNeutral, mulberry32, rollItem,
@ -70,8 +70,7 @@ for (let col = 0; col < 9; col += 1) {
check(`weight column ${col + 1} sums > 0`, total > 0);
}
const physKeys = ['baseTopSpeed', 'baseAccel', 'turnRateBase', 'hopMs', 'offroadMultMin',
'boostPadMult', 'spinMs', 'gridSpacing', 'rouletteMs', 'rubberBandGain', 'rubberBandRange',
'checkpointMissSkip', 'checkpointMissMs'];
'boostPadMult', 'spinMs', 'gridSpacing', 'rouletteMs', 'rubberBandGain', 'rubberBandRange'];
for (const k of physKeys) check(`physics.${k} present`, typeof rules.physics[k] === 'number');
check('3 cups', cups.cups.length === 3);
@ -168,76 +167,6 @@ check('deep is a crawl', surfaceMult(SURFACE.DEEP, mario.stats, rules.physics) <
check('lighter kart displaced more in a bump', bMove > aMove, `smasher ${aMove.toFixed(1)} vs kona ${bMove.toFixed(1)}`);
}
// Missed-checkpoint correction: a player who shortcuts past gates is stopped
// and put back on the last gate they legitimately crossed.
{
const state = createRace({
trackModel: model1, rules, engineClass: cls, racers, playerIndex: 0, mode: 'gp', seed: 11,
});
let missedInCountdown = 0;
while (state.phase === 'countdown') {
step(state, kartInputsNeutral());
missedInCountdown += state.events.filter((e) => e.type === 'checkpoint-miss').length;
}
check('no checkpoint miss on the starting grid / countdown', missedInCountdown === 0);
const player = state.karts[0];
const cpsArr = model1.checkpoints;
const from = player.cpIndex;
const ahead = cpsArr[(from + 6) % cpsArr.length];
player.x = ahead.x;
player.y = ahead.y;
player.splineS = ahead.s; // as if the spline projection snapped across the cut
player.speed = 400;
step(state, kartInputsNeutral());
const ev = state.events.find((e) => e.type === 'checkpoint-miss');
check('shortcutting gates emits checkpoint-miss', !!ev);
check('checkpoint-miss names the first gate skipped', ev?.checkpoint === (from + 1) % cpsArr.length,
`got ${ev?.checkpoint} want ${(from + 1) % cpsArr.length}`);
check('missed checkpoint zeroes the player speed', player.speed === 0, String(player.speed));
const home = cpsArr[from];
check('player moved back to the gate behind the one missed',
Math.hypot(player.x - home.x, player.y - home.y) < 1,
`${Math.hypot(player.x - home.x, player.y - home.y).toFixed(1)} units off`);
check('missed checkpoint starts the blink window', player.cpMissMs === rules.physics.checkpointMissMs);
check('lap chain left intact for re-driving', player.cpIndex === from);
// Settled back in its own bucket, so the correction must not retrigger.
step(state, kartInputsNeutral());
check('checkpoint miss does not retrigger next step',
!state.events.some((e) => e.type === 'checkpoint-miss'));
}
// Clean racing must never trip the miss detector. The detector only arms for
// the player seat, so the player is driven round the centerline by a simple
// lookahead autopilot (the AI's own inputs aren't exported).
{
const autopilot = (model, kart) => {
const idx = Math.round(kart.splineS / model.step) % model.samples.length;
const target = model.samples[(idx + 8) % model.samples.length];
const want = Math.atan2(target.y - kart.y, target.x - kart.x);
return {
steer: Math.max(-1, Math.min(1, 3.4 * normAngle(want - kart.heading))),
accel: true, brake: false, hop: false, item: false,
};
};
let spurious = 0;
let lapsDriven = 0;
for (const tid of ['track-001', 'track-005', 'track-009']) {
const model = models.get(tid);
const state = createRace({
trackModel: model, rules, engineClass: cls, racers, playerIndex: 0, mode: 'gp', seed: 5,
});
const player = state.karts[0];
for (let i = 0; i < 60 * 200 && !player.finished; i += 1) {
step(state, autopilot(model, player));
spurious += state.events.filter((e) => e.type === 'checkpoint-miss').length;
}
lapsDriven += player.lap - 1;
}
check('autopilot actually drove full laps', lapsDriven >= 9, `${lapsDriven} laps`);
check('clean racing never trips the checkpoint-miss detector', spurious === 0, `${spurious} fired`);
}
// pointsFor sanity.
check('winner gets top points', pointsFor(1, rules) === rules.pointsTable[0]);
check('9th gets bottom points', pointsFor(9, rules) === rules.pointsTable[8]);