Create Entity API scaffolding
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
package com.bartlomiejpluta.base.api.context;
|
||||
|
||||
import com.bartlomiejpluta.base.api.entity.Entity;
|
||||
|
||||
public interface Context {
|
||||
void openMap(String mapUid);
|
||||
|
||||
Entity createEntity(String entitySetUid);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.bartlomiejpluta.base.api.entity;
|
||||
|
||||
import com.bartlomiejpluta.base.api.geo.Vector;
|
||||
|
||||
public interface Entity {
|
||||
Vector getCoordinates();
|
||||
|
||||
void setCoordinates(Vector coordinates);
|
||||
|
||||
Movement prepareMovement(Direction direction);
|
||||
|
||||
Direction getFaceDirection();
|
||||
|
||||
void setFaceDirection(Direction direction);
|
||||
}
|
||||
@@ -4,8 +4,7 @@ import com.bartlomiejpluta.base.core.gl.object.material.Material;
|
||||
import com.bartlomiejpluta.base.core.gl.object.mesh.Mesh;
|
||||
import com.bartlomiejpluta.base.core.util.mesh.MeshManager;
|
||||
import com.bartlomiejpluta.base.game.entity.config.EntitySpriteConfiguration;
|
||||
import com.bartlomiejpluta.base.game.entity.model.Entity;
|
||||
import com.bartlomiejpluta.base.game.map.model.GameMap;
|
||||
import com.bartlomiejpluta.base.game.entity.model.DefaultEntity;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -16,11 +15,13 @@ import org.springframework.stereotype.Component;
|
||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||
public class DefaultEntityManager implements EntityManager {
|
||||
private final MeshManager meshManager;
|
||||
private final EntitySetManager entitySetManager;
|
||||
private final EntitySpriteConfiguration configuration;
|
||||
|
||||
@Override
|
||||
public Entity createEntity(Material material, GameMap map) {
|
||||
return new Entity(buildMesh(material), material, map.getStepSize(), configuration);
|
||||
public DefaultEntity createEntity(String entitySetUid) {
|
||||
var material = entitySetManager.loadObject(entitySetUid);
|
||||
return new DefaultEntity(buildMesh(material), material, configuration);
|
||||
}
|
||||
|
||||
private Mesh buildMesh(Material material) {
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
package com.bartlomiejpluta.base.game.entity.manager;
|
||||
|
||||
import com.bartlomiejpluta.base.core.gc.Cleanable;
|
||||
import com.bartlomiejpluta.base.core.gl.object.material.Material;
|
||||
import com.bartlomiejpluta.base.game.entity.model.Entity;
|
||||
import com.bartlomiejpluta.base.game.map.model.GameMap;
|
||||
import com.bartlomiejpluta.base.game.entity.model.DefaultEntity;
|
||||
|
||||
public interface EntityManager extends Cleanable {
|
||||
Entity createEntity(Material material, GameMap map);
|
||||
DefaultEntity createEntity(String entitySetUid);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.bartlomiejpluta.base.game.entity.model;
|
||||
|
||||
import com.bartlomiejpluta.base.api.entity.Direction;
|
||||
import com.bartlomiejpluta.base.api.entity.Entity;
|
||||
import com.bartlomiejpluta.base.api.geo.Vector;
|
||||
import com.bartlomiejpluta.base.core.gl.object.material.Material;
|
||||
import com.bartlomiejpluta.base.core.gl.object.mesh.Mesh;
|
||||
import com.bartlomiejpluta.base.game.entity.config.EntitySpriteConfiguration;
|
||||
@@ -13,7 +15,7 @@ import org.joml.Vector2f;
|
||||
import java.util.Map;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class Entity extends MovableSprite {
|
||||
public class DefaultEntity extends MovableSprite implements Entity {
|
||||
private final Map<Direction, Integer> spriteDirectionRows;
|
||||
private final int defaultSpriteColumn;
|
||||
|
||||
@@ -40,7 +42,7 @@ public class Entity extends MovableSprite {
|
||||
var frames = material.getTexture().getRows();
|
||||
var array = new Vector2f[frames];
|
||||
|
||||
for(int column=0; column<frames; ++column) {
|
||||
for (int column = 0; column < frames; ++column) {
|
||||
array[column] = new Vector2f(column, row);
|
||||
}
|
||||
|
||||
@@ -54,7 +56,7 @@ public class Entity extends MovableSprite {
|
||||
|
||||
@Override
|
||||
protected boolean move(Direction direction) {
|
||||
if(super.move(direction)) {
|
||||
if (super.move(direction)) {
|
||||
faceDirection = direction;
|
||||
return true;
|
||||
}
|
||||
@@ -70,8 +72,13 @@ public class Entity extends MovableSprite {
|
||||
return framesToCrossOneTile;
|
||||
}
|
||||
|
||||
public Entity(Mesh mesh, Material material, Vector2f coordinateStepSize, EntitySpriteConfiguration configuration) {
|
||||
super(mesh, material, coordinateStepSize);
|
||||
@Override
|
||||
public void setCoordinates(Vector coordinates) {
|
||||
setCoordinates(coordinates.x, coordinates.y);
|
||||
}
|
||||
|
||||
public DefaultEntity(Mesh mesh, Material material, EntitySpriteConfiguration configuration) {
|
||||
super(mesh, material);
|
||||
this.defaultSpriteColumn = configuration.getDefaultSpriteColumn();
|
||||
this.spriteDirectionRows = configuration.getSpriteDirectionRows();
|
||||
this.faceDirection = Direction.DOWN;
|
||||
@@ -13,7 +13,7 @@ import org.joml.Vector2i;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public abstract class MovableSprite extends AnimatedSprite implements Updatable {
|
||||
private final Vector2f coordinateStepSize;
|
||||
private final Vector2f coordinateStepSize = new Vector2f(0, 0);
|
||||
|
||||
private int moveTime = 0;
|
||||
private Vector2f movementVector;
|
||||
@@ -78,9 +78,15 @@ public abstract class MovableSprite extends AnimatedSprite implements Updatable
|
||||
return setCoordinates(coordinates.x, coordinates.y);
|
||||
}
|
||||
|
||||
public MovableSprite(Mesh mesh, Material material, Vector2f coordinateStepSize) {
|
||||
public MovableSprite setStepSize(float x, float y) {
|
||||
coordinateStepSize.x = x;
|
||||
coordinateStepSize.y = y;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public MovableSprite(Mesh mesh, Material material) {
|
||||
super(mesh, material);
|
||||
this.coordinateStepSize = coordinateStepSize;
|
||||
setCoordinates(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.bartlomiejpluta.base.game.project.model;
|
||||
|
||||
import com.bartlomiejpluta.base.api.context.Context;
|
||||
import com.bartlomiejpluta.base.api.entity.Entity;
|
||||
import com.bartlomiejpluta.base.api.input.Keyboard;
|
||||
import com.bartlomiejpluta.base.api.map.MapHandler;
|
||||
import com.bartlomiejpluta.base.core.gl.object.texture.TextureManager;
|
||||
@@ -52,6 +53,11 @@ public class RenderableContext implements Context, Updatable, Renderable {
|
||||
mapHandler.init(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity createEntity(String entitySetUid) {
|
||||
return entityManager.createEntity(entitySetUid);
|
||||
}
|
||||
|
||||
public void input() {
|
||||
mapHandler.input(keyboard);
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public class DefaultTileSetManager implements TileSetManager {
|
||||
var size = texture.getSpriteSize();
|
||||
var mesh = meshManager.createQuad(size.x, size.y, 0, 0);
|
||||
tileset = new TileSet(texture, mesh);
|
||||
log.info("Loading tileset from assets to cache under the key: [{}]", uid);
|
||||
log.info("Loading tile set from assets to cache under the key: [{}]", uid);
|
||||
tileSets.put(uid, tileset);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user