import { _decorator, Component, Prefab, Node, Vec2, Vec3, randomRangeInt, CCInteger, Input } from 'cc'; import ObjectPool from '../Pool/ObjectPool'; import { Ball } from '../Gameplay/Ball'; import Utilities from '../Utilities/Utilities'; import GameState from '../Enum/GameState'; import { EventManger } from './EventManger'; import GameEvent from '../Enum/GameEvent'; const { ccclass, property } = _decorator; @ccclass('GameManager') export class GameManager extends Component { //singleton private static _instance: GameManager = null; public static get instance(): GameManager { return GameManager._instance; } @property({ type: Prefab, visible: true }) private _ballPrefab: Prefab; @property({ type: Vec3, visible: true }) private _ballSpawnPosition: Vec3; @property({ type: CCInteger, visible: true }) private _balls = 3; private _ballPool: ObjectPool; private _gameState = GameState.Init; public highestStreak: number; public score = 0; protected onLoad(): void { GameManager._instance = this; this._ballPool = new ObjectPool(this._ballPrefab, 10, false, Ball); } protected async start() { // this.spawnBall(); const a = [1, 4, 4, 5]; } private changeGameState(state: GameState) { this._gameState = state; EventManger.instance.emit(GameEvent.GameStateChange, this._gameState); } public spawnBall(): Ball { const ball = this._ballPool.get(this.node, Ball); ball.node.setPosition(this._ballSpawnPosition); let dir = randomRangeInt(-1, 2); while (dir == 0) { dir = randomRangeInt(-1, 2); } const force = new Vec2(dir, 1); ball.addFocre(force.multiply2f(1, 50)); return ball; } public async ballOut(ball: Node) { this._balls--; if (this._balls === 0) { return; } this._ballPool.release(ball); await Utilities.delay(1000); // this.spawnBall(); } public onRevive() { throw new Error('Method not implemented.'); } }