mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2025-10-09 00:26:04 +00:00
game runner
This commit is contained in:
17
assets/Scripts/Game/Data/UserData.ts
Normal file
17
assets/Scripts/Game/Data/UserData.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
export class UserData {
|
||||
public soundVolume = 0;
|
||||
public musicVolume = 0;
|
||||
public game = new GameData();
|
||||
}
|
||||
|
||||
export class GameData {
|
||||
public goldCoins = 0;
|
||||
public metaUpgrades = new MetaUpgradesData();
|
||||
}
|
||||
|
||||
export class MetaUpgradesData {
|
||||
public maxHpLevel = 0;
|
||||
public overallDamageLevel = 0;
|
||||
public projectilePiercingLevel = 0;
|
||||
public movementSpeedLevel = 0;
|
||||
}
|
9
assets/Scripts/Game/Data/UserData.ts.meta
Normal file
9
assets/Scripts/Game/Data/UserData.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "7431ff7c-480c-4474-9434-654eda0a1a08",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
@@ -1,5 +1,6 @@
|
||||
import { Camera, Component, JsonAsset, KeyCode, Vec2, _decorator } from "cc";
|
||||
import { ModalWindowManager } from "../Services/ModalWindowSystem/ModalWindowManager";
|
||||
import { delay } from "../Services/Utils/AsyncUtils";
|
||||
import { PlayerCollisionSystem } from "./Collision/PlayerCollisionSystem";
|
||||
import { PlayerProjectileCollisionSystem } from "./Collision/PlayerProjectileCollisionSystem";
|
||||
import { WeaponCollisionSystem } from "./Collision/WeaponCollisionSystem";
|
||||
@@ -19,8 +20,8 @@ import { Upgrader } from "./Upgrades/Upgrader";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("GameBootstrapper")
|
||||
export class GameBootstrapper extends Component {
|
||||
@ccclass("Game")
|
||||
export class Game extends Component {
|
||||
@property(VirtualJoystic) private virtualJoystic: VirtualJoystic;
|
||||
@property(Player) private player: Player;
|
||||
@property(ProjectileLauncher) private haloProjectileLauncherComponent: ProjectileLauncher;
|
||||
@@ -39,15 +40,26 @@ export class GameBootstrapper extends Component {
|
||||
|
||||
private gamePauser: Pauser = new Pauser();
|
||||
|
||||
private static instance: Game;
|
||||
|
||||
public static get Instance(): Game {
|
||||
return this.instance;
|
||||
}
|
||||
|
||||
public start(): void {
|
||||
Game.instance = this;
|
||||
this.gamePauser.pause();
|
||||
}
|
||||
|
||||
public async playGame(): Promise<number> {
|
||||
const settings: GameSettings = <GameSettings>this.settingsAsset.json;
|
||||
|
||||
this.virtualJoystic.init();
|
||||
|
||||
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, settings.player);
|
||||
const multiInput: MultiInput = new MultiInput([this.virtualJoystic, wasd, arrowKeys]);
|
||||
this.player.init(multiInput, settings.player);
|
||||
|
||||
this.playerCollisionSystem = new PlayerCollisionSystem(this.player, settings.player.collisionDelay);
|
||||
new WeaponCollisionSystem(this.player.Weapon);
|
||||
@@ -80,6 +92,12 @@ export class GameBootstrapper extends Component {
|
||||
new GameModalLauncher(this.modalWindowManager, this.player, this.gamePauser, upgrader);
|
||||
|
||||
this.gameUI.init(this.player);
|
||||
this.gamePauser.resume();
|
||||
|
||||
await delay(10000);
|
||||
this.gamePauser.pause();
|
||||
Game.instance = null;
|
||||
return 1;
|
||||
}
|
||||
|
||||
public update(deltaTime: number): void {
|
@@ -13,12 +13,14 @@ export class Enemy extends Component {
|
||||
private movementType: EnemyMovementType;
|
||||
private health: UnitHealth = new UnitHealth(1);
|
||||
private deathEvent: Signal<Enemy> = new Signal<Enemy>();
|
||||
private speed: number;
|
||||
private speedX: number;
|
||||
private speedY: number;
|
||||
|
||||
public setup(position: Vec3, movementType: EnemyMovementType): void {
|
||||
this.movementType = movementType;
|
||||
this.health = new UnitHealth(1);
|
||||
this.speed = randomRange(40, 90);
|
||||
this.speedX = randomRange(40, 90);
|
||||
this.speedY = randomRange(40, 90);
|
||||
this.node.setWorldPosition(position);
|
||||
this.node.active = true;
|
||||
}
|
||||
@@ -52,8 +54,8 @@ export class Enemy extends Component {
|
||||
|
||||
public moveBy(move: Vec3, deltaTime: number): void {
|
||||
const newPosition: Vec3 = this.node.worldPosition;
|
||||
newPosition.x += move.x * this.speed * deltaTime;
|
||||
newPosition.y += move.y * this.speed * deltaTime;
|
||||
newPosition.x += move.x * this.speedX * deltaTime;
|
||||
newPosition.y += move.y * this.speedY * deltaTime;
|
||||
|
||||
this.node.setWorldPosition(newPosition);
|
||||
}
|
||||
|
@@ -11,7 +11,7 @@ export class WaveEnemyMover extends EnemyMover {
|
||||
let direction: Vec3 = new Vec3();
|
||||
|
||||
// if the enemy is added soon enough, move as a single group towards one direction
|
||||
if (Vec3.distance(this.lastTargetPosition, this.targetNode.worldPosition) < 10) {
|
||||
if (Vec3.equals(this.lastTargetPosition, this.targetNode.worldPosition)) {
|
||||
direction = this.lastDirection;
|
||||
} else {
|
||||
direction = Vec3.subtract(direction, this.targetNode.worldPosition, enemy.node.worldPosition);
|
||||
|
@@ -15,7 +15,7 @@ export class IndividualEnemySpawner {
|
||||
if (this.spawnTimer.tryFinishPeriod()) {
|
||||
const posX: number = randomRange(300, 600) * randomPositiveOrNegative();
|
||||
const posY: number = randomRange(300, 600) * randomPositiveOrNegative();
|
||||
this.enemySpawner.spawnNewEnemy(posX, posY, EnemyMovementType.Launch);
|
||||
this.enemySpawner.spawnNewEnemy(posX, posY, EnemyMovementType.Follow);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -48,8 +48,8 @@ export class WaveEnemySpawner {
|
||||
|
||||
private trySpawnNewGroup(): void {
|
||||
if (this.spawnTimer.tryFinishPeriod()) {
|
||||
const defaultPosX: number = 200 * randomPositiveOrNegative();
|
||||
const defaultPosY: number = 200 * randomPositiveOrNegative();
|
||||
const defaultPosX: number = (500 + randomRange(0, 100)) * randomPositiveOrNegative();
|
||||
const defaultPosY: number = randomRange(0, 500) * randomPositiveOrNegative();
|
||||
|
||||
const enemies: Enemy[] = [];
|
||||
const side: number = Math.ceil(Math.sqrt(this.enemiesPerWave));
|
||||
|
@@ -9,5 +9,6 @@ export enum UpgradeType {
|
||||
export enum MetaUpgradeType {
|
||||
MaxHp,
|
||||
OverallDamage,
|
||||
ProjectilePiercing
|
||||
ProjectilePiercing,
|
||||
MovementSpeed
|
||||
}
|
||||
|
Reference in New Issue
Block a user