Commit 4b67fd36 authored by Tt's avatar Tt

卡车运动逻辑全部完成

parent f5cc4bb1
......@@ -231,6 +231,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
/**
* 消防车入场动画
* 从左侧(-1500,-527)移动到右侧(-400,-527)并播放龙骨动画
* 根据当前页码调整消防车的初始位置和目标位置
*/
aniCarEnter() {
// 确保消防车节点存在
......@@ -238,8 +239,15 @@ export default class SceneComponent extends MyCocosSceneComponent {
return pg.logger.w("消防车节点不存在");
}
// 获取当前页码
const currentPage = Game.getIns().getCurrentPageNum();
// 根据当前页码计算初始位置和目标位置
const initialX = -1500 + 1920 * currentPage;
const targetX = -400 + 1920 * currentPage;
// 设置初始位置
this.node_firetruck.setPosition(cc.v2(-1500, -330));
this.node_firetruck.setPosition(cc.v2(initialX, -330));
// 隐藏冲水动画节点
this.node_firetruck_flush.active = false;
......@@ -249,17 +257,15 @@ export default class SceneComponent extends MyCocosSceneComponent {
pg.view.playDBAnimation(this.node_firetruck_anim, '移动', -1);
let dragonDisplay = this.node_firetruck_anim.getComponent(dragonBones.ArmatureDisplay);
if (dragonDisplay) {
dragonDisplay.timeScale = 1.2; // 将动画速度设为0,相当于暂停
dragonDisplay.timeScale = 1.2; // 设置动画速度
}
// 使用cc.tween实现移动效果
cc.tween(this.node_firetruck)
.to(2.0, { x: -400 })
.to(2.0, { x: targetX })
.call(() => {
// 播放龙骨动画
pg.view.playDBAnimation(this.node_firetruck_anim, '待机', -1);
// // 移动完成后停止动画
})
.start();
}
......@@ -268,10 +274,12 @@ export default class SceneComponent extends MyCocosSceneComponent {
* 显示当前页面
* 根据当前页码决定使用page_a还是page_b
* 并设置fire_0到fire_5这6个交互点
* 当前页面的内容完成后,layout_game会向左移动一页的距离(1920)
*/
showPage() {
// 获取当前页码
const currentPage = Game.getIns().getCurrentPageNum();
const prevPage = currentPage - 1;
// 根据页码的奇偶性决定使用哪个页面
// 偶数页使用page_a,奇数页使用page_b
......@@ -280,7 +288,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 显示当前页面,隐藏另一个页面
currentPageNode.active = true;
otherPageNode.active = false;
otherPageNode.active = true;
// 获取当前页的数据
const pageData = Game.getIns().getPageData();
......@@ -311,11 +319,22 @@ export default class SceneComponent extends MyCocosSceneComponent {
fireNode.active = false;
}
}
// 如果不是第一页,则添加layout_game向左移动的动画
if (prevPage >= 0) {
// 使用cc.tween实现layout_game向左移动一页的距离(1920)
cc.tween(this.layout_game)
.to(3.0, { x: -1920 * currentPage }, { easing: 'cubicOut' })
.start();
cc.tween(this.node_firetruck)
.to(3.0, { x: -400 + 1920 * currentPage }, { easing: 'cubicOut' })
.start();
}
}
/**
* 消防车点击事件处理
* 随机选择一个存在的火苗并触发相应的事件
* 根据选择的火苗编号调整消防车位置和喷水角度
* 根据选择的火苗编号和当前页码调整消防车位置和喷水角度
*/
onTouchFiretruck() {
// 如果正在触摸中,不响应新的触摸
......@@ -326,9 +345,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.log("没有可用的火苗节点");
// 如果当前页面没有活跃火苗,检查是否需要进入下一页
if (this.checkIsOver()) {
this.gameOver();
}
// if (this.checkIsOver()) {
// this.gameOver();
// }
return;
}
// 如果正在触摸中,不响应新的触摸
......@@ -343,9 +362,14 @@ export default class SceneComponent extends MyCocosSceneComponent {
const nodeName = selectedFireNode.name; // 例如 "fire_0", "fire_1" 等
const fireIndex = parseInt(nodeName.split('_')[1]);
// 获取当前页码
const currentPage = Game.getIns().getCurrentPageNum();
// 根据火苗编号调整消防车位置
// fire_0~fire_2 消防车位置 x=-400,fire_3~fire_5 消防车位置 x=-185
const targetX = (fireIndex <= 2) ? -400 : -185;
// 并根据当前页码进行偏移
const baseX = (fireIndex <= 2) ? -400 : -185;
const targetX = baseX + 1920 * currentPage;
// 移动消防车到指定位置
cc.tween(this.node_firetruck)
......@@ -432,6 +456,15 @@ export default class SceneComponent extends MyCocosSceneComponent {
} else {
this.log(`找不到节点: water_${fireIndex}`);
}
// 检查当前页面是否所有火苗都已处理完毕
if (this.activeFireNodes.length === 5) {
// 延迟一段时间后检查是否需要切换到下一页
this.scheduleOnce(() => {
// 检查是否需要进入下一页
this.nextPage();
}, 1.0); // 延迟2秒,给用户时间看到当前页面的完成状态
}
}
onFireFail() {
const fireNode = this.currentFireNode;
......@@ -446,6 +479,11 @@ export default class SceneComponent extends MyCocosSceneComponent {
fireNode.active = true;
}
}
nextPage() {
// 切换到下一页
Game.getIns().addPage();
this.showPage();
}
/**
......@@ -860,9 +898,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.touchData.parent.active = false;
// 检查是否所有蛋壳都已处理完毕
if (this.checkIsOver()) {
this.gameOver();
}
// if (this.checkIsOver()) {
// this.gameOver();
// }
}
// 恢复背景音乐
......@@ -886,42 +924,6 @@ export default class SceneComponent extends MyCocosSceneComponent {
}
/**
* 检查游戏是否结束
* 通过检查是否所有蛋壳都已隐藏来判断
* 如果当前页面完成,切换到下一页
* 如果所有页面都完成,游戏结束
* @returns 如果所有页面都完成,返回true;否则返回false
*/
private checkIsOver() {
// 计数活动的蛋壳数量
let count = 0;
let layout_egg = cc.find("layout_egg", this.layout_game);
// 遍历所有蛋壳,统计显示中的数量
layout_egg.children.forEach((ch) => {
if (ch.active) count++;
})
// 如果没有显示的蛋壳,当前页面完成
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