Rough Scene/SceneManager implementation
This commit is contained in:
8
src/main/java/org/hirw/game/Scene.java
Normal file
8
src/main/java/org/hirw/game/Scene.java
Normal file
@@ -0,0 +1,8 @@
|
||||
package org.hirw.game;
|
||||
|
||||
|
||||
public abstract class Scene {
|
||||
public Scene() {}
|
||||
|
||||
abstract void update();
|
||||
}
|
||||
20
src/main/java/org/hirw/game/SceneManager.java
Normal file
20
src/main/java/org/hirw/game/SceneManager.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package org.hirw.game;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import lombok.Getter;
|
||||
|
||||
final class SceneManager {
|
||||
private static final EnumMap<SceneType, Scene> SCENES =
|
||||
new EnumMap<>(
|
||||
Map.of(
|
||||
SceneType.SPLASH, new SplashScene(),
|
||||
SceneType.MENU, new SplashScene(),
|
||||
SceneType.GAME, new SplashScene()));
|
||||
|
||||
@Getter private static Scene scene = SCENES.get(SceneType.SPLASH);
|
||||
|
||||
public static void setScene(SceneType sType) {
|
||||
scene = SCENES.get(sType);
|
||||
}
|
||||
}
|
||||
7
src/main/java/org/hirw/game/SceneType.java
Normal file
7
src/main/java/org/hirw/game/SceneType.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package org.hirw.game;
|
||||
|
||||
public enum SceneType {
|
||||
SPLASH,
|
||||
MENU,
|
||||
GAME
|
||||
}
|
||||
19
src/main/java/org/hirw/game/SplashScene.java
Normal file
19
src/main/java/org/hirw/game/SplashScene.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package org.hirw.game;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
import java.util.Objects;
|
||||
import org.hirw.game.util.Time;
|
||||
|
||||
public class SplashScene extends Scene {
|
||||
private float ramp = 0.0f;
|
||||
|
||||
public void update() {
|
||||
if (Objects.isNull(Window.get().getGlfwWindow())) {
|
||||
return;
|
||||
}
|
||||
|
||||
glClearColor(this.ramp, this.ramp, this.ramp, 0.0f);
|
||||
this.ramp += 0.5f * Time.deltaTime();
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import static org.lwjgl.glfw.GLFW.*;
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
import static org.lwjgl.system.MemoryUtil.*;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.hirw.game.util.Time;
|
||||
import org.lwjgl.Version;
|
||||
import org.lwjgl.glfw.*;
|
||||
@@ -13,7 +14,7 @@ import org.lwjgl.opengl.*;
|
||||
public class Window {
|
||||
private int width, height;
|
||||
private final String title;
|
||||
private long glfwWindow;
|
||||
@Getter private long glfwWindow;
|
||||
|
||||
private static Window window = null;
|
||||
|
||||
@@ -78,13 +79,13 @@ public class Window {
|
||||
glfwShowWindow(glfwWindow);
|
||||
|
||||
GL.createCapabilities();
|
||||
glClearColor(1.0f, 0.0f, 2.0f, 0.0f);
|
||||
glClearColor(0.0f, 0.0f, 2.0f, 0.0f);
|
||||
}
|
||||
|
||||
private void loop() {
|
||||
while (!glfwWindowShouldClose(glfwWindow)) {
|
||||
Time.update();
|
||||
System.out.println(Time.deltaTime());
|
||||
SceneManager.getScene().update();
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glfwSwapBuffers(glfwWindow);
|
||||
glfwPollEvents();
|
||||
|
||||
Reference in New Issue
Block a user