Commit 71f00d52 authored by Tt's avatar Tt

页面点击增加

parent ebca1c4b
...@@ -1623,9 +1623,6 @@ ...@@ -1623,9 +1623,6 @@
}, },
{ {
"__id__": 71 "__id__": 71
},
{
"__id__": 76
} }
], ],
"_active": true, "_active": true,
...@@ -3533,6 +3530,9 @@ ...@@ -3533,6 +3530,9 @@
}, },
{ {
"__id__": 74 "__id__": 74
},
{
"__id__": 76
} }
], ],
"_active": true, "_active": true,
...@@ -3794,7 +3794,7 @@ ...@@ -3794,7 +3794,7 @@
"_name": "btn_finger", "_name": "btn_finger",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 34 "__id__": 71
}, },
"_children": [], "_children": [],
"_active": true, "_active": true,
...@@ -3826,8 +3826,8 @@ ...@@ -3826,8 +3826,8 @@
"__type__": "TypedArray", "__type__": "TypedArray",
"ctor": "Float64Array", "ctor": "Float64Array",
"array": [ "array": [
-476.036, -57.526,
-212.486, 315.152,
0, 0,
0, 0,
0, 0,
...@@ -9313,6 +9313,12 @@ ...@@ -9313,6 +9313,12 @@
"btn_finger": { "btn_finger": {
"__id__": 76 "__id__": 76
}, },
"page_a": {
"__id__": 35
},
"page_b": {
"__id__": 53
},
"_id": "db3L+4L+FH/5MIRcKcfiq+" "_id": "db3L+4L+FH/5MIRcKcfiq+"
} }
] ]
\ No newline at end of file
...@@ -139,6 +139,8 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -139,6 +139,8 @@ export default class SceneComponent extends MyCocosSceneComponent {
@property({ displayName: "消防车动画节点", type: cc.Node }) node_firetruck_anim: cc.Node = null; @property({ displayName: "消防车动画节点", type: cc.Node }) node_firetruck_anim: cc.Node = null;
@property({ displayName: "消防车冲水动画节点", type: cc.Node }) node_firetruck_flush: cc.Node = null; @property({ displayName: "消防车冲水动画节点", type: cc.Node }) node_firetruck_flush: cc.Node = null;
@property({ displayName: "提示手指节点", type: cc.Node }) btn_finger: cc.Node = null; @property({ displayName: "提示手指节点", type: cc.Node }) btn_finger: cc.Node = null;
@property({ displayName: "页面a", type: cc.Node }) page_a: cc.Node = null;
@property({ displayName: "页面b", type: cc.Node }) page_b: cc.Node = null;
// 游戏数据相关变量 // 游戏数据相关变量
/** 当前触摸的选项数据 */ /** 当前触摸的选项数据 */
...@@ -208,7 +210,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -208,7 +210,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
pg.audio.playBgAudioByUrl(Game.getIns().bgAudio); pg.audio.playBgAudioByUrl(Game.getIns().bgAudio);
// 显示问题 // 显示问题
this.showQuestions(); this.showPage();
this.aniCarEnter(); this.aniCarEnter();
} }
...@@ -249,81 +251,81 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -249,81 +251,81 @@ export default class SceneComponent extends MyCocosSceneComponent {
.start(); .start();
} }
/** /**
* 显示问题选项 * 显示当前页面
* 创建并显示蛋壳,添加点击事件 * 根据当前页码决定使用page_a还是page_b
* 并设置fire_0到fire_5这6个交互点
*/ */
private showQuestions() { showPage() {
return; // 获取当前页码
// 获取当前页的数据 const currentPage = Game.getIns().getCurrentPageNum();
const pageData = Game.getIns().getPageData();
// 获取问题数量
let len = pageData.length;
// 最多显示4个选项
let count = len >= 4 ? 4 : len;
// 创建每个蛋壳
for (let i = 0; i < count; i++) {
// 获取问题数据
let eggData = pageData[i];
// 获取蛋壳节点
let egg = cc.find("layout_egg/egg" + i, this.layout_game);
// 设置数据和显示状态
egg.data = eggData;
egg.active = true;
// 添加点击事件
egg.on(cc.Node.EventType.TOUCH_END, () => {
// 停止箭头动画
this.stopArrowAction();
// 播放锤子动画
this.hammerAction(egg.getPosition()).then(async () => {
// 获取蛋壳的各个部分
let di = cc.find("di", egg);
let intact = cc.find("intact", egg);
let broken = cc.find("broken", egg);
// 显示底部,隐藏完整蛋壳 // 根据页码的奇偶性决定使用哪个页面
di.active = true; // 偶数页使用page_a,奇数页使用page_b
intact.active = false; const currentPageNode = currentPage % 2 === 0 ? this.page_a : this.page_b;
const otherPageNode = currentPage % 2 === 0 ? this.page_b : this.page_a;
// 保存当前选中的数据 // 显示当前页面,隐藏另一个页面
this.touchData = egg.data; currentPageNode.active = true;
this.touchData.parent = egg; otherPageNode.active = false;
// 延迟显示卡片 // 获取当前页的数据
await pg.time.delay(0.7); const pageData = Game.getIns().getPageData();
// 遍历fire_0到fire_5这6个交互点
for (let i = 0; i < 6; i++) {
// 查找当前页面下的fire节点
const fireNode = cc.find(`fire_${i}`, currentPageNode);
if (!fireNode) {
this.log(`找不到节点: fire_${i}`);
continue;
}
// 设置节点可见性
if (i < pageData.length) {
// 有数据,显示节点
fireNode.active = true;
// 保存题目数据到节点
fireNode.data = pageData[i];
// 查找并设置完整蛋壳可见,破碎蛋壳不可见
const intact = cc.find("intact", fireNode);
const broken = cc.find("broken", fireNode);
const di = cc.find("di", fireNode);
if (intact) intact.active = true;
if (broken) broken.active = false;
if (di) di.active = false;
// 添加触摸事件
fireNode.off(cc.Node.EventType.TOUCH_END);
fireNode.on(cc.Node.EventType.TOUCH_END, () => {
// 如果正在触摸中,不响应新的触摸
if (this.touching) return;
this.touching = true;
// 保存触摸数据
this.touchData = fireNode.data;
this.touchData.parent = fireNode;
// 显示卡片
this.playCard(this.touchData); this.playCard(this.touchData);
// 更新录音界面
this.updateLayoutSpeak(); this.updateLayoutSpeak();
// 显示破碎的蛋壳,隐藏底部 // 播放锤子动画
broken.active = true; this.hammerAction(fireNode);
di.active = false;
})
}); });
} else {
// 添加箭头动画 // 没有数据,隐藏节点
this.eggArrowAction(egg); fireNode.active = false;
}
}
} }
// 调整布局
let layout_egg = cc.find("layout_egg", this.layout_game);
layout_egg.getComponent(cc.Layout).updateLayout();
// 根据选项数量调整间距
if (count == 2) {
layout_egg.getComponent(cc.Layout).spacingX = 200;
} else if (count == 3) {
layout_egg.getComponent(cc.Layout).spacingX = 150;
} else {
layout_egg.getComponent(cc.Layout).spacingX = 40;
}
// 更新并禁用自动布局
layout_egg.getComponent(cc.Layout).updateLayout();
layout_egg.getComponent(cc.Layout).enabled = false;
}
/** /**
* 游戏帧更新函数 * 游戏帧更新函数
* 主要用于更新倒计时显示 * 主要用于更新倒计时显示
...@@ -819,7 +821,9 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -819,7 +821,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
/** /**
* 检查游戏是否结束 * 检查游戏是否结束
* 通过检查是否所有蛋壳都已隐藏来判断 * 通过检查是否所有蛋壳都已隐藏来判断
* @returns 如果所有蛋壳都已隐藏,返回true;否则返回false * 如果当前页面完成,切换到下一页
* 如果所有页面都完成,游戏结束
* @returns 如果所有页面都完成,返回true;否则返回false
*/ */
private checkIsOver() { private checkIsOver() {
// 计数活动的蛋壳数量 // 计数活动的蛋壳数量
...@@ -831,8 +835,24 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -831,8 +835,24 @@ export default class SceneComponent extends MyCocosSceneComponent {
if (ch.active) count++; if (ch.active) count++;
}) })
// 如果没有显示的蛋壳,游戏结束 // 如果没有显示的蛋壳,当前页面完成
return count == 0; if (count == 0) {
// 增加页码
Game.getIns().addPage();
// 检查是否所有页面都完成
if (Game.getIns().isOver) {
// 所有页面都完成,游戏结束
return true;
} else {
// 还有下一页,显示下一页
this.showPage();
return false;
}
}
// 当前页面还有蛋壳,游戏未结束
return 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