mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2025-10-09 08:36:14 +00:00
Halo projectile launcher
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
export class GameSettings {
|
||||
public player: PlayerSettings = new PlayerSettings();
|
||||
public weapon: WeaponSettings = new WeaponSettings();
|
||||
public upgrades: UpgradeSettings = new UpgradeSettings();
|
||||
}
|
||||
|
||||
@@ -9,6 +8,8 @@ export class PlayerSettings {
|
||||
public requiredXP: number[] = [];
|
||||
public regenerationDelay = 0;
|
||||
public collisionDelay = 0;
|
||||
public weapon: WeaponSettings = new WeaponSettings();
|
||||
public haloLauncher: HaloLauncherSettings = new HaloLauncherSettings();
|
||||
}
|
||||
|
||||
export class WeaponSettings {
|
||||
@@ -16,10 +17,18 @@ export class WeaponSettings {
|
||||
public damage = 0;
|
||||
}
|
||||
|
||||
export class HaloLauncherSettings {
|
||||
public projectileLifetime = 0;
|
||||
public projectileSpeed = 0;
|
||||
public projectilesToSpawn = 0;
|
||||
public cooldown = 0;
|
||||
}
|
||||
|
||||
export class UpgradeSettings {
|
||||
public maxWeaponLengthUpgrades = 0;
|
||||
public maxWeaponDamageUpgrades = 0;
|
||||
public maxHorizontalProjectileUpgrades = 0;
|
||||
public maxVerticalProjectileUpgrades = 0;
|
||||
public maxHaloProjectileUpgrades = 0;
|
||||
public maxRegenerationUpgrades = 0;
|
||||
}
|
||||
|
@@ -10,8 +10,9 @@ import { GameModalLauncher } from "./ModalWIndows/GameModalLauncher";
|
||||
import { Pauser } from "./Pauser";
|
||||
import { GameUI } from "./UI/GameUI";
|
||||
import { EnemyManager } from "./Unit/Enemy/EnemyManager";
|
||||
import { HaloProjectileLauncher } from "./Unit/Player/Halo/HaloProjectileLauncher";
|
||||
import { Player } from "./Unit/Player/Player";
|
||||
import { Weapon } from "./Unit/Player/Weapon/Weapon";
|
||||
|
||||
import { Upgrader } from "./Upgrades/Upgrader";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
@@ -20,7 +21,7 @@ const { ccclass, property } = _decorator;
|
||||
export class GameBootstrapper extends Component {
|
||||
@property(VirtualJoystic) private virtualJoystic: VirtualJoystic;
|
||||
@property(Player) private player: Player;
|
||||
@property(Weapon) private weapon: Weapon;
|
||||
@property(HaloProjectileLauncher) private haloProjectiles: HaloProjectileLauncher;
|
||||
@property(EnemyManager) private enemyManager: EnemyManager;
|
||||
@property(Camera) private camera: Camera;
|
||||
@property(GameUI) private gameUI: GameUI;
|
||||
@@ -35,20 +36,23 @@ export class GameBootstrapper extends Component {
|
||||
const settings: GameSettings = <GameSettings>this.settingsAsset.json;
|
||||
|
||||
this.virtualJoystic.init();
|
||||
this.weapon.init(settings.weapon);
|
||||
|
||||
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, settings.player);
|
||||
this.player.init(dualInput, settings.player);
|
||||
|
||||
this.playerCollisionSystem = new PlayerCollisionSystem(this.player, settings.player.collisionDelay);
|
||||
new WeaponCollisionSystem(this.weapon);
|
||||
new WeaponCollisionSystem(this.player.Weapon);
|
||||
|
||||
const upgrader = new Upgrader(this.player, settings.upgrades);
|
||||
new GameModalLauncher(this.modalWindowManager, this.player, this.gamePauser, upgrader);
|
||||
|
||||
this.enemyManager.init(this.player.node);
|
||||
|
||||
this.haloProjectiles.init(this.player.node, settings.player.haloLauncher);
|
||||
this.haloProjectiles.upgrade();
|
||||
|
||||
this.gameUI.init(this.player);
|
||||
}
|
||||
|
||||
@@ -58,6 +62,7 @@ export class GameBootstrapper extends Component {
|
||||
this.player.gameTick(deltaTime);
|
||||
this.playerCollisionSystem.gameTick(deltaTime);
|
||||
this.enemyManager.gameTick(deltaTime);
|
||||
this.haloProjectiles.gameTick(deltaTime);
|
||||
|
||||
this.camera.node.worldPosition = this.player.node.worldPosition;
|
||||
}
|
||||
|
12
assets/Scripts/Game/Unit/Player/Halo.meta
Normal file
12
assets/Scripts/Game/Unit/Player/Halo.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"ver": "1.1.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "b89dc5a7-3450-47e4-bc36-ae5d08f4bc89",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"compressionType": {},
|
||||
"isRemoteBundle": {}
|
||||
}
|
||||
}
|
@@ -0,0 +1,97 @@
|
||||
import { Component, Prefab, Vec2, Vec3, _decorator, Node } from "cc";
|
||||
import { GameTimer } from "../../../../Services/GameTimer";
|
||||
import { ObjectPool } from "../../../../Services/ObjectPool";
|
||||
import { roundToOneDecimal } from "../../../../Services/Utils/MathUtils";
|
||||
import { HaloLauncherSettings } from "../../../Data/GameSettings";
|
||||
import { PlayerProjectile } from "./PlayerProjectile";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("HaloProjectileLauncher")
|
||||
export class HaloProjectileLauncher extends Component {
|
||||
@property(Prefab) private projectilePrefab: Prefab;
|
||||
private fireTimer: GameTimer;
|
||||
private lifetimeTimer: GameTimer;
|
||||
private projectilesToSpawn: number;
|
||||
private defaultCooldown: number;
|
||||
private speed: number;
|
||||
private currentLevel = 0;
|
||||
|
||||
private isFiring = false;
|
||||
|
||||
private projectilePool: ObjectPool<PlayerProjectile>;
|
||||
private projectiles: PlayerProjectile[] = [];
|
||||
private directions: Vec2[] = [];
|
||||
|
||||
private playerNode: Node;
|
||||
|
||||
public init(playerNode: Node, settings: HaloLauncherSettings): void {
|
||||
this.playerNode = playerNode;
|
||||
this.projectilesToSpawn = settings.projectilesToSpawn;
|
||||
this.projectilePool = new ObjectPool<PlayerProjectile>(this.projectilePrefab, this.node, this.projectilesToSpawn, "PlayerProjectile");
|
||||
|
||||
this.speed = settings.projectileSpeed;
|
||||
this.defaultCooldown = settings.cooldown;
|
||||
this.lifetimeTimer = new GameTimer(settings.projectileLifetime);
|
||||
this.fireTimer = new GameTimer(this.defaultCooldown);
|
||||
|
||||
const angle: number = (2 * Math.PI) / this.projectilesToSpawn;
|
||||
|
||||
for (let i = 0; i < this.projectilesToSpawn; i++) {
|
||||
const x: number = roundToOneDecimal(Math.sin(angle * i));
|
||||
const y: number = roundToOneDecimal(Math.cos(angle * i));
|
||||
this.directions.push(new Vec2(x, y).normalize());
|
||||
}
|
||||
}
|
||||
|
||||
public upgrade(): void {
|
||||
this.currentLevel++;
|
||||
this.fireTimer = new GameTimer(this.defaultCooldown - this.currentLevel);
|
||||
}
|
||||
|
||||
public gameTick(deltaTime: number): void {
|
||||
if (this.currentLevel == 0) return;
|
||||
|
||||
this.fireTimer.gameTick(deltaTime);
|
||||
if (this.isFiring) {
|
||||
this.moveAllProjectiles(deltaTime);
|
||||
this.tryRemoveAllProjectiles(deltaTime);
|
||||
} else {
|
||||
if (this.fireTimer.tryFinishPeriod()) {
|
||||
this.fireProjectiles();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fireProjectiles(): void {
|
||||
for (let index = 0; index < this.projectilesToSpawn; index++) {
|
||||
const projectile: PlayerProjectile = this.projectilePool.borrow();
|
||||
projectile.node.setWorldPosition(this.playerNode.worldPosition);
|
||||
projectile.node.active = true;
|
||||
this.projectiles.push(projectile);
|
||||
}
|
||||
|
||||
this.isFiring = true;
|
||||
}
|
||||
|
||||
private moveAllProjectiles(deltaTime: number): void {
|
||||
for (let i = 0; i < this.projectiles.length; i++) {
|
||||
const newPosition: Vec3 = this.projectiles[i].node.worldPosition;
|
||||
newPosition.x += this.directions[i].x * deltaTime * this.speed;
|
||||
newPosition.y += this.directions[i].y * deltaTime * this.speed;
|
||||
|
||||
this.projectiles[i].node.setWorldPosition(newPosition);
|
||||
}
|
||||
}
|
||||
|
||||
private tryRemoveAllProjectiles(deltaTime: number): void {
|
||||
this.lifetimeTimer.gameTick(deltaTime);
|
||||
if (this.lifetimeTimer.tryFinishPeriod()) {
|
||||
for (const projectile of this.projectiles) {
|
||||
this.projectilePool.return(projectile);
|
||||
}
|
||||
|
||||
this.projectiles = [];
|
||||
this.isFiring = false;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "422b46ec-3e15-437d-97fc-7f44a277c3be",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
14
assets/Scripts/Game/Unit/Player/Halo/PlayerProjectile.ts
Normal file
14
assets/Scripts/Game/Unit/Player/Halo/PlayerProjectile.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { _decorator, Component, Node } from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('PlayerProjectile')
|
||||
export class PlayerProjectile extends Component {
|
||||
start() {
|
||||
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "6a24e600-866b-4c0d-9a39-59bf222c2e50",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
@@ -14,22 +14,20 @@ export class Player extends Component {
|
||||
@property private speed = 0;
|
||||
@property(BoxCollider2D) private collider: BoxCollider2D;
|
||||
@property(PlayerUI) private playerUI: PlayerUI;
|
||||
@property(Weapon) private weapon: Weapon;
|
||||
|
||||
private input: IInput;
|
||||
private weapon: Weapon;
|
||||
private health: UnitHealth;
|
||||
private level: UnitLevel;
|
||||
private regeneration: PlayerRegeneration;
|
||||
|
||||
public init(input: IInput, weapon: Weapon, settings: PlayerSettings): void {
|
||||
public init(input: IInput, settings: PlayerSettings): void {
|
||||
this.input = input;
|
||||
this.weapon = weapon;
|
||||
this.health = new UnitHealth(settings.defaultHP);
|
||||
this.level = new UnitLevel(settings.requiredXP);
|
||||
this.regeneration = new PlayerRegeneration(this.health, settings.regenerationDelay);
|
||||
|
||||
this.weapon.node.parent = this.node;
|
||||
this.weapon.node.setPosition(new Vec3());
|
||||
this.weapon.init(settings.weapon);
|
||||
|
||||
this.playerUI.init(this.health);
|
||||
}
|
||||
|
Reference in New Issue
Block a user