Commit 40327941 authored by Tt's avatar Tt

小鱼错误已完成

parent 8799433b
...@@ -24,7 +24,8 @@ import { ...@@ -24,7 +24,8 @@ import {
showItem, showItem,
ShapeRectNew, ShapeRectNew,
scaleItem, scaleItem,
showBlingBling showBlingBling,
alphaItem
} from "./Unit"; } from "./Unit";
import { localImages, localAudios, localImagesSize } from "./resources"; import { localImages, localAudios, localImagesSize } from "./resources";
...@@ -777,7 +778,7 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -777,7 +778,7 @@ export class PlayComponent implements OnInit, OnDestroy {
// 修改鱼的生成逻辑,使用当前阶段的随机问题列表 // 修改鱼的生成逻辑,使用当前阶段的随机问题列表
this.m_fishInterval = 3000; // 设置鱼的生成间隔为3秒 this.m_fishInterval = 3000; // 设置鱼的生成间隔为3秒
this.m_lastFishTime = 0; // 重置上次生成鱼的时间,使下一帧立即生成鱼 this.m_lastFishTime = 0; // 重置上次生成鱼的时间,使下一帧立即生成鱼
// 每一个stage开始的时候播放一次正确问题的音频 // 每一个stage开始的时候播放一次正确问题的音频
if (currentStage.correctQuestion && currentStage.correctQuestion.audio) { if (currentStage.correctQuestion && currentStage.correctQuestion.audio) {
this.g_cartoon.playAudio(currentStage.correctQuestion.audio); this.g_cartoon.playAudio(currentStage.correctQuestion.audio);
...@@ -1067,76 +1068,127 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -1067,76 +1068,127 @@ export class PlayComponent implements OnInit, OnDestroy {
* @param fish 被点击的鱼对象 * @param fish 被点击的鱼对象
*/ */
brokePaopao(fish) { brokePaopao(fish) {
// 隐藏泡泡背景、小鱼和图片
fish['child_paopao_bg'].ref.visible = false;
fish['child_xiao_yu'].ref.visible = false;
fish['child_image'].ref.visible = false;
fish['child_paopao_ani'].ref.visible = true;
// 创建飞向水桶的小鱼动画
this.createFlyingFish(fish);
// 获取当前游戏阶段 // 获取当前游戏阶段
const currentStage = this.gameStages[this.currentStageIndex]; const currentStage = this.gameStages[this.currentStageIndex];
// 存储用户点击的鱼的数据 // 检查是否点击了正确的鱼
if (fish.questionData) { const isCorrect = fish.questionData &&
this.clickedFishData.push(fish.questionData); fish.questionData.audio === currentStage.correctQuestion.audio &&
fish.questionData.image === currentStage.correctQuestion.image;
// 检查是否点击了正确的鱼 console.log('Clicked fish data:', fish.questionData);
const isCorrect = fish.questionData.audio === currentStage.correctQuestion.audio && console.log('Is correct:', isCorrect);
fish.questionData.image === currentStage.correctQuestion.image;
console.log('Clicked fish data:', fish.questionData); // 保存鱼的原始速度,用于后续恢复
console.log('Is correct:', isCorrect); const originalSpeed = fish.speed || 0.3;
console.log('Clicked fish count:', this.clickedFishData.length); // 点击后立即停止鱼的运动
fish.speed = 0;
// 计算正确点击的次数 if (isCorrect) {
const correctClicks = this.clickedFishData.filter(data => // 正确小鱼的处理逻辑
data.audio === currentStage.correctQuestion.audio && // 隐藏泡泡背景、小鱼和图片
data.image === currentStage.correctQuestion.image fish['child_paopao_bg'].ref.visible = false;
).length; fish['child_xiao_yu'].ref.visible = false;
fish['child_image'].ref.visible = false;
fish['child_paopao_ani'].ref.visible = true;
console.log('Correct clicks:', correctClicks); // 创建飞向水桶的小鱼动画
this.createFlyingFish(fish);
// 如果有两个数据为当前Stage的正确数据,则清空画面,等待1秒后进入下一轮游戏 // 存储用户点击的鱼的数据
if (correctClicks >= 2) { if (fish.questionData) {
console.log('Stage completed! Moving to next stage...'); this.clickedFishData.push(fish.questionData);
// 清空画面(清除所有鱼) console.log('Clicked fish count:', this.clickedFishData.length);
this.clearFishes();
// 增加当前阶段索引 // 计算正确点击的次数
this.currentStageIndex++; const correctClicks = this.clickedFishData.filter(data =>
data.audio === currentStage.correctQuestion.audio &&
data.image === currentStage.correctQuestion.image
).length;
// 等待1秒后进入下一轮游戏 console.log('Correct clicks:', correctClicks);
setTimeout(() => {
this.initNextStage(); // 如果有两个数据为当前Stage的正确数据,则清空画面,等待1秒后进入下一轮游戏
}, 1000); if (correctClicks >= 2) {
console.log('Stage completed! Moving to next stage...');
// 清空画面(清除所有鱼)
this.clearFishes();
// 增加当前阶段索引
this.currentStageIndex++;
// 等待1秒后进入下一轮游戏
setTimeout(() => {
this.initNextStage();
}, 1000);
}
} }
} else {
// 错误小鱼的处理逻辑
// 播放错误音效
this.g_cartoon.playAudio('click_wrong');
this.aniOpacity(fish);
// 1秒后恢复鱼的运动
setTimeout(() => {
fish.speed = originalSpeed;
}, 1000);
} }
// 按顺序切换序列帧 pao_pao_xu_lie_zhen_1 到 pao_pao_xu_lie_zhen_9 // 对于正确的鱼,显示泡泡破裂动画
let currentFrame = 1; if (isCorrect) {
const maxFrame = 9; // 按顺序切换序列帧 pao_pao_xu_lie_zhen_1 到 pao_pao_xu_lie_zhen_9
const frameInterval = 100; // 每帧间隔时间,可以根据需要调整 let currentFrame = 1;
const maxFrame = 9;
const playNextFrame = () => { const frameInterval = 100; // 每帧间隔时间,可以根据需要调整
if (currentFrame <= maxFrame) {
// 设置当前帧的图像 const playNextFrame = () => {
fish['child_paopao_ani'].ref.init(this.g_cartoon.images.get(`pao_pao_xu_lie_zhen_${currentFrame}`)); if (currentFrame <= maxFrame) {
currentFrame++; // 设置当前帧的图像
// 设置下一帧的定时器 fish['child_paopao_ani'].ref.init(this.g_cartoon.images.get(`pao_pao_xu_lie_zhen_${currentFrame}`));
setTimeout(playNextFrame, frameInterval); currentFrame++;
} // 设置下一帧的定时器
}; setTimeout(playNextFrame, frameInterval);
}
};
// 开始播放序列帧动画 // 开始播放序列帧动画
playNextFrame(); playNextFrame();
// 正确的鱼不需要恢复运动,因为它们已经被处理了
// 确保鱼保持停止状态
fish.speed = 0;
}
return fish; return fish;
} }
aniOpacity(fish) {
// 使用alphaItem创建平滑的透明度变化动画
const childNames = ['child_image', 'child_paopao_bg']
childNames.forEach(childName => {
// 先变为半透明
alphaItem(fish[childName].ref, 0.5, 0.1, () => {
// 0.5秒后恢复原始透明度,使用0.3秒的动画时间
setTimeout(() => {
alphaItem(fish[childName].ref, 1, 0.1);
setTimeout(() => {
alphaItem(fish[childName].ref, 0.5, 0.1, () => {
// 0.5秒后恢复原始透明度,使用0.1秒的动画时间
setTimeout(() => {
alphaItem(fish[childName].ref, 1, 0.1);
}, 100);
});
}, 100);
}, 100);
});
})
}
/** /**
* 创建临时小鱼并飞向水桶 * 创建临时小鱼并飞向水桶
* @param fish 原始鱼对象 * @param fish 原始鱼对象
......
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