diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index f9c7b45..9c32aad 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,24 +4,36 @@
-
+
+
+
-
+
+
+
+
-
-
-
-
+
+
-
+
+
+
+
+
+
+
+
+
+
@@ -30,20 +42,27 @@
-
+
-
-
-
+
+
+
+
+
+
@@ -96,6 +115,17 @@
+
+
+
+
+
+
+
+
+
+
+
@@ -114,7 +144,9 @@
-
+
+
+
1648974204548
@@ -130,7 +162,14 @@
1648975130088
-
+
+ 1650351804113
+
+
+
+ 1650351804114
+
+
@@ -151,7 +190,8 @@
-
+
+
diff --git a/README.md b/README.md
index 734b005..afcd5ff 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,2 @@
-JumpGame
+JumpingGame
===============
diff --git a/resources/stage.txt b/resources/stage.txt
index e886f9f..f6ff4d2 100644
--- a/resources/stage.txt
+++ b/resources/stage.txt
@@ -1 +1 @@
-1,2,4,6,7,20,40,60,100
\ No newline at end of file
+1,4,7,10,24,28,40,42,48,50,62,66,68,74,80,82,85,90,94,100
\ No newline at end of file
diff --git a/src/main/java/GLWindow.java b/src/main/java/GLWindow.java
index a86e792..1058d46 100644
--- a/src/main/java/GLWindow.java
+++ b/src/main/java/GLWindow.java
@@ -7,83 +7,56 @@
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.system.MemoryUtil.NULL;
-//---------------------------------------------------------------
-// ウィンドウ
public class GLWindow {
- private long window; // ウィンドウハンドル
+ private long window;
- //---------------------------------------------------------------
- //---------------------------------------------------------------
- // getter
public long getWindow() {
return this.window;
}
-
- //---------------------------------------------------------------
- //---------------------------------------------------------------
- //
public void init() {
initWindow();
initRender();
}
- //---------------------------------------------------------------
- // 画面のスワップ
public void swapWindow() {
- glfwSwapBuffers(window); // バッファのスワップ
- glfwPollEvents(); // 入力とかイベントの取得
+ glfwSwapBuffers(window);
+ glfwPollEvents();
}
- //---------------------------------------------------------------
- // ウィンドウの破棄
public void destroyWindow() {
- glfwFreeCallbacks(window); // ウィンドウコールバックの解放
- glfwDestroyWindow(window); // ウィンドウの破棄
- glfwTerminate(); // GLFWの破棄
- glfwSetErrorCallback(null).free(); // エラーコールバックの解放
+ glfwFreeCallbacks(window);
+ glfwDestroyWindow(window);
+ glfwTerminate();
+ glfwSetErrorCallback(null).free();
}
- //---------------------------------------------------------------
- // ウィンドウが起動しているかどうか
public boolean windowShouldClose() {
return glfwWindowShouldClose(window);
}
- //---------------------------------------------------------------
- // ウィンドウの初期化
private void initWindow() {
- GLFWErrorCallback.createPrint(System.err).set(); // エラーコールバックの設定
+ GLFWErrorCallback.createPrint(System.err).set();
-
- // GLFWの初期化
if (!glfwInit()) throw new IllegalStateException("Unable to initialize GLFW");
-
- // ウィンドウの設定
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
- // ウィンドウの作成
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(window); //起動したウィンドウをターゲットに
- glfwSwapInterval(1); // v-syncの適応
-
- glfwShowWindow(window); // ウィンドウの表示
+ glfwMakeContextCurrent(window);
+ glfwSwapInterval(1);
+ glfwShowWindow(window);
}
- //---------------------------------------------------------------
- // 描画プロセス初期化
private void initRender() {
GL.createCapabilities();
- glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // 背景色設定
+ glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
- // OpenGLの初期化
- glEnable(GL_TEXTURE_2D); // 二次元テクスチャの有効化
- glEnable(GL_BLEND); // アルファブレンディングの有効化
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // ブレンドモードの設定
+ glEnable(GL_TEXTURE_2D);
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
- //---------------------------------------------------------------
}
diff --git a/src/main/java/GameEngine.java b/src/main/java/GameEngine.java
index 0ecdb1f..4cec237 100644
--- a/src/main/java/GameEngine.java
+++ b/src/main/java/GameEngine.java
@@ -1,46 +1,30 @@
import static org.lwjgl.opengl.GL11.*;
-//---------------------------------------------------------------
-// ゲームループ提供
public abstract class GameEngine {
private GLWindow glWindow = new GLWindow();
- //---------------------------------------------------------------
- //---------------------------------------------------------------
- // 初期化
protected void init() {
}
- //---------------------------------------------------------------
- // ゲームループ
protected void update(long window) {
}
- //---------------------------------------------------------------
- // 破棄処理
protected void destroy() {
}
- //---------------------------------------------------------------
- //---------------------------------------------------------------
- // 実行系の本体
protected void run() {
- // 初期化
glWindow.init();
init();
- // メインループ
while (!glWindow.windowShouldClose()) {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // バッファのクリア
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
update(glWindow.getWindow());
glWindow.swapWindow();
}
- // 終了処理
- destroy(); // デストラクタ
- glWindow.destroyWindow(); // ウィンドウの破棄
+ destroy();
+ glWindow.destroyWindow();
}
- //---------------------------------------------------------------
}
diff --git a/src/main/java/JumpGame.java b/src/main/java/JumpGame.java
deleted file mode 100644
index aee1977..0000000
--- a/src/main/java/JumpGame.java
+++ /dev/null
@@ -1,72 +0,0 @@
-import models.IModel;
-import models.JumpGameModel;
-import org.lwjgl.glfw.GLFWKeyCallback;
-import views.IView;
-import views.PlayerRenderer;
-import views.TileMapRenderer;
-
-import static org.lwjgl.glfw.GLFW.*;
-
-import java.util.ArrayList;
-
-public class JumpGame {
-
- private ArrayList views = new ArrayList<>();
- private IModel model = new JumpGameModel();
-
- private GLFWKeyCallback keyCallback;
-
- //---------------------------------------------------------------
- //---------------------------------------------------------------
- //
- public void gravity(double y) {
- JumpGameModel jumpGameModel = (JumpGameModel) model;
- jumpGameModel.moveX(1);
- jumpGameModel.gravity(y); //重力の更新
- jumpGameModel.updateGroundFlag();//地面の判定切り替え
- }
-
- //---------------------------------------------------------------
- // 初期化
- public void init() {
- // view
- views.add(new TileMapRenderer(model));
- views.add(new PlayerRenderer("resources/JCasC.png"));
- }
-
- //---------------------------------------------------------------
- // 更新処理
- public void update(long window) {
-
- // Viewの更新
- for (IView view : views) {
- JumpGameModel jumpGameModel = (JumpGameModel) model;
- view.update(model);
- view.display();
- }
-
- // 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.moveY(256);
-// System.out.println("jumping");
- }
- }
- });
-
- gravity(-256); //重力
- }
-
- //---------------------------------------------------------------
- // デストラクタのような処理
- public void delete() {
- for (IView view : views) view.delete();
- }
-
- //---------------------------------------------------------------
-
-}
\ No newline at end of file
diff --git a/src/main/java/JumpingGame.java b/src/main/java/JumpingGame.java
new file mode 100644
index 0000000..67beb34
--- /dev/null
+++ b/src/main/java/JumpingGame.java
@@ -0,0 +1,55 @@
+import models.IModel;
+import models.JumpingGameModel;
+import org.lwjgl.glfw.GLFWKeyCallback;
+import views.IView;
+import views.PlayerRenderer;
+import views.TileMapRenderer;
+
+import java.util.ArrayList;
+
+import static org.lwjgl.glfw.GLFW.*;
+
+public class JumpingGame {
+
+ private ArrayList views = new ArrayList<>();
+ private IModel model = new JumpingGameModel();
+
+ private GLFWKeyCallback keyCallback;
+
+ public void gravity(double y) {
+ JumpingGameModel jumpingGameModel = (JumpingGameModel) model;
+ jumpingGameModel.gravity(y);
+ jumpingGameModel.updateGroundFlag();
+ }
+
+ public void init() {
+ JumpingGameModel jumpingGameModel = (JumpingGameModel) model;
+ jumpingGameModel.run(2);
+ views.add(new TileMapRenderer(model));
+ views.add(new PlayerRenderer("resources/JCasC.png"));
+ }
+
+ public void update(long window) {
+
+ for (IView view : views) {
+ view.update(model);
+ view.display();
+ }
+
+ 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) {
+ JumpingGameModel jumpGameModel = (JumpingGameModel) model;
+ jumpGameModel.jump(256);
+ }
+ }
+ });
+
+ gravity(-256);
+ }
+
+ public void delete() {
+ for (IView view : views) view.delete();
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/Main.java b/src/main/java/Main.java
index b0f671e..1371320 100644
--- a/src/main/java/Main.java
+++ b/src/main/java/Main.java
@@ -1,40 +1,23 @@
-import javax.swing.*;
-import java.awt.*;
-
-//---------------------------------------------------------------
-// 実行本体
public class Main extends GameEngine {
- private JumpGame jumpGame = new JumpGame();
+ private JumpingGame jumpingGame = new JumpingGame();
- //---------------------------------------------------------------
- //---------------------------------------------------------------
- // エントリーポイント
public static void main(String[] args) {
new Main().run();
}
- //---------------------------------------------------------------
- //---------------------------------------------------------------
- // 初期化
@Override
protected void init() {
- jumpGame.init();
+ jumpingGame.init();
}
- //---------------------------------------------------------------
- // 更新処理
@Override
protected void update(long window) {
- jumpGame.update(window);
+ jumpingGame.update(window);
}
- //---------------------------------------------------------------
- // 破棄
@Override
protected void destroy() {
- jumpGame.delete();
+ jumpingGame.delete();
}
-
- //---------------------------------------------------------------
}
\ No newline at end of file
diff --git a/src/main/java/entities/Acceleration.java b/src/main/java/entities/Acceleration.java
index 5d52dfd..b07ec67 100644
--- a/src/main/java/entities/Acceleration.java
+++ b/src/main/java/entities/Acceleration.java
@@ -8,24 +8,24 @@
private Pair value = new Pair<>(0.0,0.0);
public void updateForce(Pair force) {
this.force = force;
- Pair temp_if10;
+ Pair temp_if1;
if (this.onground.getValue()) {
- temp_if10 = new Pair<>((force.getLeft()/mass),0.0);
+ temp_if1 = new Pair<>((force.getLeft()/mass),0.0);
} else {
- temp_if10 = new Pair<>((force.getLeft()/mass),(force.getRight()/mass));
+ temp_if1 = new Pair<>((force.getLeft()/mass),(force.getRight()/mass));
}
- value = temp_if10;
+ value = temp_if1;
velocity.updateAcceleration(value);
}
public void updateMass(double mass) {
this.mass = mass;
- Pair temp_if13;
+ Pair temp_if5;
if (this.onground.getValue()) {
- temp_if13 = new Pair<>((force.getLeft()/mass),0.0);
+ temp_if5 = new Pair<>((force.getLeft()/mass),0.0);
} else {
- temp_if13 = new Pair<>((force.getLeft()/mass),(force.getRight()/mass));
+ temp_if5 = new Pair<>((force.getLeft()/mass),(force.getRight()/mass));
}
- value = temp_if13;
+ value = temp_if5;
velocity.updateAcceleration(value);
}
public Acceleration(Velocity velocity, Onground onground) {
diff --git a/src/main/java/entities/Clear.java b/src/main/java/entities/Clear.java
index 8359ee9..7bbd560 100644
--- a/src/main/java/entities/Clear.java
+++ b/src/main/java/entities/Clear.java
@@ -1,17 +1,15 @@
package entities;
-import java.util.*;
-
public class Clear {
private boolean value = false;
public void updatePosition(Pair position) {
- boolean temp_if11;
+ boolean temp_if2;
if ((position.getLeft()>100.0)) {
- temp_if11 = true;
+ temp_if2 = true;
} else {
- temp_if11 = false;
+ temp_if2 = false;
}
- value = temp_if11;
+ value = temp_if2;
}
public boolean getValue() {
return value;
diff --git a/src/main/java/entities/Gameover.java b/src/main/java/entities/Gameover.java
index 3cbee90..15fb248 100644
--- a/src/main/java/entities/Gameover.java
+++ b/src/main/java/entities/Gameover.java
@@ -1,17 +1,15 @@
package entities;
-import java.util.*;
-
public class Gameover {
private boolean value = false;
public void updatePosition(Pair position) {
- boolean temp_if12;
+ boolean temp_if0;
if ((position.getRight()<-(1.0))) {
- temp_if12 = true;
+ temp_if0 = true;
} else {
- temp_if12 = false;
+ temp_if0 = false;
}
- value = temp_if12;
+ value = temp_if0;
}
public boolean getValue() {
return value;
diff --git a/src/main/java/entities/Move.java b/src/main/java/entities/Move.java
deleted file mode 100644
index 25ec155..0000000
--- a/src/main/java/entities/Move.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package entities;
-
-import java.util.*;
-
-public class Move {
- private Velocity velocity;
- private Pair value = new Pair<>(1.0,0.0);
- public Move(Velocity velocity) {
- this.velocity = velocity;
- }
- public void moveX(double x) {
- this.value = new Pair<>(x,0d);
- velocity.updateMove(value);
- }
- public void moveY(double y) {
- this.value = new Pair<>(this.value.getLeft(),y);
- velocity.updateMove(value);
- }
- public Pair getValue() {
- return value;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/entities/Onground.java b/src/main/java/entities/Onground.java
index 94c09a2..9c3233c 100644
--- a/src/main/java/entities/Onground.java
+++ b/src/main/java/entities/Onground.java
@@ -1,19 +1,17 @@
package entities;
-import java.util.*;
-
public class Onground {
- private Pair position = new Pair<>(0.0,0.0);
private boolean ground = true;
+ private Pair position = new Pair<>(0.0,0.0);
private boolean value = true;
- public void updatePosition(Pair position) {
- this.position = position;
- value = ((ground==true)&&(position.getRight()<=0.0));
- }
public void updateGround(boolean ground) {
this.ground = ground;
value = ((ground==true)&&(position.getRight()<=0.0));
}
+ public void updatePosition(Pair position) {
+ this.position = position;
+ value = ((ground==true)&&(position.getRight()<=0.0));
+ }
public boolean getValue() {
return value;
}
diff --git a/src/main/java/entities/Pair.java b/src/main/java/entities/Pair.java
index 025be0a..b0b9e11 100644
--- a/src/main/java/entities/Pair.java
+++ b/src/main/java/entities/Pair.java
@@ -1,7 +1,5 @@
package entities;
-import java.util.*;
-
public class Pair {
private T left;
private T right;
diff --git a/src/main/java/entities/Position.java b/src/main/java/entities/Position.java
index 44b1870..b652c67 100644
--- a/src/main/java/entities/Position.java
+++ b/src/main/java/entities/Position.java
@@ -1,27 +1,27 @@
package entities;
public class Position {
- private Onground onground;
- private Clear clear;
private Gameover gameover;
+ private Clear clear;
+ private Onground onground;
private Ground ground;
private Pair value = new Pair<>(0.0,0.0);
public void updateVelocity(Pair velocity) {
- Pair temp_if9;
+ Pair temp_if4;
if (((this.ground.getValue()==true)&&((this.value.getRight()+(0.01*velocity.getRight()))<0.0))) {
- temp_if9 = new Pair<>((this.value.getLeft()+(0.01*velocity.getLeft())),0.0);
+ temp_if4 = new Pair<>((this.value.getLeft()+(0.01*velocity.getLeft())),0.0);
} else {
- temp_if9 = new Pair<>((this.value.getLeft()+(0.01*velocity.getLeft())),(this.value.getRight()+(0.01*velocity.getRight())));
+ temp_if4 = new Pair<>((this.value.getLeft()+(0.01*velocity.getLeft())),(this.value.getRight()+(0.01*velocity.getRight())));
}
- value = temp_if9;
- onground.updatePosition(value);
- clear.updatePosition(value);
+ value = temp_if4;
gameover.updatePosition(value);
+ clear.updatePosition(value);
+ onground.updatePosition(value);
}
- public Position(Onground onground, Clear clear, Gameover gameover, Ground ground) {
- this.onground = onground;
- this.clear = clear;
+ public Position(Gameover gameover, Clear clear, Onground onground, Ground ground) {
this.gameover = gameover;
+ this.clear = clear;
+ this.onground = onground;
this.ground = ground;
}
public Pair getValue() {
diff --git a/src/main/java/entities/Time.java b/src/main/java/entities/Time.java
index fe1d7f2..0fdbfad 100644
--- a/src/main/java/entities/Time.java
+++ b/src/main/java/entities/Time.java
@@ -1,7 +1,5 @@
package entities;
-import java.util.*;
-
public class Time {
private double value = 0.0;
public void gravity(double y) {
diff --git a/src/main/java/entities/Velocity.java b/src/main/java/entities/Velocity.java
index 8ba58e9..d815ce2 100644
--- a/src/main/java/entities/Velocity.java
+++ b/src/main/java/entities/Velocity.java
@@ -1,11 +1,34 @@
package entities;
public class Velocity {
+ private double movey;
+ private double movex;
private Pair acceleration = new Pair<>(0.0,0.0);
- private Pair move = new Pair<>(1.0,0.0);
private Position position;
private Onground onground;
private Pair value = new Pair<>(0.0,0.0);
+ public void updateMovey(double movey) {
+ this.movey = movey;
+ Pair temp_if3;
+ if (this.onground.getValue()) {
+ temp_if3 = new Pair<>(this.value.getLeft(),movey);
+ } else {
+ temp_if3 = this.value;
+ }
+ value = temp_if3;
+ position.updateVelocity(value);
+ }
+ public void updateMovex(double movex) {
+ this.movex = movex;
+ Pair temp_if6;
+ if (this.onground.getValue()) {
+ temp_if6 = new Pair<>(movex,this.value.getRight());
+ } else {
+ temp_if6 = this.value;
+ }
+ value = temp_if6;
+ position.updateVelocity(value);
+ }
public void updateAcceleration(Pair acceleration) {
this.acceleration = acceleration;
Pair temp_if7;
@@ -17,17 +40,6 @@
value = temp_if7;
position.updateVelocity(value);
}
- public void updateMove(Pair move) {
- this.move = move;
- Pair temp_if8;
- if ((this.onground.getValue()&&(move.getRight()>=0.0))) {
- temp_if8 = move;
- } else {
- temp_if8 = this.value;
- }
- value = temp_if8;
- position.updateVelocity(value);
- }
public Velocity(Position position, Onground onground) {
this.position = position;
this.onground = onground;
diff --git a/src/main/java/entities/config/GLConfigVariable.java b/src/main/java/entities/config/GLConfigVariable.java
index 30869d3..dfcebb9 100644
--- a/src/main/java/entities/config/GLConfigVariable.java
+++ b/src/main/java/entities/config/GLConfigVariable.java
@@ -1,18 +1,13 @@
package entities.config;
-//---------------------------------------------------------------
-// 画面設定定数
public class GLConfigVariable {
- //---------------------------------------------------------------
- //---------------------------------------------------------------
+
private GLConfigVariable() {
}
- //---------------------------------------------------------------
- public static final String TITLE_NAME = "JumpGame";
+ public static final String TITLE_NAME = "JumpingGame";
public static final int WIDTH = 1280;
public static final int HEIGHT = 720;
- public static final int DEPTH = 100; // 追加。深度
- public static final double TARGET_FPS = 60d; //フレームレート
+ public static final int DEPTH = 100;
public static final boolean IS_FULL_SCREEN = false;
}
\ No newline at end of file
diff --git a/src/main/java/entities/modelExtentions/Stage.java b/src/main/java/entities/modelExtentions/Stage.java
index 1146f2e..fd92434 100644
--- a/src/main/java/entities/modelExtentions/Stage.java
+++ b/src/main/java/entities/modelExtentions/Stage.java
@@ -13,8 +13,6 @@
private ArrayList values = new ArrayList<>();
private int count = 0;
- //---------------------------------------------------------------
- //---------------------------------------------------------------
public Stage() {
Path file = Paths.get("resources/stage.txt");
String[] data = new String[1];
@@ -31,24 +29,16 @@
}
}
- //---------------------------------------------------------------
- //---------------------------------------------------------------
- // getter
public ArrayList getValues() {
return values;
}
- //---------------------------------------------------------------
- //---------------------------------------------------------------
- // フラグのタイミングと一致しているかをチェック
public boolean isFlag(int timing) {
for (int flag : values)
if (timing == flag) return true;
return false;
}
- //---------------------------------------------------------------
- // 奇数番目のフラグで穴を開けるフラグを提示する
public boolean isOpenFlag(double x) {
if (count % 2 != 0) return false;
@@ -61,8 +51,6 @@
return false;
}
- //---------------------------------------------------------------
- // 偶数番目のフラグで穴を閉じるフラグを提示する
public boolean isCloseFlag(double x) {
if (count % 2 == 0) return false;
@@ -73,5 +61,4 @@
}
return false;
}
-
}
diff --git a/src/main/java/models/JumpGameModel.java b/src/main/java/models/JumpGameModel.java
deleted file mode 100644
index b50a0fe..0000000
--- a/src/main/java/models/JumpGameModel.java
+++ /dev/null
@@ -1,111 +0,0 @@
-package models;
-
-import entities.*;
-import entities.modelExtentions.Stage;
-
-import java.util.*;
-
-public class JumpGameModel implements IModel{
- private Gameover gameover;
- private Time time;
- private Onground onground;
- private Ground ground;
- private Clear clear;
- private Position position;
- private Velocity velocity;
- private Move move;
- private Acceleration acceleration;
- private Mass mass;
- private Force force;
-
- private Stage stage; //added
-
- public JumpGameModel() {
- gameover = new Gameover();
- time = new Time();
- onground = new Onground();
- ground = new Ground(onground);
- clear = new Clear();
- position = new Position(onground,clear,gameover,ground);
- velocity = new Velocity(position,onground);
- move = new Move(velocity);
- acceleration = new Acceleration(velocity,onground);
- mass = new Mass(acceleration);
- force = new Force(acceleration);
- stage = new Stage(); // added
- }
- public void gravity(double y) {
- this.force.gravity(y);
- this.time.gravity(y);
- }
- public void openHole() {
- this.ground.openHole();
- }
- public void closeHole() {
- this.ground.closeHole();
- }
- public void moveY(double y) {
- System.out.println("jumping");
- this.move.moveY(y);
- }
- public void moveX(double x) {
- this.move.moveX(x);
- }
- public void setMass(double x) {
- this.mass.setMass(x);
- }
- public Pair getAcceleration() {
- return acceleration.getValue();
- }
- public Pair getMove() {
- return move.getValue();
- }
- public double getMass() {
- return mass.getValue();
- }
- public boolean getClear() {
- return clear.getValue();
- }
- public boolean getGround() {
- return ground.getValue();
- }
- public Pair getForce() {
- return force.getValue();
- }
- public Pair getVelocity() {
- return velocity.getValue();
- }
- public Pair getPosition() {
- return position.getValue();
- }
- public boolean getOnground() {
- return onground.getValue();
- }
- public double getTime() {
- return time.getValue();
- }
- public boolean getGameover() {
- return gameover.getValue();
- }
- //---------------------------------------------------------------
- //---------------------------------------------------------------
- // added
- public Stage getStage() {
- return stage;
- }
-
- //---------------------------------------------------------------
- // 地面のフラグ更新
- public void updateGroundFlag() {
- double x = position.getValue().getLeft();
-
- if (stage.isOpenFlag(x)) ground.openHole();
- if (stage.isCloseFlag(x)) ground.closeHole();
-
-// System.out.print("x: " + x + "/");
-// System.out.println("entities.Ground: " + ground.getValue() + "/");
-// System.out.print("entities.Clear: " + clear.getClear() + "/");
-// System.out.println("GameOver: " + gameover.getGameover());
-
- }
-}
\ No newline at end of file
diff --git a/src/main/java/models/JumpingGameModel.java b/src/main/java/models/JumpingGameModel.java
new file mode 100644
index 0000000..9e83965
--- /dev/null
+++ b/src/main/java/models/JumpingGameModel.java
@@ -0,0 +1,104 @@
+package models;
+
+import entities.*;
+import entities.modelExtentions.Stage;
+
+public class JumpingGameModel implements IModel{
+ private Gameover gameover;
+ private Time time;
+ private Onground onground;
+ private Ground ground;
+ private Clear clear;
+ private Position position;
+ private Velocity velocity;
+ private Movey movey;
+ private Movex movex;
+ private Acceleration acceleration;
+ private Mass mass;
+ private Force force;
+
+ private Stage stage; //added
+
+ public JumpingGameModel() {
+ gameover = new Gameover();
+ time = new Time();
+ onground = new Onground();
+ ground = new Ground(onground);
+ clear = new Clear();
+ position = new Position(gameover,clear,onground,ground);
+ velocity = new Velocity(position,onground);
+ movey = new Movey(velocity);
+ movex = new Movex(velocity);
+ acceleration = new Acceleration(velocity,onground);
+ mass = new Mass(acceleration);
+ force = new Force(acceleration);
+ stage = new Stage(); // added
+ }
+ public void gravity(double y) {
+ this.force.gravity(y);
+ this.time.gravity(y);
+ }
+ public void closeHole() {
+ this.ground.closeHole();
+ }
+ public void openHole() {
+ this.ground.openHole();
+ }
+ public void jump(double y2) {
+ this.movey.jump(y2);
+ }
+ public void run(double x2) {
+ this.movex.run(x2);
+ }
+ public void setMass(double x) {
+ this.mass.setMass(x);
+ }
+ public Pair getAcceleration() {
+ return acceleration.getValue();
+ }
+ public double getMovex() {
+ return movex.getValue();
+ }
+ public double getMass() {
+ return mass.getValue();
+ }
+ public boolean getClear() {
+ return clear.getValue();
+ }
+ public boolean getGround() {
+ return ground.getValue();
+ }
+ public Pair getForce() {
+ return force.getValue();
+ }
+ public Pair getVelocity() {
+ return velocity.getValue();
+ }
+ public Pair getPosition() {
+ return position.getValue();
+ }
+ public boolean getOnground() {
+ return onground.getValue();
+ }
+ public double getTime() {
+ return time.getValue();
+ }
+ public double getMovey() {
+ return movey.getValue();
+ }
+ public boolean getGameover() {
+ return gameover.getValue();
+ }
+
+ // added
+ public Stage getStage() {
+ return stage;
+ }
+ // added
+ public void updateGroundFlag() {
+ double x = position.getValue().getLeft();
+
+ if (stage.isOpenFlag(x)) ground.openHole();
+ if (stage.isCloseFlag(x)) ground.closeHole();
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/views/Color.java b/src/main/java/views/Color.java
index 03c2fb1..140b0a1 100644
--- a/src/main/java/views/Color.java
+++ b/src/main/java/views/Color.java
@@ -6,8 +6,6 @@
private float b;
private float a;
- //---------------------------------------------------------------
- //---------------------------------------------------------------
public Color(float r, float g, float b, float a) {
this.r = r;
this.g = g;
@@ -15,8 +13,6 @@
this.a = a;
}
- //---------------------------------------------------------------
- //---------------------------------------------------------------
public float getR() {
return r;
}
diff --git a/src/main/java/views/IView.java b/src/main/java/views/IView.java
index 449d420..663b660 100644
--- a/src/main/java/views/IView.java
+++ b/src/main/java/views/IView.java
@@ -2,19 +2,12 @@
import models.IModel;
-//---------------------------------------------------------------
-//
+
public interface IView {
- //---------------------------------------------------------------
- // モデルの監視
void update(IModel model);
- //---------------------------------------------------------------
- // 描画
void display();
- //---------------------------------------------------------------
- // テクスチャの開放
void delete();
}
diff --git a/src/main/java/views/Image2D.java b/src/main/java/views/Image2D.java
index f8e6aeb..43918d3 100644
--- a/src/main/java/views/Image2D.java
+++ b/src/main/java/views/Image2D.java
@@ -5,21 +5,16 @@
import static org.lwjgl.opengl.GL11.*;
-//---------------------------------------------------------------
-//
public class Image2D {
- private int id; // テクスチャのID
- private Pair spriteSize; // スプライトの幅高
- private Pair position; // スプライトの座標(画面座標)
- private Color color; // スプライトの色
- private double rotation; // 回転(度)
- private double scale; // 拡大
- private double alpha; // 透明度
+ private int id;
+ private Pair spriteSize;
+ private Pair position;
+ private Color color;
+ private double rotation;
+ private double scale;
+ private double alpha;
- //---------------------------------------------------------------
- //---------------------------------------------------------------
- //
public Image2D(Texture tex) {
if (tex != null)
this.id = tex.getId();
@@ -38,13 +33,6 @@
alpha = 1.0;
}
- //---------------------------------------------------------------
- //---------------------------------------------------------------
- // setter
- public void setRotation(double rotation) {
- this.rotation = rotation;
- }
-
public void setPosition(Pair position) {
this.position = position;
}
@@ -53,37 +41,21 @@
this.scale = scale;
}
- //---------------------------------------------------------------
- //---------------------------------------------------------------
- //
public void draw() {
- // テクスチャの結合
glBindTexture(GL_TEXTURE_2D, id);
-
- // 変換行列の追加
glPushMatrix();
-
- // モデルビューモード
glMatrixMode(GL_MODELVIEW);
- // 行列の設定
glLoadIdentity(); // 単位行列化
glTranslated(position.getLeft(), position.getRight(), 0); // 移動
glRotated(rotation, 0, 0, 1); // 回転
glScaled(scale, scale, 1); // 拡縮
-
- // プロジェクションモード
glMatrixMode(GL_PROJECTION);
- // 行列の設定
- glLoadIdentity(); // 単位行列化
+ glLoadIdentity();
glOrtho(0, GLConfigVariable.WIDTH, 0, GLConfigVariable.HEIGHT, -GLConfigVariable.DEPTH, GLConfigVariable.DEPTH); // 正射影投影
- // ビューポートの範囲
glViewport(0, 0, GLConfigVariable.WIDTH, GLConfigVariable.HEIGHT);
- // ポリゴンの色
glColor4d(color.getR(), color.getG(), color.getB(), alpha);
-
- // ポリゴンの作成とテクスチャの適応
glBegin(GL_TRIANGLE_STRIP);
glTexCoord2d(0, 0);
glVertex2d(-spriteSize.getLeft() / 2, spriteSize.getRight() / 2);
@@ -95,10 +67,7 @@
glVertex2d(spriteSize.getLeft() / 2, -spriteSize.getRight() / 2);
glEnd();
- // 行列の破棄
glPopMatrix();
-
- // テクスチャの解除
glBindTexture(GL_TEXTURE_2D, 0);
}
diff --git a/src/main/java/views/PlayerRenderer.java b/src/main/java/views/PlayerRenderer.java
index 5baea09..b26e7ae 100644
--- a/src/main/java/views/PlayerRenderer.java
+++ b/src/main/java/views/PlayerRenderer.java
@@ -2,48 +2,35 @@
import entities.Pair;
import models.IModel;
-import models.JumpGameModel;
+import models.JumpingGameModel;
-//---------------------------------------------------------------
-//
+
public class PlayerRenderer implements IView {
private Sprite sprite;
- //---------------------------------------------------------------
- //---------------------------------------------------------------
- //
public PlayerRenderer(String path) {
this.sprite = new Sprite(path);
this.sprite.setScaleValue(0.1);
this.sprite.setPositionValue(new Pair<>(640d, 480d));
}
- //---------------------------------------------------------------
- //---------------------------------------------------------------
- //
@Override
public void update(IModel model) {
- JumpGameModel jumpGameModel = (JumpGameModel) model;
+ JumpingGameModel jumpGameModel = (JumpingGameModel) model;
double x = this.sprite.getPositionValue().getLeft();
double y = 112 + jumpGameModel.getPosition().getRight();
this.sprite.setPositionValue(new Pair<>(x, y));
}
-
- //---------------------------------------------------------------
- // 描画する
@Override
public void display() {
sprite.draw();
}
- //---------------------------------------------------------------
- // テクスチャの開放
@Override
public void delete() {
sprite.delete();
}
- //---------------------------------------------------------------
}
diff --git a/src/main/java/views/Sprite.java b/src/main/java/views/Sprite.java
index 502eca4..f0cd2d2 100644
--- a/src/main/java/views/Sprite.java
+++ b/src/main/java/views/Sprite.java
@@ -2,8 +2,6 @@
import entities.Pair;
-//---------------------------------------------------------------
-//
public class Sprite {
private Texture texture;
@@ -11,18 +9,12 @@
private Pair positionValue;
private double scaleValue;
- //---------------------------------------------------------------
- //---------------------------------------------------------------
- //
public Sprite(String path) {
this.positionValue = new Pair<>(0d, 0d);
texture = new Texture("player", path);
img = new Image2D(texture);
}
- //---------------------------------------------------------------
- //---------------------------------------------------------------
- // getter
public double getScaleValue() {
return this.scaleValue;
}
@@ -31,8 +23,6 @@
return this.positionValue;
}
- //---------------------------------------------------------------
- // setter
public void setPositionValue(Pair positionValue) {
this.positionValue = positionValue;
}
@@ -41,21 +31,13 @@
this.scaleValue = scaleValue;
}
- //---------------------------------------------------------------
- //---------------------------------------------------------------
- //
public void draw() {
img.setScale(scaleValue);
img.setPosition(positionValue);
img.draw();
}
- //---------------------------------------------------------------
- // テクスチャの開放
public void delete() {
texture.delete();
}
-
- //---------------------------------------------------------------
-
}
diff --git a/src/main/java/views/Texture.java b/src/main/java/views/Texture.java
index 129a8e6..bc950a7 100644
--- a/src/main/java/views/Texture.java
+++ b/src/main/java/views/Texture.java
@@ -1,17 +1,16 @@
package views;
-import static org.lwjgl.opengl.GL11.*;
+import org.lwjgl.BufferUtils;
+import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
-import javax.imageio.ImageIO;
-import org.lwjgl.BufferUtils;
+import static org.lwjgl.opengl.GL11.*;
-//---------------------------------------------------------------
-//
+
public class Texture {
private int id;
@@ -19,23 +18,18 @@
private int height;
private String name;
- //---------------------------------------------------------------
- //---------------------------------------------------------------
public Texture(String name, String path) {
this.name = name;
BufferedImage bi;
try {
- // イメージファイルの読み込み
bi = ImageIO.read(new File(path));
width = bi.getWidth();
height = bi.getHeight();
- // ピクセルを保存する配列の用意
int[] pixelsRaw;
pixelsRaw = bi.getRGB(0, 0, width, height, null, 0, width);
ByteBuffer pixels = BufferUtils.createByteBuffer(width * height * 4);
- // 一ピクセルずつ読み込む
for (int i = 0; i < height; ++i) {
for (int j = 0; j < width; ++j) {
int p = pixelsRaw[i * width + j];
@@ -47,16 +41,13 @@
}
pixels.flip();
- // テクスチャの作成
- id = glGenTextures(); // IDの取得
- glBindTexture(GL_TEXTURE_2D, id); // IDとテクスチャデータを結合
+ id = glGenTextures();
+ glBindTexture(GL_TEXTURE_2D, id);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); // 作成
- // テクスチャの設定
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- // テクスチャの解除
glBindTexture(GL_TEXTURE_2D, 0);
} catch (IOException e) {
@@ -64,44 +55,31 @@
}
}
- //---------------------------------------------------------------
- //---------------------------------------------------------------
public int getHeight() {
return height;
}
- //---------------------------------------------------------------
public int getWidth() {
return width;
}
- //---------------------------------------------------------------
public int getId() {
return id;
}
- //---------------------------------------------------------------
public String getName() {
return name;
}
- //---------------------------------------------------------------
- //---------------------------------------------------------------
- // テクスチャの使用
public void bind() {
glBindTexture(GL_TEXTURE_2D, id);
}
- //---------------------------------------------------------------
- // テクスチャの解除
public void debind() {
glBindTexture(GL_TEXTURE_2D, 0);
}
- //---------------------------------------------------------------
- // テクスチャの破棄
public void delete() {
glDeleteTextures(id);
}
- //---------------------------------------------------------------
}
\ No newline at end of file
diff --git a/src/main/java/views/TileMapRenderer.java b/src/main/java/views/TileMapRenderer.java
index 8d59322..2bd1016 100644
--- a/src/main/java/views/TileMapRenderer.java
+++ b/src/main/java/views/TileMapRenderer.java
@@ -3,56 +3,41 @@
import entities.Pair;
import entities.modelExtentions.Stage;
import models.IModel;
-import models.JumpGameModel;
+import models.JumpingGameModel;
import java.util.ArrayList;
-//---------------------------------------------------------------
-// タイル生成
public class TileMapRenderer implements IView {
private double offsetY = 32d;
private TileRenderer newTile = new TileRenderer("resources/tile.png", null, 2);
private ArrayList tiles = new ArrayList<>();
- //---------------------------------------------------------------
- //---------------------------------------------------------------
public TileMapRenderer(IModel model) {
- JumpGameModel jumpGameModel = (JumpGameModel) model;
+ JumpingGameModel jumpGameModel = (JumpingGameModel) model;
initTiles(jumpGameModel.getStage());
}
- //---------------------------------------------------------------
- //---------------------------------------------------------------
- //
@Override
public void update(IModel model) {
for (TileRenderer tile : tiles) tile.update(model);
}
- //---------------------------------------------------------------
- //
@Override
public void display() {
for (TileRenderer tile : tiles) tile.display();
}
- //---------------------------------------------------------------
- // 破棄
@Override
public void delete() {
for (TileRenderer tile : tiles) tile.delete();
}
- //--------------------------------------------------------------
- //---------------------------------------------------------------
- // 初期タイル作成
private void initTiles(Stage stage) {
boolean isOpen = false;
int space = 10;
- // タイルマージン
for (int i = 0; i < space; i++) {
double x = 32 * newTile.getScaleValue() * i;
if (i == 12) addNewTile(x, TileType.OPEN);
@@ -62,21 +47,17 @@
for (int i = 0; i < 120; i++) {
double x = 32 * newTile.getScaleValue() * (i + space);
- // フラグのチェック
if (stage.isFlag(i)){
isOpen = !isOpen;
System.out.println(isOpen);
}
- // タイルの切り替え
if (isOpen) addNewTile(x, TileType.OPEN);
else addNewTile(x, TileType.CLOSE);
}
}
- //--------------------------------------------------------------
- // タイルをフラグに応じて生成する
private void addNewTile(double x, TileType tileType) {
switch (tileType) {
@@ -90,6 +71,4 @@
tiles.add(newTile);
System.out.println("New tile created.");
}
-
- //---------------------------------------------------------------
}
\ No newline at end of file
diff --git a/src/main/java/views/TileRenderer.java b/src/main/java/views/TileRenderer.java
index 55bb5ad..168a16b 100644
--- a/src/main/java/views/TileRenderer.java
+++ b/src/main/java/views/TileRenderer.java
@@ -2,25 +2,12 @@
import entities.Pair;
import models.IModel;
-import models.JumpGameModel;
+import models.JumpingGameModel;
-//---------------------------------------------------------------
-// タイルの描画
public class TileRenderer implements IView {
private Sprite sprite;
private Pair initPositionValue;
- //---------------------------------------------------------------
- //---------------------------------------------------------------
- //
- public TileRenderer(String path, Pair initPosition) {
- this.initPositionValue = initPosition;
- this.sprite = new Sprite(path);
- this.sprite.setScaleValue(1);
- this.sprite.setPositionValue(initPosition);
- }
-
- //---------------------------------------------------------------
public TileRenderer(String path, Pair initPosition, double scale) {
this.initPositionValue = initPosition;
this.sprite = new Sprite(path);
@@ -28,42 +15,25 @@
this.sprite.setPositionValue(initPosition);
}
- //---------------------------------------------------------------
- //---------------------------------------------------------------
- // getter
public double getScaleValue() {
return this.sprite.getScaleValue();
}
- //---------------------------------------------------------------
- //---------------------------------------------------------------
- // setter
- public void setScaleValue(double scaleValue) {
- this.sprite.setScaleValue(scaleValue);
- }
-
- //---------------------------------------------------------------
- //---------------------------------------------------------------
- //
@Override
public void update(IModel model) {
- JumpGameModel jumpGameModel = (JumpGameModel) model;
+ JumpingGameModel jumpingGameModel = (JumpingGameModel) model;
- Double x = this.initPositionValue.getLeft() - (jumpGameModel.getPosition().getLeft() * 64);
+ Double x = this.initPositionValue.getLeft() - (jumpingGameModel.getPosition().getLeft() * 64);
Double y = this.sprite.getPositionValue().getRight();
this.sprite.setPositionValue(new Pair<>(x, y));
}
- //---------------------------------------------------------------
- // 描画
@Override
public void display() {
sprite.draw();
}
- //---------------------------------------------------------------
- // テクスチャの開放
@Override
public void delete() {
sprite.delete();
diff --git a/src/main/java/views/TileType.java b/src/main/java/views/TileType.java
index 649cdaf..67b7f51 100644
--- a/src/main/java/views/TileType.java
+++ b/src/main/java/views/TileType.java
@@ -1,11 +1,6 @@
package views;
-//---------------------------------------------------------------
-// タイルの種類の定数クラス
public enum TileType {
-
CLOSE,
OPEN;
-
- //---------------------------------------------------------------
}
diff --git a/target/classes/JumpGame$1.class b/target/classes/JumpGame$1.class
index 5a87004..0b1af60 100644
--- a/target/classes/JumpGame$1.class
+++ b/target/classes/JumpGame$1.class
Binary files differ
diff --git a/target/classes/JumpGame.class b/target/classes/JumpGame.class
index 579e841..898af84 100644
--- a/target/classes/JumpGame.class
+++ b/target/classes/JumpGame.class
Binary files differ
diff --git a/target/classes/entities/Acceleration.class b/target/classes/entities/Acceleration.class
index 82f9c2d..36ce8ec 100644
--- a/target/classes/entities/Acceleration.class
+++ b/target/classes/entities/Acceleration.class
Binary files differ
diff --git a/target/classes/entities/Clear.class b/target/classes/entities/Clear.class
index 49f31e5..c814f34 100644
--- a/target/classes/entities/Clear.class
+++ b/target/classes/entities/Clear.class
Binary files differ
diff --git a/target/classes/entities/Force.class b/target/classes/entities/Force.class
index bd8960f..0844a3b 100644
--- a/target/classes/entities/Force.class
+++ b/target/classes/entities/Force.class
Binary files differ
diff --git a/target/classes/entities/Gameover.class b/target/classes/entities/Gameover.class
index aa05ce4..6df0b93 100644
--- a/target/classes/entities/Gameover.class
+++ b/target/classes/entities/Gameover.class
Binary files differ
diff --git a/target/classes/entities/Ground.class b/target/classes/entities/Ground.class
index e840860..7ee6b5f 100644
--- a/target/classes/entities/Ground.class
+++ b/target/classes/entities/Ground.class
Binary files differ
diff --git a/target/classes/entities/Mass.class b/target/classes/entities/Mass.class
index feab936..21cbdc1 100644
--- a/target/classes/entities/Mass.class
+++ b/target/classes/entities/Mass.class
Binary files differ
diff --git a/target/classes/entities/Move.class b/target/classes/entities/Move.class
deleted file mode 100644
index 4c83aec..0000000
--- a/target/classes/entities/Move.class
+++ /dev/null
Binary files differ
diff --git a/target/classes/entities/Onground.class b/target/classes/entities/Onground.class
index e9e89c8..8c41ae3 100644
--- a/target/classes/entities/Onground.class
+++ b/target/classes/entities/Onground.class
Binary files differ
diff --git a/target/classes/entities/Position.class b/target/classes/entities/Position.class
index f3bbf44..d796391 100644
--- a/target/classes/entities/Position.class
+++ b/target/classes/entities/Position.class
Binary files differ
diff --git a/target/classes/entities/Velocity.class b/target/classes/entities/Velocity.class
index 56be197..1d85dee 100644
--- a/target/classes/entities/Velocity.class
+++ b/target/classes/entities/Velocity.class
Binary files differ
diff --git a/target/classes/models/JumpGameModel.class b/target/classes/models/JumpGameModel.class
deleted file mode 100644
index fb8dd06..0000000
--- a/target/classes/models/JumpGameModel.class
+++ /dev/null
Binary files differ
diff --git a/target/classes/views/PlayerRenderer.class b/target/classes/views/PlayerRenderer.class
index 88d5982..f172f87 100644
--- a/target/classes/views/PlayerRenderer.class
+++ b/target/classes/views/PlayerRenderer.class
Binary files differ
diff --git a/target/classes/views/TileMapRenderer.class b/target/classes/views/TileMapRenderer.class
index 001199a..77e918c 100644
--- a/target/classes/views/TileMapRenderer.class
+++ b/target/classes/views/TileMapRenderer.class
Binary files differ
diff --git a/target/classes/views/TileRenderer.class b/target/classes/views/TileRenderer.class
index 1135757..579349e 100644
--- a/target/classes/views/TileRenderer.class
+++ b/target/classes/views/TileRenderer.class
Binary files differ