// Learn TypeScript: // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/typescript.html // - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html // Learn Attribute: // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html // - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html // - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html const {ccclass, property} = cc._decorator; @ccclass export default class GameData extends cc.Component { private static _instance: GameData = null; public selectedLevel: number = 1; public score: number = 0; public static get instance(): GameData { if (!this._instance) { this._instance = new GameData(); } return this._instance; } public setScore(score: number) { this.score = score; } public getScore(): number { return this.score; } public get enemyHealth(): number { return this.selectedLevel; } private levelConfig = { 1: { shootingSpeed: 6, spawnInterval: 6, playerSpeed: 2.5 }, 2: { shootingSpeed: 5, spawnInterval: 8, playerSpeed: 3 }, 3: { shootingSpeed: 4, spawnInterval: 10, playerSpeed: 3.5 }, 4: { shootingSpeed: 3, spawnInterval: 12, playerSpeed: 4 }, }; public get playerShootingInterval(): number { return this.levelConfig[this.selectedLevel].shootingSpeed; } public get enemySpawnInterval(): number { return this.levelConfig[this.selectedLevel].spawnInterval; } public get enemyMoveTime(): number { return this.levelConfig[this.selectedLevel].playerSpeed; } }