Add camera support in :API Context

This commit is contained in:
2021-03-02 21:23:14 +01:00
parent ed0f9ac0c5
commit 64d290503c
7 changed files with 44 additions and 6 deletions

View File

@@ -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());

View File

@@ -76,6 +76,7 @@ public class DefaultGameMap implements Renderable, Updatable, GameMap {
}
}
@Override
public Vector2f getSize() {
return new Vector2f(columns * stepSize.x, rows * stepSize.y);
}

View File

@@ -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());
}
}
}