diff --git a/assets/Data/GameSettings.json b/assets/Data/GameSettings.json index 6e6a4ac..bb7d14b 100644 --- a/assets/Data/GameSettings.json +++ b/assets/Data/GameSettings.json @@ -55,8 +55,8 @@ "upgrades": { "maxWeaponLengthUpgrades": 5, "maxWeaponDamageUpgrades": 10, - "maxHorizontalProjectileUpgrades": 0, - "maxDiagonalProjectileUpgrades": 0, + "maxHorizontalProjectileUpgrades": 5, + "maxDiagonalProjectileUpgrades": 5, "maxHaloProjectileUpgrades": 5, "maxRegenerationUpgrades": 5 }, @@ -144,7 +144,7 @@ "damage": 1, "speed": 60, "lifetime": -1, - "xpReward": 0, + "xpReward": 1, "goldReward": 0 }, { @@ -155,7 +155,7 @@ "damage": 2, "speed": 65, "lifetime": -1, - "xpReward": 0, + "xpReward": 1, "goldReward": 0.1 }, { @@ -166,7 +166,7 @@ "damage": 2, "speed": 75, "lifetime": -1, - "xpReward": 0, + "xpReward": 1, "goldReward": 0.1 }, { @@ -177,7 +177,7 @@ "damage": 1, "speed": 25, "lifetime": 29, - "xpReward": 0, + "xpReward": 1, "goldReward": 1 }, { @@ -188,7 +188,7 @@ "damage": 2, "speed": 35, "lifetime": 27, - "xpReward": 0, + "xpReward": 1, "goldReward": 2 }, { @@ -199,7 +199,7 @@ "damage": 2, "speed": 390, "lifetime": 20, - "xpReward": 0, + "xpReward": 1, "goldReward": 0.2 }, { @@ -210,7 +210,7 @@ "damage": 3, "speed": 70, "lifetime": 30, - "xpReward": 0, + "xpReward": 1, "goldReward": 1 }, { @@ -221,7 +221,7 @@ "damage": 3, "speed": 320, "lifetime": 30, - "xpReward": 0, + "xpReward": 1, "goldReward": 1 }, { @@ -232,7 +232,7 @@ "damage": 2, "speed": 65, "lifetime": -1, - "xpReward": 0, + "xpReward": 1, "goldReward": 3 }, { @@ -254,7 +254,7 @@ "damage": 1, "speed": 120, "lifetime": -1, - "xpReward": 0, + "xpReward": 1, "goldReward": 1 } ], diff --git a/assets/Media/Prefabs/Game/Bat.prefab b/assets/Media/Prefabs/Game/Bat.prefab index eff9bc5..9e3852f 100644 --- a/assets/Media/Prefabs/Game/Bat.prefab +++ b/assets/Media/Prefabs/Game/Bat.prefab @@ -182,6 +182,13 @@ "collider": { "__id__": 6 }, + "sprite": { + "__id__": 4 + }, + "whiteMaterial": { + "__uuid__": "9cb17675-370b-48ed-bfa2-bb613a88af44", + "__expectedType__": "cc.Material" + }, "_id": "" }, { diff --git a/assets/Media/Prefabs/Game/Goblin.prefab b/assets/Media/Prefabs/Game/Goblin.prefab index ba88071..0fa0be3 100644 --- a/assets/Media/Prefabs/Game/Goblin.prefab +++ b/assets/Media/Prefabs/Game/Goblin.prefab @@ -182,6 +182,13 @@ "collider": { "__id__": 6 }, + "sprite": { + "__id__": 4 + }, + "whiteMaterial": { + "__uuid__": "9cb17675-370b-48ed-bfa2-bb613a88af44", + "__expectedType__": "cc.Material" + }, "_id": "" }, { diff --git a/assets/Media/Prefabs/Game/Shark.prefab b/assets/Media/Prefabs/Game/Shark.prefab index ebdecab..f5efccf 100644 --- a/assets/Media/Prefabs/Game/Shark.prefab +++ b/assets/Media/Prefabs/Game/Shark.prefab @@ -182,6 +182,13 @@ "collider": { "__id__": 6 }, + "sprite": { + "__id__": 4 + }, + "whiteMaterial": { + "__uuid__": "9cb17675-370b-48ed-bfa2-bb613a88af44", + "__expectedType__": "cc.Material" + }, "_id": "" }, { diff --git a/assets/Scenes/Game.scene b/assets/Scenes/Game.scene index 261fa48..03975bc 100644 --- a/assets/Scenes/Game.scene +++ b/assets/Scenes/Game.scene @@ -196,7 +196,7 @@ "_enabled": true, "__prefab": null, "startTime": 0, - "startXP": 10, + "startXP": 0, "maxHpLevel": 0, "bonusDamageLevel": 0, "projectilePiercingLevel": 0, diff --git a/assets/Scripts/Game/Unit/Enemy/Enemy.ts b/assets/Scripts/Game/Unit/Enemy/Enemy.ts index 63b9aa7..d4967dc 100644 --- a/assets/Scripts/Game/Unit/Enemy/Enemy.ts +++ b/assets/Scripts/Game/Unit/Enemy/Enemy.ts @@ -1,7 +1,7 @@ -import { BoxCollider2D, Component, randomRange, Vec3, _decorator } from "cc"; -import { time } from "console"; +import { BoxCollider2D, Component, Material, randomRange, Sprite, Vec3, _decorator } from "cc"; import { ISignal } from "../../../Services/EventSystem/ISignal"; import { Signal } from "../../../Services/EventSystem/Signal"; +import { delay } from "../../../Services/Utils/AsyncUtils"; import { EnemySettings } from "../../Data/GameSettings"; import { UnitHealth } from "../UnitHealth"; import { EnemyMovementType } from "./EnemyMovementType"; @@ -10,11 +10,15 @@ const { ccclass, property } = _decorator; @ccclass("Enemy") export class Enemy extends Component { - @property(BoxCollider2D) public collider: BoxCollider2D; + @property(BoxCollider2D) private collider: BoxCollider2D; + @property(Sprite) private sprite: Sprite; + @property(Material) private whiteMaterial: Material; private deathEvent: Signal = new Signal(); private lifetimeEndedEvent: Signal = new Signal(); + private defaultMaterial: Material; + private movementType: EnemyMovementType; private health: UnitHealth; private damage: number; @@ -26,6 +30,8 @@ export class Enemy extends Component { private goldReward: number; public setup(position: Vec3, settings: EnemySettings): void { + this.defaultMaterial = this.sprite.material; + this.movementType = settings.moveType; this.health = new UnitHealth(settings.health); this.damage = settings.damage; @@ -38,6 +44,8 @@ export class Enemy extends Component { this.node.setWorldPosition(position); this.node.active = true; + + this.health.HealthPointsChangeEvent.on(this.animateHurt, this); } public get MovementType(): EnemyMovementType { @@ -60,6 +68,14 @@ export class Enemy extends Component { return this.deathEvent; } + public get XPReward(): number { + return this.xpReward; + } + + public get GoldReward(): number { + return this.goldReward; + } + public get LifetimeEndedEvent(): ISignal { return this.lifetimeEndedEvent; } @@ -85,4 +101,10 @@ export class Enemy extends Component { } } } + + private async animateHurt(): Promise { + this.sprite.material = this.whiteMaterial; + await delay(100); + this.sprite.material = this.defaultMaterial; + } } diff --git a/assets/Scripts/Game/Unit/Enemy/EnemyManager.ts b/assets/Scripts/Game/Unit/Enemy/EnemyManager.ts index bf95a56..833d20f 100644 --- a/assets/Scripts/Game/Unit/Enemy/EnemyManager.ts +++ b/assets/Scripts/Game/Unit/Enemy/EnemyManager.ts @@ -1,4 +1,5 @@ -import { Component, Node, _decorator } from "cc"; +import { Component, Node, randomRange, Vec3, _decorator } from "cc"; + import { EnemyManagerSettings } from "../../Data/GameSettings"; import { XPSpawner } from "../../XP/XPSpawner"; import { Enemy } from "./Enemy"; @@ -64,7 +65,13 @@ export class EnemyManager extends Component { private onEnemyDied(enemy: Enemy): void { enemy.DeathEvent.off(this.onEnemyDied); enemy.LifetimeEndedEvent.off(this.onEnemyLifetimeEnded); - this.xpSpawner.spawnXp(enemy.node.worldPosition, 1); + + 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); + } } private onEnemyLifetimeEnded(enemy: Enemy): void {