Commit 025ec7a3 authored by Tt's avatar Tt

整理

parent 427b4d1b
...@@ -192,138 +192,6 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -192,138 +192,6 @@ export class PlayComponent implements OnInit, OnDestroy {
this.restartGame() this.restartGame()
} }
/**
* 隐藏所有VS相关元素
*/
hideVsElements() {
// 隐藏红色渐变面板
const hong_se_jian_bian = this.g_cartoon.cartoonElementsBuffer['hong_se_jian_bian'];
if (hong_se_jian_bian && hong_se_jian_bian.ref) {
hong_se_jian_bian.ref.visible = false;
}
// 隐藏蓝色渐变面板
const lan_se_jian_bian = this.g_cartoon.cartoonElementsBuffer['lan_se_jian_bian'];
if (lan_se_jian_bian && lan_se_jian_bian.ref) {
lan_se_jian_bian.ref.visible = false;
}
// 隐藏其他VS元素
const vsElements = ['v', 's', 'ju_mao_tou', 'hui_mao_tou'];
vsElements.forEach(elementName => {
const element = this.g_cartoon.cartoonElementsBuffer[elementName];
if (element && element.ref) {
element.ref.visible = false;
}
});
}
/**
* 隐藏所有321倒计时相关元素
*/
hide321Elements() {
// 隐藏倒计时元素
const countdownElements = ['dao_ji_shi_3', 'dao_ji_shi_2', 'dao_ji_shi_1'];
countdownElements.forEach(elementName => {
const element = this.g_cartoon.cartoonElementsBuffer[elementName];
if (element && element.ref) {
element.ref.visible = false;
}
});
}
/**
* 初始化321倒计时视图
* 创建并初始化倒计时数字元素
*/
/**
* 初始化321倒计时视图
* @param type 游戏类型,'left'表示左侧猫开始玩,'right'表示右侧猫开始玩
*/
init321View(type: string = 'left') {
// 创建倒计时数字元素
const countdownElements = ['dao_ji_shi_3', 'dao_ji_shi_2', 'dao_ji_shi_1'];
// 根据type计算x坐标的偏移量
const xOffset = type === 'left' ? 140 : -190;
countdownElements.forEach(elementName => {
// 检查元素是否已存在
if (!this.g_cartoon.cartoonElementsBuffer[elementName]) {
// 创建元素
const element = this.g_cartoon.createCartoonElement(elementName, 'MySprite');
// 初始化元素
element.ref.init(this.g_cartoon.images.get(elementName));
// 设置元素缩放
element.ref.scaleX = this.g_mapScale;
element.ref.scaleY = this.g_mapScale;
// 设置元素位置(根据type调整画面中心的x坐标)
element.ref.x = this.g_canvasWidth / 2 + xOffset;
element.ref.y = this.g_canvasHeight / 2 + 60 * this.g_mapScale;
// 默认隐藏
element.ref.visible = false;
// 添加到渲染队列
this.render(element.ref, zIndexMap.card + 3);
} else {
// 如果元素已存在,更新其位置
const element = this.g_cartoon.cartoonElementsBuffer[elementName];
element.ref.x = this.g_canvasWidth / 2 + xOffset;
}
});
}
/**
* 显示321倒计时动画
* 依次显示3、2、1的倒计时动画效果
* @param type 游戏类型,'left'表示左侧猫开始玩,'right'表示右侧猫开始玩
*/
show321(type: string = 'left') {
// 动画配置参数
const config = {
// 动画时间配置
time: {
displayDuration: 0.7, // 数字显示停留时间(秒)
animDuration: 0.3, // 动画持续时间(秒)
interval: 0, // 数字切换间隔时间(秒)
afterComplete: 0.5 // 倒计时完成后的延迟时间(秒)
},
// 动画效果配置
effect: {
scaleRatio: 3, // 放大比例
finalAlpha: 0.5 // 最终透明度
}
};
// 初始化321倒计时视图,传递type参数
this.init321View(type);
// 隐藏所有倒计时元素(确保初始状态是隐藏的)
this.hide321Elements();
// 依次显示3、2、1的倒计时动画
// 先显示3
this.g_cartoon.playAudio('time_3');
this.showCountdownNumber('dao_ji_shi_3', config, () => {
this.g_cartoon.playAudio('time_2');
// 显示完3后显示2
this.showCountdownNumber('dao_ji_shi_2', config, () => {
this.g_cartoon.playAudio('time_1');
// 显示完2后显示1
this.showCountdownNumber('dao_ji_shi_1', config, () => {
// 倒计时结束后的操作,等待一段时间后显示VS动画
setTimeout(() => {
// this.showVsAni(type);
this.hideVsElements();
this.hide321Elements();
this.startBattle();
}, config.time.afterComplete * 1000);
});
});
});
}
/** /**
* 显示单个倒计时数字的动画 * 显示单个倒计时数字的动画
* @param elementName 元素名称 * @param elementName 元素名称
...@@ -928,14 +796,76 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -928,14 +796,76 @@ export class PlayComponent implements OnInit, OnDestroy {
//--------------------------------------------------------------钓鱼-初始化--------------------------------------------------------- //--------------------------------------------------------------钓鱼-初始化---------------------------------------------------------
// 第一次进入
initBattle() { initBattle() {
this.g_enableMapDown = true; this.g_enableMapDown = true;
if (this.g_formData.doubleModal) { if (this.g_formData.doubleModal) {
this.showVsAni('left'); this.showVsAni('left').then(() => {
this.show321('left').then(() => {
this.startBattle();
})
})
} else { } else {
this.startBattle(); this.startBattle();
} }
} }
// 后续完成进入
gameOver() {
// 记录当前玩家的游戏时间
if (this.g_formData.doubleModal) {
const endTime = Date.now();
const playTime = endTime - this.g_playerStartTime;
if (this.g_currentPlayer === 'left') {
// 左侧玩家结束,记录时间并切换到右侧玩家
this.g_leftPlayerTime = playTime;
console.log('左侧玩家游戏时间:', this.g_leftPlayerTime, 'ms');
this.currentStageIndex = 0;
this.isGameStart = false;
// 切换到右侧玩家
this.g_currentPlayer = 'right';
// 播放VS动画
this.showVsAni('right');
// 重置游戏状态,准备第二个玩家
this.cleanGameVar();
// 记录第二个玩家开始时间
this.g_playerStartTime = Date.now();
} else {
// 右侧玩家结束,记录时间
this.g_rightPlayerTime = playTime;
console.log('右侧玩家游戏时间:', this.g_rightPlayerTime, 'ms');
// 双人游戏全部结束,显示鱼掉落动画
// 根据游戏时间决定在哪一边显示鱼掉落动画
let fishRainPosition;
if (this.g_rightPlayerTime < this.g_leftPlayerTime) {
// 右侧玩家时间更短(更快完成),在右侧显示
fishRainPosition = 'right';
} else {
fishRainPosition = 'left';
}
// 显示鱼掉落动画
this.showFishRain(fishRainPosition);
// 重置双人模式状态
this.g_currentPlayer = 'left';
this.g_leftPlayerTime = 0;
this.g_rightPlayerTime = 0;
}
} else {
// 单人模式,直接显示中间的鱼掉落动画
this.showFishRain('center');
}
}
/** /**
* 开始游戏战斗 * 开始游戏战斗
* 初始化游戏元素并设置双人模式 * 初始化游戏元素并设置双人模式
...@@ -1042,61 +972,6 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -1042,61 +972,6 @@ export class PlayComponent implements OnInit, OnDestroy {
} }
} }
/**
* 游戏结束处理
* 在双人模式下,第一个玩家结束后切换到第二个玩家
*/
gameOver() {
// 记录当前玩家的游戏时间
if (this.g_formData.doubleModal) {
const endTime = Date.now();
const playTime = endTime - this.g_playerStartTime;
if (this.g_currentPlayer === 'left') {
// 左侧玩家结束,记录时间并切换到右侧玩家
this.g_leftPlayerTime = playTime;
console.log('左侧玩家游戏时间:', this.g_leftPlayerTime, 'ms');
this.currentStageIndex = 0;
this.isGameStart = false;
// 切换到右侧玩家
this.g_currentPlayer = 'right';
// 播放VS动画
this.showVsAni('right');
// 重置游戏状态,准备第二个玩家
this.cleanGameVar();
// 记录第二个玩家开始时间
this.g_playerStartTime = Date.now();
} else {
// 右侧玩家结束,记录时间
this.g_rightPlayerTime = playTime;
console.log('右侧玩家游戏时间:', this.g_rightPlayerTime, 'ms');
// 双人游戏全部结束,显示鱼掉落动画
// 根据游戏时间决定在哪一边显示鱼掉落动画
let fishRainPosition;
if (this.g_rightPlayerTime < this.g_leftPlayerTime) {
// 右侧玩家时间更短(更快完成),在右侧显示
fishRainPosition = 'right';
} else {
fishRainPosition = 'left';
}
// 显示鱼掉落动画
this.showFishRain(fishRainPosition);
// 重置双人模式状态
this.g_currentPlayer = 'left';
this.g_leftPlayerTime = 0;
this.g_rightPlayerTime = 0;
}
} else {
// 单人模式,直接显示中间的鱼掉落动画
this.showFishRain('center');
}
}
//-----------------------------------------------------------------钓鱼-创建--------------------------------------------------------- //-----------------------------------------------------------------钓鱼-创建---------------------------------------------------------
...@@ -1413,319 +1288,240 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -1413,319 +1288,240 @@ export class PlayComponent implements OnInit, OnDestroy {
//-----------------------------------------------------------------钓鱼-动画--------------------------------------------------------- //-----------------------------------------------------------------钓鱼-动画---------------------------------------------------------
/** /**
* 初始化VS视图,创建所有VS动画相关的元素 * 显示VS动画
* @param type 动画类型,'left' 或 'right'
*/ */
initVsView() { showVsAni(type: string) {
// 创建红色渐变面板 - 初始位置在屏幕左侧外 return new Promise<void>((resolve) => {
const hong_se_jian_bian = this.g_cartoon.createCartoonElement('hong_se_jian_bian', 'MySprite');
hong_se_jian_bian.ref.init(this.g_cartoon.images.get('hong_se_jian_bian')); // 动画配置参数
hong_se_jian_bian.ref.scaleX = this.g_mapScale; const config = {
hong_se_jian_bian.ref.scaleY = this.g_mapScale; // 面板动画配置
hong_se_jian_bian.ref.x = -400 * this.g_mapScale; // 初始位置在屏幕左侧外 panel: {
hong_se_jian_bian.ref.y = this.g_canvasHeight / 2; // 红色面板配置
this.render(hong_se_jian_bian.ref, zIndexMap.card); hong: {
offsetX: 350, // 红色面板X轴偏移量
initialOffsetX: -400, // 红色面板初始X轴偏移量(屏幕外)
moveTime: 0.3, // 移动动画时间
scaleRatio: 1.5, // 放大比例
moveDistance: 210 // 移动距离
},
// 蓝色面板配置
lan: {
offsetX: 340, // 蓝色面板X轴偏移量
initialOffsetX: 400, // 蓝色面板初始X轴偏移量(屏幕外)
moveTime: 0.3, // 移动动画时间
scaleRatio: 1.5, // 放大比例
moveDistance: 130 // 移动距离
}
},
// VS元素动画配置
vs: {
// V元素配置
v: {
offsetX: 20, // V元素X轴偏移量
initialOffsetX: -100, // V元素初始X轴偏移量(屏幕外)
moveTime: 0.2 // 移动动画时间
},
// S元素配置
s: {
offsetX: 20, // S元素X轴偏移量
initialOffsetX: 100, // S元素初始X轴偏移量(屏幕外)
moveTime: 0.2 // 移动动画时间
}
},
// 猫猫头动画配置
cat: {
// 橘猫头配置
ju: {
scaleRatio: 1.5, // 放大比例
shrinkRatio: 0.8, // 缩小比例
moveDistance: 80, // 移动距离
animTime: 0.3 // 动画时间
},
// 灰猫头配置
hui: {
scaleRatio: 1.5, // 放大比例
shrinkRatio: 0.8, // 缩小比例
moveDistance: 20, // 移动距离
animTime: 0.3 // 动画时间
}
},
// 通用配置
common: {
vsAnimDelay: 200, // VS元素动画延迟时间
hideDelay: 3000 // 隐藏元素延迟时间
}
};
// 创建蓝色渐变面板 - 初始位置在屏幕右侧外 // 初始化VS视图
const lan_se_jian_bian = this.g_cartoon.createCartoonElement('lan_se_jian_bian', 'MySprite'); this.createVsView();
lan_se_jian_bian.ref.init(this.g_cartoon.images.get('lan_se_jian_bian'));
lan_se_jian_bian.ref.scaleX = this.g_mapScale;
lan_se_jian_bian.ref.scaleY = this.g_mapScale;
lan_se_jian_bian.ref.x = this.g_canvasWidth + 400 * this.g_mapScale; // 初始位置在屏幕右侧外
lan_se_jian_bian.ref.y = this.g_canvasHeight / 2;
this.render(lan_se_jian_bian.ref, zIndexMap.card);
const v_element = this.g_cartoon.createCartoonElement('v', 'MySprite'); // 获取红色和蓝色渐变面板元素
v_element.ref.init(this.g_cartoon.images.get('v')); const hong_se_jian_bian = this.g_cartoon.cartoonElementsBuffer['hong_se_jian_bian'].ref;
v_element.ref.scaleX = this.g_mapScale; const lan_se_jian_bian = this.g_cartoon.cartoonElementsBuffer['lan_se_jian_bian'].ref;
v_element.ref.scaleY = this.g_mapScale;
v_element.ref.x = this.g_canvasWidth / 2 - 20 * this.g_mapScale;
v_element.ref.y = this.g_canvasHeight / 2;
this.render(v_element.ref, zIndexMap.card + 2);
const s_element = this.g_cartoon.createCartoonElement('s', 'MySprite'); // 设置红色渐变面板的目标位置
s_element.ref.init(this.g_cartoon.images.get('s')); const hongTargetX = this.g_canvasWidth / 2 - config.panel.hong.offsetX * this.g_mapScale;
s_element.ref.scaleX = this.g_mapScale; // 设置蓝色渐变面板的目标位置
s_element.ref.scaleY = this.g_mapScale; const lanTargetX = this.g_canvasWidth / 2 + config.panel.lan.offsetX * this.g_mapScale;
s_element.ref.x = this.g_canvasWidth / 2 + 20 * this.g_mapScale;
s_element.ref.y = this.g_canvasHeight / 2;
this.render(s_element.ref, zIndexMap.card + 2);
// 创建其他VS动画元素 // 使用moveItem函数实现红色渐变面板从左侧移动到目标位置的动画
// 左侧元素:橘猫头和V moveItem(hong_se_jian_bian, hongTargetX, hong_se_jian_bian.y, config.panel.hong.moveTime);
const ju_mao_tou = this.g_cartoon.createCartoonElement('ju_mao_tou', 'MySprite');
ju_mao_tou.ref.init(this.g_cartoon.images.get('ju_mao_tou'));
ju_mao_tou.ref.scaleX = this.g_mapScale;
ju_mao_tou.ref.scaleY = this.g_mapScale;
ju_mao_tou.ref.x = this.g_canvasWidth / 4;
ju_mao_tou.ref.y = this.g_canvasHeight / 2;
this.render(ju_mao_tou.ref, zIndexMap.card + 1);
// 右侧元素:灰猫头和S // 使用moveItem函数实现蓝色渐变面板从右侧移动到目标位置的动画
const hui_mao_tou = this.g_cartoon.createCartoonElement('hui_mao_tou', 'MySprite'); moveItem(lan_se_jian_bian, lanTargetX, lan_se_jian_bian.y, config.panel.lan.moveTime);
hui_mao_tou.ref.init(this.g_cartoon.images.get('hui_mao_tou'));
hui_mao_tou.ref.scaleX = this.g_mapScale;
hui_mao_tou.ref.scaleY = this.g_mapScale;
hui_mao_tou.ref.x = this.g_canvasWidth * 3 / 4;
hui_mao_tou.ref.y = this.g_canvasHeight / 2;
this.render(hui_mao_tou.ref, zIndexMap.card + 1);
// 播放VS音效 // 获取VS元素
this.g_cartoon.playAudio('vs'); const v_element = this.g_cartoon.cartoonElementsBuffer['v'].ref;
} const s_element = this.g_cartoon.cartoonElementsBuffer['s'].ref;
const ju_mao_tou = this.g_cartoon.cartoonElementsBuffer['ju_mao_tou'].ref;
const hui_mao_tou = this.g_cartoon.cartoonElementsBuffer['hui_mao_tou'].ref;
/** // 设置VS元素的初始位置(屏幕外)
* 显示VS动画 v_element.x = config.vs.v.initialOffsetX * this.g_mapScale; // V元素初始位置在屏幕左侧外
* @param type 动画类型,'left' 或 'right' s_element.x = this.g_canvasWidth + config.vs.s.initialOffsetX * this.g_mapScale; // S元素初始位置在屏幕右侧外
*/
showVsAni(type: string) {
// 动画配置参数
const config = {
// 面板动画配置
panel: {
// 红色面板配置
hong: {
offsetX: 350, // 红色面板X轴偏移量
initialOffsetX: -400, // 红色面板初始X轴偏移量(屏幕外)
moveTime: 0.3, // 移动动画时间
scaleRatio: 1.5, // 放大比例
moveDistance: 210 // 移动距离
},
// 蓝色面板配置
lan: {
offsetX: 340, // 蓝色面板X轴偏移量
initialOffsetX: 400, // 蓝色面板初始X轴偏移量(屏幕外)
moveTime: 0.3, // 移动动画时间
scaleRatio: 1.5, // 放大比例
moveDistance: 130 // 移动距离
}
},
// VS元素动画配置
vs: {
// V元素配置
v: {
offsetX: 20, // V元素X轴偏移量
initialOffsetX: -100, // V元素初始X轴偏移量(屏幕外)
moveTime: 0.2 // 移动动画时间
},
// S元素配置
s: {
offsetX: 20, // S元素X轴偏移量
initialOffsetX: 100, // S元素初始X轴偏移量(屏幕外)
moveTime: 0.2 // 移动动画时间
}
},
// 猫猫头动画配置
cat: {
// 橘猫头配置
ju: {
scaleRatio: 1.5, // 放大比例
shrinkRatio: 0.8, // 缩小比例
moveDistance: 80, // 移动距离
animTime: 0.3 // 动画时间
},
// 灰猫头配置
hui: {
scaleRatio: 1.5, // 放大比例
shrinkRatio: 0.8, // 缩小比例
moveDistance: 20, // 移动距离
animTime: 0.3 // 动画时间
}
},
// 通用配置
common: {
vsAnimDelay: 200, // VS元素动画延迟时间
hideDelay: 3000 // 隐藏元素延迟时间
}
};
// 初始化VS视图
this.initVsView();
// 获取红色和蓝色渐变面板元素
const hong_se_jian_bian = this.g_cartoon.cartoonElementsBuffer['hong_se_jian_bian'].ref;
const lan_se_jian_bian = this.g_cartoon.cartoonElementsBuffer['lan_se_jian_bian'].ref;
// 设置红色渐变面板的目标位置
const hongTargetX = this.g_canvasWidth / 2 - config.panel.hong.offsetX * this.g_mapScale;
// 设置蓝色渐变面板的目标位置
const lanTargetX = this.g_canvasWidth / 2 + config.panel.lan.offsetX * this.g_mapScale;
// 使用moveItem函数实现红色渐变面板从左侧移动到目标位置的动画 // VS元素动画延迟执行
moveItem(hong_se_jian_bian, hongTargetX, hong_se_jian_bian.y, config.panel.hong.moveTime);
// 使用moveItem函数实现蓝色渐变面板从右侧移动到目标位置的动画
moveItem(lan_se_jian_bian, lanTargetX, lan_se_jian_bian.y, config.panel.lan.moveTime);
// 获取VS元素
const v_element = this.g_cartoon.cartoonElementsBuffer['v'].ref;
const s_element = this.g_cartoon.cartoonElementsBuffer['s'].ref;
const ju_mao_tou = this.g_cartoon.cartoonElementsBuffer['ju_mao_tou'].ref;
const hui_mao_tou = this.g_cartoon.cartoonElementsBuffer['hui_mao_tou'].ref;
// 设置VS元素的初始位置(屏幕外)
v_element.x = config.vs.v.initialOffsetX * this.g_mapScale; // V元素初始位置在屏幕左侧外
s_element.x = this.g_canvasWidth + config.vs.s.initialOffsetX * this.g_mapScale; // S元素初始位置在屏幕右侧外
// VS元素动画延迟执行
setTimeout(() => {
// 使用moveItem函数实现V元素从屏幕外移动到目标位置的动画
moveItem(v_element, this.g_canvasWidth / 2 - config.vs.v.offsetX * this.g_mapScale, v_element.y, config.vs.v.moveTime);
// 使用moveItem函数实现S元素从屏幕外移动到目标位置的动画
moveItem(s_element, this.g_canvasWidth / 2 + config.vs.s.offsetX * this.g_mapScale, s_element.y, config.vs.s.moveTime, () => {
// VS元素移动完成后,调用showVsShadow函数创建阴影效果
this.showVsShadow();
this.g_cartoon.playAudio('vs');
});
setTimeout(() => { setTimeout(() => {
// 隐藏VS元素 // 使用moveItem函数实现V元素从屏幕外移动到目标位置的动画
v_element.visible = false; moveItem(v_element, this.g_canvasWidth / 2 - config.vs.v.offsetX * this.g_mapScale, v_element.y, config.vs.v.moveTime);
s_element.visible = false;
// 根据类型设置不同的动画效果 // 使用moveItem函数实现S元素从屏幕外移动到目标位置的动画
if (type === 'left') { moveItem(s_element, this.g_canvasWidth / 2 + config.vs.s.offsetX * this.g_mapScale, s_element.y, config.vs.s.moveTime, () => {
// 左侧胜利的动画效果 - 左侧猫猫头和红色面板放大,右侧猫猫头缩小并向右移动,蓝色底板向右移动 // VS元素移动完成后,调用showVsShadow函数创建阴影效果
// 左侧猫猫头放大 this.showVsShadow();
ju_mao_tou.scaleX = ju_mao_tou.scaleY = this.g_mapScale; this.g_cartoon.playAudio('vs');
tweenChange(ju_mao_tou, { });
scaleX: this.g_mapScale * config.cat.ju.scaleRatio,
scaleY: this.g_mapScale * config.cat.ju.scaleRatio
}, config.cat.ju.animTime);
// 红色面板放大
const hong_se_jian_bian_ref = this.g_cartoon.cartoonElementsBuffer['hong_se_jian_bian'].ref;
tweenChange(hong_se_jian_bian_ref, {
scaleX: this.g_mapScale * config.panel.hong.scaleRatio,
scaleY: this.g_mapScale * config.panel.hong.scaleRatio
}, config.panel.hong.moveTime);
// 右侧猫猫头缩小并向右移动
hui_mao_tou.scaleX = hui_mao_tou.scaleY = this.g_mapScale;
tweenChange(hui_mao_tou, {
scaleX: this.g_mapScale * config.cat.hui.shrinkRatio,
scaleY: this.g_mapScale * config.cat.hui.shrinkRatio,
x: hui_mao_tou.x + config.cat.hui.moveDistance * this.g_mapScale,
y: hui_mao_tou.y + 95 * this.g_mapScale
}, config.cat.hui.animTime);
// 蓝色底板向右移动
const lan_se_jian_bian_ref = this.g_cartoon.cartoonElementsBuffer['lan_se_jian_bian'].ref;
moveItem(
lan_se_jian_bian_ref,
lan_se_jian_bian_ref.x + config.panel.lan.moveDistance * this.g_mapScale,
lan_se_jian_bian_ref.y + 95 * this.g_mapScale,
config.panel.lan.moveTime
);
} else if (type === 'right') {
// 右侧胜利的动画效果 - 右侧猫猫头和蓝色面板放大,左侧猫猫头缩小并向左移动,红色底板向左移动
// 右侧猫猫头放大
hui_mao_tou.scaleX = hui_mao_tou.scaleY = this.g_mapScale;
tweenChange(hui_mao_tou, {
scaleX: this.g_mapScale * config.cat.hui.scaleRatio,
scaleY: this.g_mapScale * config.cat.hui.scaleRatio
}, config.cat.hui.animTime);
// 蓝色面板放大
const lan_se_jian_bian_ref = this.g_cartoon.cartoonElementsBuffer['lan_se_jian_bian'].ref;
tweenChange(lan_se_jian_bian_ref, {
scaleX: this.g_mapScale * config.panel.lan.scaleRatio,
scaleY: this.g_mapScale * config.panel.lan.scaleRatio
}, config.panel.lan.moveTime);
// 左侧猫猫头缩小并向左移动
ju_mao_tou.scaleX = ju_mao_tou.scaleY = this.g_mapScale;
tweenChange(ju_mao_tou, {
scaleX: this.g_mapScale * config.cat.ju.shrinkRatio,
scaleY: this.g_mapScale * config.cat.ju.shrinkRatio,
x: ju_mao_tou.x - config.cat.ju.moveDistance * this.g_mapScale,
y: ju_mao_tou.y + 95 * this.g_mapScale
}, config.cat.ju.animTime);
// 红色底板向左移动
const hong_se_jian_bian_ref = this.g_cartoon.cartoonElementsBuffer['hong_se_jian_bian'].ref;
moveItem(
hong_se_jian_bian_ref,
hong_se_jian_bian_ref.x - config.panel.hong.moveDistance * this.g_mapScale,
hong_se_jian_bian_ref.y + 92 * this.g_mapScale,
config.panel.hong.moveTime
);
}
setTimeout(() => { setTimeout(() => {
this.show321(type); // 隐藏VS元素
}, 1000); v_element.visible = false;
}, config.vs.v.moveTime * 1000 + 500); s_element.visible = false;
}, config.common.vsAnimDelay); // 根据类型设置不同的动画效果
if (type === 'left') {
// 左侧胜利的动画效果 - 左侧猫猫头和红色面板放大,右侧猫猫头缩小并向右移动,蓝色底板向右移动
// 左侧猫猫头放大
ju_mao_tou.scaleX = ju_mao_tou.scaleY = this.g_mapScale;
tweenChange(ju_mao_tou, {
scaleX: this.g_mapScale * config.cat.ju.scaleRatio,
scaleY: this.g_mapScale * config.cat.ju.scaleRatio
}, config.cat.ju.animTime);
// 红色面板放大
const hong_se_jian_bian_ref = this.g_cartoon.cartoonElementsBuffer['hong_se_jian_bian'].ref;
tweenChange(hong_se_jian_bian_ref, {
scaleX: this.g_mapScale * config.panel.hong.scaleRatio,
scaleY: this.g_mapScale * config.panel.hong.scaleRatio
}, config.panel.hong.moveTime);
// 右侧猫猫头缩小并向右移动
hui_mao_tou.scaleX = hui_mao_tou.scaleY = this.g_mapScale;
tweenChange(hui_mao_tou, {
scaleX: this.g_mapScale * config.cat.hui.shrinkRatio,
scaleY: this.g_mapScale * config.cat.hui.shrinkRatio,
x: hui_mao_tou.x + config.cat.hui.moveDistance * this.g_mapScale,
y: hui_mao_tou.y + 95 * this.g_mapScale
}, config.cat.hui.animTime);
// 蓝色底板向右移动
const lan_se_jian_bian_ref = this.g_cartoon.cartoonElementsBuffer['lan_se_jian_bian'].ref;
moveItem(
lan_se_jian_bian_ref,
lan_se_jian_bian_ref.x + config.panel.lan.moveDistance * this.g_mapScale,
lan_se_jian_bian_ref.y + 95 * this.g_mapScale,
config.panel.lan.moveTime
);
} else if (type === 'right') {
// 右侧胜利的动画效果 - 右侧猫猫头和蓝色面板放大,左侧猫猫头缩小并向左移动,红色底板向左移动
// 右侧猫猫头放大
hui_mao_tou.scaleX = hui_mao_tou.scaleY = this.g_mapScale;
tweenChange(hui_mao_tou, {
scaleX: this.g_mapScale * config.cat.hui.scaleRatio,
scaleY: this.g_mapScale * config.cat.hui.scaleRatio
}, config.cat.hui.animTime);
// 蓝色面板放大
const lan_se_jian_bian_ref = this.g_cartoon.cartoonElementsBuffer['lan_se_jian_bian'].ref;
tweenChange(lan_se_jian_bian_ref, {
scaleX: this.g_mapScale * config.panel.lan.scaleRatio,
scaleY: this.g_mapScale * config.panel.lan.scaleRatio
}, config.panel.lan.moveTime);
// 左侧猫猫头缩小并向左移动
ju_mao_tou.scaleX = ju_mao_tou.scaleY = this.g_mapScale;
tweenChange(ju_mao_tou, {
scaleX: this.g_mapScale * config.cat.ju.shrinkRatio,
scaleY: this.g_mapScale * config.cat.ju.shrinkRatio,
x: ju_mao_tou.x - config.cat.ju.moveDistance * this.g_mapScale,
y: ju_mao_tou.y + 95 * this.g_mapScale
}, config.cat.ju.animTime);
// 红色底板向左移动
const hong_se_jian_bian_ref = this.g_cartoon.cartoonElementsBuffer['hong_se_jian_bian'].ref;
moveItem(
hong_se_jian_bian_ref,
hong_se_jian_bian_ref.x - config.panel.hong.moveDistance * this.g_mapScale,
hong_se_jian_bian_ref.y + 92 * this.g_mapScale,
config.panel.hong.moveTime
);
}
setTimeout(() => {
resolve();
}, 1000);
}, config.vs.v.moveTime * 1000 + 500);
}, config.common.vsAnimDelay);
})
} }
/** /**
* 显示VS阴影动画效果 * 显示321倒计时动画
* 在VS动画运动后的位置创建两个VS图标,并执行放大5倍、透明度为0的动画 * 依次显示3、2、1的倒计时动画效果
* V字母向左移动50,S字母向右移动50,动画时间为0.1秒 * @param type 游戏类型,'left'表示左侧猫开始玩,'right'表示右侧猫开始玩
*/ */
showVsShadow() { show321(type: string = 'left') {
// 创建V阴影元素 return new Promise((resolve, reject) => {
const v_shadow = this.g_cartoon.createCartoonElement('v_shadow', 'MySprite');
v_shadow.ref.init(this.g_cartoon.images.get('v')); // 动画配置参数
v_shadow.ref.scaleX = this.g_mapScale; const config = {
v_shadow.ref.scaleY = this.g_mapScale; // 动画时间配置
v_shadow.ref.x = this.g_canvasWidth / 2 - 20 * this.g_mapScale; // 与原始V元素位置相同 time: {
v_shadow.ref.y = this.g_canvasHeight / 2; displayDuration: 0.7, // 数字显示停留时间(秒)
this.render(v_shadow.ref, zIndexMap.card + 1); // 放在原始VS元素下方 animDuration: 0.3, // 动画持续时间(秒)
interval: 0, // 数字切换间隔时间(秒)
// 创建S阴影元素 afterComplete: 0.5 // 倒计时完成后的延迟时间(秒)
const s_shadow = this.g_cartoon.createCartoonElement('s_shadow', 'MySprite'); },
s_shadow.ref.init(this.g_cartoon.images.get('s')); // 动画效果配置
s_shadow.ref.scaleX = this.g_mapScale; effect: {
s_shadow.ref.scaleY = this.g_mapScale; scaleRatio: 3, // 放大比例
s_shadow.ref.x = this.g_canvasWidth / 2 + 20 * this.g_mapScale; // 与原始S元素位置相同 finalAlpha: 0.5 // 最终透明度
s_shadow.ref.y = this.g_canvasHeight / 2; }
this.render(s_shadow.ref, zIndexMap.card + 1); // 放在原始VS元素下方 };
// 执行V阴影元素的动画:放大5倍,透明度为0,向左移动50
tweenChange(v_shadow.ref, {
scaleX: this.g_mapScale * 4,
scaleY: this.g_mapScale * 4,
alpha: 0.3,
x: v_shadow.ref.x - 50 * this.g_mapScale
}, 0.3, () => {
// 动画完成后移除元素
this.g_cartoon.cartoonElementsBuffer['v_shadow'].ref.visible = false;
});
// 执行S阴影元素的动画:放大5倍,透明度为0,向右移动50
tweenChange(s_shadow.ref, {
scaleX: this.g_mapScale * 4,
scaleY: this.g_mapScale * 4,
alpha: 0.3,
x: s_shadow.ref.x + 50 * this.g_mapScale
}, 0.3, () => {
// 动画完成后移除元素
this.g_cartoon.cartoonElementsBuffer['s_shadow'].ref.visible = false;
});
}
brokePaopaoAni(fish) {
// this.g_cartoon.playAudio('pop_bomb');
// 对于正确的鱼,显示泡泡破裂动画
// 按顺序切换序列帧 pao_pao_xu_lie_zhen_1 到 pao_pao_xu_lie_zhen_9
let currentFrame = 1;
const maxFrame = 9;
const frameInterval = 100; // 每帧间隔时间,可以根据需要调整
const playNextFrame = () => {
if (currentFrame <= maxFrame) {
// 设置当前帧的图像
fish['child_paopao_ani'].ref.init(this.g_cartoon.images.get(`pao_pao_xu_lie_zhen_${currentFrame}`));
currentFrame++;
// 设置下一帧的定时器
setTimeout(playNextFrame, frameInterval);
}
};
// 开始播放序列帧动画
playNextFrame();
// 正确的鱼不需要恢复运动,因为它们已经被处理了 // 初始化321倒计时视图,传递type参数
// 确保鱼保持停止状态 this.create321View(type);
fish.speed = 0;
// 隐藏所有倒计时元素(确保初始状态是隐藏的)
this.hide321Elements();
// 依次显示3、2、1的倒计时动画
// 先显示3
this.g_cartoon.playAudio('time_3');
this.showCountdownNumber('dao_ji_shi_3', config, () => {
this.g_cartoon.playAudio('time_2');
// 显示完3后显示2
this.showCountdownNumber('dao_ji_shi_2', config, () => {
this.g_cartoon.playAudio('time_1');
// 显示完2后显示1
this.showCountdownNumber('dao_ji_shi_1', config, () => {
// 倒计时结束后的操作,等待一段时间后显示VS动画
setTimeout(() => {
this.hideVsElements();
this.hide321Elements();
resolve(true);
}, config.time.afterComplete * 1000);
});
});
});
})
} }
/** /**
...@@ -1903,7 +1699,7 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -1903,7 +1699,7 @@ export class PlayComponent implements OnInit, OnDestroy {
playNextFrame(); playNextFrame();
} }
aniOpacity(fish) { aniOpacity(fish) {
// 使用alphaItem创建平滑的透明度变化动画 // 使用alphaItem创建平滑的透明度变化动画
const childNames = ['child_image', 'child_paopao_bg'] const childNames = ['child_image', 'child_paopao_bg']
...@@ -1926,6 +1722,33 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -1926,6 +1722,33 @@ export class PlayComponent implements OnInit, OnDestroy {
}) })
} }
brokePaopaoAni(fish) {
// this.g_cartoon.playAudio('pop_bomb');
// 对于正确的鱼,显示泡泡破裂动画
// 按顺序切换序列帧 pao_pao_xu_lie_zhen_1 到 pao_pao_xu_lie_zhen_9
let currentFrame = 1;
const maxFrame = 9;
const frameInterval = 100; // 每帧间隔时间,可以根据需要调整
const playNextFrame = () => {
if (currentFrame <= maxFrame) {
// 设置当前帧的图像
fish['child_paopao_ani'].ref.init(this.g_cartoon.images.get(`pao_pao_xu_lie_zhen_${currentFrame}`));
currentFrame++;
// 设置下一帧的定时器
setTimeout(playNextFrame, frameInterval);
}
};
// 开始播放序列帧动画
playNextFrame();
// 正确的鱼不需要恢复运动,因为它们已经被处理了
// 确保鱼保持停止状态
fish.speed = 0;
}
//----------------------------------------------------------------UI部分---------------------------------------------------------------- //----------------------------------------------------------------UI部分----------------------------------------------------------------
...@@ -2061,9 +1884,197 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -2061,9 +1884,197 @@ export class PlayComponent implements OnInit, OnDestroy {
/**
* 初始化VS视图,创建所有VS动画相关的元素
*/
createVsView() {
// 创建红色渐变面板 - 初始位置在屏幕左侧外
const hong_se_jian_bian = this.g_cartoon.createCartoonElement('hong_se_jian_bian', 'MySprite');
hong_se_jian_bian.ref.init(this.g_cartoon.images.get('hong_se_jian_bian'));
hong_se_jian_bian.ref.scaleX = this.g_mapScale;
hong_se_jian_bian.ref.scaleY = this.g_mapScale;
hong_se_jian_bian.ref.x = -400 * this.g_mapScale; // 初始位置在屏幕左侧外
hong_se_jian_bian.ref.y = this.g_canvasHeight / 2;
this.render(hong_se_jian_bian.ref, zIndexMap.card);
// 创建蓝色渐变面板 - 初始位置在屏幕右侧外
const lan_se_jian_bian = this.g_cartoon.createCartoonElement('lan_se_jian_bian', 'MySprite');
lan_se_jian_bian.ref.init(this.g_cartoon.images.get('lan_se_jian_bian'));
lan_se_jian_bian.ref.scaleX = this.g_mapScale;
lan_se_jian_bian.ref.scaleY = this.g_mapScale;
lan_se_jian_bian.ref.x = this.g_canvasWidth + 400 * this.g_mapScale; // 初始位置在屏幕右侧外
lan_se_jian_bian.ref.y = this.g_canvasHeight / 2;
this.render(lan_se_jian_bian.ref, zIndexMap.card);
const v_element = this.g_cartoon.createCartoonElement('v', 'MySprite');
v_element.ref.init(this.g_cartoon.images.get('v'));
v_element.ref.scaleX = this.g_mapScale;
v_element.ref.scaleY = this.g_mapScale;
v_element.ref.x = this.g_canvasWidth / 2 - 20 * this.g_mapScale;
v_element.ref.y = this.g_canvasHeight / 2;
this.render(v_element.ref, zIndexMap.card + 2);
const s_element = this.g_cartoon.createCartoonElement('s', 'MySprite');
s_element.ref.init(this.g_cartoon.images.get('s'));
s_element.ref.scaleX = this.g_mapScale;
s_element.ref.scaleY = this.g_mapScale;
s_element.ref.x = this.g_canvasWidth / 2 + 20 * this.g_mapScale;
s_element.ref.y = this.g_canvasHeight / 2;
this.render(s_element.ref, zIndexMap.card + 2);
// 创建其他VS动画元素
// 左侧元素:橘猫头和V
const ju_mao_tou = this.g_cartoon.createCartoonElement('ju_mao_tou', 'MySprite');
ju_mao_tou.ref.init(this.g_cartoon.images.get('ju_mao_tou'));
ju_mao_tou.ref.scaleX = this.g_mapScale;
ju_mao_tou.ref.scaleY = this.g_mapScale;
ju_mao_tou.ref.x = this.g_canvasWidth / 4;
ju_mao_tou.ref.y = this.g_canvasHeight / 2;
this.render(ju_mao_tou.ref, zIndexMap.card + 1);
// 右侧元素:灰猫头和S
const hui_mao_tou = this.g_cartoon.createCartoonElement('hui_mao_tou', 'MySprite');
hui_mao_tou.ref.init(this.g_cartoon.images.get('hui_mao_tou'));
hui_mao_tou.ref.scaleX = this.g_mapScale;
hui_mao_tou.ref.scaleY = this.g_mapScale;
hui_mao_tou.ref.x = this.g_canvasWidth * 3 / 4;
hui_mao_tou.ref.y = this.g_canvasHeight / 2;
this.render(hui_mao_tou.ref, zIndexMap.card + 1);
// 播放VS音效
this.g_cartoon.playAudio('vs');
}
/**
* 隐藏所有VS相关元素
*/
hideVsElements() {
// 隐藏红色渐变面板
const hong_se_jian_bian = this.g_cartoon.cartoonElementsBuffer['hong_se_jian_bian'];
if (hong_se_jian_bian && hong_se_jian_bian.ref) {
hong_se_jian_bian.ref.visible = false;
}
// 隐藏蓝色渐变面板
const lan_se_jian_bian = this.g_cartoon.cartoonElementsBuffer['lan_se_jian_bian'];
if (lan_se_jian_bian && lan_se_jian_bian.ref) {
lan_se_jian_bian.ref.visible = false;
}
// 隐藏其他VS元素
const vsElements = ['v', 's', 'ju_mao_tou', 'hui_mao_tou'];
vsElements.forEach(elementName => {
const element = this.g_cartoon.cartoonElementsBuffer[elementName];
if (element && element.ref) {
element.ref.visible = false;
}
});
}
/**
* 隐藏所有321倒计时相关元素
*/
hide321Elements() {
// 隐藏倒计时元素
const countdownElements = ['dao_ji_shi_3', 'dao_ji_shi_2', 'dao_ji_shi_1'];
countdownElements.forEach(elementName => {
const element = this.g_cartoon.cartoonElementsBuffer[elementName];
if (element && element.ref) {
element.ref.visible = false;
}
});
}
/**
* 初始化321倒计时视图
* 创建并初始化倒计时数字元素
*/
/**
* 初始化321倒计时视图
* @param type 游戏类型,'left'表示左侧猫开始玩,'right'表示右侧猫开始玩
*/
create321View(type: string = 'left') {
// 创建倒计时数字元素
const countdownElements = ['dao_ji_shi_3', 'dao_ji_shi_2', 'dao_ji_shi_1'];
// 根据type计算x坐标的偏移量
const xOffset = type === 'left' ? 140 : -190;
countdownElements.forEach(elementName => {
// 检查元素是否已存在
if (!this.g_cartoon.cartoonElementsBuffer[elementName]) {
// 创建元素
const element = this.g_cartoon.createCartoonElement(elementName, 'MySprite');
// 初始化元素
element.ref.init(this.g_cartoon.images.get(elementName));
// 设置元素缩放
element.ref.scaleX = this.g_mapScale;
element.ref.scaleY = this.g_mapScale;
// 设置元素位置(根据type调整画面中心的x坐标)
element.ref.x = this.g_canvasWidth / 2 + xOffset;
element.ref.y = this.g_canvasHeight / 2 + 60 * this.g_mapScale;
// 默认隐藏
element.ref.visible = false;
// 添加到渲染队列
this.render(element.ref, zIndexMap.card + 3);
} else {
// 如果元素已存在,更新其位置
const element = this.g_cartoon.cartoonElementsBuffer[elementName];
element.ref.x = this.g_canvasWidth / 2 + xOffset;
}
});
}
/**
* 显示VS阴影动画效果
* 在VS动画运动后的位置创建两个VS图标,并执行放大5倍、透明度为0的动画
* V字母向左移动50,S字母向右移动50,动画时间为0.1秒
*/
showVsShadow() {
// 创建V阴影元素
const v_shadow = this.g_cartoon.createCartoonElement('v_shadow', 'MySprite');
v_shadow.ref.init(this.g_cartoon.images.get('v'));
v_shadow.ref.scaleX = this.g_mapScale;
v_shadow.ref.scaleY = this.g_mapScale;
v_shadow.ref.x = this.g_canvasWidth / 2 - 20 * this.g_mapScale; // 与原始V元素位置相同
v_shadow.ref.y = this.g_canvasHeight / 2;
this.render(v_shadow.ref, zIndexMap.card + 1); // 放在原始VS元素下方
// 创建S阴影元素
const s_shadow = this.g_cartoon.createCartoonElement('s_shadow', 'MySprite');
s_shadow.ref.init(this.g_cartoon.images.get('s'));
s_shadow.ref.scaleX = this.g_mapScale;
s_shadow.ref.scaleY = this.g_mapScale;
s_shadow.ref.x = this.g_canvasWidth / 2 + 20 * this.g_mapScale; // 与原始S元素位置相同
s_shadow.ref.y = this.g_canvasHeight / 2;
this.render(s_shadow.ref, zIndexMap.card + 1); // 放在原始VS元素下方
// 执行V阴影元素的动画:放大5倍,透明度为0,向左移动50
tweenChange(v_shadow.ref, {
scaleX: this.g_mapScale * 4,
scaleY: this.g_mapScale * 4,
alpha: 0.3,
x: v_shadow.ref.x - 50 * this.g_mapScale
}, 0.3, () => {
// 动画完成后移除元素
this.g_cartoon.cartoonElementsBuffer['v_shadow'].ref.visible = false;
});
// 执行S阴影元素的动画:放大5倍,透明度为0,向右移动50
tweenChange(s_shadow.ref, {
scaleX: this.g_mapScale * 4,
scaleY: this.g_mapScale * 4,
alpha: 0.3,
x: s_shadow.ref.x + 50 * this.g_mapScale
}, 0.3, () => {
// 动画完成后移除元素
this.g_cartoon.cartoonElementsBuffer['s_shadow'].ref.visible = false;
});
}
......
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