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,71 +1288,12 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -1413,71 +1288,12 @@ 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;
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动画
* @param type 动画类型,'left' 或 'right'
*/
showVsAni(type: string) {
// 动画配置参数 // 动画配置参数
const config = { const config = {
// 面板动画配置 // 面板动画配置
...@@ -1539,7 +1355,7 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -1539,7 +1355,7 @@ export class PlayComponent implements OnInit, OnDestroy {
}; };
// 初始化VS视图 // 初始化VS视图
this.initVsView(); this.createVsView();
// 获取红色和蓝色渐变面板元素 // 获取红色和蓝色渐变面板元素
const hong_se_jian_bian = this.g_cartoon.cartoonElementsBuffer['hong_se_jian_bian'].ref; const hong_se_jian_bian = this.g_cartoon.cartoonElementsBuffer['hong_se_jian_bian'].ref;
...@@ -1648,84 +1464,64 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -1648,84 +1464,64 @@ export class PlayComponent implements OnInit, OnDestroy {
); );
} }
setTimeout(() => { setTimeout(() => {
this.show321(type); resolve();
}, 1000); }, 1000);
}, config.vs.v.moveTime * 1000 + 500); }, config.vs.v.moveTime * 1000 + 500);
}, config.common.vsAnimDelay); }, 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;
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;
});
}
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) { const config = {
// 设置当前帧的图像 // 动画时间配置
fish['child_paopao_ani'].ref.init(this.g_cartoon.images.get(`pao_pao_xu_lie_zhen_${currentFrame}`)); time: {
currentFrame++; displayDuration: 0.7, // 数字显示停留时间(秒)
// 设置下一帧的定时器 animDuration: 0.3, // 动画持续时间(秒)
setTimeout(playNextFrame, frameInterval); interval: 0, // 数字切换间隔时间(秒)
afterComplete: 0.5 // 倒计时完成后的延迟时间(秒)
},
// 动画效果配置
effect: {
scaleRatio: 3, // 放大比例
finalAlpha: 0.5 // 最终透明度
} }
}; };
// 开始播放序列帧动画 // 初始化321倒计时视图,传递type参数
playNextFrame(); this.create321View(type);
// 正确的鱼不需要恢复运动,因为它们已经被处理了 // 隐藏所有倒计时元素(确保初始状态是隐藏的)
// 确保鱼保持停止状态 this.hide321Elements();
fish.speed = 0;
// 依次显示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);
});
});
});
})
} }
/** /**
...@@ -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