use of de.gurkenlabs.litiengine.entities.Direction in project litiengine by gurkenlabs.
the class CreaturePanel method getCreatureSpriteName.
public static String getCreatureSpriteName(String name) {
if (name.endsWith(CreatureAnimationController.IDLE)) {
return name.substring(0, name.length() - CreatureAnimationController.IDLE.length());
}
if (name.endsWith(CreatureAnimationController.WALK)) {
return name.substring(0, name.length() - CreatureAnimationController.WALK.length());
}
if (name.endsWith(CreatureAnimationController.DEAD)) {
return name.substring(0, name.length() - CreatureAnimationController.DEAD.length());
}
for (Direction dir : Direction.values()) {
String idle = CreatureAnimationController.IDLE + "-" + dir.toString().toLowerCase();
if (name.endsWith(idle)) {
return name.substring(0, name.length() - idle.length());
}
String walk = CreatureAnimationController.WALK + "-" + dir.toString().toLowerCase();
if (name.endsWith(walk)) {
return name.substring(0, name.length() - walk.length());
}
}
return null;
}
use of de.gurkenlabs.litiengine.entities.Direction in project litiengine by gurkenlabs.
the class SpawnpointMapObjectLoader method load.
@Override
public Collection<IEntity> load(IEnvironment environment, IMapObject mapObject) {
if (MapObjectType.get(mapObject.getType()) != MapObjectType.SPAWNPOINT) {
throw new IllegalArgumentException("Cannot load a mapobject of the type " + mapObject.getType() + " with a loader of the type " + SpawnpointMapObjectLoader.class);
}
final Direction direction = mapObject.getCustomProperty(MapObjectProperty.SPAWN_DIRECTION) != null ? Direction.valueOf(mapObject.getCustomProperty(MapObjectProperty.SPAWN_DIRECTION)) : Direction.DOWN;
final String spawnType = mapObject.getCustomProperty(MapObjectProperty.SPAWN_TYPE);
final Spawnpoint spawn = this.createSpawnpoint(mapObject, direction, spawnType);
loadDefaultProperties(spawn, mapObject);
Collection<IEntity> entities = super.load(environment, mapObject);
entities.add(spawn);
return entities;
}
use of de.gurkenlabs.litiengine.entities.Direction in project litiengine by gurkenlabs.
the class CreatureAnimationController method getFallbackSpriteName.
private String getFallbackSpriteName(String state, Direction dir) {
String fallbackStateName = this.getSpriteName(getOppositeState(state)) + "-" + dir.toString().toLowerCase();
if (this.hasAnimation(fallbackStateName)) {
return fallbackStateName;
}
String baseName = this.getSpriteName(state);
if (this.hasAnimation(baseName)) {
return baseName;
}
// search for any animation for the specified state with dir information
for (Direction d : Direction.values()) {
final String name = this.getSpriteName(state) + "-" + d.toString().toLowerCase();
if (this.hasAnimation(name)) {
return name;
}
}
return this.getDefaultAnimation() != null ? this.getDefaultAnimation().getName() : null;
}
use of de.gurkenlabs.litiengine.entities.Direction in project litiengine by gurkenlabs.
the class CreatureAnimationController method initializeAvailableAnimations.
private void initializeAvailableAnimations() {
for (Direction dir : Direction.values()) {
// initialize walking animations
Spritesheet walkSprite = Spritesheet.find(this.getSpriteName(WALK) + "-" + dir.toString().toLowerCase());
if (walkSprite != null) {
this.add(new Animation(walkSprite, true));
}
// initialize idle animations
Spritesheet idleSprite = Spritesheet.find(this.getSpriteName(IDLE) + "-" + dir.toString().toLowerCase());
if (idleSprite != null) {
this.add(new Animation(idleSprite, true));
}
}
Spritesheet deadSprite = Spritesheet.find(this.getSpritePrefix() + DEAD);
if (deadSprite != null) {
this.add(new Animation(deadSprite, true));
}
Spritesheet baseIdle = Spritesheet.find(this.getSpriteName(IDLE));
if (baseIdle != null) {
this.add(new Animation(baseIdle, true));
}
Spritesheet baseWalk = Spritesheet.find(this.getSpriteName(WALK));
if (baseWalk != null) {
this.add(new Animation(baseWalk, true));
}
}
Aggregations