|
|
@@ -2,7 +2,7 @@
|
|
|
* @Author: mojunshou 1637302775@qq.com
|
|
|
* @Date: 2025-03-20 15:01:09
|
|
|
* @LastEditors: mojunshou 1637302775@qq.com
|
|
|
- * @LastEditTime: 2025-04-25 11:12:46
|
|
|
+ * @LastEditTime: 2025-04-25 16:03:04
|
|
|
* @Description: 消除游戏主场景
|
|
|
*/
|
|
|
import { _decorator, Button, Color, EventTouch, instantiate, JsonAsset, v3, Label, Node, Prefab, randomRangeInt, Sprite, tween, UITransform, Vec2, Vec3, Widget } from "cc";
|
|
|
@@ -121,8 +121,8 @@ export class EliminateViewComp extends CCComp {
|
|
|
@property({ type: Label, displayName: "每次放置添加的分数" })
|
|
|
private lab_addScore: Label = null!;
|
|
|
|
|
|
- @property({ type: Button, displayName: "自动按钮" })
|
|
|
- private autoBtn: Button = null!;
|
|
|
+ @property({ type: Node, displayName: "自动按钮节点" })
|
|
|
+ private autoBtnNode: Node = null!;
|
|
|
//二倍速按钮
|
|
|
@property({ type: Button, displayName: "二倍速按钮" })
|
|
|
private doubleSpeedBtn: Button = null!;
|
|
|
@@ -257,16 +257,15 @@ export class EliminateViewComp extends CCComp {
|
|
|
this.initData();
|
|
|
this.setData();
|
|
|
this.addEventList();
|
|
|
- // smc.account.AccountModel.curLevel = 1;
|
|
|
if (this.guideStep === 0 && smc.account.AccountModel.curLevel == 1) {
|
|
|
this.startGuideMode()
|
|
|
} else {
|
|
|
this.guideNode.active = false;
|
|
|
this.initGrid();
|
|
|
}
|
|
|
- //更新福利点
|
|
|
this.updateWelfarePoint();
|
|
|
DCHandler.inst.reportData(3000005);
|
|
|
+ oops.audio.playMusicLoop("common/audios/bgm");
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -275,7 +274,6 @@ export class EliminateViewComp extends CCComp {
|
|
|
oops.message.on(GameEvent.DoubleSpeedOpenSuccess, this.doubleSpeedOpenSuccess, this);
|
|
|
oops.message.on(GameEvent.openView, this.openView, this);
|
|
|
oops.message.on(GameEvent.showCoinAnimation, this.showCoinAnimation, this);
|
|
|
- // oops.message.on(GameEvent.Resurrection, this.onResurrection, this);
|
|
|
oops.message.on(GameEvent.updateHbAndWxCoin, this.updateCoin, this);
|
|
|
oops.message.on(GameEvent.StartAutoGame, this.startAutoGame, this);
|
|
|
oops.message.on(GameEvent.updateGameState, this.updateGameState, this);
|
|
|
@@ -288,7 +286,11 @@ export class EliminateViewComp extends CCComp {
|
|
|
this.gameState = GameState.PAUSED;
|
|
|
break;
|
|
|
case "playing":
|
|
|
- this.gameState = GameState.PLAYING;
|
|
|
+ this.scheduleOnce(() => {
|
|
|
+ if (this.gameState == GameState.PAUSED) {
|
|
|
+ this.gameState = GameState.PLAYING;
|
|
|
+ }
|
|
|
+ }, 0.5)
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
@@ -306,16 +308,16 @@ export class EliminateViewComp extends CCComp {
|
|
|
//初始化按钮状态
|
|
|
private initButtonState(state: boolean) {
|
|
|
//自动按钮默认关闭
|
|
|
- if (this.autoBtn) {
|
|
|
+ if (this.autoBtnNode) {
|
|
|
//关闭
|
|
|
- const on = this.autoBtn.node.getChildByName("on");
|
|
|
+ const on = this.autoBtnNode.getChildByName("on");
|
|
|
on ? on.active = state : null;
|
|
|
- const off = this.autoBtn.node.getChildByName("off");
|
|
|
+ const off = this.autoBtnNode.getChildByName("off");
|
|
|
off ? off.active = !state : null;
|
|
|
}
|
|
|
//第一关隐藏二倍速和自动放置按钮
|
|
|
const curLevel = smc.account.AccountModel.curLevel;
|
|
|
- this.autoBtn.node.active = curLevel > 1;
|
|
|
+ this.autoBtnNode.active = curLevel > 1;
|
|
|
this.doubleSpeedBtn.node.active = curLevel > 1;
|
|
|
}
|
|
|
|
|
|
@@ -327,7 +329,6 @@ export class EliminateViewComp extends CCComp {
|
|
|
this.targetScore = 0;
|
|
|
this.money = 0;
|
|
|
this.cash = 0;
|
|
|
- this.autoState = false;
|
|
|
this.operateFlag = true
|
|
|
this.shouldResetEliminateCount = true;
|
|
|
this.currentCombo = 0;
|
|
|
@@ -341,11 +342,11 @@ export class EliminateViewComp extends CCComp {
|
|
|
this.eliminateInterval = smc.game.GameModel.curLevelConfig.eliminateScope || [];
|
|
|
}
|
|
|
}
|
|
|
- this.score = smc.game.GameModel.curScore;
|
|
|
- this.money = smc.account.AccountModel.wxCoin;
|
|
|
- this.cash = smc.account.AccountModel.hbCoin;
|
|
|
- this.targetScore = smc.game.GameModel.targetScore;
|
|
|
- // this.targetScore = 1000;
|
|
|
+ this.gameState = GameState.PLAYING;
|
|
|
+ this.score = smc.game.GameModel.curScore || 0;
|
|
|
+ this.money = smc.account.AccountModel.wxCoin || 0;
|
|
|
+ this.cash = smc.account.AccountModel.hbCoin || 0;
|
|
|
+ this.targetScore = smc.game.GameModel.targetScore || 0;
|
|
|
this.popupType = smc.game.GameModel.popupType;
|
|
|
this.lab_score.string = this.score.toString();
|
|
|
this.lab_wxCoin.string = Format.formatWxCoin(this.money);
|
|
|
@@ -354,9 +355,7 @@ export class EliminateViewComp extends CCComp {
|
|
|
//金砖数量要加1
|
|
|
const num = smc.account.AccountModel.goldCoin
|
|
|
this.lab_goldNum.string = `${num + 1}`;
|
|
|
- this.gameState = GameState.PLAYING;
|
|
|
this.randomList = this.getRandomUniqueInts();
|
|
|
-
|
|
|
const curLevel = smc.account.AccountModel.curLevel;
|
|
|
DCHandler.inst.reportData(3000500, curLevel);
|
|
|
}
|
|
|
@@ -370,7 +369,7 @@ export class EliminateViewComp extends CCComp {
|
|
|
|
|
|
//开始自动游戏
|
|
|
startAutoGame() {
|
|
|
- this.btn_auto();
|
|
|
+ this.autoGame();
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -1219,28 +1218,8 @@ export class EliminateViewComp extends CCComp {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
- // 计算放置的格子数量
|
|
|
- const placedGridCount = this.editingData.gridList.length;
|
|
|
- // 获取中心位置用于显示分数
|
|
|
- let centerPos = new Vec3(0, 0, 0);
|
|
|
- if (this.editingData.gridList.length > 0 && this.editingData.gridList[0].gridNode) {
|
|
|
- centerPos = this.editingData.gridList[0].gridNode.getWorldPosition().clone();
|
|
|
- if (this.editingData.gridList.length > 1) {
|
|
|
- // 计算所有格子的平均位置作为中心点
|
|
|
- for (let i = 1; i < this.editingData.gridList.length; i++) {
|
|
|
- const gridNode = this.editingData.gridList[i].gridNode;
|
|
|
- if (gridNode) {
|
|
|
- centerPos.add(gridNode.getWorldPosition());
|
|
|
- }
|
|
|
- }
|
|
|
- const validGridCount = this.editingData.gridList.filter(grid => grid.gridNode).length;
|
|
|
- centerPos.x /= validGridCount;
|
|
|
- centerPos.y /= validGridCount;
|
|
|
- }
|
|
|
- }
|
|
|
// 显示放置得分动画(显示一次,包含总格子数)
|
|
|
- this.showScoreAnimation(centerPos, placedGridCount);
|
|
|
+ this.showScoreAnimation();
|
|
|
// 放置方块到网格
|
|
|
this.editingData.gridList.forEach(grid => {
|
|
|
grid.status = CellState.FILLED;
|
|
|
@@ -1356,9 +1335,33 @@ export class EliminateViewComp extends CCComp {
|
|
|
}
|
|
|
|
|
|
// 显示分数增加动画
|
|
|
- showScoreAnimation(position: Vec3, score: number) {
|
|
|
+ showScoreAnimation() {
|
|
|
if (!this.lab_addScore) return;
|
|
|
|
|
|
+
|
|
|
+ // 计算放置的格子数量
|
|
|
+ const placedGridCount = this.editingData.gridList.length;
|
|
|
+ // 获取中心位置用于显示分数
|
|
|
+ let centerPos = new Vec3(0, 0, 0);
|
|
|
+ if (this.editingData.gridList.length > 0 && this.editingData.gridList[0].gridNode) {
|
|
|
+ centerPos = this.editingData.gridList[0].gridNode.getWorldPosition().clone();
|
|
|
+ if (this.editingData.gridList.length > 1) {
|
|
|
+ // 计算所有格子的平均位置作为中心点
|
|
|
+ for (let i = 1; i < this.editingData.gridList.length; i++) {
|
|
|
+ const gridNode = this.editingData.gridList[i].gridNode;
|
|
|
+ if (gridNode) {
|
|
|
+ centerPos.add(gridNode.getWorldPosition());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const validGridCount = this.editingData.gridList.filter(grid => grid.gridNode).length;
|
|
|
+ centerPos.x /= validGridCount;
|
|
|
+ centerPos.y /= validGridCount;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ let score = placedGridCount;
|
|
|
+ let position = centerPos
|
|
|
+
|
|
|
// 计算得分(未消除时的得分)
|
|
|
const calculatedScore = score * this.placementBaseScore;
|
|
|
|
|
|
@@ -1487,7 +1490,6 @@ export class EliminateViewComp extends CCComp {
|
|
|
const num = this.isDoubleSpeed ? this.doubleNum : 1;
|
|
|
gridEliminateList.forEach((gridData) => {
|
|
|
if (gridData.gridNode?.children[0]) {
|
|
|
- // const startPos = gridData.gridNode.getWorldPosition();
|
|
|
tween(gridData.gridNode.children[0])
|
|
|
.to(0.2 / num, { scale: new Vec3(0.5, 0.5) })
|
|
|
.call(() => {
|
|
|
@@ -1497,6 +1499,7 @@ export class EliminateViewComp extends CCComp {
|
|
|
.start()
|
|
|
}
|
|
|
})
|
|
|
+ oops.audio.playEffect("common/audios/eliminate")
|
|
|
|
|
|
this.scheduleOnce(() => {
|
|
|
// 计算分数:每行/列的基础分 + 每个额外格子的分数
|
|
|
@@ -1531,16 +1534,19 @@ export class EliminateViewComp extends CCComp {
|
|
|
const randomNum = randomRangeInt(minNum, maxNum + 1);
|
|
|
//这个数可以被总消除次数整除那就可以弹广告
|
|
|
if (this.eliminateTotal % randomNum === 0) {
|
|
|
- // oops.gui.open(UIID.DoubleSpeed);
|
|
|
//如果有自动就暂停自动
|
|
|
- this.gameState = GameState.PAUSED;
|
|
|
- if (smc.game.GameModel.skipAdConfig != 1) {
|
|
|
- if (smc.game.GameModel.skipAdCount % smc.game.GameModel.skipAdConfig == 0) {
|
|
|
+ if (this.autoState) {
|
|
|
+ this.gameState = GameState.PAUSED;
|
|
|
+ }
|
|
|
+ if (smc.game.GameModel.skipAdConfig != -1) {
|
|
|
+ if (smc.game.GameModel.skipAdCount > 0 && smc.game.GameModel.skipAdCount % smc.game.GameModel.skipAdConfig == 0) {
|
|
|
smc.game.GameModel.viewType = "double_reward";
|
|
|
ADHandler.inst.showAd(AD_TYPE.Double_Receive);
|
|
|
} else {
|
|
|
ServerHandler.inst.getDoubleSurprise();
|
|
|
}
|
|
|
+ } else {
|
|
|
+ ServerHandler.inst.getDoubleSurprise();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -1897,6 +1903,7 @@ export class EliminateViewComp extends CCComp {
|
|
|
//更新游戏分数
|
|
|
updateGameScore() {
|
|
|
this.lab_score.string = this.score.toString();
|
|
|
+ smc.game.GameModel.curScore = this.score;
|
|
|
if (this.score >= this.targetScore) {
|
|
|
this.gameState = GameState.GAME_PASS;
|
|
|
//弹出通关奖励界面
|
|
|
@@ -1971,7 +1978,22 @@ export class EliminateViewComp extends CCComp {
|
|
|
|
|
|
|
|
|
//自动放置,不让点击方块
|
|
|
- private btn_auto() {
|
|
|
+ private btn_auto(event: EventTouch) {
|
|
|
+ //这要有一个tweeen 放大缩小效果
|
|
|
+ // if (this.autoBtnNode) {
|
|
|
+ // tween(this.autoBtnNode)
|
|
|
+ // .to(0.1, { scale: v3(1.2, 1.2) })
|
|
|
+ // .call(() => {
|
|
|
+ // this.autoBtnNode.scale_x = 1;
|
|
|
+ // this.autoBtnNode.scale_y = 1;
|
|
|
+ // })
|
|
|
+ // .start();
|
|
|
+ // }
|
|
|
+ this.autoGame();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private autoGame() {
|
|
|
this.autoState = !this.autoState;
|
|
|
this.initButtonState(this.autoState);
|
|
|
if (this.autoState) {
|
|
|
@@ -1997,13 +2019,14 @@ export class EliminateViewComp extends CCComp {
|
|
|
|
|
|
// 执行自动放置
|
|
|
executeAutoPlace() {
|
|
|
+ console.log("自动放置状态", this.autoState);
|
|
|
+ console.log("当前游戏状态", this.gameState);
|
|
|
if (!this.autoState || this.gameState !== GameState.PLAYING) {
|
|
|
return
|
|
|
}
|
|
|
const bestPlacement = this.findBestPlacement()
|
|
|
if (!bestPlacement) {
|
|
|
// 所有方块都无法放置,游戏结束
|
|
|
- this.autoState = false;
|
|
|
this.gameState = GameState.GAME_OVER;
|
|
|
this.gameOver()
|
|
|
return
|
|
|
@@ -2145,12 +2168,13 @@ export class EliminateViewComp extends CCComp {
|
|
|
const originPos = brickData.brickNode.getWorldPosition()
|
|
|
brickData.brickNode.setParent(this.moveNode)
|
|
|
brickData.brickNode.setWorldPosition(originPos);
|
|
|
-
|
|
|
+ //显示增加分数
|
|
|
// 动画放置方块
|
|
|
tween(brickData.brickNode)
|
|
|
.to(this.autoMoveTime, { worldPosition: centerPos })
|
|
|
.call(() => {
|
|
|
// ✅ 更新格子状态(像手动放置那样)
|
|
|
+ this.showScoreAnimation();
|
|
|
this.editingData.gridList.forEach(gridData => {
|
|
|
gridData.status = CellState.FILLED
|
|
|
gridData.type = brickData.type;
|
|
|
@@ -2162,13 +2186,11 @@ export class EliminateViewComp extends CCComp {
|
|
|
|
|
|
// ✅ 补充新的砖块
|
|
|
this.addBrick(brickData.index)
|
|
|
-
|
|
|
// ✅ 消除检查逻辑保持和手动一致
|
|
|
this.scheduleOnce(() => {
|
|
|
this.gridEliminate().then(() => {
|
|
|
this.prompt(false).then((promptFlag) => {
|
|
|
if (!promptFlag) {
|
|
|
- this.autoState = false
|
|
|
this.gameOver()
|
|
|
}
|
|
|
})
|
|
|
@@ -2199,7 +2221,7 @@ export class EliminateViewComp extends CCComp {
|
|
|
return
|
|
|
}
|
|
|
if (!this.autoState) {
|
|
|
- this.btn_auto();
|
|
|
+ this.autoGame();
|
|
|
//改按钮状态
|
|
|
this.autoState = true;
|
|
|
this.initButtonState(this.autoState);
|
|
|
@@ -2239,7 +2261,7 @@ export class EliminateViewComp extends CCComp {
|
|
|
this.initData();
|
|
|
this.setData();
|
|
|
this.reopenGrid();
|
|
|
- // this.initButtonState(this.autoState);
|
|
|
+ this.initButtonState(this.autoState);
|
|
|
this.updateWelfarePoint();
|
|
|
}
|
|
|
|
|
|
@@ -2297,7 +2319,6 @@ export class EliminateViewComp extends CCComp {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
btn_text() {
|
|
|
// const param = {
|
|
|
// "showReward": [
|