Add camera support in :API Context
This commit is contained in:
@@ -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