diff --git a/src/main/java/JumpGame.java b/src/main/java/JumpGame.java index 86e3f11..9927138 100644 --- a/src/main/java/JumpGame.java +++ b/src/main/java/JumpGame.java @@ -1,45 +1,31 @@ -import models.GroundModel; import models.IModel; -import entities.ModelType; -import models.PlayerModel; +import models.JumpGameModel; import views.IView; import views.PlayerRenderer; import views.TileMapRenderer; -import views.TileRenderer; import java.util.ArrayList; public class JumpGame { //--------------------------------------------------------------- -// private Time time = new Time(); -// private Gameover gameover = new Gameover(position); -// private Clear clear = new Clear(position); //--------------------------------------------------------------- // new - private int i = 0; private ArrayList views = new ArrayList<>(); - private ArrayList models = new ArrayList<>(); + private IModel model = new JumpGameModel(); //--------------------------------------------------------------- //--------------------------------------------------------------- // public void gravity(double y) { // this.time.gravity(y); - PlayerModel playerModel = (PlayerModel) models.get(ModelType.PLAYER_MODEL); - playerModel.updateGravity(y); + JumpGameModel jumpGameModel = (JumpGameModel) model; + jumpGameModel.updateGravity(y); } //--------------------------------------------------------------- // 初期化 public void init() { - - // model - models.add(new GroundModel()); - - GroundModel groundModel = (GroundModel) models.get(ModelType.GROUND_MODEL); - models.add(new PlayerModel(groundModel.getGround())); - // view views.add(new TileMapRenderer()); views.add(new PlayerRenderer("resources/chicken.png")); @@ -50,8 +36,9 @@ public void update() { // Viewの更新 - for (IModel model : models) { - for (IView view : views) view.display(model); + for (IView view : views){ + view.update(model); + view.display(); } // Modelの更新 diff --git a/src/main/java/entities/Acceleration.java b/src/main/java/entities/Acceleration.java deleted file mode 100644 index 0d80c79..0000000 --- a/src/main/java/entities/Acceleration.java +++ /dev/null @@ -1,48 +0,0 @@ -package entities; - -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); - 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; - } -} \ No newline at end of file diff --git a/src/main/java/entities/Clear.java b/src/main/java/entities/Clear.java index 3f33d64..d2345d4 100644 --- a/src/main/java/entities/Clear.java +++ b/src/main/java/entities/Clear.java @@ -1,5 +1,7 @@ package entities; +import entities.player.Position; + public class Clear { private Position position; diff --git a/src/main/java/entities/Force.java b/src/main/java/entities/Force.java deleted file mode 100644 index c6654b6..0000000 --- a/src/main/java/entities/Force.java +++ /dev/null @@ -1,19 +0,0 @@ -package entities; - -public class Force { - private Acceleration acceleration; - private Pair value = new Pair<>(0.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; - } -} \ No newline at end of file diff --git a/src/main/java/entities/Gameover.java b/src/main/java/entities/Gameover.java index 751be25..b248c05 100644 --- a/src/main/java/entities/Gameover.java +++ b/src/main/java/entities/Gameover.java @@ -1,5 +1,7 @@ package entities; +import entities.player.Position; + public class Gameover { private Position position; diff --git a/src/main/java/entities/Mass.java b/src/main/java/entities/Mass.java deleted file mode 100644 index f7d4012..0000000 --- a/src/main/java/entities/Mass.java +++ /dev/null @@ -1,19 +0,0 @@ -package entities; - -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; - } -} \ No newline at end of file diff --git a/src/main/java/entities/ModelType.java b/src/main/java/entities/ModelType.java deleted file mode 100644 index 193b2e6..0000000 --- a/src/main/java/entities/ModelType.java +++ /dev/null @@ -1,17 +0,0 @@ -package entities; - -//--------------------------------------------------------------- -// モデルのタイプ識別 -public class ModelType { - - public static final int GROUND_MODEL = 0; - public static final int PLAYER_MODEL = 1; - public static final int GAME_MODEL = 2; - - //--------------------------------------------------------------- - //--------------------------------------------------------------- - private ModelType() { - - } - //--------------------------------------------------------------- -} diff --git a/src/main/java/entities/Move.java b/src/main/java/entities/Move.java deleted file mode 100644 index c7e92ac..0000000 --- a/src/main/java/entities/Move.java +++ /dev/null @@ -1,23 +0,0 @@ -package entities; - -public class Move { - private Velocity velocity; - private Pair value = new Pair<>(0d, 0d); - - 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); - } - - 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 deleted file mode 100644 index 6b58b90..0000000 --- a/src/main/java/entities/Onground.java +++ /dev/null @@ -1,14 +0,0 @@ -package entities; - -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)); } -} \ No newline at end of file diff --git a/src/main/java/entities/Position.java b/src/main/java/entities/Position.java deleted file mode 100644 index 4cef46d..0000000 --- a/src/main/java/entities/Position.java +++ /dev/null @@ -1,42 +0,0 @@ -package entities; - -//--------------------------------------------------------------- -// -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; - } - - //--------------------------------------------------------------- - // - public Position(Pair value, Ground ground) { - this.value = value; - this.ground = ground; - } - - //--------------------------------------------------------------- - //--------------------------------------------------------------- - // getter - public Pair getValue() { - return value; - } -} \ No newline at end of file diff --git a/src/main/java/entities/Sprite.java b/src/main/java/entities/Sprite.java index 239e96d..b84e749 100644 --- a/src/main/java/entities/Sprite.java +++ b/src/main/java/entities/Sprite.java @@ -6,10 +6,10 @@ // public class Sprite { - private Pair positionValue; - private double scaleValue; private Texture texture; private Image2D img; + private Pair positionValue; + private double scaleValue; //--------------------------------------------------------------- //--------------------------------------------------------------- @@ -23,10 +23,14 @@ //--------------------------------------------------------------- //--------------------------------------------------------------- // getter - public double getScaleValue(){ + public double getScaleValue() { return this.scaleValue; } + public Pair getPositionValue() { + return this.positionValue; + } + //--------------------------------------------------------------- // setter public void setPositionValue(Pair positionValue) { diff --git a/src/main/java/entities/Velocity.java b/src/main/java/entities/Velocity.java deleted file mode 100644 index 5c82b80..0000000 --- a/src/main/java/entities/Velocity.java +++ /dev/null @@ -1,51 +0,0 @@ -package entities; - - -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<>(0d, 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; - } -} \ No newline at end of file diff --git a/src/main/java/entities/player/Acceleration.java b/src/main/java/entities/player/Acceleration.java new file mode 100644 index 0000000..fe00b13 --- /dev/null +++ b/src/main/java/entities/player/Acceleration.java @@ -0,0 +1,50 @@ +package entities.player; + +import entities.Pair; + +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); + 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; + } +} \ No newline at end of file diff --git a/src/main/java/entities/player/Force.java b/src/main/java/entities/player/Force.java new file mode 100644 index 0000000..9c034d9 --- /dev/null +++ b/src/main/java/entities/player/Force.java @@ -0,0 +1,21 @@ +package entities.player; + +import entities.Pair; + +public class Force { + private Acceleration acceleration; + private Pair value = new Pair<>(0.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; + } +} \ No newline at end of file diff --git a/src/main/java/entities/player/Mass.java b/src/main/java/entities/player/Mass.java new file mode 100644 index 0000000..16283e6 --- /dev/null +++ b/src/main/java/entities/player/Mass.java @@ -0,0 +1,19 @@ +package entities.player; + +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; + } +} \ No newline at end of file diff --git a/src/main/java/entities/player/Move.java b/src/main/java/entities/player/Move.java new file mode 100644 index 0000000..460d0d1 --- /dev/null +++ b/src/main/java/entities/player/Move.java @@ -0,0 +1,25 @@ +package entities.player; + +import entities.Pair; + +public class Move { + private Velocity velocity; + private Pair value = new Pair<>(0d, 0d); + + 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); + } + + public Pair getValue() { + return value; + } +} \ No newline at end of file diff --git a/src/main/java/entities/player/Onground.java b/src/main/java/entities/player/Onground.java new file mode 100644 index 0000000..71abfda --- /dev/null +++ b/src/main/java/entities/player/Onground.java @@ -0,0 +1,16 @@ +package entities.player; + +import entities.Ground; + +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)); } +} \ No newline at end of file diff --git a/src/main/java/entities/player/Position.java b/src/main/java/entities/player/Position.java new file mode 100644 index 0000000..05c9f06 --- /dev/null +++ b/src/main/java/entities/player/Position.java @@ -0,0 +1,45 @@ +package entities.player; + +import entities.Ground; +import entities.Pair; + +//--------------------------------------------------------------- +// +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; + } + + //--------------------------------------------------------------- + // + public Position(Pair value, Ground ground) { + this.value = value; + this.ground = ground; + } + + //--------------------------------------------------------------- + //--------------------------------------------------------------- + // getter + public Pair getValue() { + return value; + } +} \ No newline at end of file diff --git a/src/main/java/entities/player/Velocity.java b/src/main/java/entities/player/Velocity.java new file mode 100644 index 0000000..8209abb --- /dev/null +++ b/src/main/java/entities/player/Velocity.java @@ -0,0 +1,53 @@ +package entities.player; + + +import entities.Pair; + +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<>(0d, 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; + } +} \ No newline at end of file diff --git a/src/main/java/models/GroundModel.java b/src/main/java/models/GroundModel.java deleted file mode 100644 index 86a094c..0000000 --- a/src/main/java/models/GroundModel.java +++ /dev/null @@ -1,32 +0,0 @@ -package models; - -import entities.Ground; - -import java.util.ArrayList; - -//--------------------------------------------------------------- -// -public class GroundModel implements IModel { - //--------------------------------------------------------------- - private Ground ground; - private ArrayList flagTimings = new ArrayList<>(); // フラグ切り替え - - //--------------------------------------------------------------- - //--------------------------------------------------------------- - public GroundModel() { - ground = new Ground(); - } - - //--------------------------------------------------------------- - //--------------------------------------------------------------- - // getter - public Ground getGround() { - return ground; - } - - //--------------------------------------------------------------- - //--------------------------------------------------------------- - // - - //--------------------------------------------------------------- -} diff --git a/src/main/java/models/JumpGameModel.java b/src/main/java/models/JumpGameModel.java new file mode 100644 index 0000000..b0617aa --- /dev/null +++ b/src/main/java/models/JumpGameModel.java @@ -0,0 +1,77 @@ +package models; + +import entities.*; +import entities.player.*; + +import java.util.ArrayList; + +//--------------------------------------------------------------- +// +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 double jumpPower = 32; + private ArrayList flagTimings = new ArrayList<>(); // フラグ切り替え + + //--------------------------------------------------------------- + //--------------------------------------------------------------- + // + public JumpGameModel() { + ground = new 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); + time = new Time(); + gameover = new Gameover(position); + clear = new Clear(position); + } + + //--------------------------------------------------------------- + //--------------------------------------------------------------- + // getter + public Position getPosition() { + return position; + } + + public Ground getGround() { + return ground; + } + + //--------------------------------------------------------------- + //--------------------------------------------------------------- + // + public void jump() { + this.move.moveY(jumpPower); + } + + //--------------------------------------------------------------- + // + public void updateGravity(double gravity) { + this.time.gravity(gravity); + this.force.gravity(gravity); + System.out.println("swapWindow Gravity"); + } + + //--------------------------------------------------------------- +} diff --git a/src/main/java/models/PlayerModel.java b/src/main/java/models/PlayerModel.java deleted file mode 100644 index af983bb..0000000 --- a/src/main/java/models/PlayerModel.java +++ /dev/null @@ -1,52 +0,0 @@ -package models; - -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.moveX(jumpPower); - } - - //--------------------------------------------------------------- - // - public void updateGravity(double gravity) { - this.force.gravity(gravity); - System.out.println("swapWindow Gravity"); - } -} diff --git a/src/main/java/views/IView.java b/src/main/java/views/IView.java index 2e9b5f2..449d420 100644 --- a/src/main/java/views/IView.java +++ b/src/main/java/views/IView.java @@ -7,8 +7,12 @@ public interface IView { //--------------------------------------------------------------- + // モデルの監視 + void update(IModel model); + + //--------------------------------------------------------------- // 描画 - void display(IModel model); + void display(); //--------------------------------------------------------------- // テクスチャの開放 diff --git a/src/main/java/views/PlayerRenderer.java b/src/main/java/views/PlayerRenderer.java index 20c1456..7d071b1 100644 --- a/src/main/java/views/PlayerRenderer.java +++ b/src/main/java/views/PlayerRenderer.java @@ -2,7 +2,7 @@ import entities.*; import models.IModel; -import models.PlayerModel; +import models.JumpGameModel; //--------------------------------------------------------------- // @@ -18,20 +18,24 @@ //--------------------------------------------------------------- //--------------------------------------------------------------- - // PlayerModelから座標を取得して描画する - public void display(IModel model) { + // JumpGameModelから座標を取得 + @Override + public void update(IModel model){ + JumpGameModel jumpGameModel = (JumpGameModel) model; + sprite.setPositionValue(jumpGameModel.getPosition().getValue()); + } - // Modelがキャスト可能か判定 - if (model instanceof PlayerModel) { - PlayerModel playerModel = (PlayerModel) model; - sprite.setPositionValue(playerModel.getPosition().getValue()); - } + //--------------------------------------------------------------- + // 描画する + @Override + public void display() { sprite.draw(); } //--------------------------------------------------------------- // テクスチャの開放 + @Override public void delete() { sprite.delete(); } diff --git a/src/main/java/views/TileMapRenderer.java b/src/main/java/views/TileMapRenderer.java index 5dd33e3..71aff43 100644 --- a/src/main/java/views/TileMapRenderer.java +++ b/src/main/java/views/TileMapRenderer.java @@ -12,8 +12,9 @@ public class TileMapRenderer implements IView { private double offsetY = 256d; - private TileRenderer newTile = new TileRenderer("resources/tile.png",null,2); + private TileRenderer newTile = new TileRenderer("resources/tile.png", null, 2); private ArrayList tiles = new ArrayList<>(); + private int tileLen = 150; // //--------------------------------------------------------------- //--------------------------------------------------------------- @@ -24,16 +25,40 @@ //--------------------------------------------------------------- //--------------------------------------------------------------- // - public void display(IModel model) { - for (TileRenderer tile : tiles) tile.display(model); + @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() { + + for (int i = 0; i < tileLen; i++) { + double x = 32 * newTile.getScaleValue() * i; + + newTile = new TileRenderer("resources/tile.png", new Pair<>(x, offsetY)); + newTile.setScaleValue(2); + tiles.add(newTile); + } + } + //-------------------------------------------------------------- // タイルをフラグに応じて生成する private void createTile(TileType tileType) { @@ -44,7 +69,7 @@ break; case OPEN: - newTile = new TileRenderer("resources/hole.png", new Pair<>((double) GLConfigVariable.WIDTH, 0d),2); + newTile = new TileRenderer("resources/hole.png", new Pair<>((double) GLConfigVariable.WIDTH, 0d), 2); break; } @@ -52,14 +77,4 @@ } //--------------------------------------------------------------- - // 初期タイル作成 - private void initTiles() { - - for (double x = 0; x <= GLConfigVariable.WIDTH; x += 32 * newTile.getScaleValue()) { - newTile = new TileRenderer("resources/tile.png", new Pair<>(x, offsetY)); - newTile.setScaleValue(2); - tiles.add(newTile); - } - } - //--------------------------------------------------------------- } \ No newline at end of file diff --git a/src/main/java/views/TileRenderer.java b/src/main/java/views/TileRenderer.java index c839575..8521a97 100644 --- a/src/main/java/views/TileRenderer.java +++ b/src/main/java/views/TileRenderer.java @@ -8,9 +8,11 @@ // タイルの描画 public class TileRenderer implements IView { private Sprite sprite; + private double moveSpeed = -1; //--------------------------------------------------------------- //--------------------------------------------------------------- + // public TileRenderer(String path, Pair initPosition) { this.sprite = new Sprite(path); this.sprite.setScaleValue(1); @@ -34,22 +36,40 @@ //--------------------------------------------------------------- //--------------------------------------------------------------- // setter - public void setScaleValue(double scaleValue){ + public void setScaleValue(double scaleValue) { this.sprite.setScaleValue(scaleValue); } - //--------------------------------------------------------------- //--------------------------------------------------------------- // - public void display(IModel model) { + @Override + public void update(IModel model) { + } + + //--------------------------------------------------------------- + // 描画 + @Override + public void display() { sprite.draw(); + move(); } //--------------------------------------------------------------- // テクスチャの開放 + @Override public void delete() { sprite.delete(); } + + //--------------------------------------------------------------- + //--------------------------------------------------------------- + // 移動 + private void move() { + double x = sprite.getPositionValue().getFirst() + moveSpeed; + double y = sprite.getPositionValue().getSecond(); + + sprite.setPositionValue(new Pair<>(x, y)); + } //--------------------------------------------------------------- }