Add support for setting animation frame

This commit is contained in:
2022-08-18 14:41:50 +02:00
parent f09fb6a944
commit 46132c556c
6 changed files with 38 additions and 2 deletions

View File

@@ -16,4 +16,6 @@ public interface Animated extends Updatable {
float getAnimationSpeed();
void setAnimationSpeed(float speed);
void setAnimationFrame(int frame);
}

View File

@@ -66,6 +66,11 @@ public abstract class AnimationDelegate implements Animation {
animation.toggleAnimationEnabled();
}
@Override
public void setAnimationFrame(int frame) {
animation.setAnimationFrame(frame);
}
@Override
public float getAnimationSpeed() {
return animation.getAnimationSpeed();

View File

@@ -95,6 +95,11 @@ public abstract class EntityDelegate implements Entity {
entity.toggleAnimationEnabled();
}
@Override
public void setAnimationFrame(int frame) {
entity.setAnimationFrame(frame);
}
@Override
public float getAnimationSpeed() {
return entity.getAnimationSpeed();

View File

@@ -37,6 +37,11 @@ public class EntityPath<T extends Entity> implements Path<T> {
return this;
}
public EntityPath<T> turn(Direction direction, int newAnimationFrame) {
path.add(new TurnSegment<>(direction, newAnimationFrame));
return this;
}
public EntityPath<T> wait(float seconds) {
path.add(new WaitSegment<>(seconds));
return this;

View File

@@ -3,19 +3,30 @@ package com.bartlomiejpluta.base.util.path;
import com.bartlomiejpluta.base.api.entity.Entity;
import com.bartlomiejpluta.base.api.map.layer.object.ObjectLayer;
import com.bartlomiejpluta.base.api.move.Direction;
import lombok.NonNull;
import static java.util.Objects.requireNonNull;
public class TurnSegment<T extends Entity> implements PathSegment<T> {
private final Direction direction;
private final Integer newAnimationFrame;
public TurnSegment(Direction direction) {
this.direction = requireNonNull(direction);
public TurnSegment(@NonNull Direction direction, int newAnimationFrame) {
this.direction = direction;
this.newAnimationFrame = newAnimationFrame;
}
public TurnSegment(@NonNull Direction direction) {
this.direction = direction;
this.newAnimationFrame = null;
}
@Override
public PathProgress perform(T entity, ObjectLayer layer, float dt) {
entity.setFaceDirection(direction);
if (newAnimationFrame != null) {
entity.setAnimationFrame(newAnimationFrame);
}
return PathProgress.SEGMENT_DONE;
}
}