Skip to content

Commit 272732d

Browse files
committed
Double F1 speed with progressive acceleration
1 parent 16465df commit 272732d

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

racing.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<meta name="description" content="帅气逼人吊炸天 · 漫画风 F1 赛车" />
77
<title>F1 赛车 · 帅气逼人吊炸天</title>
8-
<link rel="stylesheet" href="racing.css?v=6" />
8+
<link rel="stylesheet" href="racing.css?v=7" />
99
</head>
1010
<body>
1111
<main class="game-shell">
@@ -40,8 +40,8 @@ <h1>漫画 F1 极速赛</h1>
4040
</div>
4141
</section>
4242

43-
<p class="game-note">驾驶宽体 F1 沿车印路线前进;赛道边缘使用不可见空气墙,碰撞时会自动阻挡车辆</p>
43+
<p class="game-note">按住油门逐级加速,最高可达 376 KM/H;赛道边缘使用不可见空气墙。</p>
4444
</main>
45-
<script src="racing.js?v=6"></script>
45+
<script src="racing.js?v=7"></script>
4646
</body>
4747
</html>

racing.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const stage = document.querySelector("#gameStage");
44
const speedValue = document.querySelector("#speedValue");
55
const driveState = document.querySelector("#driveState");
66
const controlCard = document.querySelector("#controlCard");
7+
const TOP_SPEED_KMH = 376;
8+
const SPEED_MULTIPLIER = 9.2;
79

810
const controls = {
911
up: false,
@@ -272,8 +274,7 @@ function drawTrack() {
272274
}
273275

274276
function updateCar(deltaTime) {
275-
const maximumSpeed = car.length * 4.6;
276-
const acceleration = maximumSpeed * 0.92;
277+
const maximumSpeed = car.length * SPEED_MULTIPLIER;
277278
const cosine = Math.cos(car.angle);
278279
const sine = Math.sin(car.angle);
279280
let forwardSpeed = car.velocityX * cosine + car.velocityY * sine;
@@ -282,6 +283,9 @@ function updateCar(deltaTime) {
282283
const throttle = Number(controls.up) - Number(controls.down);
283284

284285
if (throttle !== 0) {
286+
const speedRatio = clamp(Math.abs(forwardSpeed) / maximumSpeed, 0, 1);
287+
// Strong but progressive acceleration: quick launch, then a smooth approach to top speed.
288+
const acceleration = maximumSpeed * 0.48 * (1 - speedRatio * 0.72);
285289
forwardSpeed += throttle * acceleration * deltaTime;
286290
hasDriven = true;
287291
}
@@ -336,7 +340,7 @@ function updateCar(deltaTime) {
336340
car.x = clamp(car.x, -margin, worldWidth + margin);
337341
car.y = clamp(car.y, -margin, worldHeight + margin);
338342

339-
const speed = Math.round(Math.abs(forwardSpeed) / maximumSpeed * 188);
343+
const speed = Math.round(Math.abs(forwardSpeed) / maximumSpeed * TOP_SPEED_KMH);
340344
speedValue.textContent = String(speed);
341345
driveState.textContent = !hasDriven
342346
? "待发车"
@@ -572,6 +576,9 @@ function publishDiagnostics() {
572576
stage.dataset.vehicle = "f1";
573577
stage.dataset.driftEnabled = "false";
574578
stage.dataset.visibleFences = "false";
579+
stage.dataset.topSpeedKmh = String(TOP_SPEED_KMH);
580+
stage.dataset.speedMultiplier = String(SPEED_MULTIPLIER);
581+
stage.dataset.accelerationProfile = "progressive";
575582
stage.dataset.cameraZoom = String(cameraZoom);
576583
stage.dataset.worldTiltX = String(worldTiltX);
577584
stage.dataset.worldTiltY = String(worldTiltY);
@@ -658,6 +665,9 @@ window.raceDebug = {
658665
vehicle: "f1",
659666
driftEnabled: false,
660667
airWallHits,
668+
topSpeedKmh: TOP_SPEED_KMH,
669+
speedMultiplier: SPEED_MULTIPLIER,
670+
accelerationProfile: "progressive",
661671
trackSamples: trackSamples.length,
662672
}),
663673
};

0 commit comments

Comments
 (0)