2022-11-30 09:37:09 +01:00
|
|
|
import { Camera, Component, JsonAsset, KeyCode, Vec2, _decorator } from "cc";
|
2022-11-17 18:28:39 +01:00
|
|
|
import { ModalWindowManager } from "../Services/ModalWindowSystem/ModalWindowManager";
|
2022-12-07 10:47:46 +01:00
|
|
|
import { delay } from "../Services/Utils/AsyncUtils";
|
2022-12-13 10:21:44 +01:00
|
|
|
import { Background } from "./Background/Background";
|
2022-11-08 19:45:57 +01:00
|
|
|
import { PlayerCollisionSystem } from "./Collision/PlayerCollisionSystem";
|
2022-11-30 08:21:22 +01:00
|
|
|
import { PlayerProjectileCollisionSystem } from "./Collision/PlayerProjectileCollisionSystem";
|
2022-11-08 19:45:57 +01:00
|
|
|
import { WeaponCollisionSystem } from "./Collision/WeaponCollisionSystem";
|
2022-11-24 13:17:05 +01:00
|
|
|
import { GameSettings } from "./Data/GameSettings";
|
2022-11-16 12:26:20 +01:00
|
|
|
import { KeyboardInput } from "./Input/KeyboardInput";
|
2022-11-14 16:35:47 +01:00
|
|
|
import { MultiInput } from "./Input/MultiInput";
|
2022-11-08 19:45:57 +01:00
|
|
|
import { VirtualJoystic } from "./Input/VirtualJoystic";
|
2022-11-25 12:00:09 +01:00
|
|
|
import { GameModalLauncher } from "./ModalWIndows/GameModalLauncher";
|
|
|
|
import { Pauser } from "./Pauser";
|
2022-11-16 14:04:23 +01:00
|
|
|
import { GameUI } from "./UI/GameUI";
|
2022-11-28 12:19:04 +01:00
|
|
|
import { EnemyManager } from "./Unit/Enemy/EnemyManager";
|
|
|
|
import { Player } from "./Unit/Player/Player";
|
2022-11-30 11:44:20 +01:00
|
|
|
import { HaloProjectileLauncher } from "./Unit/Player/ProjectileLauncher/HaloProjectileLauncher";
|
2022-11-30 09:37:09 +01:00
|
|
|
import { ProjectileLauncher } from "./Unit/Player/ProjectileLauncher/ProjectileLauncher";
|
2022-12-01 12:16:52 +01:00
|
|
|
import { WaveProjectileLauncher } from "./Unit/Player/ProjectileLauncher/WaveProjectileLauncher";
|
2022-11-24 13:17:05 +01:00
|
|
|
import { Upgrader } from "./Upgrades/Upgrader";
|
2022-11-28 11:49:16 +01:00
|
|
|
|
2022-11-08 19:45:57 +01:00
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
2022-12-07 10:47:46 +01:00
|
|
|
@ccclass("Game")
|
|
|
|
export class Game extends Component {
|
2022-11-08 19:45:57 +01:00
|
|
|
@property(VirtualJoystic) private virtualJoystic: VirtualJoystic;
|
|
|
|
@property(Player) private player: Player;
|
2022-11-30 11:44:20 +01:00
|
|
|
@property(ProjectileLauncher) private haloProjectileLauncherComponent: ProjectileLauncher;
|
2022-12-01 12:16:52 +01:00
|
|
|
@property(ProjectileLauncher) private horizontalProjectileLauncherComponent: ProjectileLauncher;
|
|
|
|
@property(ProjectileLauncher) private diagonalProjectileLauncherComponent: ProjectileLauncher;
|
2022-11-16 12:26:20 +01:00
|
|
|
@property(EnemyManager) private enemyManager: EnemyManager;
|
|
|
|
@property(Camera) private camera: Camera;
|
2022-11-16 14:04:23 +01:00
|
|
|
@property(GameUI) private gameUI: GameUI;
|
2022-12-13 10:21:44 +01:00
|
|
|
@property(Background) private background: Background;
|
2022-11-17 18:28:39 +01:00
|
|
|
@property(ModalWindowManager) private modalWindowManager: ModalWindowManager;
|
2022-11-24 13:17:05 +01:00
|
|
|
@property(JsonAsset) private settingsAsset: JsonAsset;
|
2022-11-17 18:28:39 +01:00
|
|
|
|
2022-11-08 19:45:57 +01:00
|
|
|
private playerCollisionSystem: PlayerCollisionSystem;
|
2022-11-30 11:44:20 +01:00
|
|
|
private haloProjectileLauncher: HaloProjectileLauncher;
|
2022-12-01 12:16:52 +01:00
|
|
|
private horizontalProjectileLauncher: WaveProjectileLauncher;
|
|
|
|
private diagonalProjectileLauncher: WaveProjectileLauncher;
|
2022-11-08 19:45:57 +01:00
|
|
|
|
2022-11-25 12:00:09 +01:00
|
|
|
private gamePauser: Pauser = new Pauser();
|
2022-11-23 09:01:01 +01:00
|
|
|
|
2022-12-07 10:47:46 +01:00
|
|
|
private static instance: Game;
|
|
|
|
|
|
|
|
public static get Instance(): Game {
|
|
|
|
return this.instance;
|
|
|
|
}
|
|
|
|
|
2022-11-08 19:45:57 +01:00
|
|
|
public start(): void {
|
2022-12-07 10:47:46 +01:00
|
|
|
Game.instance = this;
|
|
|
|
this.gamePauser.pause();
|
|
|
|
}
|
|
|
|
|
|
|
|
public async playGame(): Promise<number> {
|
2022-11-28 11:49:16 +01:00
|
|
|
const settings: GameSettings = <GameSettings>this.settingsAsset.json;
|
2022-11-24 13:17:05 +01:00
|
|
|
|
2022-11-08 19:45:57 +01:00
|
|
|
this.virtualJoystic.init();
|
2022-11-29 15:55:47 +01:00
|
|
|
|
2022-11-14 16:35:47 +01:00
|
|
|
const wasd = new KeyboardInput(KeyCode.KEY_W, KeyCode.KEY_S, KeyCode.KEY_A, KeyCode.KEY_D);
|
|
|
|
const arrowKeys = new KeyboardInput(KeyCode.ARROW_UP, KeyCode.ARROW_DOWN, KeyCode.ARROW_LEFT, KeyCode.ARROW_RIGHT);
|
2022-12-07 10:47:46 +01:00
|
|
|
const multiInput: MultiInput = new MultiInput([this.virtualJoystic, wasd, arrowKeys]);
|
|
|
|
this.player.init(multiInput, settings.player);
|
2022-11-14 16:35:47 +01:00
|
|
|
|
2022-11-28 11:49:16 +01:00
|
|
|
this.playerCollisionSystem = new PlayerCollisionSystem(this.player, settings.player.collisionDelay);
|
2022-11-29 15:55:47 +01:00
|
|
|
new WeaponCollisionSystem(this.player.Weapon);
|
2022-11-16 12:26:20 +01:00
|
|
|
|
2022-12-06 10:00:18 +01:00
|
|
|
this.enemyManager.init(this.player.node, settings.enemyManager);
|
2022-11-16 14:04:23 +01:00
|
|
|
|
2022-11-30 11:44:20 +01:00
|
|
|
this.haloProjectileLauncher = new HaloProjectileLauncher(
|
|
|
|
this.haloProjectileLauncherComponent,
|
|
|
|
this.player.node,
|
|
|
|
settings.player.haloLauncher
|
|
|
|
);
|
|
|
|
|
2022-12-01 12:16:52 +01:00
|
|
|
this.horizontalProjectileLauncher = new WaveProjectileLauncher(
|
|
|
|
this.horizontalProjectileLauncherComponent,
|
2022-11-30 11:44:20 +01:00
|
|
|
this.player.node,
|
2022-12-01 12:16:52 +01:00
|
|
|
[new Vec2(-1, 0), new Vec2(1, 0)],
|
|
|
|
settings.player.horizontalLauncher
|
2022-11-30 11:44:20 +01:00
|
|
|
);
|
2022-11-30 09:37:09 +01:00
|
|
|
|
2022-12-01 12:16:52 +01:00
|
|
|
this.diagonalProjectileLauncher = new WaveProjectileLauncher(
|
|
|
|
this.diagonalProjectileLauncherComponent,
|
|
|
|
this.player.node,
|
|
|
|
[new Vec2(-0.5, -0.5), new Vec2(0.5, -0.5)],
|
|
|
|
settings.player.diagonalLauncher
|
|
|
|
);
|
|
|
|
|
|
|
|
new PlayerProjectileCollisionSystem([this.haloProjectileLauncher, this.horizontalProjectileLauncher, this.diagonalProjectileLauncher]);
|
2022-11-30 16:04:48 +01:00
|
|
|
|
2022-12-12 14:41:08 +01:00
|
|
|
const upgrader = new Upgrader(
|
|
|
|
this.player,
|
|
|
|
this.horizontalProjectileLauncher,
|
|
|
|
this.haloProjectileLauncher,
|
|
|
|
this.diagonalProjectileLauncher,
|
|
|
|
settings.upgrades
|
|
|
|
);
|
2022-11-30 16:04:48 +01:00
|
|
|
new GameModalLauncher(this.modalWindowManager, this.player, this.gamePauser, upgrader);
|
2022-11-30 08:21:22 +01:00
|
|
|
|
2022-11-16 14:04:23 +01:00
|
|
|
this.gameUI.init(this.player);
|
2022-12-13 10:21:44 +01:00
|
|
|
this.background.init(this.player.node);
|
2022-12-07 10:47:46 +01:00
|
|
|
this.gamePauser.resume();
|
|
|
|
|
2022-12-12 12:04:31 +01:00
|
|
|
// while not dead
|
2022-12-12 14:04:37 +01:00
|
|
|
await delay(1000000);
|
2022-12-07 10:47:46 +01:00
|
|
|
this.gamePauser.pause();
|
|
|
|
Game.instance = null;
|
|
|
|
return 1;
|
2022-11-08 19:45:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public update(deltaTime: number): void {
|
2022-11-25 12:00:09 +01:00
|
|
|
if (this.gamePauser.IsPaused) return;
|
2022-11-23 09:01:01 +01:00
|
|
|
|
2022-11-08 19:45:57 +01:00
|
|
|
this.player.gameTick(deltaTime);
|
|
|
|
this.playerCollisionSystem.gameTick(deltaTime);
|
2022-11-16 12:26:20 +01:00
|
|
|
this.enemyManager.gameTick(deltaTime);
|
2022-11-30 11:44:20 +01:00
|
|
|
this.haloProjectileLauncher.gameTick(deltaTime);
|
2022-11-30 16:04:48 +01:00
|
|
|
this.horizontalProjectileLauncher.gameTick(deltaTime);
|
2022-12-01 12:16:52 +01:00
|
|
|
this.diagonalProjectileLauncher.gameTick(deltaTime);
|
2022-12-13 10:21:44 +01:00
|
|
|
this.background.gameTick();
|
2022-11-16 12:26:20 +01:00
|
|
|
|
|
|
|
this.camera.node.worldPosition = this.player.node.worldPosition;
|
2022-11-08 19:45:57 +01:00
|
|
|
}
|
|
|
|
}
|