mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2025-09-24 04:39:05 +00:00
barbarian anim
This commit is contained in:
36
assets/Scripts/Game/Unit/Enemy/AnimatedEnemy.ts
Normal file
36
assets/Scripts/Game/Unit/Enemy/AnimatedEnemy.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { Animation, Vec3, _decorator } from "cc";
|
||||
import { Enemy } from "./Enemy";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("AnimatedEnemy")
|
||||
export class AnimatedEnemy extends Enemy {
|
||||
@property(Animation) private animation: Animation;
|
||||
|
||||
private isAnimatingIdle = false;
|
||||
|
||||
public gameTick(move: Vec3, deltaTime: number): void {
|
||||
super.gameTick(move, deltaTime);
|
||||
|
||||
console.log("Move x: " + move.x + " Move y: " + move.y);
|
||||
|
||||
if (move.x === 0 && move.y === 0) {
|
||||
this.animateIdle();
|
||||
} else {
|
||||
this.animateRun();
|
||||
}
|
||||
}
|
||||
|
||||
private animateIdle(): void {
|
||||
if (this.isAnimatingIdle) return;
|
||||
this.isAnimatingIdle = true;
|
||||
|
||||
this.animation.play("Idle");
|
||||
}
|
||||
|
||||
private animateRun(): void {
|
||||
if (!this.isAnimatingIdle) return;
|
||||
this.isAnimatingIdle = false;
|
||||
|
||||
this.animation.play("Run");
|
||||
}
|
||||
}
|
9
assets/Scripts/Game/Unit/Enemy/AnimatedEnemy.ts.meta
Normal file
9
assets/Scripts/Game/Unit/Enemy/AnimatedEnemy.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "2fbd70cb-9a23-45c9-bbc8-271c6b5ba22e",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
@@ -118,7 +118,7 @@ export class Enemy extends Component {
|
||||
|
||||
if (move.x < 0) {
|
||||
this.sprite.node.setScale(-1, 1, 1);
|
||||
} else {
|
||||
} else if (0 < move.x) {
|
||||
this.sprite.node.setScale(1, 1, 1);
|
||||
}
|
||||
|
||||
|
@@ -26,12 +26,13 @@ export class PeriodicFollowTargetEnemyMover extends EnemyMover {
|
||||
this.switchEnemyFollowState(enemy);
|
||||
} else {
|
||||
this.enemyToStateTimeLeft.set(enemy, stateTimeLeft);
|
||||
|
||||
if (this.enemyToFollowState.get(enemy) === EnemyFollowState.Follow) {
|
||||
let direction: Vec3 = new Vec3();
|
||||
direction = Vec3.subtract(direction, this.targetNode.worldPosition, enemy.node.worldPosition);
|
||||
enemy.gameTick(direction.normalize(), deltaTime);
|
||||
}
|
||||
}
|
||||
if (this.enemyToFollowState.get(enemy) === EnemyFollowState.Follow) {
|
||||
let direction: Vec3 = new Vec3();
|
||||
direction = Vec3.subtract(direction, this.targetNode.worldPosition, enemy.node.worldPosition);
|
||||
enemy.gameTick(direction.normalize(), deltaTime);
|
||||
} else if (this.enemyToFollowState.get(enemy) === EnemyFollowState.Wait) {
|
||||
enemy.gameTick(new Vec3(), deltaTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user