Commit b659e3a4 authored by Tt's avatar Tt

游戏基础调整

parent 79617c0a
......@@ -7199,7 +7199,7 @@
"__id__": 156
}
],
"_active": false,
"_active": true,
"_components": [
{
"__id__": 158
......@@ -7379,13 +7379,13 @@
},
{
"__type__": "cc.Node",
"_name": "Comeon",
"_name": "ani_comeon",
"_objFlags": 0,
"_parent": {
"__id__": 146
},
"_children": [],
"_active": true,
"_active": false,
"_components": [
{
"__id__": 151
......@@ -7481,13 +7481,13 @@
},
{
"__type__": "cc.Node",
"_name": "Excellent",
"_name": "ani_excellent",
"_objFlags": 0,
"_parent": {
"__id__": 146
},
"_children": [],
"_active": true,
"_active": false,
"_components": [
{
"__id__": 153
......@@ -7583,13 +7583,13 @@
},
{
"__type__": "cc.Node",
"_name": "Nice",
"_name": "ani_nice",
"_objFlags": 0,
"_parent": {
"__id__": 146
},
"_children": [],
"_active": true,
"_active": false,
"_components": [
{
"__id__": 155
......@@ -7685,13 +7685,13 @@
},
{
"__type__": "cc.Node",
"_name": "Tryagain",
"_name": "ani_tryagain",
"_objFlags": 0,
"_parent": {
"__id__": 146
},
"_children": [],
"_active": true,
"_active": false,
"_components": [
{
"__id__": 157
......@@ -7721,7 +7721,7 @@
"ctor": "Float64Array",
"array": [
0,
-254,
-225.221,
0,
0,
0,
......@@ -7759,7 +7759,7 @@
}
],
"_armatureName": "armatureName",
"_animationName": "",
"_animationName": "结算",
"_preCacheMode": 0,
"_cacheMode": 0,
"playTimes": -1,
......@@ -7778,7 +7778,7 @@
"__uuid__": "94fe694d-23eb-4878-911f-699e779e09f8"
},
"_N$_defaultArmatureIndex": 0,
"_N$_animationIndex": 0,
"_N$_animationIndex": 1,
"_N$_defaultCacheMode": 0,
"_N$timeScale": 1,
"_N$debugBones": false,
......@@ -9689,7 +9689,6 @@
"btn_audio_on": {
"__id__": 94
},
"bg_countdown": null,
"layout_card": {
"__id__": 97
},
......
......@@ -47,9 +47,10 @@ let courseware = win.courseware;
* 提示状态枚举
*/
enum TIPS_STATE {
GOOD = 1, // 好的提示
TRY, // 再试一次提示
COM, // 完成提示
TRYAGAIN = 1, // 再试一次提示 (0星,10分以下)
COMEON, // 加油提示 (1星,60分以下)
NICE, // 不错提示 (2星,80分以下)
EXCELLENT, // 优秀提示 (3星,80分及以上)
}
/**
* 场景组件类
......@@ -127,9 +128,6 @@ export default class SceneComponent extends MyCocosSceneComponent {
/** 音频开启按钮 */
@property(cc.Node)
btn_audio_on: cc.Node = null;
/** 倒计时背景节点 */
@property(cc.Node)
bg_countdown: cc.Node = null;
/** 卡片布局节点 */
@property(cc.Node)
layout_card: cc.Node = null;
......@@ -224,7 +222,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.layout_speak.active = false;
this.layout_tip.active = false;
// 显示问题
this.showPage();
......@@ -405,24 +403,20 @@ export default class SceneComponent extends MyCocosSceneComponent {
* @param e 事件对象或包含target属性的模拟事件对象
*/
private currentFireNode;
onTouchFireNode(e) {
async onTouchFireNode(e) {
const fireNode = e.target;
// 保存触摸数据
this.touchData = fireNode.data;
this.touchData.parent = fireNode;
this.currentFireNode = fireNode;
// 1. 播放node_firetruck_flush动画(喷水)
this.node_firetruck_flush.active = true;
pg.view.addDBAnimationCallback(this.node_firetruck_flush, () => {
// 切换到持续喷水动画
pg.view.addDBAnimationCallback(this.node_firetruck_flush, null)
pg.view.playDBAnimation(this.node_firetruck_flush, '持续喷水', 1);
this.showCard();
})
pg.view.playDBAnimation(this.node_firetruck_flush, '喷水', 1);
await pg.time.delay(2);
pg.view.playDBAnimation(this.node_firetruck_flush, '持续喷水', 1);
await pg.time.delay(1);
this.showCard(false, 'init');
}
onFireSuccess() {
......@@ -452,11 +446,10 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.log(`找不到节点: water_${fireIndex}`);
}
pg.view.addDBAnimationCallback(this.node_firetruck_flush, () => {
pg.view.addDBAnimationCallback(this.node_firetruck_flush, null)
this.node_firetruck_flush.active = false;
})
pg.view.playDBAnimation(this.node_firetruck_flush, '收水', 1);
setTimeout(() => {
this.node_firetruck_flush.active = false;
}, 2000);
this.touching = false;
// 检查当前页面是否所有火苗都已处理完毕
......@@ -487,7 +480,16 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.showPage();
}
showCard(hide: boolean = false) {
/**
* 显示或隐藏录音卡片
* 根据录音状态动态显示不同的按钮:
* - 未录制:显示 btn_start
* - 录制中:显示 btn_stop
* - 录制完成:显示 btn_record_replay 和 btn_start_reset
* @param hide 是否隐藏卡片,默认为false(显示)
* @param recordState 录音状态,可选值:'init'(初始状态), 'recording'(录制中), 'recorded'(录制完成)
*/
showCard(hide: boolean = false, recordState: string = 'init') {
if (!hide) {
// 显示卡片
const currentData = this.currentFireNode.data;
......@@ -509,9 +511,32 @@ export default class SceneComponent extends MyCocosSceneComponent {
pg.view.touchOn(btn_stop, this.onTouchRecordEnd, this);
pg.view.touchOn(btn_record_replay, this.onTouchPlayRecord, this);
// 显示开始按钮,隐藏停止按钮
// 根据录音状态显示不同的按钮
switch (recordState) {
case 'init': // 初始状态,未录制
btn_start.active = true;
btn_stop.active = false;
btn_start_reset.active = false;
btn_record_replay.active = false;
break;
case 'recording': // 录制中
btn_start.active = false;
btn_stop.active = true;
btn_start_reset.active = false;
btn_record_replay.active = false;
break;
case 'recorded': // 录制完成
btn_start.active = false;
btn_stop.active = false;
btn_start_reset.active = true;
btn_record_replay.active = true;
break;
default: // 默认显示初始状态
btn_start.active = true;
btn_stop.active = false;
btn_start_reset.active = false;
btn_record_replay.active = false;
}
} else {
// 隐藏录音界面
this.layout_speak.active = false;
......@@ -527,47 +552,6 @@ export default class SceneComponent extends MyCocosSceneComponent {
update(dt) {
// 只在游戏运行状态下更新
if (Game.getIns().state != GAME_STATE.RUNNING) return;
// 倒计时不显示时不更新
if (!this.bg_countdown || !this.bg_countdown.active) return;
// 获取时间显示节点
let time = cc.find("time", this.bg_countdown);
let time2 = cc.find("time2", this.bg_countdown);
if (!time || !time2) return;
// 倒计时结束处理
if (this.countDown <= 0) {
this.onTouchRecordEnd();
this.bg_countdown.active = false;
cc.Tween.stopAllByTarget(time2)
return;
}
// 更新倒计时时间
this.countDown = this.countDown - dt;
// 倒计时小于6秒时的特殊显示
if (this.countDown < 6) {
let count = Math.floor(this.countDown);
time.active = false;
time2.active = true;
time2.getComponent(cc.Label).string = "" + parseInt("" + this.countDown);
// 当秒数变化时播放缩放动画
if (count != this.timeCount) {
this.timeCount = count;
cc.tween(time2)
.to(0.3, { scale: 1.1 })
.to(0.3, { scale: 1 })
.to(0.3, { scale: 0.9 })
.start()
}
} else {
time2.active = false;
time.active = true;
time.getComponent(cc.Label).string = "" + parseInt("" + this.countDown);
}
}
......@@ -580,19 +564,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 停止背景音乐
this.stopBgAudio();
// 获取UI元素
let ske = pg.view.find(this.layout_speak, 'speak_ske');
let btn_start = pg.view.find(this.layout_speak, 'btn_start');
let btn_stop = pg.view.find(this.layout_speak, 'btn_stop');
// 更新按钮状态
btn_start.active = false;
btn_stop.active = true;
// 设置动画速度
ske.getComponent(dragonBones.ArmatureDisplay).timeScale = 1;
// 使用更新后的showCard方法,传入'recording'状态
this.showCard(false, 'recording');
// 显示倒计时并设置时间
this.bg_countdown.active = true;
this.countDown = this.startCount;
this.countDown = this.touchData.time || this.startCount; //使用问题指定的时间或默认时间
......@@ -601,41 +575,15 @@ export default class SceneComponent extends MyCocosSceneComponent {
}
/**
* 结束录音按钮点击处理
* 停止倒计时,隐藏按钮,结束录音
* 停止倒计时,显示播放和重新录制按钮,结束录音
*/
private onTouchRecordEnd() {
// 获取UI元素
let ske = pg.view.find(this.layout_speak, 'speak_ske');
let btn_start = pg.view.find(this.layout_speak, 'btn_start');
let btn_stop = pg.view.find(this.layout_speak, 'btn_stop');
// 播放动画并设置极快的速度(实际上是为了立即结束动画)
pg.view.playDBAnimation(ske, 'newAnimation', 1);
ske.getComponent(dragonBones.ArmatureDisplay).timeScale = 10000;
// 隐藏所有按钮
btn_stop.active = false;
btn_start.active = false;
// 使用更新后的showCard方法,传入'recorded'状态
this.showCard(false, 'recorded');
// 隐藏倒计时并设置一个很大的值防止倒计时继续
this.bg_countdown.active = false;
this.countDown = 999999;
// 停止喷水动画
if (this.node_firetruck_flush && this.node_firetruck_flush.active) {
// 停止持续喷水动画,切换回待机状态
pg.view.playDBAnimation(this.node_firetruck_flush, '喷水', 1);
let flushDisplay = this.node_firetruck_flush.getComponent(dragonBones.ArmatureDisplay);
if (flushDisplay) {
flushDisplay.timeScale = 10; // 快速播放完成动画
flushDisplay.addEventListener(dragonBones.EventObject.COMPLETE, () => {
this.node_firetruck_flush.active = false;
// 恢复消防车待机动画
pg.view.playDBAnimation(this.node_firetruck_anim, '待机', -1);
}, this);
}
}
let testData = {
"audioUrl": "https://staging-teach.cdn.ireadabc.com/a8ea7bb153a46941e6f28b7d0dda49f4.mp3",
"eof": 1,
......@@ -742,11 +690,25 @@ export default class SceneComponent extends MyCocosSceneComponent {
let isSuccess = this.checkWords(data);
this.log("data: " + JSON.stringify(data));
// 评分达标且单词正确
if (score >= 70 && isSuccess) {
// 根据评分和单词正确性显示不同的提示
if (isSuccess) {
this.recordTouching = false;
// 显示成功提示
this.updateTips(TIPS_STATE.GOOD);
// 根据分数区间显示不同的提示
if (score >= 80) {
// 80分及以上,显示优秀提示(3星)
this.updateTips(TIPS_STATE.EXCELLENT);
} else if (score >= 60) {
// 60-80分,显示不错提示(2星)
this.updateTips(TIPS_STATE.NICE);
} else if (score >= 10) {
// 10-60分,显示加油提示(1星)
this.updateTips(TIPS_STATE.COMEON);
} else {
// 10分以下,显示再试一次提示(0星)
this.updateTips(TIPS_STATE.TRYAGAIN);
}
// 增加正确计数
Game.getIns().player.addRight();
this.tryAgain = false;
......@@ -760,13 +722,17 @@ export default class SceneComponent extends MyCocosSceneComponent {
await pg.time.delay(3);
this.showCard(true);
this.updateTips(null);
this.nextEgg();
if (score >= 10) {
this.onFireSuccess();
} else {
this.onFireFail();
}
return;
} else {
// 评分未达标或单词不正确
// 单词不正确
if (this.tryData.some(td => td.id == this.touchData.id)) {
// 已经尝试过的题目,显示完成提示
this.updateTips(TIPS_STATE.COM);
// 已经尝试过的题目,显示加油提示
this.updateTips(TIPS_STATE.COMEON);
if (this.tryAgain) {
// 第二次尝试后,无论结果如何都进入下一题
......@@ -781,12 +747,12 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.showCard(true);
this.updateTips(null);
this.recordTouching = false;
this.nextEgg();
this.onFireFail();
return;
}
} else {
// 首次尝试失败,显示再试一次提示
this.updateTips(TIPS_STATE.TRY);
this.updateTips(TIPS_STATE.TRYAGAIN);
this.tryData.push(this.touchData);
this.tryAgain = true;
......@@ -803,8 +769,8 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 根据是否需要再次尝试决定显示卡片或进入下一题
if (this.tryAgain) {
// 需要再次尝试,显示卡片和录音界面
this.showCard()
// 需要再次尝试,显示卡片和录音界面,重置为初始状态
this.showCard(false, 'init')
} else {
// 不需要再次尝试,隐藏卡片和录音界面
this.showCard(true)
......@@ -828,113 +794,36 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.layout_tip.active = true;
// 获取所有提示图标
let img_co = pg.view.find(this.layout_tip, 'img_co'); // 完成提示
let img_gj = pg.view.find(this.layout_tip, 'img_gj'); // 很棒提示
let img_ta = pg.view.find(this.layout_tip, 'img_ta'); // 再试一次提示
// 先隐藏所有图标
img_co.active = false;
img_gj.active = false;
img_ta.active = false;
// 根据状态选择要显示的图标和光效
let img = null;
let img_light = null;
let ani_tryagain = pg.view.find(this.layout_tip, 'ani_tryagain'); // 完成提示
let ani_comeon = pg.view.find(this.layout_tip, 'ani_comeon'); // 完成提示
let ani_nice = pg.view.find(this.layout_tip, 'ani_nice'); // 完成提示
let ani_excellent = pg.view.find(this.layout_tip, 'ani_excellent'); // 完成提示
ani_tryagain.active = false;
ani_comeon.active = false;
ani_nice.active = false;
ani_excellent.active = false;
switch (state) {
case TIPS_STATE.COM: // 完成
img = img_co;
img_light = cc.find("bg_light", img_co);
this.playLocalAudio("co"); // 播放完成音效
case TIPS_STATE.TRYAGAIN: // 再试一次(0星,10分以下)
ani_tryagain.active = true;
pg.view.playDBAnimation(ani_tryagain, '结算', 1);
break;
case TIPS_STATE.GOOD: // 很棒
img = img_gj;
this.playLocalAudio("gj"); // 播放很棒音效
img_light = cc.find("bg_light", img_gj);
case TIPS_STATE.COMEON: // 加油(1星,60分以下)
ani_comeon.active = true;
pg.view.playDBAnimation(ani_comeon, '结算', 1);
break;
case TIPS_STATE.TRY: // 再试一次
img = img_ta;
this.playLocalAudio("ta"); // 播放再试一次音效
img_light = cc.find("bg_light", img_ta);
case TIPS_STATE.NICE: // 不错(2星,80分以下)
ani_nice.active = true;
pg.view.playDBAnimation(ani_nice, '结算', 1);
break;
case TIPS_STATE.EXCELLENT: // 优秀(3星,80分及以上)
ani_excellent.active = true;
pg.view.playDBAnimation(ani_excellent, '结算', 1);
break;
}
// 设置初始缩放为0并显示
img.scale = 0;
img.active = true;
// 停止之前的动画并激活光效
cc.Tween.stopAllByTarget(img_light)
img_light.active = true;
// 创建光效旋转动画
cc.tween(img_light).repeatForever(cc.tween().by(5, { angle: 360 })).start();
// 创建图标缩放动画,延迟后自动隐藏
cc.tween(img).to(0.5, { scale: 1 }).delay(2).call(() => {
cc.Tween.stopAllByTarget(img_light)
this.layout_tip.active = false;
}).start();
}
/**
* 处理下一个蛋壳的显示
* 如果还有问题,重置当前蛋壳并显示新问题
* 如果没有问题了,检查游戏是否结束
*/
private nextEgg() {
// 获取下一个问题数据
let eggInfo = Game.getIns().getCardInfo();
if (eggInfo) {
// 还有问题,重置当前蛋壳
let egg = this.touchData.parent;
let di = cc.find("di", egg);
let intact = cc.find("intact", egg);
let broken = cc.find("broken", egg);
// 恢复蛋壳完整状态
di.active = false;
broken.active = false;
intact.active = true;
// 设置新的问题数据
egg.data = eggInfo;
// 将重置的火苗节点添加回活跃列表
if (!this.activeFireNodes.includes(egg)) {
this.activeFireNodes.push(egg);
}
} else {
// 没有问题了,隐藏当前蛋壳
this.touchData.parent.active = false;
// 检查是否所有蛋壳都已处理完毕
// if (this.checkIsOver()) {
// this.gameOver();
// }
}
// 恢复背景音乐
this.playBgAudio();
}
/**
* 为蛋壳添加箭头上下移动动画
* @param target 目标蛋壳节点
*/
private eggArrowAction(target) {
// 获取箭头节点
let icon_arrow = cc.find("icon_arrow", target);
if (!icon_arrow) return;
// 显示箭头并创建上下移动的循环动画
icon_arrow.active = true;
cc.tween(icon_arrow).repeatForever(
cc.tween().to(0.5, { y: 180 }).to(0.5, { y: 220 })
).start();
}
/**
* 检查录音单词的正确性
......
......@@ -619,6 +619,38 @@ let pg = {
return skl;
},
/**
* 为DragonBones动画添加一次性的动画完成回调事件,回调触发一次后自动移除
* @param {cc.Node|cc.Component} item - 包含DragonBones组件的节点或组件
* @returns {dragonBones.ArmatureDisplay} DragonBones骨骼组件
*/
addDBAnimationCallbackOnce(item, callback) {
if (!item || !cc.isValid(item)) return pg.logger.w("添加一次性动画回调失败,传入了错误的item");
if (!callback) return pg.logger.w("添加一次性动画回调失败,未传入回调函数");
let node = item.node ? item.node : item;
if (!cc.isValid(node)) return pg.logger.w("节点已销毁");
let skl: dragonBones.ArmatureDisplay = node.getComponent(dragonBones.ArmatureDisplay);
if (!skl) return pg.logger.w("节点上没有DragonBones组件");
// 创建一个包装回调,在执行原始回调后自动移除监听器
const onceCallback = (event) => {
// 先移除监听器,防止回调中可能的异常导致监听器未被移除
skl.removeEventListener(dragonBones.EventObject.COMPLETE);
// 执行原始回调
callback(event);
};
// 移除之前可能存在的监听器,避免重复添加
skl.removeEventListener(dragonBones.EventObject.COMPLETE, onceCallback);
// 添加一次性动画完成事件监听
skl.addEventListener(dragonBones.EventObject.COMPLETE, onceCallback);
return skl;
},
/**
* 设置DragonBones动画的播放速度
* @param {cc.Node|cc.Component} item - 包含DragonBones组件的节点或组件
......
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