Merge pull request #19 from nitta-lab/feature/#16_scroll_ground
Feature/#16 scroll ground
commit 24fdf36429bf0cc1edbc355d8a580a47355b1592
2 parents fca060f + d96fc79
fujii kouta authored on 18 Nov 2021
Showing 26 changed files
View
29
src/main/java/JumpGame.java
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<IView> views = new ArrayList<>();
private ArrayList<IModel> 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"));
}
// 更新処理
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の更新
//
View
48
src/main/java/entities/Acceleration.java 100644 → 0
package entities;
 
public class Acceleration {
private double massValue = 1.0;
private Pair<Double> forceValue = new Pair<>(0d, 0d);
private Velocity velocity;
private Onground onground;
private Pair<Double> value = new Pair<>(0d, 0d);
 
//---------------------------------------------------------------
//
public void updateByMass(double mass) {
this.massValue = mass;
Pair<Double> 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<Double> force) {
this.forceValue = force;
Pair<Double> 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<Double> getValue() {
return value;
}
}
View
2
■■■
src/main/java/entities/Clear.java
package entities;
 
import entities.player.Position;
 
public class Clear {
private Position position;
 
View
19
src/main/java/entities/Force.java 100644 → 0
package entities;
 
public class Force {
private Acceleration acceleration;
private Pair<Double> 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<Double> getValue() {
return value;
}
}
View
2
■■■
src/main/java/entities/Gameover.java
package entities;
 
import entities.player.Position;
 
public class Gameover {
private Position position;
 
View
19
src/main/java/entities/Mass.java 100644 → 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;
}
}
View
18
src/main/java/entities/ModelType.java 100644 → 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() {
 
}
//---------------------------------------------------------------
}
View
23
src/main/java/entities/Move.java 100644 → 0
package entities;
 
public class Move {
private Velocity velocity;
private Pair<Double> 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<Double> getValue() {
return value;
}
}
View
14
src/main/java/entities/Onground.java 100644 → 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)); }
}
View
42
src/main/java/entities/Position.java 100644 → 0
package entities;
 
//---------------------------------------------------------------
//
public class Position {
private Ground ground;
private Pair<Double> value = new Pair<>(0d, 0d);
 
//---------------------------------------------------------------
//---------------------------------------------------------------
//
public void updateByVelocity(Pair<Double> velocity) {
Pair<Double> 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<Double> value, Ground ground) {
this.value = value;
this.ground = ground;
}
 
//---------------------------------------------------------------
//---------------------------------------------------------------
// getter
public Pair<Double> getValue() {
return value;
}
}
View
10
src/main/java/entities/Sprite.java
//---------------------------------------------------------------
//
public class Sprite {
 
private Texture texture;
private Image2D img;
private Pair<Double> positionValue;
private double scaleValue;
private Texture texture;
private Image2D img;
 
//---------------------------------------------------------------
//---------------------------------------------------------------
//
 
//---------------------------------------------------------------
//---------------------------------------------------------------
// getter
public double getScaleValue(){
public double getScaleValue() {
return this.scaleValue;
}
 
public Pair<Double> getPositionValue() {
return this.positionValue;
}
 
//---------------------------------------------------------------
// setter
View
src/main/java/entities/Velocity.java 100644 → 0
View
src/main/java/entities/player/Acceleration.java 0 → 100644
View
src/main/java/entities/player/Force.java 0 → 100644
View
src/main/java/entities/player/Mass.java 0 → 100644
View
src/main/java/entities/player/Move.java 0 → 100644
View
src/main/java/entities/player/Onground.java 0 → 100644
View
src/main/java/entities/player/Position.java 0 → 100644
View
src/main/java/entities/player/Velocity.java 0 → 100644
View
src/main/java/models/GroundModel.java 100644 → 0
View
src/main/java/models/JumpGameModel.java 0 → 100644
View
src/main/java/models/PlayerModel.java 100644 → 0
View
src/main/java/views/IView.java
View
src/main/java/views/PlayerRenderer.java
View
src/main/java/views/TileMapRenderer.java
View
src/main/java/views/TileRenderer.java