mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2025-10-09 16:46:00 +00:00
Boss anim, open close
This commit is contained in:
41
assets/Scripts/Game/Unit/Enemy/BossEnemy.ts
Normal file
41
assets/Scripts/Game/Unit/Enemy/BossEnemy.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { Animation, Collider2D, Contact2DType, _decorator } from "cc";
|
||||
import { GroupType } from "../../GroupType";
|
||||
import { Enemy } from "./Enemy";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("BossEnemy")
|
||||
export class BossEnemy extends Enemy {
|
||||
@property(Collider2D) private bossCollider: Collider2D;
|
||||
@property(Animation) private animation: Animation;
|
||||
|
||||
private isAnimatingAttack = false;
|
||||
|
||||
public start(): void {
|
||||
this.bossCollider.on(Contact2DType.BEGIN_CONTACT, this.collisionBegin, this);
|
||||
this.bossCollider.on(Contact2DType.END_CONTACT, this.collisionEnd, this);
|
||||
}
|
||||
|
||||
private collisionBegin(_selfCollider: Collider2D, otherCollider: Collider2D): void {
|
||||
if (otherCollider.group === GroupType.PLAYER) {
|
||||
this.animateAttack();
|
||||
}
|
||||
}
|
||||
|
||||
private collisionEnd(_selfCollider: Collider2D, otherCollider: Collider2D): void {
|
||||
if (otherCollider.group === GroupType.PLAYER) {
|
||||
this.animateMove();
|
||||
}
|
||||
}
|
||||
|
||||
private animateAttack(): void {
|
||||
if (this.isAnimatingAttack) return;
|
||||
this.isAnimatingAttack = true;
|
||||
this.animation.play("Attack");
|
||||
}
|
||||
|
||||
private animateMove(): void {
|
||||
if (!this.isAnimatingAttack) return;
|
||||
this.isAnimatingAttack = false;
|
||||
this.animation.play("Run");
|
||||
}
|
||||
}
|
9
assets/Scripts/Game/Unit/Enemy/BossEnemy.ts.meta
Normal file
9
assets/Scripts/Game/Unit/Enemy/BossEnemy.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "8daaec86-a8d5-4dce-9f68-37df7115c4b0",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
33
assets/Scripts/Utils/OpenCloseAnimator.ts
Normal file
33
assets/Scripts/Utils/OpenCloseAnimator.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { Animation, Component, _decorator } from "cc";
|
||||
import { delay } from "../Services/Utils/AsyncUtils";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("OpenCloseAnimator")
|
||||
export class OpenCloseAnimator extends Component {
|
||||
@property(Animation) private animation: Animation;
|
||||
|
||||
private readonly openStateName = "Open";
|
||||
private readonly closeStateName = "Close";
|
||||
|
||||
private openDuration = 0;
|
||||
private closeDuration = 0;
|
||||
|
||||
public start(): void {
|
||||
this.node.active = false;
|
||||
this.openDuration = this.animation.getState(this.openStateName).duration;
|
||||
this.closeDuration = this.animation.getState(this.closeStateName).duration;
|
||||
}
|
||||
|
||||
public async playOpen(): Promise<void> {
|
||||
this.node.active = true;
|
||||
this.animation.play(this.openStateName);
|
||||
await delay(this.openDuration);
|
||||
}
|
||||
|
||||
public async playClose(): Promise<void> {
|
||||
this.node.active = true;
|
||||
this.animation.play(this.openStateName);
|
||||
await delay(this.closeDuration);
|
||||
this.node.active = false;
|
||||
}
|
||||
}
|
9
assets/Scripts/Utils/OpenCloseAnimator.ts.meta
Normal file
9
assets/Scripts/Utils/OpenCloseAnimator.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "f9bdc2e9-98c7-4882-a58d-3a07ad74cbf5",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
Reference in New Issue
Block a user