mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2024-12-26 03:38:58 +00:00
Merge branch 'master' into Enemies-Players-Animations
This commit is contained in:
commit
a82f0a6360
@ -28,10 +28,13 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"__id__": 6
|
"__id__": 6
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__id__": 8
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"_prefab": {
|
"_prefab": {
|
||||||
"__id__": 8
|
"__id__": 10
|
||||||
},
|
},
|
||||||
"_lpos": {
|
"_lpos": {
|
||||||
"__type__": "cc.Vec3",
|
"__type__": "cc.Vec3",
|
||||||
@ -160,6 +163,26 @@
|
|||||||
"__type__": "cc.CompPrefabInfo",
|
"__type__": "cc.CompPrefabInfo",
|
||||||
"fileId": "3ag4rexLNJW6A/sp6OpwZ8"
|
"fileId": "3ag4rexLNJW6A/sp6OpwZ8"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"__type__": "0f2b2zQHR5IYoIfX8uDxOwj",
|
||||||
|
"_name": "",
|
||||||
|
"_objFlags": 0,
|
||||||
|
"node": {
|
||||||
|
"__id__": 1
|
||||||
|
},
|
||||||
|
"_enabled": true,
|
||||||
|
"__prefab": {
|
||||||
|
"__id__": 9
|
||||||
|
},
|
||||||
|
"animation": {
|
||||||
|
"__id__": 6
|
||||||
|
},
|
||||||
|
"_id": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.CompPrefabInfo",
|
||||||
|
"fileId": "a1aUx8U+FGmqrGQlPCmH17"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"__type__": "cc.PrefabInfo",
|
"__type__": "cc.PrefabInfo",
|
||||||
"root": {
|
"root": {
|
||||||
|
@ -2928,6 +2928,9 @@
|
|||||||
"animation": {
|
"animation": {
|
||||||
"__id__": 7
|
"__id__": 7
|
||||||
},
|
},
|
||||||
|
"sprite": {
|
||||||
|
"__id__": 5
|
||||||
|
},
|
||||||
"_id": ""
|
"_id": ""
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,11 +1,13 @@
|
|||||||
import { Collider2D, Contact2DType } from "cc";
|
import { Collider2D, Contact2DType, Node } from "cc";
|
||||||
import { GroupType } from "../GroupType";
|
import { ISignal } from "../../Services/EventSystem/ISignal";
|
||||||
import { Player } from "../Unit/Player/Player";
|
import { Signal } from "../../Services/EventSystem/Signal";
|
||||||
import { GameTimer } from "../../Services/GameTimer";
|
import { GameTimer } from "../../Services/GameTimer";
|
||||||
import { XP } from "../XP/XP";
|
import { GroupType } from "../GroupType";
|
||||||
|
import { Gold } from "../Items/Gold/Gold";
|
||||||
|
import { ItemManager } from "../Items/ItemManager";
|
||||||
|
import { XP } from "../Items/XP/XP";
|
||||||
import { Enemy } from "../Unit/Enemy/Enemy";
|
import { Enemy } from "../Unit/Enemy/Enemy";
|
||||||
import { Gold } from "../Gold/Gold";
|
import { Player } from "../Unit/Player/Player";
|
||||||
import { GameResult } from "../Game";
|
|
||||||
|
|
||||||
export class PlayerCollisionSystem {
|
export class PlayerCollisionSystem {
|
||||||
private playerContacts: Collider2D[] = [];
|
private playerContacts: Collider2D[] = [];
|
||||||
@ -13,7 +15,9 @@ export class PlayerCollisionSystem {
|
|||||||
|
|
||||||
private groupToResolver: Map<number, (collider: Collider2D) => void> = new Map<number, (collider: Collider2D) => void>();
|
private groupToResolver: Map<number, (collider: Collider2D) => void> = new Map<number, (collider: Collider2D) => void>();
|
||||||
|
|
||||||
public constructor(private player: Player, collisionDelay: number, private gameResult: GameResult) {
|
private itemPickedUpEvent = new Signal<Node>();
|
||||||
|
|
||||||
|
public constructor(private player: Player, collisionDelay: number, private itemManager: ItemManager) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
|
|
||||||
player.Collider.on(Contact2DType.BEGIN_CONTACT, this.onPlayerContactBegin, this);
|
player.Collider.on(Contact2DType.BEGIN_CONTACT, this.onPlayerContactBegin, this);
|
||||||
@ -33,6 +37,10 @@ export class PlayerCollisionSystem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get ItemPickedUpEvent(): ISignal<Node> {
|
||||||
|
return this.itemPickedUpEvent;
|
||||||
|
}
|
||||||
|
|
||||||
private onPlayerContactBegin(_selfCollider: Collider2D, otherCollider: Collider2D): void {
|
private onPlayerContactBegin(_selfCollider: Collider2D, otherCollider: Collider2D): void {
|
||||||
this.playerContacts.push(otherCollider);
|
this.playerContacts.push(otherCollider);
|
||||||
this.resolveContact(otherCollider);
|
this.resolveContact(otherCollider);
|
||||||
@ -66,18 +74,11 @@ export class PlayerCollisionSystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private resolveXpContact(xpCollider: Collider2D): void {
|
private resolveXpContact(xpCollider: Collider2D): void {
|
||||||
const xp: XP = xpCollider.node.getComponent(XP);
|
console.log("Collided with XP");
|
||||||
this.player.Level.addXp(xp.Value);
|
this.itemManager.pickupXP(xpCollider.node.getComponent(XP));
|
||||||
xp.pickup();
|
|
||||||
|
|
||||||
console.log("Collided with xp: " + xp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private resolveGoldContact(goldCollider: Collider2D): void {
|
private resolveGoldContact(goldCollider: Collider2D): void {
|
||||||
const gold: Gold = goldCollider.node.getComponent(Gold);
|
this.itemManager.pickupGold(goldCollider.node.getComponent(Gold));
|
||||||
gold.pickup();
|
|
||||||
this.gameResult.goldCoins++;
|
|
||||||
|
|
||||||
console.log("Collided with gold " + gold);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { Camera, Component, JsonAsset, KeyCode, Vec2, _decorator } from "cc";
|
import { Camera, Component, KeyCode, Vec2, _decorator } from "cc";
|
||||||
import { runInThisContext } from "vm";
|
|
||||||
import { ModalWindowManager } from "../Services/ModalWindowSystem/ModalWindowManager";
|
import { ModalWindowManager } from "../Services/ModalWindowSystem/ModalWindowManager";
|
||||||
import { delay } from "../Services/Utils/AsyncUtils";
|
import { delay } from "../Services/Utils/AsyncUtils";
|
||||||
import { GameAudioAdapter } from "./Audio/GameAudioAdapter";
|
import { GameAudioAdapter } from "./Audio/GameAudioAdapter";
|
||||||
@ -13,6 +12,7 @@ import { UserData } from "./Data/UserData";
|
|||||||
import { KeyboardInput } from "./Input/KeyboardInput";
|
import { KeyboardInput } from "./Input/KeyboardInput";
|
||||||
import { MultiInput } from "./Input/MultiInput";
|
import { MultiInput } from "./Input/MultiInput";
|
||||||
import { VirtualJoystic } from "./Input/VirtualJoystic";
|
import { VirtualJoystic } from "./Input/VirtualJoystic";
|
||||||
|
import { ItemManager } from "./Items/ItemManager";
|
||||||
import { GameModalLauncher } from "./ModalWIndows/GameModalLauncher";
|
import { GameModalLauncher } from "./ModalWIndows/GameModalLauncher";
|
||||||
import { Pauser } from "./Pauser";
|
import { Pauser } from "./Pauser";
|
||||||
import { TestValues } from "./TestGameRunner";
|
import { TestValues } from "./TestGameRunner";
|
||||||
@ -36,6 +36,7 @@ export class Game extends Component {
|
|||||||
@property(ProjectileLauncher) private horizontalProjectileLauncherComponent: ProjectileLauncher;
|
@property(ProjectileLauncher) private horizontalProjectileLauncherComponent: ProjectileLauncher;
|
||||||
@property(ProjectileLauncher) private diagonalProjectileLauncherComponent: ProjectileLauncher;
|
@property(ProjectileLauncher) private diagonalProjectileLauncherComponent: ProjectileLauncher;
|
||||||
@property(EnemyManager) private enemyManager: EnemyManager;
|
@property(EnemyManager) private enemyManager: EnemyManager;
|
||||||
|
@property(ItemManager) private itemManager: ItemManager;
|
||||||
@property(Camera) private camera: Camera;
|
@property(Camera) private camera: Camera;
|
||||||
@property(GameUI) private gameUI: GameUI;
|
@property(GameUI) private gameUI: GameUI;
|
||||||
@property(Background) private background: Background;
|
@property(Background) private background: Background;
|
||||||
@ -77,11 +78,11 @@ export class Game extends Component {
|
|||||||
const multiInput: MultiInput = new MultiInput([this.virtualJoystic, wasd, arrowKeys]);
|
const multiInput: MultiInput = new MultiInput([this.virtualJoystic, wasd, arrowKeys]);
|
||||||
|
|
||||||
this.player.init(multiInput, this.createPlayerData(settings.player, metaUpgrades));
|
this.player.init(multiInput, this.createPlayerData(settings.player, metaUpgrades));
|
||||||
|
|
||||||
this.playerCollisionSystem = new PlayerCollisionSystem(this.player, settings.player.collisionDelay, gameResult);
|
|
||||||
new WeaponCollisionSystem(this.player.Weapon);
|
|
||||||
|
|
||||||
this.enemyManager.init(this.player.node, settings.enemyManager);
|
this.enemyManager.init(this.player.node, settings.enemyManager);
|
||||||
|
this.itemManager.init(this.enemyManager, this.player, gameResult);
|
||||||
|
|
||||||
|
this.playerCollisionSystem = new PlayerCollisionSystem(this.player, settings.player.collisionDelay, this.itemManager);
|
||||||
|
new WeaponCollisionSystem(this.player.Weapon);
|
||||||
|
|
||||||
const projectileData = new ProjectileData();
|
const projectileData = new ProjectileData();
|
||||||
projectileData.damage = 1 + metaUpgrades.getUpgradeValue(MetaUpgradeType.OverallDamage);
|
projectileData.damage = 1 + metaUpgrades.getUpgradeValue(MetaUpgradeType.OverallDamage);
|
||||||
|
12
assets/Scripts/Game/Items.meta
Normal file
12
assets/Scripts/Game/Items.meta
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"ver": "1.1.0",
|
||||||
|
"importer": "directory",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "363c5a59-0b4d-48d4-8b20-7163f1a82ad6",
|
||||||
|
"files": [],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {
|
||||||
|
"compressionType": {},
|
||||||
|
"isRemoteBundle": {}
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
import { Component, Vec3, _decorator } from "cc";
|
import { Component, Vec3, _decorator } from "cc";
|
||||||
import { ISignal } from "../../Services/EventSystem/ISignal";
|
import { ISignal } from "../../../Services/EventSystem/ISignal";
|
||||||
import { Signal } from "../../Services/EventSystem/Signal";
|
import { Signal } from "../../../Services/EventSystem/Signal";
|
||||||
|
|
||||||
const { ccclass, property } = _decorator;
|
const { ccclass, property } = _decorator;
|
||||||
|
|
||||||
@ccclass("Gold")
|
@ccclass("Gold")
|
@ -1,5 +1,5 @@
|
|||||||
import { Component, Prefab, Vec3, _decorator } from "cc";
|
import { Component, Prefab, Vec3, _decorator } from "cc";
|
||||||
import { ObjectPool } from "../../Services/ObjectPool";
|
import { ObjectPool } from "../../../Services/ObjectPool";
|
||||||
import { Gold } from "./Gold";
|
import { Gold } from "./Gold";
|
||||||
|
|
||||||
const { ccclass, property } = _decorator;
|
const { ccclass, property } = _decorator;
|
88
assets/Scripts/Game/Items/ItemManager.ts
Normal file
88
assets/Scripts/Game/Items/ItemManager.ts
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
import { Component, random, randomRange, Vec3, _decorator } from "cc";
|
||||||
|
import { GameResult } from "../Game";
|
||||||
|
import { Enemy } from "../Unit/Enemy/Enemy";
|
||||||
|
import { EnemyManager } from "../Unit/Enemy/EnemyManager";
|
||||||
|
import { Player } from "../Unit/Player/Player";
|
||||||
|
import { Gold } from "./Gold/Gold";
|
||||||
|
import { GoldSpawner } from "./Gold/GoldSpawner";
|
||||||
|
import { PickupEffectManager } from "./PickupEffect/PickupEffectManager";
|
||||||
|
import { XP } from "./XP/XP";
|
||||||
|
import { XPSpawner } from "./XP/XPSpawner";
|
||||||
|
const { ccclass, property } = _decorator;
|
||||||
|
|
||||||
|
@ccclass("ItemManager")
|
||||||
|
export class ItemManager extends Component {
|
||||||
|
@property(XPSpawner) private xpSpawner: XPSpawner;
|
||||||
|
@property(GoldSpawner) private goldSpawner: GoldSpawner;
|
||||||
|
@property(PickupEffectManager) private pickupEffectManager: PickupEffectManager;
|
||||||
|
|
||||||
|
private player: Player;
|
||||||
|
private gameResult: GameResult;
|
||||||
|
|
||||||
|
public init(enemyManager: EnemyManager, player: Player, gameResult: GameResult): void {
|
||||||
|
this.player = player;
|
||||||
|
this.gameResult = gameResult;
|
||||||
|
|
||||||
|
enemyManager.EnemyAddedEvent.on(this.addEnemyListeners, this);
|
||||||
|
enemyManager.EnemyRemovedEvent.on(this.removeEnemyListeners, this);
|
||||||
|
|
||||||
|
this.xpSpawner.init();
|
||||||
|
this.goldSpawner.init();
|
||||||
|
this.pickupEffectManager.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
public pickupXP(xp: XP): void {
|
||||||
|
this.pickupEffectManager.showEffect(xp.node.worldPosition);
|
||||||
|
|
||||||
|
this.player.Level.addXp(xp.Value);
|
||||||
|
xp.pickup();
|
||||||
|
}
|
||||||
|
|
||||||
|
public pickupGold(gold: Gold): void {
|
||||||
|
this.pickupEffectManager.showEffect(gold.node.worldPosition);
|
||||||
|
|
||||||
|
gold.pickup();
|
||||||
|
this.gameResult.goldCoins++;
|
||||||
|
}
|
||||||
|
|
||||||
|
private addEnemyListeners(enemy: Enemy): void {
|
||||||
|
enemy.DeathEvent.on(this.trySpawnItems, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private removeEnemyListeners(enemy: Enemy): void {
|
||||||
|
enemy.DeathEvent.off(this.trySpawnItems);
|
||||||
|
}
|
||||||
|
|
||||||
|
private trySpawnItems(enemy: Enemy): void {
|
||||||
|
this.trySpawnXP(enemy);
|
||||||
|
this.trySpawnGold(enemy);
|
||||||
|
}
|
||||||
|
|
||||||
|
private trySpawnXP(enemy: Enemy): void {
|
||||||
|
for (let index = 0; index < enemy.XPReward; index++) {
|
||||||
|
this.xpSpawner.spawnXp(this.getRandomPosition(enemy), 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private trySpawnGold(enemy: Enemy): void {
|
||||||
|
if (enemy.GoldReward <= 0) return;
|
||||||
|
|
||||||
|
if (enemy.GoldReward < 1) {
|
||||||
|
if (random() < enemy.GoldReward) {
|
||||||
|
this.goldSpawner.spawn(enemy.node.worldPosition);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (let i = 0; i < enemy.GoldReward; i++) {
|
||||||
|
this.goldSpawner.spawn(this.getRandomPosition(enemy));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private getRandomPosition(enemy: Enemy): Vec3 {
|
||||||
|
const position: Vec3 = enemy.node.worldPosition;
|
||||||
|
position.x += randomRange(-10, 10);
|
||||||
|
position.y += randomRange(-10, 10);
|
||||||
|
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
}
|
9
assets/Scripts/Game/Items/ItemManager.ts.meta
Normal file
9
assets/Scripts/Game/Items/ItemManager.ts.meta
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"ver": "4.0.23",
|
||||||
|
"importer": "typescript",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "7f3f8f02-b61e-4a07-8d52-1c326f889fca",
|
||||||
|
"files": [],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {}
|
||||||
|
}
|
12
assets/Scripts/Game/Items/PickupEffect.meta
Normal file
12
assets/Scripts/Game/Items/PickupEffect.meta
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"ver": "1.1.0",
|
||||||
|
"importer": "directory",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "264a4734-6753-4278-b3b7-b6b100e059a4",
|
||||||
|
"files": [],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {
|
||||||
|
"compressionType": {},
|
||||||
|
"isRemoteBundle": {}
|
||||||
|
}
|
||||||
|
}
|
10
assets/Scripts/Game/Items/PickupEffect/PickupEffect.ts
Normal file
10
assets/Scripts/Game/Items/PickupEffect/PickupEffect.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import { Animation, Component, _decorator } from "cc";
|
||||||
|
const { ccclass, property } = _decorator;
|
||||||
|
|
||||||
|
@ccclass("PickupEffect")
|
||||||
|
export class PickupEffect extends Component {
|
||||||
|
@property(Animation) private animation: Animation;
|
||||||
|
public init(): void {
|
||||||
|
this.animation.play("PickBonus");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"ver": "4.0.23",
|
||||||
|
"importer": "typescript",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "0f2b2cd0-1d1e-4862-821f-5fcb83c4ec23",
|
||||||
|
"files": [],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
import { _decorator, Component, Node, Prefab, Vec3 } from "cc";
|
||||||
|
import { ObjectPool } from "../../../Services/ObjectPool";
|
||||||
|
import { delay } from "../../../Services/Utils/AsyncUtils";
|
||||||
|
import { PickupEffect } from "./PickupEffect";
|
||||||
|
const { ccclass, property } = _decorator;
|
||||||
|
|
||||||
|
@ccclass("PickupEffectManager")
|
||||||
|
export class PickupEffectManager extends Component {
|
||||||
|
@property(Prefab) private pickupEffect: Prefab;
|
||||||
|
|
||||||
|
private effectPool: ObjectPool<PickupEffect>;
|
||||||
|
|
||||||
|
public init(): void {
|
||||||
|
this.effectPool = new ObjectPool(this.pickupEffect, this.node, 5, "PickupEffect");
|
||||||
|
}
|
||||||
|
|
||||||
|
public async showEffect(position: Vec3): Promise<void> {
|
||||||
|
const effect = this.effectPool.borrow();
|
||||||
|
effect.node.setWorldPosition(position);
|
||||||
|
effect.node.active = true;
|
||||||
|
|
||||||
|
await delay(450);
|
||||||
|
|
||||||
|
this.effectPool.return(effect);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"ver": "4.0.23",
|
||||||
|
"importer": "typescript",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "65b4121f-a4cf-47e1-97d4-1e0d3fc72eec",
|
||||||
|
"files": [],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {}
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
import { Animation, Component, Vec3, _decorator } from "cc";
|
import { Animation, Component, Vec3, _decorator } from "cc";
|
||||||
import { ISignal } from "../../Services/EventSystem/ISignal";
|
import { ISignal } from "../../../Services/EventSystem/ISignal";
|
||||||
import { Signal } from "../../Services/EventSystem/Signal";
|
import { Signal } from "../../../Services/EventSystem/Signal";
|
||||||
|
|
||||||
const { ccclass, property } = _decorator;
|
const { ccclass, property } = _decorator;
|
||||||
|
|
||||||
@ccclass("XP")
|
@ccclass("XP")
|
@ -1,5 +1,6 @@
|
|||||||
import { Component, Prefab, Vec3, _decorator } from "cc";
|
import { Component, Prefab, Vec3, _decorator } from "cc";
|
||||||
import { ObjectPool } from "../../Services/ObjectPool";
|
import { ObjectPool } from "../../../Services/ObjectPool";
|
||||||
|
|
||||||
import { XP } from "./XP";
|
import { XP } from "./XP";
|
||||||
const { ccclass, property } = _decorator;
|
const { ccclass, property } = _decorator;
|
||||||
|
|
12
assets/Scripts/Game/Pickups.meta
Normal file
12
assets/Scripts/Game/Pickups.meta
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"ver": "1.1.0",
|
||||||
|
"importer": "directory",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "363c5a59-0b4d-48d4-8b20-7163f1a82ad6",
|
||||||
|
"files": [],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {
|
||||||
|
"compressionType": {},
|
||||||
|
"isRemoteBundle": {}
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +1,6 @@
|
|||||||
import { Component, Node, random, randomRange, Vec3, _decorator } from "cc";
|
import { Component, Node, _decorator } from "cc";
|
||||||
import { ISignal } from "../../../Services/EventSystem/ISignal";
|
import { ISignal } from "../../../Services/EventSystem/ISignal";
|
||||||
import { EnemyManagerSettings } from "../../Data/GameSettings";
|
import { EnemyManagerSettings } from "../../Data/GameSettings";
|
||||||
import { GoldSpawner } from "../../Gold/GoldSpawner";
|
|
||||||
import { XPSpawner } from "../../XP/XPSpawner";
|
|
||||||
import { Enemy } from "./Enemy";
|
import { Enemy } from "./Enemy";
|
||||||
import { EnemyMovementType } from "./EnemyMovementType";
|
import { EnemyMovementType } from "./EnemyMovementType";
|
||||||
import { EnemyMover } from "./EnemyMover/EnemyMover";
|
import { EnemyMover } from "./EnemyMover/EnemyMover";
|
||||||
@ -20,8 +18,6 @@ const { ccclass, property } = _decorator;
|
|||||||
@ccclass("EnemyManager")
|
@ccclass("EnemyManager")
|
||||||
export class EnemyManager extends Component {
|
export class EnemyManager extends Component {
|
||||||
@property(EnemySpawner) private enemySpawner: EnemySpawner;
|
@property(EnemySpawner) private enemySpawner: EnemySpawner;
|
||||||
@property(XPSpawner) private xpSpawner: XPSpawner;
|
|
||||||
@property(GoldSpawner) private goldSpawner: GoldSpawner;
|
|
||||||
|
|
||||||
private movementTypeToMover: Map<EnemyMovementType, EnemyMover> = new Map<EnemyMovementType, EnemyMover>();
|
private movementTypeToMover: Map<EnemyMovementType, EnemyMover> = new Map<EnemyMovementType, EnemyMover>();
|
||||||
|
|
||||||
@ -50,9 +46,6 @@ export class EnemyManager extends Component {
|
|||||||
this.movementTypeToMover.set(EnemyMovementType.Follow, new FollowTargetEnemyMover(targetNode));
|
this.movementTypeToMover.set(EnemyMovementType.Follow, new FollowTargetEnemyMover(targetNode));
|
||||||
this.movementTypeToMover.set(EnemyMovementType.Launch, new WaveEnemyMover(targetNode));
|
this.movementTypeToMover.set(EnemyMovementType.Launch, new WaveEnemyMover(targetNode));
|
||||||
this.movementTypeToMover.set(EnemyMovementType.PeriodicFollow, new PeriodicFollowTargetEnemyMover(targetNode, 5, 5));
|
this.movementTypeToMover.set(EnemyMovementType.PeriodicFollow, new PeriodicFollowTargetEnemyMover(targetNode, 5, 5));
|
||||||
|
|
||||||
this.xpSpawner.init();
|
|
||||||
this.goldSpawner.init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public gameTick(deltaTime: number): void {
|
public gameTick(deltaTime: number): void {
|
||||||
@ -74,39 +67,13 @@ export class EnemyManager extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private onEnemyAdded(enemy: Enemy): void {
|
private onEnemyAdded(enemy: Enemy): void {
|
||||||
enemy.DeathEvent.on(this.onEnemyDied, this);
|
|
||||||
this.getEnemyMover(enemy).addEnemy(enemy);
|
this.getEnemyMover(enemy).addEnemy(enemy);
|
||||||
}
|
}
|
||||||
|
|
||||||
private onEnemyRemoved(enemy: Enemy): void {
|
private onEnemyRemoved(enemy: Enemy): void {
|
||||||
enemy.DeathEvent.off(this.onEnemyDied);
|
|
||||||
this.getEnemyMover(enemy).removeEnemy(enemy);
|
this.getEnemyMover(enemy).removeEnemy(enemy);
|
||||||
}
|
}
|
||||||
|
|
||||||
private onEnemyDied(enemy: Enemy): void {
|
|
||||||
for (let index = 0; index < enemy.XPReward; index++) {
|
|
||||||
const position: Vec3 = enemy.node.worldPosition;
|
|
||||||
position.x += randomRange(-10, 10);
|
|
||||||
position.y += randomRange(-10, 10);
|
|
||||||
this.xpSpawner.spawnXp(position, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (0 < enemy.GoldReward) {
|
|
||||||
if (enemy.GoldReward < 1) {
|
|
||||||
if (random() < enemy.GoldReward) {
|
|
||||||
this.goldSpawner.spawn(enemy.node.worldPosition);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (let i = 0; i < enemy.GoldReward; i++) {
|
|
||||||
const position: Vec3 = enemy.node.worldPosition;
|
|
||||||
position.x += randomRange(-10, 10);
|
|
||||||
position.y += randomRange(-10, 10);
|
|
||||||
this.goldSpawner.spawn(position);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private getEnemyMover(enemy: Enemy): EnemyMover {
|
private getEnemyMover(enemy: Enemy): EnemyMover {
|
||||||
if (this.movementTypeToMover.has(enemy.MovementType)) {
|
if (this.movementTypeToMover.has(enemy.MovementType)) {
|
||||||
return this.movementTypeToMover.get(enemy.MovementType);
|
return this.movementTypeToMover.get(enemy.MovementType);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { Animation, Node, BoxCollider2D, Collider2D, Component, Vec2, Vec3, _decorator, Details } from "cc";
|
import { Animation, Node, BoxCollider2D, Collider2D, Component, Vec2, Vec3, _decorator, Details, Sprite, Color } from "cc";
|
||||||
|
import { delay } from "../../../Services/Utils/AsyncUtils";
|
||||||
import { IInput } from "../../Input/IInput";
|
import { IInput } from "../../Input/IInput";
|
||||||
import { UnitHealth } from "../UnitHealth";
|
import { UnitHealth } from "../UnitHealth";
|
||||||
import { UnitLevel } from "../UnitLevel";
|
import { UnitLevel } from "../UnitLevel";
|
||||||
@ -15,6 +16,7 @@ export class Player extends Component {
|
|||||||
@property(Weapon) private weapon: Weapon;
|
@property(Weapon) private weapon: Weapon;
|
||||||
@property(Node) private playerGraphics: Node;
|
@property(Node) private playerGraphics: Node;
|
||||||
@property(Animation) private animation: Animation;
|
@property(Animation) private animation: Animation;
|
||||||
|
@property(Sprite) private sprite: Sprite;
|
||||||
|
|
||||||
private input: IInput;
|
private input: IInput;
|
||||||
private health: UnitHealth;
|
private health: UnitHealth;
|
||||||
@ -32,7 +34,7 @@ export class Player extends Component {
|
|||||||
this.speed = data.speed;
|
this.speed = data.speed;
|
||||||
|
|
||||||
this.weapon.init(data.strikeDelay, data.damage);
|
this.weapon.init(data.strikeDelay, data.damage);
|
||||||
|
this.health.HealthPointsChangeEvent.on(this.animateHurt, this);
|
||||||
this.playerUI.init(this.health);
|
this.playerUI.init(this.health);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,6 +93,12 @@ export class Player extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async animateHurt(): Promise<void> {
|
||||||
|
this.sprite.color = Color.RED;
|
||||||
|
await delay(100);
|
||||||
|
this.sprite.color = Color.WHITE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class PlayerData {
|
export class PlayerData {
|
||||||
|
Loading…
Reference in New Issue
Block a user