mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2025-10-09 08:36:14 +00:00
Added magnet functionality
This commit is contained in:
33
assets/Scripts/Game/Unit/Player/Magnet.ts
Normal file
33
assets/Scripts/Game/Unit/Player/Magnet.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { _decorator, Component, Node, Collider2D, CircleCollider2D } from "cc";
|
||||
import { GameTimer } from "../../../Services/GameTimer";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("Magnet")
|
||||
export class Magnet extends Component {
|
||||
@property(CircleCollider2D) private collider: CircleCollider2D;
|
||||
|
||||
private timer: GameTimer;
|
||||
private duration: number;
|
||||
|
||||
public get Collider(): Collider2D {
|
||||
return this.collider;
|
||||
}
|
||||
public init(duration: number): void {
|
||||
this.duration = duration;
|
||||
this.node.active = false;
|
||||
}
|
||||
|
||||
public activate(): void {
|
||||
this.timer = new GameTimer(this.duration);
|
||||
this.node.active = true;
|
||||
}
|
||||
|
||||
public gameTick(deltaTime: number): void {
|
||||
if (!this.node.active) return;
|
||||
|
||||
this.timer.gameTick(deltaTime);
|
||||
if (this.timer.tryFinishPeriod()) {
|
||||
this.node.active = false;
|
||||
}
|
||||
}
|
||||
}
|
9
assets/Scripts/Game/Unit/Player/Magnet.ts.meta
Normal file
9
assets/Scripts/Game/Unit/Player/Magnet.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "05a1d2ca-9083-4d11-ad38-1892bc0d5082",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
@@ -3,6 +3,7 @@ import { delay } from "../../../Services/Utils/AsyncUtils";
|
||||
import { IInput } from "../../Input/IInput";
|
||||
import { UnitHealth } from "../UnitHealth";
|
||||
import { UnitLevel } from "../UnitLevel";
|
||||
import { Magnet } from "./Magnet";
|
||||
import { PlayerRegeneration } from "./PlayerRegeneration";
|
||||
import { PlayerUI } from "./PlayerUI/PlayerUI";
|
||||
import { Weapon } from "./Weapon/Weapon";
|
||||
@@ -14,6 +15,7 @@ export class Player extends Component {
|
||||
@property(BoxCollider2D) private collider: BoxCollider2D;
|
||||
@property(PlayerUI) private playerUI: PlayerUI;
|
||||
@property(Weapon) private weapon: Weapon;
|
||||
@property(Magnet) private magnet: Magnet;
|
||||
@property(Node) private playerGraphics: Node;
|
||||
@property(Animation) private animation: Animation;
|
||||
@property(Sprite) private sprite: Sprite;
|
||||
@@ -34,6 +36,7 @@ export class Player extends Component {
|
||||
this.speed = data.speed;
|
||||
|
||||
this.weapon.init(data.strikeDelay, data.damage);
|
||||
this.magnet.init(data.magnetDuration);
|
||||
this.health.HealthPointsChangeEvent.on(this.animateHpChange, this);
|
||||
this.playerUI.init(this.health);
|
||||
}
|
||||
@@ -50,6 +53,10 @@ export class Player extends Component {
|
||||
return this.weapon;
|
||||
}
|
||||
|
||||
public get Magnet(): Magnet {
|
||||
return this.magnet;
|
||||
}
|
||||
|
||||
public get Regeneration(): PlayerRegeneration {
|
||||
return this.regeneration;
|
||||
}
|
||||
@@ -61,6 +68,7 @@ export class Player extends Component {
|
||||
public gameTick(deltaTime: number): void {
|
||||
this.move(deltaTime);
|
||||
this.weapon.gameTick(deltaTime);
|
||||
this.magnet.gameTick(deltaTime);
|
||||
this.regeneration.gameTick(deltaTime);
|
||||
}
|
||||
|
||||
@@ -117,4 +125,7 @@ export class PlayerData {
|
||||
// Weapon
|
||||
public strikeDelay = 0;
|
||||
public damage = 0;
|
||||
|
||||
// Magnet
|
||||
public magnetDuration = 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user