diff --git a/README.md b/README.md index 61522cd..734b005 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -entities.JumpGame +JumpGame =============== diff --git a/src/main/java/JumpGame.java b/src/main/java/JumpGame.java new file mode 100644 index 0000000..9026eae --- /dev/null +++ b/src/main/java/JumpGame.java @@ -0,0 +1,75 @@ +import entities.*; +import models.IModel; +import models.PlayerModel; +import views.IView; +import views.PlayerRenderer; + +import java.util.ArrayList; + +public class JumpGame { + //--------------------------------------------------------------- +// private Time time = new Time(); + private Ground ground = new Ground(); +// private Position position = new Position(ground); +// private Gameover gameover = new Gameover(position); +// private Onground onground = new Onground(ground, position); +// private Velocity velocity = new Velocity(position, onground); +// private Clear clear = new Clear(position); +// private Move move = new Move(velocity); +// private Acceleration acceleration = new Acceleration(velocity, onground); +// private Force force = new Force(acceleration); +// private Mass mass = new Mass(acceleration); + + //--------------------------------------------------------------- + // new + private ArrayList views = new ArrayList<>(); + private ArrayList models = new ArrayList<>(); + + private PlayerModel playerModel = new PlayerModel(ground); + + //--------------------------------------------------------------- + //--------------------------------------------------------------- + // + public void gravity(double y) { + // this.force.gravity(y); + // this.time.gravity(y); + } + + //--------------------------------------------------------------- + // 初期化 + public void init() { + + // model + models.add(new PlayerModel(ground)); + + // view + views.add(new PlayerRenderer("resources/test.png")); + } + + //--------------------------------------------------------------- + // 更新処理 + public void update() { + + // Viewの更新 + for (IModel model : models) { + for (IView view : views) view.display(model); + } + // Modelの更新 + // + // Space キーのインプット + // + // マイフレーム更新 + + gravity(0.01); //重力 + } + + //--------------------------------------------------------------- + // デストラクタのような処理 + 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 7f58425..15c69c2 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,8 +1,6 @@ import entities.Const; -import entities.Pair; import org.lwjgl.glfw.*; import org.lwjgl.opengl.*; -import views.PlayerRenderer; import static org.lwjgl.glfw.Callbacks.*; import static org.lwjgl.glfw.GLFW.*; @@ -15,7 +13,7 @@ private long hWnd; // - private PlayerRenderer playerRenderer; + private JumpGame jumpGame = new JumpGame(); // フルスクリーン public boolean fullScreen; @@ -36,13 +34,14 @@ // 色々初期化 initWindow(); initRender(); - - playerRenderer = new PlayerRenderer("resources/test.png", new Pair<>(640d, 480d)); + jumpGame.init(); // メインループ while (!glfwWindowShouldClose(hWnd)) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // バッファのクリア - playerRenderer.display(); + + jumpGame.update(); + glfwSwapBuffers(hWnd); // バッファのスワップ glfwPollEvents(); // 入力とかイベントの取得 } @@ -98,7 +97,7 @@ //--------------------------------------------------------------- // デストラクタ public void delete() { - playerRenderer.delete(); + jumpGame.delete(); } //--------------------------------------------------------------- } \ No newline at end of file diff --git a/src/main/java/entities/Image2D.java b/src/main/java/entities/Image2D.java index 163c273..58bc4fd 100644 --- a/src/main/java/entities/Image2D.java +++ b/src/main/java/entities/Image2D.java @@ -19,17 +19,17 @@ //--------------------------------------------------------------- //--------------------------------------------------------------- // - public Image2D(Texture tex, double x, double y) { + public Image2D(Texture tex) { if (tex != null) this.id = tex.getId(); else this.id = 0; - this.position = new Pair<>(x, y); + this.position = new Pair<>(0.0, 0.0); this.color = new Color(1, 1, 1, 1); if (tex != null) - wh = new Pair<>((double)tex.getWidth(), (double)tex.getHeight()); + wh = new Pair<>((double) tex.getWidth(), (double) tex.getHeight()); else wh = new Pair<>(30d, 30d); @@ -45,6 +45,10 @@ this.rotation = rotation; } + public void setPosition(Pair position) { + this.position = position; + } + //--------------------------------------------------------------- //--------------------------------------------------------------- // diff --git a/src/main/java/entities/JumpGame.java b/src/main/java/entities/JumpGame.java deleted file mode 100644 index 1f93c45..0000000 --- a/src/main/java/entities/JumpGame.java +++ /dev/null @@ -1,76 +0,0 @@ -package entities; - -public class JumpGame { - private Time time = new Time(); - private Ground ground = new Ground(); - private Position position = new Position(ground); - private Gameover gameover = new Gameover(position); - private Onground onground = new Onground(ground, position); - private Velocity velocity = new Velocity(position, onground); - private Clear clear = new Clear(position); - private Move move = new Move(velocity); - private Acceleration acceleration = new Acceleration(velocity, onground); - private Force force = new Force(acceleration); - private Mass mass = new Mass(acceleration); - - public void gravity(double y) { - this.force.gravity(y); - this.time.gravity(y); - } - - 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 Pair getPosition() { - return position.getValue(); - } - - public boolean getOnground() { - return onground.getOnground(); - } - - public double getTime() { - return time.getValue(); - } - - public boolean getGameover() { - return gameover.getGameover(); - } -} \ No newline at end of file diff --git a/src/main/java/entities/Position.java b/src/main/java/entities/Position.java index 0dd45c9..651c13c 100644 --- a/src/main/java/entities/Position.java +++ b/src/main/java/entities/Position.java @@ -1,9 +1,14 @@ package entities; +//--------------------------------------------------------------- +// public class Position { private Ground ground; private Pair value; + //--------------------------------------------------------------- + //--------------------------------------------------------------- + // public void updateByVelocity(Pair velocity) { Pair temp_l3; if (((this.ground.getValue() == true) && ((this.value.getSecond() + (0.01 * velocity.getSecond())) < 0.0))) { @@ -14,10 +19,23 @@ value = temp_l3; } + //--------------------------------------------------------------- + //--------------------------------------------------------------- + // public Position(Ground ground) { this.ground = ground; } + //--------------------------------------------------------------- + // + public Position(Pair value, Ground ground) { + this.value = value; + this.ground = ground; + } + + //--------------------------------------------------------------- + //--------------------------------------------------------------- + // getter public Pair getValue() { return value; } diff --git a/src/main/java/entities/Sprite.java b/src/main/java/entities/Sprite.java new file mode 100644 index 0000000..0566eb5 --- /dev/null +++ b/src/main/java/entities/Sprite.java @@ -0,0 +1,45 @@ +package entities; + +import views.IView; + +//--------------------------------------------------------------- +// +public class Sprite { + + private Pair positionValue; + private Texture texture; + private Image2D img; + + //--------------------------------------------------------------- + //--------------------------------------------------------------- + // + public Sprite(String path) { + this.positionValue = new Pair<>(0d, 0d); + texture = new Texture("player", path); + img = new Image2D(texture); + } + + //--------------------------------------------------------------- + //--------------------------------------------------------------- + // setter + public void setPositionValue(Pair positionValue) { + this.positionValue = positionValue; + } + + //--------------------------------------------------------------- + //--------------------------------------------------------------- + // + public void draw() { + img.setPosition(positionValue); + img.draw(); + } + + //--------------------------------------------------------------- + // テクスチャの開放 + public void delete() { + texture.delete(); + } + + //--------------------------------------------------------------- + +} diff --git a/src/main/java/entities/Velocity.java b/src/main/java/entities/Velocity.java index eee5e77..9f218ea 100644 --- a/src/main/java/entities/Velocity.java +++ b/src/main/java/entities/Velocity.java @@ -8,6 +8,8 @@ private Onground onground; private Pair value; + //--------------------------------------------------------------- + //--------------------------------------------------------------- public void updateByMove(Pair move) { this.moveValue = move; Pair temp_l2; @@ -20,6 +22,8 @@ position.updateByVelocity(value); } + //--------------------------------------------------------------- + //--------------------------------------------------------------- public void updateByAcceleration(Pair acceleration) { this.accelerationValue = acceleration; Pair temp_l5; @@ -32,11 +36,15 @@ position.updateByVelocity(value); } + //--------------------------------------------------------------- + //--------------------------------------------------------------- public Velocity(Position position, Onground onground) { this.position = position; this.onground = onground; } + //--------------------------------------------------------------- + //--------------------------------------------------------------- public Pair getValue() { return value; } diff --git a/src/main/java/models/IModel.java b/src/main/java/models/IModel.java new file mode 100644 index 0000000..700df1f --- /dev/null +++ b/src/main/java/models/IModel.java @@ -0,0 +1,4 @@ +package models; + +public interface IModel { +} diff --git a/src/main/java/models/PlayerModel.java b/src/main/java/models/PlayerModel.java index 7ba8b3c..bbdb8cc 100644 --- a/src/main/java/models/PlayerModel.java +++ b/src/main/java/models/PlayerModel.java @@ -1,4 +1,45 @@ package models; -public class PlayerModel { +import entities.*; + +//--------------------------------------------------------------- +// +public class PlayerModel implements IModel { + //--------------------------------------------------------------- + private Acceleration acceleration; + private Force force; + private Mass mass; + private Move move; + private Position position; + private Velocity velocity; + private Onground onground; + + //--------------------------------------------------------------- + private double jumpPower = 32; + + //--------------------------------------------------------------- + public PlayerModel(Ground ground) { + position = new Position(new Pair<>(640d, 480d), 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); + } + + //--------------------------------------------------------------- + //--------------------------------------------------------------- + // getter + public Position getPosition() { + return position; + } + + //--------------------------------------------------------------- + // + public void jump() { + this.move.moveY(jumpPower); + } + //--------------------------------------------------------------- + } diff --git a/src/main/java/views/IView.java b/src/main/java/views/IView.java index 6a9a0e8..2e9b5f2 100644 --- a/src/main/java/views/IView.java +++ b/src/main/java/views/IView.java @@ -1,12 +1,14 @@ package views; +import models.IModel; + //--------------------------------------------------------------- // public interface IView { //--------------------------------------------------------------- // 描画 - void display(); + void display(IModel model); //--------------------------------------------------------------- // テクスチャの開放 diff --git a/src/main/java/views/PlayerRenderer.java b/src/main/java/views/PlayerRenderer.java index 2ce4485..4da715c 100644 --- a/src/main/java/views/PlayerRenderer.java +++ b/src/main/java/views/PlayerRenderer.java @@ -1,35 +1,34 @@ package views; -import entities.Image2D; -import entities.Pair; -import entities.Texture; +import entities.*; +import models.IModel; +import models.PlayerModel; //--------------------------------------------------------------- // public class PlayerRenderer implements IView { - - private Texture texture; - private Image2D img; + private Sprite sprite; //--------------------------------------------------------------- //--------------------------------------------------------------- - // - public PlayerRenderer(String path, Pair position) { - texture = new Texture("player", path); - img = new Image2D(texture, position.getFirst(), position.getSecond()); + public PlayerRenderer(String path) { + this.sprite = new Sprite(path); } //--------------------------------------------------------------- //--------------------------------------------------------------- - // - public void display() { - img.draw(); + // PlayerModelから座標を取得して描画する + public void display(IModel model) { + PlayerModel playerModel = (PlayerModel)model; + + sprite.draw(); + sprite.setPositionValue(playerModel.getPosition().getValue()); } //--------------------------------------------------------------- // テクスチャの開放 - public void delete(){ - texture.delete(); + public void delete() { + sprite.delete(); } //--------------------------------------------------------------- }