Replace Scene with GameMap | improve GameMap to allow variable layers
From now on, GameMap is the central container for objects and is acting as a scene was before. What's more, GameMap is not restricted to 4 layers anymore. User can combine TileLayers (which define the terrain) and ObjectLayers (which can contain movable objects) together and is no limited to have only one ObjectLayer. Thanks to that it would be easier to implement i.e. birds which actually are a movable objects and are flying above the map and the highest terrain (top TileLayers in fact).
This commit is contained in:
@@ -3,7 +3,7 @@ package com.bartlomiejpluta.base.game.world.entity.manager;
|
||||
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.core.world.scene.Scene;
|
||||
import com.bartlomiejpluta.base.core.world.map.GameMap;
|
||||
import com.bartlomiejpluta.base.game.world.entity.config.EntitySpriteConfiguration;
|
||||
import com.bartlomiejpluta.base.game.world.entity.model.Entity;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -19,8 +19,8 @@ public class DefaultEntityManager implements EntityManager {
|
||||
private final EntitySpriteConfiguration configuration;
|
||||
|
||||
@Override
|
||||
public Entity createEntity(Material material, Scene scene) {
|
||||
return new Entity(scene, buildMesh(material), material, scene.getMap().getStepSize(), configuration);
|
||||
public Entity createEntity(Material material, GameMap map) {
|
||||
return new Entity(buildMesh(material), material, map.getStepSize(), configuration);
|
||||
}
|
||||
|
||||
private Mesh buildMesh(Material material) {
|
||||
|
||||
@@ -2,10 +2,9 @@ package com.bartlomiejpluta.base.game.world.entity.manager;
|
||||
|
||||
import com.bartlomiejpluta.base.core.gc.Cleanable;
|
||||
import com.bartlomiejpluta.base.core.gl.object.material.Material;
|
||||
import com.bartlomiejpluta.base.core.world.scene.Scene;
|
||||
import com.bartlomiejpluta.base.core.world.map.GameMap;
|
||||
import com.bartlomiejpluta.base.game.world.entity.model.Entity;
|
||||
import org.joml.Vector2f;
|
||||
|
||||
public interface EntityManager extends Cleanable {
|
||||
Entity createEntity(Material material, Scene scene);
|
||||
Entity createEntity(Material material, GameMap map);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import com.bartlomiejpluta.base.core.gl.object.material.Material;
|
||||
import com.bartlomiejpluta.base.core.gl.object.mesh.Mesh;
|
||||
import com.bartlomiejpluta.base.core.world.movement.Direction;
|
||||
import com.bartlomiejpluta.base.core.world.movement.MovableObject;
|
||||
import com.bartlomiejpluta.base.core.world.scene.Scene;
|
||||
import com.bartlomiejpluta.base.game.world.entity.config.EntitySpriteConfiguration;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
@@ -13,14 +12,10 @@ import org.joml.Vector2f;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@EqualsAndHashCode(exclude = "scene", callSuper = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class Entity extends MovableObject {
|
||||
private final Map<Direction, Integer> spriteDirectionRows;
|
||||
private final int defaultSpriteColumn;
|
||||
private final Scene scene;
|
||||
|
||||
@Getter
|
||||
private boolean onScene;
|
||||
|
||||
@Setter
|
||||
private int animationSpeed = 100;
|
||||
@@ -75,26 +70,10 @@ public class Entity extends MovableObject {
|
||||
return framesToCrossOneTile;
|
||||
}
|
||||
|
||||
public void pushToScene() {
|
||||
if(!onScene) {
|
||||
scene.addObject(this);
|
||||
onScene = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void removeFromScene() {
|
||||
if(onScene) {
|
||||
scene.removeObject(this);
|
||||
onScene = false;
|
||||
}
|
||||
}
|
||||
|
||||
public Entity(Scene scene, Mesh mesh, Material material, Vector2f coordinateStepSize, EntitySpriteConfiguration configuration) {
|
||||
public Entity(Mesh mesh, Material material, Vector2f coordinateStepSize, EntitySpriteConfiguration configuration) {
|
||||
super(mesh, material, coordinateStepSize, configuration.getDimension().asVector());
|
||||
this.scene = scene;
|
||||
this.defaultSpriteColumn = configuration.getDefaultSpriteColumn();
|
||||
this.spriteDirectionRows = configuration.getSpriteDirectionRows();
|
||||
this.onScene = false;
|
||||
this.faceDirection = Direction.DOWN;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user