完善关卡逻辑

This commit is contained in:
2025-05-19 19:51:17 +08:00
parent d51c122d57
commit e9e60706a4
23 changed files with 792 additions and 113 deletions

View File

@@ -1,4 +1,9 @@
import { respath } from "../constants/respath";
import { config } from "../constants/config";
import { UIManager } from "../models/UIManager";
import { StorageManager } from "../models/StorageManager";
import { LevelManager } from "../models/LevelManager";
import { Difficulty } from "./Difficulty";
const { regClass, property } = Laya;
@@ -16,13 +21,35 @@ export class GameOver extends Laya.Script {
//组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次
onAwake(): void {
this.btn_restart.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
UIManager.getInstance().loadStage("first", true);
this.owner.destroy()
var doStage = StorageManager.getInstance().loadStage(config.DEFAULT_STAGE_ID)
var difficulty = doStage.get_difficulty()
StorageManager.getInstance().cleanStage(config.DEFAULT_STAGE_ID)
var user = StorageManager.getInstance().getUser()
user.set_isCompletedMain(false)
StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, difficulty, difficulty, user.get_progress(difficulty))
UIManager.getInstance().loadStageUI(config.DEFAULT_STAGE_ID);
this.owner.destroy()
})
this.btn_new.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
UIManager.getInstance().loadStage("first", true);
this.owner.destroy()
Laya.loader.load(respath.difficulty_ui_res).then((go)=>{
var prefab = go.create()
var d = UIManager.getInstance().getUIRoot().addChild(prefab).getComponent(Difficulty)
d.onInit((value: string)=> {
console.log("选择难度", value)
StorageManager.getInstance().cleanStage(config.DEFAULT_STAGE_ID)
var user = StorageManager.getInstance().getUser()
user.set_isCompletedMain(false)
var index = user.get_progress(value)
var levelStr = LevelManager.getInstance().getLevelStr(value, index)
if (!levelStr || levelStr.length <= 0) {//说明当前难度已经打通了,所以给他从头开始
user.update_progress(value, 0)
}
StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, value, value, user.get_progress(value))
UIManager.getInstance().loadStageUI(config.DEFAULT_STAGE_ID);
this.owner.destroy()
})
})
})
}