barbarian anim

This commit is contained in:
Martin
2022-12-31 12:53:49 +01:00
parent e03274d3cb
commit 50c44b7d64
13 changed files with 107 additions and 231 deletions

View 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");
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "2fbd70cb-9a23-45c9-bbc8-271c6b5ba22e",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -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);
}

View File

@@ -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);
}
}
}