diff --git a/assets/Data/GameSettings.json b/assets/Data/GameSettings.json index 69ac28f..2092852 100644 --- a/assets/Data/GameSettings.json +++ b/assets/Data/GameSettings.json @@ -13,16 +13,18 @@ 20, 20 ], + "regenerationDelay": 5, "collisionDelay": 0.5 }, "weapon": { - "strikeDelay": 2 + "strikeDelay": 2, + "damage": 1 }, "upgrades": { "maxWeaponLengthUpgrades": 5, "maxWeaponDamageUpgrades": 5, "maxHorizontalProjectileUpgrades": 0, "maxVerticalProjectileUpgrades": 0, - "maxRegenerationUpgrades": 0 + "maxRegenerationUpgrades": 5 } } \ No newline at end of file diff --git a/assets/Scripts/Game/Data/GameSettings.ts b/assets/Scripts/Game/Data/GameSettings.ts index e7e0fea..3004318 100644 --- a/assets/Scripts/Game/Data/GameSettings.ts +++ b/assets/Scripts/Game/Data/GameSettings.ts @@ -7,6 +7,7 @@ export class GameSettings { export class PlayerSettings { public defaultHP = 0; public requiredXP: number[] = []; + public regenerationDelay = 0; public collisionDelay = 0; } diff --git a/assets/Scripts/Game/GameBootstrapper.ts b/assets/Scripts/Game/GameBootstrapper.ts index e48f85b..033690a 100644 --- a/assets/Scripts/Game/GameBootstrapper.ts +++ b/assets/Scripts/Game/GameBootstrapper.ts @@ -39,7 +39,7 @@ export class GameBootstrapper extends Component { 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.defaultHP, settings.player.requiredXP); + this.player.init(dualInput, this.weapon, settings.player); this.playerCollisionSystem = new PlayerCollisionSystem(this.player, settings.player.collisionDelay); new WeaponCollisionSystem(this.weapon); diff --git a/assets/Scripts/Game/Unit/Player/Player.ts b/assets/Scripts/Game/Unit/Player/Player.ts index c40b1d5..c2437b0 100644 --- a/assets/Scripts/Game/Unit/Player/Player.ts +++ b/assets/Scripts/Game/Unit/Player/Player.ts @@ -1,7 +1,9 @@ import { BoxCollider2D, Collider2D, Component, Vec2, Vec3, _decorator } from "cc"; +import { PlayerSettings } from "../../Data/GameSettings"; import { IInput } from "../../Input/IInput"; import { UnitHealth } from "../UnitHealth"; import { UnitLevel } from "../UnitLevel"; +import { PlayerRegeneration } from "./PlayerRegeneration"; import { PlayerUI } from "./PlayerUI/PlayerUI"; import { Weapon } from "./Weapon/Weapon"; @@ -17,12 +19,14 @@ export class Player extends Component { private weapon: Weapon; private health: UnitHealth; private level: UnitLevel; + private regeneration: PlayerRegeneration; - public init(input: IInput, weapon: Weapon, maxHp: number, requiredLevelXps: number[]): void { + public init(input: IInput, weapon: Weapon, settings: PlayerSettings): void { this.input = input; this.weapon = weapon; - this.health = new UnitHealth(maxHp); - this.level = new UnitLevel(requiredLevelXps); + 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()); @@ -42,6 +46,10 @@ export class Player extends Component { return this.weapon; } + public get Regeneration(): PlayerRegeneration { + return this.regeneration; + } + public get Collider(): Collider2D { return this.collider; } @@ -58,5 +66,6 @@ export class Player extends Component { this.node.setWorldPosition(newPosition); this.weapon.gameTick(deltaTime); + this.regeneration.gameTick(deltaTime); } } diff --git a/assets/Scripts/Game/Unit/Player/PlayerRegeneration.ts b/assets/Scripts/Game/Unit/Player/PlayerRegeneration.ts new file mode 100644 index 0000000..14c30dd --- /dev/null +++ b/assets/Scripts/Game/Unit/Player/PlayerRegeneration.ts @@ -0,0 +1,28 @@ +import { GameTimer } from "../../../Services/GameTimer"; +import { UnitHealth } from "../UnitHealth"; + +export class PlayerRegeneration { + private currentRegenerationAmount = 0; + private regenerationDelay: number; + private regenerationTimer: GameTimer = new GameTimer(0); + private health: UnitHealth; + + public constructor(health: UnitHealth, regenerationDelay: number) { + this.health = health; + this.regenerationDelay = regenerationDelay; + } + + public upgrade(): void { + this.currentRegenerationAmount++; + this.regenerationTimer = new GameTimer(this.regenerationDelay / this.currentRegenerationAmount); + } + + public gameTick(deltaTime: number): void { + if (this.currentRegenerationAmount <= 0) return; + + this.regenerationTimer.gameTick(deltaTime); + if (this.regenerationTimer.tryFinishPeriod()) { + this.health.heal(1); + } + } +} diff --git a/assets/Scripts/Game/Unit/Player/PlayerRegeneration.ts.meta b/assets/Scripts/Game/Unit/Player/PlayerRegeneration.ts.meta new file mode 100644 index 0000000..7a3d547 --- /dev/null +++ b/assets/Scripts/Game/Unit/Player/PlayerRegeneration.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.23", + "importer": "typescript", + "imported": true, + "uuid": "d7c2f178-5239-4c80-b3f5-6b6a797bb71f", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/assets/Scripts/Game/Upgrades/Upgrader.ts b/assets/Scripts/Game/Upgrades/Upgrader.ts index b8c76a5..fec4cad 100644 --- a/assets/Scripts/Game/Upgrades/Upgrader.ts +++ b/assets/Scripts/Game/Upgrades/Upgrader.ts @@ -12,7 +12,8 @@ export class Upgrader { this.player = player; this.setTypeMaps(UpgradeType.WeaponLength, this.upgradeWeaponLength.bind(this), settings.maxWeaponLengthUpgrades); - this.setTypeMaps(UpgradeType.WeaponDamage, this.upgradeWeaponDamage, settings.maxWeaponDamageUpgrades); + this.setTypeMaps(UpgradeType.WeaponDamage, this.upgradeWeaponDamage.bind(this), settings.maxWeaponDamageUpgrades); + this.setTypeMaps(UpgradeType.Regeneration, this.upgradeRegeneration.bind(this), settings.maxRegenerationUpgrades); } public upgradeSkill(type: UpgradeType): void { @@ -49,6 +50,10 @@ export class Upgrader { this.player.Weapon.upgradeWeaponDamage(); } + private upgradeRegeneration(): void { + this.player.Regeneration.upgrade(); + } + private isMaxLevel(type: UpgradeType): boolean { return this.typeToMaxLevel.get(type) <= this.typeToLevel.get(type); }