|
|
@@ -2,7 +2,7 @@
|
|
|
* @Author: mojunshou 1637302775@qq.com
|
|
|
* @Date: 2025-03-20 15:01:09
|
|
|
* @LastEditors: mojunshou 1637302775@qq.com
|
|
|
- * @LastEditTime: 2025-03-28 17:23:57
|
|
|
+ * @LastEditTime: 2025-03-31 14:11:58
|
|
|
* @Description: 消除游戏主场景
|
|
|
*/
|
|
|
import { _decorator, Color, EventTouch, instantiate, JsonAsset, Label, Node, Prefab, randomRangeInt, Sprite, Toggle, tween, UITransform, Vec2, Vec3, Widget } from "cc";
|
|
|
@@ -145,6 +145,7 @@ export class EliminateViewComp extends CCComp {
|
|
|
private money: number = 0; //左边金钱
|
|
|
private cash: number = 0; //右边红包钱数
|
|
|
|
|
|
+
|
|
|
private totalNum: number = 0; //累计消除次数,断了就是又从0开始
|
|
|
|
|
|
//网格列表
|
|
|
@@ -196,6 +197,20 @@ export class EliminateViewComp extends CCComp {
|
|
|
private shouldResetEliminateCount: boolean = true;
|
|
|
private consecutiveEliminations: boolean = false;
|
|
|
|
|
|
+ // 添加配置属性 - 消除基础分
|
|
|
+ @property({ displayName: "消除一行/列基础分" })
|
|
|
+ private eliminateBaseScore: number = 10;
|
|
|
+
|
|
|
+ //当前局数
|
|
|
+ private curGameNum: number = 0;
|
|
|
+ //第一通关开始新人模式
|
|
|
+ //第二局开始马上播放新的弹窗
|
|
|
+ //往后根据每局需要弹窗就弹窗
|
|
|
+ //通关一局算一块金砖
|
|
|
+ //通关比例算金砖比例
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/** 视图层逻辑代码分离演示 */
|
|
|
async start() {
|
|
|
// const entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象
|
|
|
@@ -465,15 +480,8 @@ export class EliminateViewComp extends CCComp {
|
|
|
addBrick(index: number) {
|
|
|
//随机名字
|
|
|
const brickKey = Object.keys(this.brickConfig['bricks'])[randomRangeInt(0, Object.keys(this.brickConfig['bricks']).length)]
|
|
|
- // // console.log("brickKey>>>>>", brickKey)
|
|
|
- // //随机颜色-一个颜色出来
|
|
|
- // const gridColorKey = Object.keys(this.brickConfig['GridType'])[randomRangeInt(0, Object.keys(this.brickConfig['GridType']).length)]
|
|
|
- // // console.log("gridColorKey>>>>>", gridColorKey)
|
|
|
- // //随机配置-通过名字拿到那个配置
|
|
|
const brickConfig = this.brickConfig['bricks'][brickKey];
|
|
|
- // console.log("brickConfig>>>>>", brickConfig)
|
|
|
- const randomIndex = RandomManager.instance.getRandomInt(1, 5, 2);
|
|
|
- console.log("随机颜色>>>>>", randomIndex)
|
|
|
+ const randomIndex = oops.random.getRandomInt(1, 5);
|
|
|
// 生成方块
|
|
|
const brickData: BrickData = {
|
|
|
index,
|
|
|
@@ -494,10 +502,6 @@ export class EliminateViewComp extends CCComp {
|
|
|
this.brickNode.addChild(brickNode)
|
|
|
}
|
|
|
brickData.brickNode = brickNode;
|
|
|
- // 方块间隔
|
|
|
-
|
|
|
- //这里修改一下,分别放到3个Node中,然后
|
|
|
-
|
|
|
let offset = 220
|
|
|
if (this.brickNum % 2 === 1) {
|
|
|
const middleNum = Math.floor(this.brickNum / 2) + 1
|
|
|
@@ -1017,14 +1021,12 @@ export class EliminateViewComp extends CCComp {
|
|
|
// 计算所有被消除格子的平均Y轴位置
|
|
|
let totalY = 0;
|
|
|
let validGrids = 0;
|
|
|
-
|
|
|
for (const grid of gridEliminateList) {
|
|
|
if (grid.gridNode) {
|
|
|
totalY += grid.gridNode.getWorldPosition().y;
|
|
|
validGrids++;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
// 计算平均Y位置
|
|
|
const avgY = validGrids > 0 ? totalY / validGrids : 0;
|
|
|
|
|
|
@@ -1038,7 +1040,6 @@ export class EliminateViewComp extends CCComp {
|
|
|
gridEliminateList.forEach((gridData) => {
|
|
|
if (gridData.gridNode?.children[0]) {
|
|
|
const startPos = gridData.gridNode.getWorldPosition();
|
|
|
-
|
|
|
tween(gridData.gridNode.children[0])
|
|
|
.to(0.2, { scale: new Vec3(0.5, 0.5) })
|
|
|
.call(() => {
|
|
|
@@ -1066,25 +1067,59 @@ export class EliminateViewComp extends CCComp {
|
|
|
})
|
|
|
|
|
|
this.scheduleOnce(() => {
|
|
|
- let score = 0
|
|
|
- for (let i = 1; i <= eliminateRowNum; i++) {
|
|
|
- score += this.cols * i
|
|
|
- }
|
|
|
- for (let i = 1; i <= eliminateColumnNum; i++) {
|
|
|
- score += this.rows * i
|
|
|
- }
|
|
|
- this.score += score
|
|
|
+ // 新的分数计算逻辑
|
|
|
+ let baseScore = 0;
|
|
|
+ // 计算基础分(每行/列 * 基础分值)
|
|
|
+ baseScore = (eliminateRowNum + eliminateColumnNum) * this.eliminateBaseScore;
|
|
|
+
|
|
|
+ // 格子数量分
|
|
|
+ const gridScore = gridEliminateList.length;
|
|
|
+
|
|
|
+ // 总分 = 基础分 + 格子数量分
|
|
|
+ const totalScore = baseScore + gridScore;
|
|
|
+
|
|
|
+ // 更新总分
|
|
|
+ this.score += totalScore;
|
|
|
this.lab_score.string = this.score.toString();
|
|
|
|
|
|
- const lastGrid = gridEliminateList[gridEliminateList.length - 1];
|
|
|
- if (lastGrid?.gridNode && this.coinPrefab && this.amountLb?.node) {
|
|
|
- const lastPos = lastGrid.gridNode.getWorldPosition();
|
|
|
- this.createCoinFlyAnimation(
|
|
|
- this.coinPrefab,
|
|
|
- lastPos,
|
|
|
- this.amountLb.node.getWorldPosition(),
|
|
|
- score
|
|
|
- );
|
|
|
+ // 显示分数增加动画
|
|
|
+ if (gridEliminateList.length > 0) {
|
|
|
+ const lastGrid = gridEliminateList[gridEliminateList.length - 1];
|
|
|
+ if (lastGrid?.gridNode) {
|
|
|
+ const lastPos = lastGrid.gridNode.getWorldPosition();
|
|
|
+
|
|
|
+ // 创建分数提示
|
|
|
+ const scoreNode = new Node();
|
|
|
+ this.node.addChild(scoreNode);
|
|
|
+ scoreNode.setWorldPosition(lastPos);
|
|
|
+
|
|
|
+ const scoreLabel = scoreNode.addComponent(Label);
|
|
|
+ scoreLabel.string = `+${totalScore}`;
|
|
|
+ scoreLabel.fontSize = 40;
|
|
|
+ scoreLabel.color = Color.YELLOW;
|
|
|
+
|
|
|
+ // 分数飞行动画
|
|
|
+ tween(scoreNode)
|
|
|
+ .to(0.5, {
|
|
|
+ position: new Vec3(scoreNode.position.x, scoreNode.position.y + 100, 0),
|
|
|
+ scale: new Vec3(1.5, 1.5, 1.5)
|
|
|
+ })
|
|
|
+ .to(0.3, { opacity: 0 })
|
|
|
+ .call(() => {
|
|
|
+ scoreNode.destroy();
|
|
|
+ })
|
|
|
+ .start();
|
|
|
+
|
|
|
+ // 金币飞行动画
|
|
|
+ if (this.coinPrefab && this.amountLb?.node) {
|
|
|
+ this.createCoinFlyAnimation(
|
|
|
+ this.coinPrefab,
|
|
|
+ lastPos,
|
|
|
+ this.amountLb.node.getWorldPosition(),
|
|
|
+ totalScore
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 告诉调用者有消除发生
|
|
|
@@ -1621,8 +1656,13 @@ export class EliminateViewComp extends CCComp {
|
|
|
}
|
|
|
|
|
|
private onToggleContainerAutoClick(toggle: Toggle) {
|
|
|
+
|
|
|
switch (toggle.node.name) {
|
|
|
case "On":
|
|
|
+ if (this.autoClick) {
|
|
|
+ oops.gui.toast("已经是自动模式啦")
|
|
|
+ return;
|
|
|
+ }
|
|
|
this.autoClick = true;
|
|
|
break;
|
|
|
case "Off":
|
|
|
@@ -1639,6 +1679,10 @@ export class EliminateViewComp extends CCComp {
|
|
|
this.editingFlag
|
|
|
) return
|
|
|
// 切换自动模式状态
|
|
|
+ //如果状态一样,不做任何操作
|
|
|
+ if (this.isAutoMode === this.autoClick) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
this.isAutoMode = this.autoClick;
|
|
|
if (this.isAutoMode) {
|
|
|
this._isAutoFunc = () => {
|
|
|
@@ -1651,7 +1695,6 @@ export class EliminateViewComp extends CCComp {
|
|
|
this._isAutoFunc = null
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
|