mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2024-12-26 11:48:54 +00:00
Added regeneration
This commit is contained in:
parent
692bb7c35c
commit
a0bd11b61d
@ -13,16 +13,18 @@
|
|||||||
20,
|
20,
|
||||||
20
|
20
|
||||||
],
|
],
|
||||||
|
"regenerationDelay": 5,
|
||||||
"collisionDelay": 0.5
|
"collisionDelay": 0.5
|
||||||
},
|
},
|
||||||
"weapon": {
|
"weapon": {
|
||||||
"strikeDelay": 2
|
"strikeDelay": 2,
|
||||||
|
"damage": 1
|
||||||
},
|
},
|
||||||
"upgrades": {
|
"upgrades": {
|
||||||
"maxWeaponLengthUpgrades": 5,
|
"maxWeaponLengthUpgrades": 5,
|
||||||
"maxWeaponDamageUpgrades": 5,
|
"maxWeaponDamageUpgrades": 5,
|
||||||
"maxHorizontalProjectileUpgrades": 0,
|
"maxHorizontalProjectileUpgrades": 0,
|
||||||
"maxVerticalProjectileUpgrades": 0,
|
"maxVerticalProjectileUpgrades": 0,
|
||||||
"maxRegenerationUpgrades": 0
|
"maxRegenerationUpgrades": 5
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,6 +7,7 @@ export class GameSettings {
|
|||||||
export class PlayerSettings {
|
export class PlayerSettings {
|
||||||
public defaultHP = 0;
|
public defaultHP = 0;
|
||||||
public requiredXP: number[] = [];
|
public requiredXP: number[] = [];
|
||||||
|
public regenerationDelay = 0;
|
||||||
public collisionDelay = 0;
|
public collisionDelay = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 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 arrowKeys = new KeyboardInput(KeyCode.ARROW_UP, KeyCode.ARROW_DOWN, KeyCode.ARROW_LEFT, KeyCode.ARROW_RIGHT);
|
||||||
const dualInput: MultiInput = new MultiInput([this.virtualJoystic, wasd, arrowKeys]);
|
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);
|
this.playerCollisionSystem = new PlayerCollisionSystem(this.player, settings.player.collisionDelay);
|
||||||
new WeaponCollisionSystem(this.weapon);
|
new WeaponCollisionSystem(this.weapon);
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
import { BoxCollider2D, Collider2D, Component, Vec2, Vec3, _decorator } from "cc";
|
import { BoxCollider2D, Collider2D, Component, Vec2, Vec3, _decorator } from "cc";
|
||||||
|
import { PlayerSettings } from "../../Data/GameSettings";
|
||||||
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";
|
||||||
|
import { PlayerRegeneration } from "./PlayerRegeneration";
|
||||||
import { PlayerUI } from "./PlayerUI/PlayerUI";
|
import { PlayerUI } from "./PlayerUI/PlayerUI";
|
||||||
import { Weapon } from "./Weapon/Weapon";
|
import { Weapon } from "./Weapon/Weapon";
|
||||||
|
|
||||||
@ -17,12 +19,14 @@ export class Player extends Component {
|
|||||||
private weapon: Weapon;
|
private weapon: Weapon;
|
||||||
private health: UnitHealth;
|
private health: UnitHealth;
|
||||||
private level: UnitLevel;
|
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.input = input;
|
||||||
this.weapon = weapon;
|
this.weapon = weapon;
|
||||||
this.health = new UnitHealth(maxHp);
|
this.health = new UnitHealth(settings.defaultHP);
|
||||||
this.level = new UnitLevel(requiredLevelXps);
|
this.level = new UnitLevel(settings.requiredXP);
|
||||||
|
this.regeneration = new PlayerRegeneration(this.health, settings.regenerationDelay);
|
||||||
|
|
||||||
this.weapon.node.parent = this.node;
|
this.weapon.node.parent = this.node;
|
||||||
this.weapon.node.setPosition(new Vec3());
|
this.weapon.node.setPosition(new Vec3());
|
||||||
@ -42,6 +46,10 @@ export class Player extends Component {
|
|||||||
return this.weapon;
|
return this.weapon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get Regeneration(): PlayerRegeneration {
|
||||||
|
return this.regeneration;
|
||||||
|
}
|
||||||
|
|
||||||
public get Collider(): Collider2D {
|
public get Collider(): Collider2D {
|
||||||
return this.collider;
|
return this.collider;
|
||||||
}
|
}
|
||||||
@ -58,5 +66,6 @@ export class Player extends Component {
|
|||||||
this.node.setWorldPosition(newPosition);
|
this.node.setWorldPosition(newPosition);
|
||||||
|
|
||||||
this.weapon.gameTick(deltaTime);
|
this.weapon.gameTick(deltaTime);
|
||||||
|
this.regeneration.gameTick(deltaTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
28
assets/Scripts/Game/Unit/Player/PlayerRegeneration.ts
Normal file
28
assets/Scripts/Game/Unit/Player/PlayerRegeneration.ts
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"ver": "4.0.23",
|
||||||
|
"importer": "typescript",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "d7c2f178-5239-4c80-b3f5-6b6a797bb71f",
|
||||||
|
"files": [],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {}
|
||||||
|
}
|
@ -12,7 +12,8 @@ export class Upgrader {
|
|||||||
this.player = player;
|
this.player = player;
|
||||||
|
|
||||||
this.setTypeMaps(UpgradeType.WeaponLength, this.upgradeWeaponLength.bind(this), settings.maxWeaponLengthUpgrades);
|
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 {
|
public upgradeSkill(type: UpgradeType): void {
|
||||||
@ -49,6 +50,10 @@ export class Upgrader {
|
|||||||
this.player.Weapon.upgradeWeaponDamage();
|
this.player.Weapon.upgradeWeaponDamage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private upgradeRegeneration(): void {
|
||||||
|
this.player.Regeneration.upgrade();
|
||||||
|
}
|
||||||
|
|
||||||
private isMaxLevel(type: UpgradeType): boolean {
|
private isMaxLevel(type: UpgradeType): boolean {
|
||||||
return this.typeToMaxLevel.get(type) <= this.typeToLevel.get(type);
|
return this.typeToMaxLevel.get(type) <= this.typeToLevel.get(type);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user