Commit 8799433b authored by Tt's avatar Tt

feat(游戏组件): 添加发音按钮并优化游戏阶段逻辑

parent 7b63c40f
......@@ -47,12 +47,6 @@ export interface FormData {
questions: Question[];
/** 类型 */
type?: number;
/** 第一部分数据 */
part_1?: any[];
/** 第二部分数据 */
part_2?: any[];
/** 第三部分数据 */
part_3?: any[];
/** 数据数组(兼容旧版数据结构) */
dataArray?: any[];
}
......
......@@ -268,6 +268,9 @@ export class PlayComponent implements OnInit, OnDestroy {
this.initListPage();
this.initFishGame();
// 初始化发音按钮
this.initFaYinBtn();
// 初始化退出按钮
// this.initBtnBack();
// // 初始化标题
......@@ -484,6 +487,7 @@ export class PlayComponent implements OnInit, OnDestroy {
// 添加点击事件
this.m_mapDownQueue['check_btn'] = () => {
if (!this.layoutPage.ref.visible) return
// 播放点击音效
this.g_cartoon.playAudio('sm-click');
......@@ -773,6 +777,11 @@ export class PlayComponent implements OnInit, OnDestroy {
// 修改鱼的生成逻辑,使用当前阶段的随机问题列表
this.m_fishInterval = 3000; // 设置鱼的生成间隔为3秒
this.m_lastFishTime = 0; // 重置上次生成鱼的时间,使下一帧立即生成鱼
// 每一个stage开始的时候播放一次正确问题的音频
if (currentStage.correctQuestion && currentStage.correctQuestion.audio) {
this.g_cartoon.playAudio(currentStage.correctQuestion.audio);
}
}
initVsView() {
......@@ -1181,6 +1190,44 @@ export class PlayComponent implements OnInit, OnDestroy {
/**
* 初始化发音按钮
* 创建发音按钮并放置在右下角
*/
initFaYinBtn() {
// 创建发音按钮元素
const faYinBtn = this.g_cartoon.createCartoonElement('fa_yin_btn', 'MySprite');
// 初始化按钮图像,使用resources.js中的fa_yin资源
faYinBtn.ref.init(this.g_cartoon.images.get('fa_yin'));
// 设置按钮X方向和Y方向的缩放比例
faYinBtn.ref.scaleX = this.g_mapScale;
faYinBtn.ref.scaleY = this.g_mapScale;
// 获取按钮尺寸信息
const buttonWidth = 91 * this.g_mapScale; // fa_yin的宽度是91
const buttonHeight = 94 * this.g_mapScale; // fa_yin的高度是94
// 设置按钮位置 - 屏幕右下角
faYinBtn.ref.x = this.g_canvasWidth - buttonWidth / 2 - 50 * this.g_mapScale; // 距离右边50像素
faYinBtn.ref.y = this.g_canvasHeight - buttonHeight / 2 - 50 * this.g_mapScale; // 距离底部150像素,避免与其他按钮重叠
// 渲染按钮元素(使用较高的zIndex确保按钮显示在上层)
this.render(faYinBtn.ref, zIndexMap.card + 3);
// 为发音按钮添加点击事件
this.m_mapDownQueue['fa_yin_btn'] = () => {
this.g_enableMapDown = true;
// 如果当前有游戏阶段且有正确问题,播放其音频
const currentStage = this.gameStages[this.currentStageIndex];
console.log("btn_fa_yin", currentStage)
if (currentStage && currentStage.correctQuestion && currentStage.correctQuestion.audio) {
// 播放当前正确问题的音频
this.g_cartoon.playAudio(currentStage.correctQuestion.audio);
}
};
}
/**
* 初始化退出按钮
* 创建退出按钮并放置在标题背景的最左侧
......@@ -1456,33 +1503,11 @@ export class PlayComponent implements OnInit, OnDestroy {
return;
}
// 添加字母音频资源
// 处理part_1数据中的音频
if (contentObj.part_1 && contentObj.part_1.length > 0) {
contentObj.part_1.forEach(item => {
if (item.audio) {
this.g_cartoon.addAudio(item.audio, item.audio);
}
});
}
// 处理part_2数据中的音频
if (contentObj.part_2 && contentObj.part_2.length > 0) {
contentObj.part_2.forEach(item => {
if (item.audio) {
this.g_cartoon.addAudio(item.audio, item.audio);
}
});
}
// 处理part_3数据中的音频
if (contentObj.part_3 && contentObj.part_3.length > 0) {
contentObj.part_3.forEach(item => {
if (item.audio) {
this.g_cartoon.addAudio(item.audio, item.audio);
}
});
contentObj.questions.forEach(question => {
if (question.audio) {
this.g_cartoon.addAudio(question.audio, question.audio);
}
})
// 兼容旧版数据结构
const arr = contentObj.dataArray;
......
......@@ -7,6 +7,7 @@ const localImages = {
'bei_jing___jiao_shi': 'assets/game/bei_jing___jiao_shi.png',
'bei_jing': 'assets/game/bei_jing.jpg',
'chuan': 'assets/game/chuan.png',
'fa_yin': 'assets/game/fa_yin.png',
'fa_yin_an_niu': 'assets/game/fa_yin_an_niu.png',
'fa_yin_an_niu___fa_yin': 'assets/game/fa_yin_an_niu___fa_yin.png',
'fa_yin_an_niu___la_ba': 'assets/game/fa_yin_an_niu___la_ba.png',
......@@ -155,6 +156,7 @@ const localImagesSize = {
'bei_jing': { width: 1280, height: 720 },
'bei_jing___jiao_shi': { width: 1280, height: 173 },
'chuan': { width: 320, height: 77 },
'fa_yin': { width: 91, height: 94 },
'fa_yin_an_niu': { width: 91, height: 94 },
'fa_yin_an_niu___fa_yin': { width: 32, height: 38 },
'fa_yin_an_niu___la_ba': { width: 46, height: 46 },
......
1. 本局开始 播放音频
2. 点击鱼 正确 播放音频
3. 获取星星表示当前进度
......
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