Commit 407525e5 authored by Tt's avatar Tt

fix(play): 修复游戏结束状态下的时间显示问题

parent 5cdf73a9
......@@ -899,6 +899,8 @@ export class PlayComponent implements OnInit, OnDestroy {
})
}
private isOver = false;
// 后续完成进入
gameOver() {
// 记录当前玩家的游戏时间
......@@ -917,6 +919,7 @@ export class PlayComponent implements OnInit, OnDestroy {
let fishRainPosition = this.rightPlayerTime < this.leftPlayerTime ? 'right' : 'left';
// 显示鱼掉落动画
this.showFishRain(fishRainPosition);
this.isOver = true;
}
......@@ -1830,8 +1833,14 @@ export class PlayComponent implements OnInit, OnDestroy {
const starSpacing = 10 * this.g_mapScale; // 星星之间的间距
const totalStarsWidth = stageCount * starWidth + (stageCount - 1) * starSpacing; // 星星总宽度加上间距
// 计算背景所需的最小宽度,确保能容纳所有星星并留有边距
const minBgWidth = totalStarsWidth + 40 * this.g_mapScale; // 两侧各留20像素的边距
// 计算背景所需的最小宽度
let minBgWidth = totalStarsWidth + 40 * this.g_mapScale; // 两侧各留20像素的边距
// 如果不是center位置,需要为时间显示预留额外空间
if (position !== 'center') {
// 为时间显示预留150像素的宽度
minBgWidth += 150 * this.g_mapScale;
}
// 创建星星背景
const starBg = this.g_cartoon.createCartoonElement(`star_bg_element_${position}`, 'MySprite');
......@@ -1853,12 +1862,12 @@ export class PlayComponent implements OnInit, OnDestroy {
// 根据位置设置X坐标
switch (position) {
case 'left':
// 左侧位置,向左移动100像素,为时间显示留出空间
starBg.ref.x = bgWidth / 2 + 20 * this.g_mapScale - 100 * this.g_mapScale;
// 左侧位置
starBg.ref.x = bgWidth / 2 + 20 * this.g_mapScale;
break;
case 'right':
// 右侧位置,向左移动100像素,为时间显示留出空间
starBg.ref.x = this.g_canvasWidth - bgWidth / 2 - 20 * this.g_mapScale - 100 * this.g_mapScale;
// 右侧位置
starBg.ref.x = this.g_canvasWidth - bgWidth / 2 - 20 * this.g_mapScale;
break;
case 'center':
default:
......@@ -1880,8 +1889,15 @@ export class PlayComponent implements OnInit, OnDestroy {
this.starElements[position] = [];
// 使用前面计算好的星星宽度和总宽度
// 计算第一个星星的X坐标,确保星星在背景上居中排列
const startX = starBg.ref.x - totalStarsWidth / 2 + starWidth / 2; // 第一个星星的X坐标
// 计算第一个星星的X坐标
let startX;
if (position !== 'center') {
// 非center位置,星星居左排列,为时间显示留出空间
startX = starBg.ref.x - bgWidth / 2 + 20 * this.g_mapScale + starWidth / 2; // 第一个星星的X坐标,距离背景左边缘20像素
} else {
// center位置,星星居中排列
startX = starBg.ref.x - totalStarsWidth / 2 + starWidth / 2; // 第一个星星的X坐标
}
// 创建星星元素
for (let i = 0; i < stageCount; i++) {
......@@ -1909,10 +1925,8 @@ export class PlayComponent implements OnInit, OnDestroy {
timeLabel.setOutline(3, '#000000'); // 设置黑色描边,增强可读性
timeLabel.text = '00:00'; // 初始时间显示
// 设置标签位置在星星的右侧
const lastStarIndex = stageCount - 1;
const lastStarX = startX + lastStarIndex * (starWidth + starSpacing);
timeLabel.x = lastStarX + starWidth / 2 + 50 * this.g_mapScale; // 最后一个星星右侧50像素
// 设置标签位置在背景板的右侧
timeLabel.x = starBg.ref.x + bgWidth / 2 - 120 * this.g_mapScale; // 背景板右边缘向左100像素
timeLabel.y = starBg.ref.y; // 与星星Y坐标相同
// 存储时间标签引用
......@@ -1996,13 +2010,13 @@ export class PlayComponent implements OnInit, OnDestroy {
let playerTime = 0;
if (position === 'left') {
// 左侧玩家时间 = 当前累计时间 + 当前回合时间
if (this.currentPlayer === 'left') {
if (this.currentPlayer === 'left' && !this.isOver) {
playerTime = currentTime - this.playerStartTime
} else {
playerTime = this.leftPlayerTime
}
} else if (position === 'right') {
if (this.currentPlayer === 'right') {
if (this.currentPlayer === 'right' && !this.isOver) {
playerTime = currentTime - this.playerStartTime
} else {
playerTime = this.rightPlayerTime
......
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