2022-11-16 11:26:20 +00:00
|
|
|
import { Camera, CCFloat, 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";
|
|
|
|
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-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]);
|
|
|
|
this.player.init(dualInput, this.weapon, 50);
|
|
|
|
|
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-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
|
|
|
}
|
|
|
|
}
|