Add camera support in :API Context
This commit is contained in:
@@ -1,9 +1,14 @@
|
|||||||
package com.bartlomiejpluta.base.api.context;
|
package com.bartlomiejpluta.base.api.context;
|
||||||
|
|
||||||
import com.bartlomiejpluta.base.api.entity.Entity;
|
import com.bartlomiejpluta.base.api.entity.Entity;
|
||||||
|
import org.joml.Vector2f;
|
||||||
|
|
||||||
public interface Context {
|
public interface Context {
|
||||||
void openMap(String mapUid);
|
void openMap(String mapUid);
|
||||||
|
|
||||||
Entity createEntity(String entitySetUid);
|
Entity createEntity(String entitySetUid);
|
||||||
|
|
||||||
|
void setCameraPosition(Vector2f position);
|
||||||
|
|
||||||
|
void setCameraPosition(float x, float y);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,16 +2,23 @@ package com.bartlomiejpluta.base.api.map;
|
|||||||
|
|
||||||
import com.bartlomiejpluta.base.api.entity.Entity;
|
import com.bartlomiejpluta.base.api.entity.Entity;
|
||||||
import com.bartlomiejpluta.base.api.entity.Movement;
|
import com.bartlomiejpluta.base.api.entity.Movement;
|
||||||
|
import org.joml.Vector2f;
|
||||||
|
|
||||||
public interface GameMap {
|
public interface GameMap {
|
||||||
|
Vector2f getSize();
|
||||||
|
|
||||||
void addEntity(int objectLayerIndex, Entity entity);
|
void addEntity(int objectLayerIndex, Entity entity);
|
||||||
|
|
||||||
void removeEntity(int objectLayerIndex, Entity entity);
|
void removeEntity(int objectLayerIndex, Entity entity);
|
||||||
|
|
||||||
boolean isMovementPossible(int objectLayerIndex, Movement movement);
|
boolean isMovementPossible(int objectLayerIndex, Movement movement);
|
||||||
|
|
||||||
void setPassageAbility(int objectLayerIndex, int row, int column, PassageAbility passageAbility);
|
void setPassageAbility(int objectLayerIndex, int row, int column, PassageAbility passageAbility);
|
||||||
|
|
||||||
void setTile(int tileLayerIndex, int row, int column, int tileId);
|
void setTile(int tileLayerIndex, int row, int column, int tileId);
|
||||||
|
|
||||||
void setTile(int tileLayerIndex, int row, int column, int tileSetRow, int tileSetColumn);
|
void setTile(int tileLayerIndex, int row, int column, int tileSetRow, int tileSetColumn);
|
||||||
|
|
||||||
void clearTile(int tileLayerIndex, int row, int column);
|
void clearTile(int tileLayerIndex, int row, int column);
|
||||||
|
|
||||||
void setColor(int colorLayerIndex, float r, float g, float b, float alpha);
|
void setColor(int colorLayerIndex, float r, float g, float b, float alpha);
|
||||||
|
|||||||
@@ -9,4 +9,6 @@ public interface MapHandler {
|
|||||||
void input(Keyboard keyboard);
|
void input(Keyboard keyboard);
|
||||||
|
|
||||||
void update(Context context, GameMap map, float dt);
|
void update(Context context, GameMap map, float dt);
|
||||||
|
|
||||||
|
void postRender(float windowWidth, float windowHeight);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,16 +9,21 @@ public class ${className} implements MapHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(Context context, GameMap map) {
|
public void init(Context context, GameMap map) {
|
||||||
throw new RuntimeException("Not implemented yet");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void input(Keyboard keyboard) {
|
void input(Keyboard keyboard) {
|
||||||
throw new RuntimeException("Not implemented yet");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(Context context, GameMap map, float dt) {
|
public void update(Context context, GameMap map, float dt) {
|
||||||
throw new RuntimeException("Not implemented yet");
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void postRender(float windowWidth, float windowHeight) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -51,7 +51,7 @@ public class DefaultGameLogic implements GameLogic {
|
|||||||
public void init(Window window) {
|
public void init(Window window) {
|
||||||
log.info("Initializing game logic");
|
log.info("Initializing game logic");
|
||||||
renderer.init();
|
renderer.init();
|
||||||
context.init(window);
|
context.init(window, camera);
|
||||||
|
|
||||||
project = projectLoader.loadProject();
|
project = projectLoader.loadProject();
|
||||||
var runnerClass = classLoader.<GameRunner>loadClass(project.getRunner());
|
var runnerClass = classLoader.<GameRunner>loadClass(project.getRunner());
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ public class DefaultGameMap implements Renderable, Updatable, GameMap {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Vector2f getSize() {
|
public Vector2f getSize() {
|
||||||
return new Vector2f(columns * stepSize.x, rows * stepSize.y);
|
return new Vector2f(columns * stepSize.x, rows * stepSize.y);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import com.bartlomiejpluta.base.game.project.loader.ClassLoader;
|
|||||||
import com.bartlomiejpluta.base.game.tileset.manager.TileSetManager;
|
import com.bartlomiejpluta.base.game.tileset.manager.TileSetManager;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
|
import org.joml.Vector2f;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@@ -38,8 +39,11 @@ public class RenderableContext implements Context, Updatable, Renderable {
|
|||||||
private DefaultGameMap map;
|
private DefaultGameMap map;
|
||||||
private MapHandler mapHandler;
|
private MapHandler mapHandler;
|
||||||
|
|
||||||
public void init(Window window) {
|
private Camera camera;
|
||||||
keyboard = new GLFWKeyboard(window);
|
|
||||||
|
public void init(Window window, Camera camera) {
|
||||||
|
this.keyboard = new GLFWKeyboard(window);
|
||||||
|
this.camera = camera;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
@@ -58,6 +62,16 @@ public class RenderableContext implements Context, Updatable, Renderable {
|
|||||||
return entityManager.createEntity(entitySetUid);
|
return entityManager.createEntity(entitySetUid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCameraPosition(Vector2f position) {
|
||||||
|
camera.setPosition(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCameraPosition(float x, float y) {
|
||||||
|
camera.setPosition(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
public void input() {
|
public void input() {
|
||||||
mapHandler.input(keyboard);
|
mapHandler.input(keyboard);
|
||||||
}
|
}
|
||||||
@@ -78,5 +92,9 @@ public class RenderableContext implements Context, Updatable, Renderable {
|
|||||||
if (map != null) {
|
if (map != null) {
|
||||||
map.render(window, camera, shaderManager);
|
map.render(window, camera, shaderManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mapHandler != null) {
|
||||||
|
mapHandler.postRender(window.getWidth(), window.getHeight());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user