29 lines
794 B
TypeScript
29 lines
794 B
TypeScript
import { BaseAnimation } from "../../Enums/BaseAnimation";
|
|
import { IPlayerState } from "../IPlayerState";
|
|
import { PlayerContext } from "../PlayerContext";
|
|
import { PlayerStateType } from "../PlayerStateType";
|
|
|
|
export class IdleState implements IPlayerState {
|
|
enter(context: PlayerContext): void {
|
|
if (context.skipStateEnterAnimation) {
|
|
context.skipStateEnterAnimation = false;
|
|
return;
|
|
}
|
|
|
|
context.character.playAnimation(BaseAnimation.Idle);
|
|
}
|
|
|
|
exit(_context: PlayerContext): void {}
|
|
|
|
update(context: PlayerContext, _deltaTime: number): void {
|
|
if (context.isMoving()) {
|
|
context.stateMachine.setState(PlayerStateType.Run);
|
|
return;
|
|
}
|
|
|
|
const body = context.physics.getPhysicsBody();
|
|
body.velocity.set(0, 0, 0);
|
|
body.wakeUp();
|
|
}
|
|
}
|