diff --git a/src/main/java/GLWindow.java b/src/main/java/GLWindow.java index 9ce64be..a86e792 100644 --- a/src/main/java/GLWindow.java +++ b/src/main/java/GLWindow.java @@ -11,7 +11,15 @@ // ウィンドウ public class GLWindow { - private long hWnd; // ウィンドウハンドル + private long window; // ウィンドウハンドル + + //--------------------------------------------------------------- + //--------------------------------------------------------------- + // getter + public long getWindow() { + return this.window; + } + //--------------------------------------------------------------- //--------------------------------------------------------------- @@ -24,15 +32,15 @@ //--------------------------------------------------------------- // 画面のスワップ public void swapWindow() { - glfwSwapBuffers(hWnd); // バッファのスワップ + glfwSwapBuffers(window); // バッファのスワップ glfwPollEvents(); // 入力とかイベントの取得 } //--------------------------------------------------------------- // ウィンドウの破棄 public void destroyWindow() { - glfwFreeCallbacks(hWnd); // ウィンドウコールバックの解放 - glfwDestroyWindow(hWnd); // ウィンドウの破棄 + glfwFreeCallbacks(window); // ウィンドウコールバックの解放 + glfwDestroyWindow(window); // ウィンドウの破棄 glfwTerminate(); // GLFWの破棄 glfwSetErrorCallback(null).free(); // エラーコールバックの解放 } @@ -40,7 +48,7 @@ //--------------------------------------------------------------- // ウィンドウが起動しているかどうか public boolean windowShouldClose() { - return glfwWindowShouldClose(hWnd); + return glfwWindowShouldClose(window); } //--------------------------------------------------------------- @@ -56,14 +64,14 @@ glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); // ウィンドウの作成 - hWnd = glfwCreateWindow(GLConfigVariable.WIDTH, GLConfigVariable.HEIGHT, GLConfigVariable.TITLE_NAME, GLConfigVariable.IS_FULL_SCREEN ? glfwGetPrimaryMonitor() : NULL, NULL); - if (hWnd == NULL) + window = glfwCreateWindow(GLConfigVariable.WIDTH, GLConfigVariable.HEIGHT, GLConfigVariable.TITLE_NAME, GLConfigVariable.IS_FULL_SCREEN ? glfwGetPrimaryMonitor() : NULL, NULL); + if (window == NULL) throw new RuntimeException("Failed to create the window."); - glfwMakeContextCurrent(hWnd); //起動したウィンドウをターゲットに + glfwMakeContextCurrent(window); //起動したウィンドウをターゲットに glfwSwapInterval(1); // v-syncの適応 - glfwShowWindow(hWnd); // ウィンドウの表示 + glfwShowWindow(window); // ウィンドウの表示 } //--------------------------------------------------------------- diff --git a/src/main/java/GameEngine.java b/src/main/java/GameEngine.java index 50627dc..0ecdb1f 100644 --- a/src/main/java/GameEngine.java +++ b/src/main/java/GameEngine.java @@ -14,7 +14,7 @@ //--------------------------------------------------------------- // ゲームループ - protected void update() { + protected void update(long window) { } //--------------------------------------------------------------- @@ -34,7 +34,7 @@ // メインループ while (!glWindow.windowShouldClose()) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // バッファのクリア - update(); + update(glWindow.getWindow()); glWindow.swapWindow(); } diff --git a/src/main/java/JumpGame.java b/src/main/java/JumpGame.java index 344a7a1..d4c478a 100644 --- a/src/main/java/JumpGame.java +++ b/src/main/java/JumpGame.java @@ -1,9 +1,16 @@ import models.IModel; import models.JumpGameModel; +import org.lwjgl.glfw.GLFW; +import org.lwjgl.glfw.GLFWKeyCallback; import views.IView; import views.PlayerRenderer; import views.TileMapRenderer; +import static org.lwjgl.glfw.Callbacks.glfwFreeCallbacks; +import static org.lwjgl.glfw.GLFW.*; +import static org.lwjgl.opengl.GL11.*; +import static org.lwjgl.system.MemoryUtil.NULL; + import java.util.ArrayList; public class JumpGame { @@ -11,6 +18,8 @@ private ArrayList views = new ArrayList<>(); private IModel model = new JumpGameModel(); + private GLFWKeyCallback keyCallback; + //--------------------------------------------------------------- //--------------------------------------------------------------- // @@ -29,7 +38,7 @@ //--------------------------------------------------------------- // 更新処理 - public void update() { + public void update(long window) { // Viewの更新 for (IView view : views) { @@ -42,9 +51,19 @@ // Modelの更新 // // Space キーのインプット - // - // マイフレーム更新 + glfwSetKeyCallback(window, keyCallback = new GLFWKeyCallback() { + @Override + public void invoke(long window, int key, int scancode, int action, int mods) { + if(key == GLFW_KEY_SPACE && action != GLFW_PRESS){ + JumpGameModel jumpGameModel = (JumpGameModel)model; + jumpGameModel.jump(); + System.out.println("jumping"); + } + } + }); + + // マイフレーム更新 gravity(-256); //重力 } diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 4cb5cb0..f51def6 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -15,15 +15,15 @@ //--------------------------------------------------------------- // 初期化 @Override - protected void init(){ + protected void init() { jumpGame.init(); } //--------------------------------------------------------------- // 更新処理 @Override - protected void update(){ - jumpGame.update(); + protected void update(long window) { + jumpGame.update(window); } //--------------------------------------------------------------- diff --git a/src/main/java/entities/Move.java b/src/main/java/entities/Move.java index c7e92ac..a966f75 100644 --- a/src/main/java/entities/Move.java +++ b/src/main/java/entities/Move.java @@ -2,7 +2,7 @@ public class Move { private Velocity velocity; - private Pair value = new Pair<>(0d, 0d); + private Pair value = new Pair<>(1d, 256d); public Move(Velocity velocity) { this.velocity = velocity; @@ -15,6 +15,7 @@ public void moveY(double y) { this.value = new Pair(this.value.getFirst(), y); + velocity.updateByMove(value); } public Pair getValue() { diff --git a/src/main/java/models/JumpGameModel.java b/src/main/java/models/JumpGameModel.java index 6c730b9..7638270 100644 --- a/src/main/java/models/JumpGameModel.java +++ b/src/main/java/models/JumpGameModel.java @@ -33,7 +33,7 @@ private Ground ground; //--------------------------------------------------------------- - private double jumpPower = 32; + private double jumpPower = 256; //--------------------------------------------------------------- private Flags flags; diff --git a/src/main/java/views/PlayerRenderer.java b/src/main/java/views/PlayerRenderer.java index 2eabe4f..011130a 100644 --- a/src/main/java/views/PlayerRenderer.java +++ b/src/main/java/views/PlayerRenderer.java @@ -4,6 +4,7 @@ import models.IModel; import models.JumpGameModel; + //--------------------------------------------------------------- // public class PlayerRenderer implements IView { @@ -22,6 +23,11 @@ // @Override public void update(IModel model) { + JumpGameModel jumpGameModel = (JumpGameModel) model; + + double x = this.sprite.getPositionValue().getFirst(); + double y = 128 + jumpGameModel.getPosition().getValue().getSecond(); + this.sprite.setPositionValue(new Pair<>(x, y)); }