Slash-The-Hordes/assets/Scripts/Game/GameBootstrapper.ts

65 lines
2.9 KiB
TypeScript
Raw Normal View History

2022-11-24 12:17:05 +00:00
import { Camera, CCFloat, CCInteger, Component, director, JsonAsset, KeyCode, _decorator } from "cc";
2022-11-17 17:28:39 +00:00
import { ModalWindowManager } from "../Services/ModalWindowSystem/ModalWindowManager";
2022-11-08 18:45:57 +00:00
import { PlayerCollisionSystem } from "./Collision/PlayerCollisionSystem";
import { WeaponCollisionSystem } from "./Collision/WeaponCollisionSystem";
2022-11-24 12:17:05 +00:00
import { GameSettings } from "./Data/GameSettings";
2022-11-16 11:26:20 +00:00
import { EnemyManager } from "./Enemy/EnemyManager";
import { KeyboardInput } from "./Input/KeyboardInput";
2022-11-14 15:35:47 +00:00
import { MultiInput } from "./Input/MultiInput";
2022-11-08 18:45:57 +00:00
import { VirtualJoystic } from "./Input/VirtualJoystic";
2022-11-25 11:00:09 +00:00
import { GameModalLauncher } from "./ModalWIndows/GameModalLauncher";
import { Pauser } from "./Pauser";
2022-11-08 18:45:57 +00:00
import { Player } from "./Player/Player";
2022-11-16 13:04:23 +00:00
import { GameUI } from "./UI/GameUI";
2022-11-24 12:17:05 +00:00
import { Upgrader } from "./Upgrades/Upgrader";
import { UpgradeType } from "./Upgrades/UpgradeType";
2022-11-08 18:45:57 +00:00
import { Weapon } from "./Weapon";
const { ccclass, property } = _decorator;
@ccclass("GameBootstrapper")
export class GameBootstrapper extends Component {
@property(VirtualJoystic) private virtualJoystic: VirtualJoystic;
@property(Player) private player: Player;
@property(Weapon) private weapon: Weapon;
2022-11-16 11:26:20 +00:00
@property(EnemyManager) private enemyManager: EnemyManager;
@property(Camera) private camera: Camera;
2022-11-16 13:04:23 +00:00
@property(GameUI) private gameUI: GameUI;
2022-11-17 17:28:39 +00:00
@property(ModalWindowManager) private modalWindowManager: ModalWindowManager;
2022-11-24 12:17:05 +00:00
@property(JsonAsset) private settingsAsset: JsonAsset;
2022-11-17 17:28:39 +00:00
2022-11-08 18:45:57 +00:00
private playerCollisionSystem: PlayerCollisionSystem;
2022-11-25 11:00:09 +00:00
private gamePauser: Pauser = new Pauser();
2022-11-23 08:01:01 +00:00
2022-11-08 18:45:57 +00:00
public start(): void {
2022-11-24 12:17:05 +00:00
const gameSettings: GameSettings = <GameSettings>this.settingsAsset.json;
2022-11-08 18:45:57 +00:00
this.virtualJoystic.init();
2022-11-25 11:00:09 +00:00
this.weapon.init(gameSettings.weaponSettings.strikeDelay);
2022-11-14 15:35:47 +00: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);
const dualInput: MultiInput = new MultiInput([this.virtualJoystic, wasd, arrowKeys]);
2022-11-25 11:00:09 +00:00
this.player.init(dualInput, this.weapon, gameSettings.playerSettings.defaultHP, gameSettings.playerSettings.requiredXP);
2022-11-14 15:35:47 +00:00
2022-11-25 11:00:09 +00:00
this.playerCollisionSystem = new PlayerCollisionSystem(this.player, gameSettings.playerSettings.collisionDelay);
2022-11-08 18:45:57 +00:00
new WeaponCollisionSystem(this.weapon);
2022-11-16 11:26:20 +00:00
2022-11-25 11:00:09 +00:00
const upgrader = new Upgrader(this.player);
new GameModalLauncher(this.modalWindowManager, this.player, this.gamePauser, upgrader);
2022-11-24 12:17:05 +00:00
2022-11-16 11:26:20 +00:00
this.enemyManager.init(this.player.node);
2022-11-16 13:04:23 +00:00
this.gameUI.init(this.player);
2022-11-08 18:45:57 +00:00
}
public update(deltaTime: number): void {
2022-11-25 11:00:09 +00:00
if (this.gamePauser.IsPaused) return;
2022-11-23 08:01:01 +00:00
2022-11-08 18:45:57 +00:00
this.player.gameTick(deltaTime);
this.playerCollisionSystem.gameTick(deltaTime);
2022-11-16 11:26:20 +00:00
this.enemyManager.gameTick(deltaTime);
this.camera.node.worldPosition = this.player.node.worldPosition;
2022-11-08 18:45:57 +00:00
}
}