Commit d54c5fa8 authored by 董政锦's avatar 董政锦

fix: 全程加速马和全程不加速对比;

parent c68d1520
......@@ -106,7 +106,19 @@ const updateRankPlayers = (data: any) => {
);
};
const gotoLoading = () => {
const gotoLoading = (reset = false) => {
if (reset) {
playerCount.value = 0;
loadingPlayers.value = Array.from(
{ length: PLAYER_LIMIT },
emptyLoadingPlayer,
);
rankPlayers.value = Array.from(
{ length: RANK_LIMIT },
(_, index) => emptyRankPlayer(index),
);
isPlayingStartAnimation = false;
}
screen.value = "loading";
};
......@@ -117,7 +129,7 @@ const gotoRank1WithIntro = async () => {
screen.value = "rank1";
await nextTick();
await rank1Ref.value?.startIntro();
screen.value = "rank2";
// 结果页已在 Rank1View 内部渲染,不需要切到 rank2
isPlayingStartAnimation = false;
};
......@@ -128,7 +140,7 @@ function handleRoomState(data: any) {
switch (data?.status) {
case 0:
gotoLoading();
gotoLoading(true);
createRoom(1);
break;
case 1:
......@@ -143,7 +155,7 @@ function handleRoomState(data: any) {
}
}
const { startGame, createRoom, requestRoomState } = useAdminGameSocket({
const { startGame, createRoom, backRoom, requestRoomState } = useAdminGameSocket({
gameId: "game4",
// loginRedirectPath: '/game4',
onRoomState: handleRoomState,
......@@ -156,8 +168,9 @@ const { startGame, createRoom, requestRoomState } = useAdminGameSocket({
});
const nextRound = () => {
gotoLoading();
createRoom(1);
gotoLoading(true);
// 使用 backRoom 重置已有房间,而非 createRoom 重复创建
backRoom(1);
setTimeout(() => {
requestRoomState();
}, 200);
......@@ -186,7 +199,7 @@ onUnmounted(() => {
:rank-list="rankPlayers"
:horse-boosts="horseBoosts"
@start="startGame"
@next="screen = 'rank2'"
@next="nextRound"
/>
<Rank2 v-else-if="screen === 'rank2'" :rank-list="rankPlayers" @next="nextRound" />
<!-- <Rank2 v-else-if="screen === 'rank2'" :rank-list="rankPlayers" @next="nextRound" /> -->
</template>
......@@ -39,14 +39,18 @@ const imageUrls = {
avatarAnimation: cssAssetUrl("avatar_animation.png"),
};
// ========== 速度基准: 90秒从屏幕左侧跑到右侧(调低初始速度) ==========
// ========== 速度基准:330秒从屏幕左侧跑到右侧 ==========
// 60s 游戏 × 基准速度(0.303%/s) = 18.2% → 不加速几乎原地
// 60s 游戏 × 最大5.5x(1.667%/s) = 100% → 全程猛摇刚好到达终点
const TOTAL_DISTANCE_PX = 2160; // -120px ~ 2040px
const BASE_DURATION_SEC = 90;
const BASE_SPEED_PERCENT_PER_SEC = 100 / BASE_DURATION_SEC; // ≈ 1.111%/s 基准速度
const BASE_DURATION_SEC = 330;
const BASE_SPEED_PERCENT_PER_SEC = 100 / BASE_DURATION_SEC; // ≈ 0.303%/s 基准速度
// ========== 瞬时加速脉冲机制 ==========
// H5 每次摇一摇发送累计积分,PC 端检测 score 增长 → 触发短暂加速脉冲 → 迅速衰减
const BOOST_PULSE = 1.5; // 每次操作的加速幅度(+150% 额外速度,即 2.5x 基准)
// 快速连摇时脉冲可叠加(每次 +1.0),最高不超过 4.5(即 5.5x 基准速度)
const BOOST_PULSE = 1.0; // 每次操作的加速幅度(+100% 额外速度,即 2x 基准)
const MAX_PULSE = 4.5; // 最大叠加脉冲上限(即 5.5x 基准速度)
const BOOST_DECAY = 0.985; // 每帧衰减系数(60fps 下约 1.5s 衰减到 40%,约 3s 衰减归零)
/** 瞬时加速值: { [userid]: currentBoost },每帧衰减 */
......@@ -69,11 +73,12 @@ const detectScoreChanges = (players: Player[]) => {
const prev = prevScores[id] ?? 0;
if (newScore > prev) {
// 积分增长 = 玩家又摇了一次 → 触发瞬时加速脉冲
updated[id] = BOOST_PULSE;
// 积分增长 = 玩家又摇了一次 → 叠加瞬时加速脉冲(连摇可累积到 MAX_PULSE)
const current = updated[id] || 0;
updated[id] = Math.min(current + BOOST_PULSE, MAX_PULSE);
hasNewBoost = true;
console.log(
`[Rank1View] 🚀 ${p.nickname} score ${prev}${newScore}, 触发瞬时加速 pulse=${BOOST_PULSE}`,
`[Rank1View] 🚀 ${p.nickname} score ${prev}${newScore}, boost: ${current.toFixed(1)}+${BOOST_PULSE}=${updated[id].toFixed(1)}`,
);
}
......@@ -177,8 +182,9 @@ watch(
Object.keys(boosts).forEach((id) => {
const val = Number(boosts[id] ?? 0);
if (val > 0) {
// 每次收到有效数据都刷新脉冲(叠加摇一摇的连续加速感)
updated[id] = BOOST_PULSE;
// 每次收到有效数据都叠加脉冲(连摇可累积到 MAX_PULSE)
const current = updated[id] || 0;
updated[id] = Math.min(current + BOOST_PULSE, MAX_PULSE);
hasNew = true;
}
});
......@@ -204,7 +210,6 @@ const startGameLoop = () => {
gameLoopTimer = setInterval(() => {
if (!isGameRunning.value) return;
let allFinished = true;
const newTransientBoosts: Record<string, number> = {};
horses.value.forEach((horse) => {
......@@ -215,6 +220,7 @@ const startGameLoop = () => {
horse.boost = boost;
// 实际速度 = 基准速度 × (1 + 瞬时boost)
// 最大5.5x时刚好在60s游戏结束时到达100%
horse.xPercent = Math.min(
100,
horse.xPercent +
......@@ -226,16 +232,10 @@ const startGameLoop = () => {
if (decayed > 0.005) {
newTransientBoosts[horse.id] = decayed;
}
if (horse.xPercent < 100) allFinished = false;
});
// 更新衰减后的加速值
transientBoosts.value = newTransientBoosts;
if (allFinished && horses.value.length > 0) {
stopGame();
}
}, TICK_MS);
};
......@@ -346,19 +346,8 @@ const startIntro = async () => {
startMockBoost();
}
// 监测提前结束(所有马跑完 → 提前停止倒计时)
const earlyCheck = setInterval(() => {
const allDone =
horses.value.length > 0 &&
horses.value.every((h) => h.xPercent >= 100);
if (allDone && isGameRunning.value) {
designStage.value?.stopCountdown();
}
}, 200);
// 等待 60s 游戏倒计时结束
// 等待 60s 游戏倒计时完全结束 → 才出现结果页
await countdownPromise;
clearInterval(earlyCheck);
stopGame();
};
......@@ -414,7 +403,7 @@ defineExpose({
<template>
<DesignStage ref="designStage">
<div class="screen-container" :class="{ paused: !gameStarted }">
<div class="screen-container" :class="{ paused: !gameStarted || showResult }">
<div class="img-logo"></div>
<div class="img-title-bg"></div>
<div class="img-big-brum"></div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment