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