first commit

This commit is contained in:
zzc
2026-04-30 00:13:37 +08:00
commit 493b4709bc
189 changed files with 24791 additions and 0 deletions

View File

@@ -0,0 +1,104 @@
import { _decorator, Component, Node, tween, UITransform, Vec3 } from "cc";
import { EventDispatcher } from "../libs/EventDispatcher";
import { GlobalData } from "../config/GlobalData";
import { GameState } from "../config/Config";
const { ccclass, property } = _decorator;
@ccclass("ContonueModal")
export class ContonueModal extends Component {
// 滑动区域的节点
@property(Node)
private swipeNode: Node = null;
// 提示 1 节点
@property(Node)
private tipNode1: Node = null;
// 提示 2 节点
@property(Node)
private tipNode2: Node = null;
start() {
// 隐藏继续游戏弹窗
this.node.active = false;
// 初始化位置
this.node.setPosition(0, 0, 0);
// 监听继续游戏事件
EventDispatcher.getTarget().on(
EventDispatcher.SHOW_CONTINUE_MODAL,
this.showModal,
this,
);
// 监听滑动事件
this.swipeNode.on(Node.EventType.TOUCH_START, this.onSwipeStart, this);
}
// 显示继续游戏弹窗
showModal() {
// 游戏暂停
GlobalData.gameState = GameState.PAUSED;
// 显示继续游戏弹窗
this.node.active = true;
// 操作提示动画
if (GlobalData.lifeNumPerRound > 0) {
// 执行提示1的动画
this.playTipAnimation(this.tipNode1);
} else {
// 执行提示2的动画
this.playTipAnimation(this.tipNode2);
}
}
// 关闭继续游戏弹窗
closeModal() {
// 关闭继续游戏弹窗
this.node.active = false;
}
// 滑动开始事件
onSwipeStart() {
// 关闭继续游戏弹窗
this.closeModal();
// 等 2 s之后恢复游戏
this.scheduleOnce(() => {
GlobalData.gameState = GameState.PLAYING;
// 发送继续游戏事件
EventDispatcher.getTarget().emit(EventDispatcher.GAME_RESUME);
}, 2);
}
// 暂停游戏
onPauseGame() {
console.log(111, "暂停游戏");
// 发送暂停事件
EventDispatcher.getTarget().emit(EventDispatcher.SHOW_PAUSE_MODAL);
}
// 播放提示1的动画
playTipAnimation(tNode: Node) {
// 显示提示1
tNode.active = true;
// 获取提示节点的位置
const oriPos = tNode.getPosition().clone();
// 获取提示的宽度
const tipWidth = tNode.getComponent(UITransform).width + 5;
// 执行动画
tween(tNode)
.to(0.3, {
position: new Vec3(oriPos.x - tipWidth, oriPos.y, 0),
})
.delay(0.8)
.to(0.3, {
position: oriPos,
})
.call(() => {
// 隐藏提示1
tNode.active = false;
// 重置节点位置
tNode.setPosition(oriPos);
})
.start();
}
update(deltaTime: number) {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "6ae5f280-b903-4537-b1d2-b9bbccba26b8",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,53 @@
import { _decorator, Component, director, Node } from "cc";
import { EventDispatcher } from "../libs/EventDispatcher";
const { ccclass, property } = _decorator;
@ccclass("PauseModal")
export class PauseModal extends Component {
start() {
// 隐藏暂停游戏弹窗
this.node.active = false;
// 初始化位置
this.node.setPosition(0, 0, 0);
// 监听继续游戏事件
EventDispatcher.getTarget().on(
EventDispatcher.SHOW_PAUSE_MODAL,
this.showModal,
this,
);
}
// 显示弹窗
showModal() {
this.node.active = true;
// 暂停游戏
director.pause();
// 发送暂停游戏事件
EventDispatcher.getTarget().emit(EventDispatcher.GAME_PAUSE);
// 发送继续游戏弹窗
EventDispatcher.getTarget().emit(EventDispatcher.SHOW_CONTINUE_MODAL);
}
// 关闭弹窗
closeModal() {
this.node.active = false;
// 恢复游戏继续
director.resume();
}
// 回到首页
backToHome() {
// 恢复游戏继续
director.resume();
// 跳转到首页
director.loadScene("home");
}
// 继续游戏
resumeGame() {
// 关闭弹窗
this.closeModal();
}
update(deltaTime: number) {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "976546b4-b786-4c64-b005-ca9feafa8dbd",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,193 @@
import {
_decorator,
Component,
director,
Label,
Node,
tween,
UITransform,
Vec3,
} from "cc";
import { EventDispatcher } from "../libs/EventDispatcher";
import { GlobalData } from "../config/GlobalData";
import AudioEffect from "../libs/AudioEffect";
const { ccclass, property } = _decorator;
@ccclass("ResultModal")
export class ResultModal extends Component {
// 本局得分的 label
@property(Label)
scoreLabel: Label = null;
// 最佳得分 label
@property(Label)
bestScoreLabel: Label = null;
// 总的金币数 label
@property(Label)
totalScoreLabel: Label = null;
// 回到首页的按钮节点
@property(Node)
backToHomeBtn: Node = null;
// 提示节点
@property(Node)
tipNode: Node = null;
start() {
// 隐藏结果弹窗
this.node.active = false;
// 设置位置
this.node.setPosition(0, 0);
// 注册打开结果弹窗的事件
EventDispatcher.getTarget().on(
EventDispatcher.SHOW_RESULT_MODAL,
this.openModal,
this,
);
}
// 打开结果弹窗
openModal() {
// 显示结果弹窗
this.node.active = true;
// 设置当前得分
this.scoreLabel.string = GlobalData.curRoundTotalScore.toString();
// 累计总的金币数
GlobalData.totalScore += GlobalData.curRoundTotalScore;
// 设置总的金币数
this.setTotalScoreLabel();
// 设置当前用户最好的得分成绩
this.setCurUserBestScoreLabel();
// 执行相关动效
this.scheduleOnce(async () => {
await this.playGoldEffect();
// 再执行提示信息的动画
this.playTipAni();
// 显示回到首页的按钮
this.backToHomeBtn.active = true;
}, 1);
}
// 关闭游戏结束弹窗方法
closeModal() {
this.node.active = false;
// 隐藏回到首页的按钮
this.backToHomeBtn.active = false;
// 重置分数
this.scoreLabel.string = "0";
}
setTotalScoreLabel() {
this.totalScoreLabel.string = GlobalData.totalScore.toString();
}
setCurUserBestScoreLabel() {
const bestScore = GlobalData.bestScore;
// 如果当前成绩大于最好成绩 更新最好成绩
if (GlobalData.curRoundTotalScore > bestScore) {
GlobalData.bestScore = GlobalData.curRoundTotalScore;
}
// 设置最佳得分 label
this.bestScoreLabel.string = GlobalData.bestScore.toString();
}
setBestScoreLabel() {}
// 播放金币特效
async playGoldEffect() {
// 获取 gold coins 节点
const goldCoinsNode = this.node
.getChildByName("panel")
.getChildByName("gold_coins");
// 开启此节点
goldCoinsNode.active = true;
// 播放撒金币音效
AudioEffect.playGoldAudio();
// 0.5 s 后执行入账音效
this.scheduleOnce(() => {
AudioEffect.playCoinsEntryAudio();
}, 0.5);
// 获取所有金币子节点
const goldCoinsList = goldCoinsNode.children;
// 获取显示金币数量的标签节点
const goldCoinsNumNode = this.node
.getChildByName("gold_label")
.getChildByName("gold_num");
// 获取目标节点的位置
const targetPos = goldCoinsNumNode.getWorldPosition();
// 遍历金币子节点
for (let i = 0; i < goldCoinsList.length; i++) {
// 克隆位置
const targetPosColne = targetPos.clone();
// 执行单个金币的动画
const goldCoin = goldCoinsList[i];
await this.playSingleGoldAni(goldCoin, targetPosColne);
}
}
// 执行单个金币的动画
async playSingleGoldAni(goldCoin: Node, targetPos: Vec3) {
return new Promise((resolve) => {
tween(goldCoin)
.by(0.2, {
position: new Vec3(0, -30, 0),
})
.call(() => {
// 开始执行下一个
resolve(true);
// 获取金币的世界坐标
const goleCoinWorldPos = goldCoin.getWorldPosition();
// 计算金币节点与目标距离的差值
const diffPost = targetPos.subtract(goleCoinWorldPos);
// 再缓动到目标位置
tween(goldCoin)
.by(0.5, { position: diffPost })
.call(() => {
// 金币消失
goldCoin.active = false;
})
.start();
})
.start();
});
}
// 执行提示动画
playTipAni() {
// 开启提示
this.tipNode.active = true;
// 获取提示的位置
const oriPos = this.tipNode.getPosition().clone();
// 获取提示的宽度
const tipWidth = this.tipNode.getComponent(UITransform).width + 5;
// 执行动画
tween(this.tipNode)
.to(0.3, {
position: new Vec3(oriPos.x - tipWidth, oriPos.y, 0),
})
.delay(0.8)
.to(0.3, {
position: oriPos,
})
.call(() => {
// 隐藏提示1
this.tipNode.active = false;
// 重置节点位置
this.tipNode.setPosition(oriPos);
})
.start();
}
// 回到首页
backToHome() {
// 播放点击音效
AudioEffect.playClickAudio();
director.loadScene("home");
}
update(deltaTime: number) {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "44c80c77-90c5-4293-84b6-4c2d541d2f1b",
"files": [],
"subMetas": {},
"userData": {}
}