2022-11-16 13:04:23 +00:00
|
|
|
import { Camera, CCFloat, CCInteger, Component, KeyCode, _decorator } from "cc";
|
2022-11-08 18:45:57 +00:00
|
|
|
import { PlayerCollisionSystem } from "./Collision/PlayerCollisionSystem";
|
|
|
|
import { WeaponCollisionSystem } from "./Collision/WeaponCollisionSystem";
|
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";
|
|
|
|
import { Player } from "./Player/Player";
|
2022-11-16 13:04:23 +00:00
|
|
|
import { GameUI } from "./UI/GameUI";
|
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(CCFloat) private strikeDelay = 0;
|
|
|
|
@property(CCFloat) private collisionDelay = 0;
|
|
|
|
@property(Camera) private camera: Camera;
|
2022-11-16 13:04:23 +00:00
|
|
|
@property(GameUI) private gameUI: GameUI;
|
|
|
|
@property(Number) private requiredLevelXps: number[] = [];
|
2022-11-08 18:45:57 +00:00
|
|
|
private playerCollisionSystem: PlayerCollisionSystem;
|
|
|
|
|
|
|
|
public start(): void {
|
|
|
|
this.virtualJoystic.init();
|
|
|
|
this.weapon.init(this.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-16 13:04:23 +00:00
|
|
|
this.player.init(dualInput, this.weapon, 50, this.requiredLevelXps);
|
2022-11-14 15:35:47 +00:00
|
|
|
|
2022-11-08 18:45:57 +00:00
|
|
|
this.playerCollisionSystem = new PlayerCollisionSystem(this.player, this.collisionDelay);
|
|
|
|
new WeaponCollisionSystem(this.weapon);
|
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 {
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|