diff --git a/jumpGame.iml b/jumpGame.iml
index 6ba17f4..273d838 100644
--- a/jumpGame.iml
+++ b/jumpGame.iml
@@ -25,5 +25,6 @@
+
\ No newline at end of file
diff --git a/src/main/java/JumpGame.java b/src/main/java/JumpGame.java
index bfbf201..4a7b5ca 100644
--- a/src/main/java/JumpGame.java
+++ b/src/main/java/JumpGame.java
@@ -1,16 +1,12 @@
import models.IModel;
import models.JumpGameModel;
-import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWKeyCallback;
import views.BackgroundRenderer;
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;
@@ -26,7 +22,7 @@
//
public void gravity(double y) {
JumpGameModel jumpGameModel = (JumpGameModel) model;
- jumpGameModel.updateGravity(y); //重力の更新
+ jumpGameModel.gravity(y); //重力の更新
jumpGameModel.updateGroundFlag();//地面の判定切り替え
}
diff --git a/src/main/java/entities/Acceleration.java b/src/main/java/entities/Acceleration.java
index 0d80c79..930cd85 100644
--- a/src/main/java/entities/Acceleration.java
+++ b/src/main/java/entities/Acceleration.java
@@ -1,5 +1,7 @@
package entities;
+import java.util.*;
+
public class Acceleration {
private double massValue = 1.0;
private Pair forceValue = new Pair<>(0d, 0d);
@@ -13,8 +15,11 @@
this.massValue = mass;
Pair temp_l0;
- if (this.onground.getOnground()) temp_l0 = new Pair((forceValue.getFirst() / mass), 0.0);
- else temp_l0 = new Pair((forceValue.getFirst() / mass), (forceValue.getSecond() / mass));
+ if (this.onground.getOnground()) {
+ temp_l0 = new Pair((forceValue.getFirst() / mass), 0.0);
+ } else {
+ temp_l0 = new Pair((forceValue.getFirst() / mass), (forceValue.getSecond() / mass));
+ }
this.value = temp_l0;
velocity.updateByAcceleration(value);
@@ -26,9 +31,11 @@
this.forceValue = force;
Pair temp_l1;
- if (this.onground.getOnground()) temp_l1 = new Pair((force.getFirst() / massValue), 0.0);
- temp_l1 = new Pair((force.getFirst() / massValue), (force.getSecond() / massValue));
-
+ if (this.onground.getOnground()) {
+ temp_l1 = new Pair((force.getFirst() / massValue), 0.0);
+ } else {
+ temp_l1 = new Pair((force.getFirst() / massValue), (force.getSecond() / massValue));
+ }
value = temp_l1;
velocity.updateByAcceleration(value);
}
diff --git a/src/main/java/entities/Clear.java b/src/main/java/entities/Clear.java
index 3f33d64..abdcc20 100644
--- a/src/main/java/entities/Clear.java
+++ b/src/main/java/entities/Clear.java
@@ -1,5 +1,7 @@
package entities;
+import java.util.*;
+
public class Clear {
private Position position;
diff --git a/src/main/java/entities/Force.java b/src/main/java/entities/Force.java
index 5a544e0..c5cb410 100644
--- a/src/main/java/entities/Force.java
+++ b/src/main/java/entities/Force.java
@@ -1,5 +1,7 @@
package entities;
+import java.util.*;
+
public class Force {
private Acceleration acceleration;
private Pair value = new Pair<>(-1.0d, 0.0d);
diff --git a/src/main/java/entities/Gameover.java b/src/main/java/entities/Gameover.java
index 751be25..c84d3a0 100644
--- a/src/main/java/entities/Gameover.java
+++ b/src/main/java/entities/Gameover.java
@@ -1,5 +1,7 @@
package entities;
+import java.util.*;
+
public class Gameover {
private Position position;
diff --git a/src/main/java/entities/Ground.java b/src/main/java/entities/Ground.java
index 3fc328f..7f755ba 100644
--- a/src/main/java/entities/Ground.java
+++ b/src/main/java/entities/Ground.java
@@ -1,5 +1,7 @@
package entities;
+import java.util.*;
+
public class Ground {
private boolean value = true;
diff --git a/src/main/java/entities/Mass.java b/src/main/java/entities/Mass.java
index f7d4012..73cddd7 100644
--- a/src/main/java/entities/Mass.java
+++ b/src/main/java/entities/Mass.java
@@ -1,5 +1,7 @@
package entities;
+import java.util.*;
+
public class Mass {
private Acceleration acceleration;
private double value;
diff --git a/src/main/java/entities/Move.java b/src/main/java/entities/Move.java
index a966f75..7de2f12 100644
--- a/src/main/java/entities/Move.java
+++ b/src/main/java/entities/Move.java
@@ -1,5 +1,7 @@
package entities;
+import java.util.*;
+
public class Move {
private Velocity velocity;
private Pair value = new Pair<>(1d, 256d);
diff --git a/src/main/java/entities/Onground.java b/src/main/java/entities/Onground.java
index 6b58b90..117f49d 100644
--- a/src/main/java/entities/Onground.java
+++ b/src/main/java/entities/Onground.java
@@ -1,5 +1,7 @@
package entities;
+import java.util.*;
+
public class Onground {
private Ground ground;
private Position position;
@@ -10,5 +12,6 @@
}
public boolean getOnground() {
- return ((this.ground.getValue() == true) && (this.position.getValue().getSecond() <= 0.0)); }
+ return ((this.ground.getValue() == true) && (this.position.getValue().getSecond() <= 0.0));
+ }
}
\ No newline at end of file
diff --git a/src/main/java/entities/Pair.java b/src/main/java/entities/Pair.java
index 4f17624..6a62008 100644
--- a/src/main/java/entities/Pair.java
+++ b/src/main/java/entities/Pair.java
@@ -1,5 +1,7 @@
package entities;
+import java.util.*;
+
public class Pair {
private T first;
private T second;
diff --git a/src/main/java/entities/Position.java b/src/main/java/entities/Position.java
index 20fa323..a84e966 100644
--- a/src/main/java/entities/Position.java
+++ b/src/main/java/entities/Position.java
@@ -1,7 +1,6 @@
package entities;
-import entities.Ground;
-import entities.Pair;
+import java.util.*;
//---------------------------------------------------------------
//
@@ -30,13 +29,6 @@
}
//---------------------------------------------------------------
- //
- public Position(Pair value, Ground ground) {
- this.value = value;
- this.ground = ground;
- }
-
- //---------------------------------------------------------------
//---------------------------------------------------------------
// getter
public Pair getValue() {
diff --git a/src/main/java/entities/Time.java b/src/main/java/entities/Time.java
index 0b96add..16381eb 100644
--- a/src/main/java/entities/Time.java
+++ b/src/main/java/entities/Time.java
@@ -1,5 +1,7 @@
package entities;
+import java.util.*;
+
public class Time {
private double value;
diff --git a/src/main/java/entities/Velocity.java b/src/main/java/entities/Velocity.java
index 4e7c568..c1c1c0a 100644
--- a/src/main/java/entities/Velocity.java
+++ b/src/main/java/entities/Velocity.java
@@ -1,5 +1,6 @@
package entities;
+import java.util.*;
public class Velocity {
private Pair moveValue = new Pair<>(0d, 0d);
@@ -44,13 +45,6 @@
}
//---------------------------------------------------------------
- public Velocity(Pair value,Position position, Onground onground) {
- this.value = value;
- this.position = position;
- this.onground = onground;
- }
-
- //---------------------------------------------------------------
//---------------------------------------------------------------
public Pair getValue() {
return value;
diff --git a/src/main/java/entities/modelExtentions/Flags.java b/src/main/java/entities/modelExtentions/Flags.java
deleted file mode 100644
index 95f5d80..0000000
--- a/src/main/java/entities/modelExtentions/Flags.java
+++ /dev/null
@@ -1,77 +0,0 @@
-package entities.modelExtentions;
-
-import java.io.IOException;
-import java.nio.charset.Charset;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.ArrayList;
-import java.util.List;
-
-public class Flags {
-
- private ArrayList values = new ArrayList<>();
- private int count = 0;
-
- //---------------------------------------------------------------
- //---------------------------------------------------------------
- public Flags() {
- Path file = Paths.get("resources/stage.txt");
- String[] data = new String[1];
-
- try {
- List lines = Files.readAllLines(file, Charset.forName("Shift-JIS"));
-
- for (int i = 0; i < lines.size(); i++) data = lines.get(i).split(",");
- for (int i = 0; i < data.length; i++) values.add(Integer.parseInt(data[i]));
- for (int v : values) System.out.println(v);
-
- } catch (IOException e) {
- System.out.println("Failed to load stage.txt");
- }
- }
-
- //---------------------------------------------------------------
- //---------------------------------------------------------------
- // 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;
-
- double cx = (double) values.get(count) - 0.5;
- if (cx <= x) {
- if (count < values.size() - 1) count++;
- return true;
- }
- return false;
- }
-
- //---------------------------------------------------------------
- // 偶数番目のフラグで穴を閉じるフラグを提示する
- public boolean isCloseFlag(double x) {
- if (count % 2 == 0) return false;
-
- double cx = (double) values.get(count) - 0.5;
- if (cx <= x + 0.25) {
- if (count < values.size() - 1) count++;
- return true;
- }
- return false;
- }
-
-}
diff --git a/src/main/java/entities/modelExtentions/Stage.java b/src/main/java/entities/modelExtentions/Stage.java
new file mode 100644
index 0000000..1146f2e
--- /dev/null
+++ b/src/main/java/entities/modelExtentions/Stage.java
@@ -0,0 +1,77 @@
+package entities.modelExtentions;
+
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
+
+public class Stage {
+
+ private ArrayList values = new ArrayList<>();
+ private int count = 0;
+
+ //---------------------------------------------------------------
+ //---------------------------------------------------------------
+ public Stage() {
+ Path file = Paths.get("resources/stage.txt");
+ String[] data = new String[1];
+
+ try {
+ List lines = Files.readAllLines(file, Charset.forName("Shift-JIS"));
+
+ for (int i = 0; i < lines.size(); i++) data = lines.get(i).split(",");
+ for (int i = 0; i < data.length; i++) values.add(Integer.parseInt(data[i]));
+ for (int v : values) System.out.println(v);
+
+ } catch (IOException e) {
+ System.out.println("Failed to load stage.txt");
+ }
+ }
+
+ //---------------------------------------------------------------
+ //---------------------------------------------------------------
+ // 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;
+
+ double cx = (double) values.get(count) - 0.5;
+ if (cx <= x) {
+ if (count < values.size() - 1) count++;
+ return true;
+ }
+ return false;
+ }
+
+ //---------------------------------------------------------------
+ // 偶数番目のフラグで穴を閉じるフラグを提示する
+ public boolean isCloseFlag(double x) {
+ if (count % 2 == 0) return false;
+
+ double cx = (double) values.get(count) - 0.5;
+ if (cx <= x + 0.25) {
+ if (count < values.size() - 1) count++;
+ return true;
+ }
+ return false;
+ }
+
+}
diff --git a/src/main/java/models/JumpGameModel.java b/src/main/java/models/JumpGameModel.java
index 6f35976..97880b9 100644
--- a/src/main/java/models/JumpGameModel.java
+++ b/src/main/java/models/JumpGameModel.java
@@ -1,16 +1,9 @@
package models;
-import entities.*;
-import entities.modelExtentions.Flags;
+import java.util.*;
-import javax.swing.plaf.synth.SynthTextAreaUI;
-import java.io.IOException;
-import java.nio.charset.Charset;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.ArrayList;
-import java.util.List;
+import entities.*;
+import entities.modelExtentions.Stage;
//---------------------------------------------------------------
//
@@ -23,20 +16,15 @@
private Position position;
private Velocity velocity;
private Onground onground;
-
- //---------------------------------------------------------------
private Time time;
private Gameover gameover;
private Clear clear;
-
- //---------------------------------------------------------------
private Ground ground;
//---------------------------------------------------------------
+ private Stage stage;
private double jumpPower = 256;
- //---------------------------------------------------------------
- private Flags flags;
//---------------------------------------------------------------
//---------------------------------------------------------------
@@ -45,7 +33,7 @@
ground = new Ground();
position = new Position(ground);
onground = new Onground(ground, position);
- velocity = new Velocity(new Pair<>(1d, 0d), position, onground);
+ velocity = new Velocity(position, onground);
acceleration = new Acceleration(velocity, onground);
force = new Force(acceleration);
mass = new Mass(acceleration);
@@ -53,26 +41,70 @@
time = new Time();
gameover = new Gameover(position);
clear = new Clear(position);
- flags = new Flags();
+ stage = new Stage();
}
//---------------------------------------------------------------
//---------------------------------------------------------------
// getter
- public Flags getFlags() {
- return flags;
+ public Stage getStage() {
+ return stage;
}
- public Position getPosition() {
- return position;
+ public Pair getPosition() {
+ return position.getValue();
}
- public Velocity getVelocity() {
- return velocity;
+ public void moveX(double x) {
+ this.move.moveX(x);
}
- public Ground getGround() {
- return ground;
+ public void moveY(double y) {
+ this.move.moveY(y);
+ }
+
+ public void setMass(double x) {
+ this.mass.setValue(x);
+ }
+
+ public Pair getAcceleration() {
+ return acceleration.getValue();
+ }
+
+ public Pair getMove() {
+ return move.getValue();
+ }
+
+ public double getMass() {
+ return mass.getValue();
+ }
+
+ public boolean getClear() {
+ return clear.getClear();
+ }
+
+ public boolean getGround() {
+ return ground.getValue();
+ }
+
+ public Pair getForce() {
+ return force.getValue();
+ }
+
+ public Pair getVelocity() {
+ return velocity.getValue();
+ }
+
+ public boolean getOnground() {
+ return onground.getOnground();
+ }
+
+ public double getTime() {
+ return time.getValue();
+ }
+
+ public boolean getGameover() {
+ return gameover.getGameover();
}
//---------------------------------------------------------------
@@ -84,9 +116,9 @@
//---------------------------------------------------------------
// マイフレーム更新処理
- public void updateGravity(double gravity) {
- this.time.gravity(gravity);
- this.force.gravity(gravity);
+ public void gravity(double y) {
+ this.time.gravity(y);
+ this.force.gravity(y);
// System.out.println("swapWindow Gravity");
}
@@ -95,25 +127,14 @@
public void updateGroundFlag() {
double x = position.getValue().getFirst();
- if (flags.isOpenFlag(x)) ground.openHole();
- if (flags.isCloseFlag(x)) ground.closeHole();
+ if (stage.isOpenFlag(x)) ground.openHole();
+ if (stage.isCloseFlag(x)) ground.closeHole();
- System.out.print("x: " + x + "/");
- System.out.println("Ground: " + ground.getValue() + "/");
+// System.out.print("x: " + x + "/");
+// System.out.println("Ground: " + ground.getValue() + "/");
// System.out.print("Clear: " + clear.getClear() + "/");
// System.out.println("GameOver: " + gameover.getGameover());
}
-
- //---------------------------------------------------------------
- //
-
- //---------------------------------------------------------------
- //
- private void init() {
-
- }
-
-
//---------------------------------------------------------------
}
diff --git a/src/main/java/views/PlayerRenderer.java b/src/main/java/views/PlayerRenderer.java
index f0a9772..01d154d 100644
--- a/src/main/java/views/PlayerRenderer.java
+++ b/src/main/java/views/PlayerRenderer.java
@@ -27,7 +27,7 @@
JumpGameModel jumpGameModel = (JumpGameModel) model;
double x = this.sprite.getPositionValue().getFirst();
- double y = 112 + jumpGameModel.getPosition().getValue().getSecond();
+ double y = 112 + jumpGameModel.getPosition().getSecond();
this.sprite.setPositionValue(new Pair<>(x, y));
}
diff --git a/src/main/java/views/TileMapRenderer.java b/src/main/java/views/TileMapRenderer.java
index cff741f..b7d4c64 100644
--- a/src/main/java/views/TileMapRenderer.java
+++ b/src/main/java/views/TileMapRenderer.java
@@ -1,7 +1,7 @@
package views;
import entities.Pair;
-import entities.modelExtentions.Flags;
+import entities.modelExtentions.Stage;
import models.IModel;
import models.JumpGameModel;
@@ -19,7 +19,7 @@
//---------------------------------------------------------------
public TileMapRenderer(IModel model) {
JumpGameModel jumpGameModel = (JumpGameModel) model;
- initTiles(jumpGameModel.getFlags());
+ initTiles(jumpGameModel.getStage());
}
//---------------------------------------------------------------
@@ -48,7 +48,7 @@
//--------------------------------------------------------------
//---------------------------------------------------------------
// 初期タイル作成
- private void initTiles(Flags flags) {
+ private void initTiles(Stage stage) {
boolean isOpen = false;
int space = 10;
@@ -63,7 +63,7 @@
double x = 32 * newTile.getScaleValue() * (i + space);
// フラグのチェック
- if (flags.isFlag(i)) isOpen = !isOpen;
+ if (stage.isFlag(i)) isOpen = !isOpen;
// タイルの切り替え
if (isOpen) addNewTile(x, TileType.OPEN);
diff --git a/src/main/java/views/TileRenderer.java b/src/main/java/views/TileRenderer.java
index 52b9a2d..e8f9f37 100644
--- a/src/main/java/views/TileRenderer.java
+++ b/src/main/java/views/TileRenderer.java
@@ -51,7 +51,7 @@
public void update(IModel model) {
JumpGameModel jumpGameModel = (JumpGameModel) model;
- Double x = this.initPositionValue.getFirst() - (jumpGameModel.getPosition().getValue().getFirst() * 64);
+ Double x = this.initPositionValue.getFirst() - (jumpGameModel.getPosition().getFirst() * 64);
Double y = this.sprite.getPositionValue().getSecond();
this.sprite.setPositionValue(new Pair<>(x, y));