diff --git a/.idea/misc.xml b/.idea/misc.xml index 71bba8c..e104ddd 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -8,7 +8,7 @@ - + \ No newline at end of file diff --git a/resources/stage.txt b/resources/stage.txt new file mode 100644 index 0000000..eaed1d1 --- /dev/null +++ b/resources/stage.txt @@ -0,0 +1 @@ +1,2,1,1,1,1,1,1,2,1 \ No newline at end of file diff --git a/src/main/java/GameEngine.java b/src/main/java/GameEngine.java index 1a3f5ab..0ecdb1f 100644 --- a/src/main/java/GameEngine.java +++ b/src/main/java/GameEngine.java @@ -1,7 +1,3 @@ -import models.JumpGameModel; -import org.lwjgl.glfw.GLFWKeyCallback; - -import static org.lwjgl.glfw.GLFW.*; import static org.lwjgl.opengl.GL11.*; //--------------------------------------------------------------- diff --git a/src/main/java/JumpGame.java b/src/main/java/JumpGame.java index 4a7b5ca..314895b 100644 --- a/src/main/java/JumpGame.java +++ b/src/main/java/JumpGame.java @@ -38,6 +38,7 @@ //--------------------------------------------------------------- // 更新処理 public void update(long window) { + JumpGameModel jumpGameModel = (JumpGameModel) model; // Viewの更新 for (IView view : views) { @@ -51,13 +52,13 @@ @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(); + jumpGameModel.moveY(256); // System.out.println("jumping"); } } }); + jumpGameModel.moveX(1); gravity(-256); //重力 } diff --git a/src/main/java/entities/Acceleration.java b/src/main/java/entities/Acceleration.java index 930cd85..a0e330e 100644 --- a/src/main/java/entities/Acceleration.java +++ b/src/main/java/entities/Acceleration.java @@ -1,55 +1,39 @@ package entities; - import java.util.*; public class Acceleration { - private double massValue = 1.0; - private Pair forceValue = new Pair<>(0d, 0d); - private Velocity velocity; - private Onground onground; - private Pair value = new Pair<>(0d, 0d); - - //--------------------------------------------------------------- - // - public void updateByMass(double mass) { - 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)); - } - - this.value = temp_l0; - velocity.updateByAcceleration(value); - } - - //--------------------------------------------------------------- - // - public void updateByForce(Pair force) { - this.forceValue = force; - Pair temp_l1; - - 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); - } - - //--------------------------------------------------------------- - //--------------------------------------------------------------- - public Acceleration(Velocity velocity, Onground onground) { - this.velocity = velocity; - this.onground = onground; - } - - //--------------------------------------------------------------- - // - public Pair getValue() { - return value; - } + private Pair force = new Pair<>(0.0,0.0); + private double mass = 1.0; + private Velocity velocity; + private Onground onground; + private Pair value = new Pair<>(0.0,0.0); + public void updateForce(Pair force) { + this.force = force; + Pair temp_if0; + if (this.onground.getValue()) { + temp_if0 = new Pair<>((force.getLeft()/mass),0.0); + } else { + temp_if0 = new Pair<>((force.getLeft()/mass),(force.getRight()/mass)); + } + value = temp_if0; + velocity.updateAcceleration(value); + } + public void updateMass(double mass) { + this.mass = mass; + Pair temp_if2; + if (this.onground.getValue()) { + temp_if2 = new Pair<>((force.getLeft()/mass),0.0); + } else { + temp_if2 = new Pair<>((force.getLeft()/mass),(force.getRight()/mass)); + } + value = temp_if2; + velocity.updateAcceleration(value); + } + public Acceleration(Velocity velocity, Onground onground) { + this.velocity = velocity; + this.onground = onground; + } + public Pair getValue() { + return value; + } } \ No newline at end of file diff --git a/src/main/java/entities/Clear.java b/src/main/java/entities/Clear.java index abdcc20..8ed248c 100644 --- a/src/main/java/entities/Clear.java +++ b/src/main/java/entities/Clear.java @@ -3,19 +3,17 @@ import java.util.*; public class Clear { - private Position position; - - public Clear(Position position) { - this.position = position; - } - - public boolean getClear() { - boolean temp_l4; - if ((this.position.getValue().getFirst() > 100.0)) { - temp_l4 = true; - } else { - temp_l4 = false; - } - return temp_l4; - } + private boolean value = false; + public void updatePosition(Pair position) { + boolean temp_if5; + if ((position.getLeft()>100.0)) { + temp_if5 = true; + } else { + temp_if5 = false; + } + value = temp_if5; + } + public boolean getValue() { + return value; + } } \ No newline at end of file diff --git a/src/main/java/entities/Force.java b/src/main/java/entities/Force.java index c5cb410..5e8897f 100644 --- a/src/main/java/entities/Force.java +++ b/src/main/java/entities/Force.java @@ -3,19 +3,16 @@ import java.util.*; public class Force { - private Acceleration acceleration; - private Pair value = new Pair<>(-1.0d, 0.0d); - - public Force(Acceleration acceleration) { - this.acceleration = acceleration; - } - - public void gravity(double y) { - this.value = new Pair(0.0, y); - acceleration.updateByForce(value); - } - - public Pair getValue() { - return value; - } + private Acceleration acceleration; + private Pair value = new Pair<>(0.0,0.0); + public Force(Acceleration acceleration) { + this.acceleration = acceleration; + } + public void gravity(double y) { + this.value = new Pair<>(0.0,y); + acceleration.updateForce(value); + } + public Pair getValue() { + return value; + } } \ No newline at end of file diff --git a/src/main/java/entities/Gameover.java b/src/main/java/entities/Gameover.java index c84d3a0..babc4ae 100644 --- a/src/main/java/entities/Gameover.java +++ b/src/main/java/entities/Gameover.java @@ -1,21 +1,18 @@ package entities; - import java.util.*; public class Gameover { - private Position position; - - public Gameover(Position position) { - this.position = position; - } - - public boolean getGameover() { - boolean temp_l6; - if ((this.position.getValue().getSecond() < -(1.0))) { - temp_l6 = true; - } else { - temp_l6 = false; - } - return temp_l6; - } + private boolean value = false; + public void updatePosition(Pair position) { + boolean temp_if6; + if ((position.getRight()<-(1.0))) { + temp_if6 = true; + } else { + temp_if6 = false; + } + value = temp_if6; + } + public boolean getValue() { + return value; + } } \ No newline at end of file diff --git a/src/main/java/entities/Ground.java b/src/main/java/entities/Ground.java index 7f755ba..69c5290 100644 --- a/src/main/java/entities/Ground.java +++ b/src/main/java/entities/Ground.java @@ -3,27 +3,20 @@ import java.util.*; public class Ground { - private boolean value = true; - - - //--------------------------------------------------------------- - // getter - public boolean getValue() { - return value; - } - - //--------------------------------------------------------------- - //--------------------------------------------------------------- - // - public void openHole(){ - this.value = false; - } - - //--------------------------------------------------------------- - // - public void closeHole(){ - this.value = true; - } - - //--------------------------------------------------------------- + private Onground onground; + private boolean value = true; + public Ground(Onground onground) { + this.onground = onground; + } + public void openHole() { + this.value = false; + onground.updateGround(value); + } + public void closeHole() { + this.value = true; + onground.updateGround(value); + } + public boolean getValue() { + return value; + } } \ No newline at end of file diff --git a/src/main/java/entities/Mass.java b/src/main/java/entities/Mass.java index 73cddd7..d8dd95d 100644 --- a/src/main/java/entities/Mass.java +++ b/src/main/java/entities/Mass.java @@ -1,21 +1,17 @@ package entities; - import java.util.*; public class Mass { - private Acceleration acceleration; - private double value; - - public Mass(Acceleration acceleration) { - this.acceleration = acceleration; - } - - public void setValue(double x) { - this.value = x; - acceleration.updateByMass(value); - } - - public double getValue() { - return value; - } + private Acceleration acceleration; + private double value = 1.0; + public Mass(Acceleration acceleration) { + this.acceleration = acceleration; + } + public void setMass(double x) { + this.value = x; + acceleration.updateMass(value); + } + public double getValue() { + return value; + } } \ No newline at end of file diff --git a/src/main/java/entities/Move.java b/src/main/java/entities/Move.java index 7de2f12..b91e605 100644 --- a/src/main/java/entities/Move.java +++ b/src/main/java/entities/Move.java @@ -3,24 +3,20 @@ import java.util.*; public class Move { - private Velocity velocity; - private Pair value = new Pair<>(1d, 256d); - - public Move(Velocity velocity) { - this.velocity = velocity; - } - - public void moveX(double x) { - this.value = new Pair(x, this.value.getSecond()); - velocity.updateByMove(value); - } - - public void moveY(double y) { - this.value = new Pair(this.value.getFirst(), y); - velocity.updateByMove(value); - } - - public Pair getValue() { - return value; - } + private Velocity velocity; + private Pair value = new Pair<>(0.0,0.0); + public Move(Velocity velocity) { + this.velocity = velocity; + } + public void moveY(double y) { + this.value = new Pair<>(this.value.getLeft(),y); + velocity.updateMove(value); + } + public void moveX(double x) { + this.value = new Pair<>(x,this.value.getRight()); + 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 117f49d..9a54eb0 100644 --- a/src/main/java/entities/Onground.java +++ b/src/main/java/entities/Onground.java @@ -3,15 +3,18 @@ import java.util.*; public class Onground { - private Ground ground; - private Position position; - - public Onground(Ground ground, Position position) { - this.ground = ground; - this.position = position; - } - - public boolean getOnground() { - return ((this.ground.getValue() == true) && (this.position.getValue().getSecond() <= 0.0)); - } + private boolean ground = true; + private Pair position = new Pair<>(0.0,0.0); + private boolean value = true; + 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; + } } \ No newline at end of file diff --git a/src/main/java/entities/Pair.java b/src/main/java/entities/Pair.java index 6a62008..025be0a 100644 --- a/src/main/java/entities/Pair.java +++ b/src/main/java/entities/Pair.java @@ -3,19 +3,16 @@ import java.util.*; public class Pair { - private T first; - private T second; - - public Pair(T first, T second) { - this.first = first; - this.second = second; - } - - public T getFirst() { - return this.first; - } - - public T getSecond() { - return this.second; - } -} + private T left; + private T right; + public Pair(T left, T right) { + this.left = left; + this.right = right; + } + public T getLeft() { + return left; + } + public T getRight() { + return right; + } +} \ No newline at end of file diff --git a/src/main/java/entities/Position.java b/src/main/java/entities/Position.java index a84e966..03b164c 100644 --- a/src/main/java/entities/Position.java +++ b/src/main/java/entities/Position.java @@ -1,37 +1,31 @@ package entities; - import java.util.*; -//--------------------------------------------------------------- -// public class Position { - private Ground ground; - private Pair value = new Pair<>(0d, 0d); - - //--------------------------------------------------------------- - //--------------------------------------------------------------- - // - public void updateByVelocity(Pair velocity) { - Pair temp_l3; - if (((this.ground.getValue() == true) && ((this.value.getSecond() + (0.01 * velocity.getSecond())) < 0.0))) { - temp_l3 = new Pair((this.value.getFirst() + (0.01 * velocity.getFirst())), 0.0); - } else { - temp_l3 = new Pair((this.value.getFirst() + (0.01 * velocity.getFirst())), (this.value.getSecond() + (0.01 * velocity.getSecond()))); - } - value = temp_l3; - } - - //--------------------------------------------------------------- - //--------------------------------------------------------------- - // - public Position(Ground ground) { - this.ground = ground; - } - - //--------------------------------------------------------------- - //--------------------------------------------------------------- - // getter - public Pair getValue() { - return value; - } + private Onground onground; + private Clear clear; + private Gameover gameover; + private Ground ground; + private Pair value = new Pair<>(0.0,0.0); + public void updateVelocity(Pair velocity) { + Pair temp_if4; + if (((this.ground.getValue()==true)&&((this.value.getRight()+(0.01*velocity.getRight()))<0.0))) { + temp_if4 = new Pair<>((this.value.getLeft()+(0.01*velocity.getLeft())),0.0); + } else { + temp_if4 = new Pair<>((this.value.getLeft()+(0.01*velocity.getLeft())),(this.value.getRight()+(0.01*velocity.getRight()))); + } + value = temp_if4; + onground.updatePosition(value); + clear.updatePosition(value); + gameover.updatePosition(value); + } + public Position(Onground onground, Clear clear, Gameover gameover, Ground ground) { + this.onground = onground; + this.clear = clear; + this.gameover = gameover; + this.ground = ground; + } + public Pair getValue() { + return value; + } } \ No newline at end of file diff --git a/src/main/java/entities/Time.java b/src/main/java/entities/Time.java index 16381eb..5ee12e9 100644 --- a/src/main/java/entities/Time.java +++ b/src/main/java/entities/Time.java @@ -1,15 +1,12 @@ package entities; - import java.util.*; public class Time { - private double value; - - public void gravity(double y) { - this.value = (this.value + 1); - } - - public double getValue() { - return value; - } + private double value = 0.0; + public void gravity(double y) { + this.value = (this.value+0.01); + } + public double getValue() { + return value; + } } \ No newline at end of file diff --git a/src/main/java/entities/Velocity.java b/src/main/java/entities/Velocity.java index c1c1c0a..1d9d6ff 100644 --- a/src/main/java/entities/Velocity.java +++ b/src/main/java/entities/Velocity.java @@ -3,50 +3,38 @@ import java.util.*; public class Velocity { - private Pair moveValue = new Pair<>(0d, 0d); - private Pair accelerationValue = new Pair<>(0d, 0d); - private Position position; - private Onground onground; - private Pair value = new Pair<>(1d, 0d); - - //--------------------------------------------------------------- - //--------------------------------------------------------------- - public void updateByMove(Pair move) { - this.moveValue = move; - Pair temp_l2; - if ((this.onground.getOnground() && (move.getSecond() >= 0.0))) { - temp_l2 = move; - } else { - temp_l2 = this.value; - } - value = temp_l2; - position.updateByVelocity(value); - } - - //--------------------------------------------------------------- - //--------------------------------------------------------------- - public void updateByAcceleration(Pair acceleration) { - this.accelerationValue = acceleration; - Pair temp_l5; - if ((this.onground.getOnground() && (this.value.getSecond() < 0.0))) { - temp_l5 = new Pair((this.value.getFirst() + (0.01 * acceleration.getFirst())), 0.0); - } else { - temp_l5 = new Pair((this.value.getFirst() + (0.01 * acceleration.getFirst())), (this.value.getSecond() + (0.01 * acceleration.getSecond()))); - } - value = temp_l5; - position.updateByVelocity(value); - } - - //--------------------------------------------------------------- - //--------------------------------------------------------------- - public Velocity(Position position, Onground onground) { - this.position = position; - this.onground = onground; - } - - //--------------------------------------------------------------- - //--------------------------------------------------------------- - public Pair getValue() { - return value; - } + private Pair move = new Pair<>(0.0,0.0); + private Pair acceleration = new Pair<>(0.0,0.0); + private Position position; + private Onground onground; + private Pair value = new Pair<>(0.0,0.0); + public void updateMove(Pair move) { + this.move = move; + Pair temp_if1; + if ((this.onground.getValue()&&(move.getRight()>=0.0))) { + temp_if1 = move; + } else { + temp_if1 = this.value; + } + value = temp_if1; + position.updateVelocity(value); + } + public void updateAcceleration(Pair acceleration) { + this.acceleration = acceleration; + Pair temp_if3; + if ((this.onground.getValue()&&(this.value.getRight()<0.0))) { + temp_if3 = new Pair<>((this.value.getLeft()+(0.01*acceleration.getLeft())),0.0); + } else { + temp_if3 = new Pair<>((this.value.getLeft()+(0.01*acceleration.getLeft())),(this.value.getRight()+(0.01*acceleration.getRight()))); + } + value = temp_if3; + position.updateVelocity(value); + } + public Velocity(Position position, Onground onground) { + this.position = position; + this.onground = onground; + } + public Pair getValue() { + return value; + } } \ No newline at end of file diff --git a/src/main/java/models/JumpGameModel.java b/src/main/java/models/JumpGameModel.java deleted file mode 100644 index 97880b9..0000000 --- a/src/main/java/models/JumpGameModel.java +++ /dev/null @@ -1,140 +0,0 @@ -package models; - -import java.util.*; - -import entities.*; -import entities.modelExtentions.Stage; - -//--------------------------------------------------------------- -// -public class JumpGameModel implements IModel { - - private Acceleration acceleration; - private Force force; - private Mass mass; - private Move move; - 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; - - - //--------------------------------------------------------------- - //--------------------------------------------------------------- - // - public JumpGameModel() { - ground = new Ground(); - position = new Position(ground); - onground = new Onground(ground, position); - velocity = new Velocity(position, onground); - acceleration = new Acceleration(velocity, onground); - force = new Force(acceleration); - mass = new Mass(acceleration); - move = new Move(velocity); - time = new Time(); - gameover = new Gameover(position); - clear = new Clear(position); - stage = new Stage(); - } - - //--------------------------------------------------------------- - //--------------------------------------------------------------- - // getter - public Stage getStage() { - return stage; - } - - public Pair getPosition() { - return position.getValue(); - } - - public void moveX(double x) { - this.move.moveX(x); - } - - 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(); - } - - //--------------------------------------------------------------- - //--------------------------------------------------------------- - // ジャンプ - public void jump() { - this.move.moveY(jumpPower); - } - - //--------------------------------------------------------------- - // マイフレーム更新処理 - public void gravity(double y) { - this.time.gravity(y); - this.force.gravity(y); -// System.out.println("swapWindow Gravity"); - } - - //--------------------------------------------------------------- - // 地面のフラグ更新 - public void updateGroundFlag() { - double x = position.getValue().getFirst(); - - 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("Clear: " + clear.getClear() + "/"); -// System.out.println("GameOver: " + gameover.getGameover()); - - } - //--------------------------------------------------------------- -} diff --git a/src/main/java/views/Image2D.java b/src/main/java/views/Image2D.java index 45644af..69c8684 100644 --- a/src/main/java/views/Image2D.java +++ b/src/main/java/views/Image2D.java @@ -67,7 +67,7 @@ glMatrixMode(GL_MODELVIEW); // 行列の設定 glLoadIdentity(); // 単位行列化 - glTranslated(position.getFirst(), position.getSecond(), 0); // 移動 + glTranslated(position.getLeft(), position.getRight(), 0); // 移動 glRotated(rotation, 0, 0, 1); // 回転 glScaled(scale, scale, 1); // 拡縮 @@ -86,13 +86,13 @@ // ポリゴンの作成とテクスチャの適応 glBegin(GL_TRIANGLE_STRIP); glTexCoord2d(0, 0); - glVertex2d(-spriteSize.getFirst() / 2, spriteSize.getSecond() / 2); + glVertex2d(-spriteSize.getLeft() / 2, spriteSize.getRight() / 2); glTexCoord2d(0, 1); - glVertex2d(-spriteSize.getFirst() / 2, -spriteSize.getSecond() / 2); + glVertex2d(-spriteSize.getLeft() / 2, -spriteSize.getRight() / 2); glTexCoord2d(1, 0); - glVertex2d(spriteSize.getFirst() / 2, spriteSize.getSecond() / 2); + glVertex2d(spriteSize.getLeft() / 2, spriteSize.getRight() / 2); glTexCoord2d(1, 1); - glVertex2d(spriteSize.getFirst() / 2, -spriteSize.getSecond() / 2); + glVertex2d(spriteSize.getLeft() / 2, -spriteSize.getRight() / 2); glEnd(); // 行列の破棄 diff --git a/src/main/java/views/PlayerRenderer.java b/src/main/java/views/PlayerRenderer.java index 01d154d..5baea09 100644 --- a/src/main/java/views/PlayerRenderer.java +++ b/src/main/java/views/PlayerRenderer.java @@ -26,8 +26,8 @@ public void update(IModel model) { JumpGameModel jumpGameModel = (JumpGameModel) model; - double x = this.sprite.getPositionValue().getFirst(); - double y = 112 + jumpGameModel.getPosition().getSecond(); + double x = this.sprite.getPositionValue().getLeft(); + double y = 112 + jumpGameModel.getPosition().getRight(); this.sprite.setPositionValue(new Pair<>(x, y)); } diff --git a/src/main/java/views/TileRenderer.java b/src/main/java/views/TileRenderer.java index e8f9f37..55bb5ad 100644 --- a/src/main/java/views/TileRenderer.java +++ b/src/main/java/views/TileRenderer.java @@ -4,8 +4,6 @@ import models.IModel; import models.JumpGameModel; -import java.lang.reflect.Parameter; - //--------------------------------------------------------------- // タイルの描画 public class TileRenderer implements IView { @@ -51,8 +49,8 @@ public void update(IModel model) { JumpGameModel jumpGameModel = (JumpGameModel) model; - Double x = this.initPositionValue.getFirst() - (jumpGameModel.getPosition().getFirst() * 64); - Double y = this.sprite.getPositionValue().getSecond(); + Double x = this.initPositionValue.getLeft() - (jumpGameModel.getPosition().getLeft() * 64); + Double y = this.sprite.getPositionValue().getRight(); this.sprite.setPositionValue(new Pair<>(x, y)); }