diff --git a/README.md b/README.md index 7f7d58d..61522cd 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -entity.JumpGame +entities.JumpGame =============== diff --git a/src/main/java/Main.java b/src/main/java/Main.java index d29a70c..e91d4af 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,7 +1,5 @@ -import entity.Const; -import entity.Image2D; -import entity.Texture; -import entity.Vec2; +import entities.Const; +import entities.Vec2; import org.lwjgl.glfw.*; import org.lwjgl.opengl.*; import views.PlayerRenderer; diff --git a/src/main/java/entities/Acceleration.java b/src/main/java/entities/Acceleration.java new file mode 100644 index 0000000..68ee34c --- /dev/null +++ b/src/main/java/entities/Acceleration.java @@ -0,0 +1,42 @@ +package entities; + +public class Acceleration { + private double massValue; + private Pair forceValue; + private Velocity velocity; + private Onground onground; + private Pair value; + + 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)); + } + 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; + } +} \ No newline at end of file diff --git a/src/main/java/entities/Clear.java b/src/main/java/entities/Clear.java new file mode 100644 index 0000000..3f33d64 --- /dev/null +++ b/src/main/java/entities/Clear.java @@ -0,0 +1,19 @@ +package entities; + +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; + } +} \ No newline at end of file diff --git a/src/main/java/entities/Color.java b/src/main/java/entities/Color.java new file mode 100644 index 0000000..e7ae250 --- /dev/null +++ b/src/main/java/entities/Color.java @@ -0,0 +1,35 @@ +package entities; + +public class Color { + private float r; + private float g; + private float b; + private float a; + + //--------------------------------------------------------------- + //--------------------------------------------------------------- + public Color(float r, float g, float b, float a) { + this.r = r; + this.g = g; + this.b = b; + this.a = a; + } + + //--------------------------------------------------------------- + //--------------------------------------------------------------- + public float getR() { + return r; + } + + public float getG() { + return g; + } + + public float getB() { + return b; + } + + public float getA() { + return a; + } +} diff --git a/src/main/java/entities/Const.java b/src/main/java/entities/Const.java new file mode 100644 index 0000000..a45780f --- /dev/null +++ b/src/main/java/entities/Const.java @@ -0,0 +1,11 @@ +package entities; + +public class Const { + private Const() { + } + + public static final String TITLE_NAME = "JumpGame"; + public static final int WIDTH = 1280; + public static final int HEIGHT = 960; + public static final int DEPTH = 100; // 追加。深度 +} \ No newline at end of file diff --git a/src/main/java/entities/Force.java b/src/main/java/entities/Force.java new file mode 100644 index 0000000..9e74af0 --- /dev/null +++ b/src/main/java/entities/Force.java @@ -0,0 +1,19 @@ +package entities; + +public class Force { + private Acceleration acceleration; + private Pair value; + + 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 new file mode 100644 index 0000000..751be25 --- /dev/null +++ b/src/main/java/entities/Gameover.java @@ -0,0 +1,19 @@ +package entities; + +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; + } +} \ No newline at end of file diff --git a/src/main/java/entities/Ground.java b/src/main/java/entities/Ground.java new file mode 100644 index 0000000..58ab6f6 --- /dev/null +++ b/src/main/java/entities/Ground.java @@ -0,0 +1,9 @@ +package entities; + +public class Ground { + private boolean value; + + public boolean getValue() { + return value; + } +} \ No newline at end of file diff --git a/src/main/java/entities/Image2D.java b/src/main/java/entities/Image2D.java new file mode 100644 index 0000000..278530e --- /dev/null +++ b/src/main/java/entities/Image2D.java @@ -0,0 +1,96 @@ +package entities; + +import static org.lwjgl.opengl.GL11.*; + +//--------------------------------------------------------------- +// +public class Image2D { + + private int id; // テクスチャのID + private Vec2 wh; // スプライトの幅高 + private Vec2 position; // スプライトの座標(画面座標) + private Color color; // スプライトの色 + private double rotation; // 回転(度) + private double scale; // 拡大 + private double alpha; // 透明度 + + //--------------------------------------------------------------- + //--------------------------------------------------------------- + // + public Image2D(Texture tex, double x, double y) { + if (tex != null) + this.id = tex.getId(); + else + this.id = 0; + + this.position = new Vec2(x, y); + this.color = new Color(1, 1, 1, 1); + + if (tex != null) + wh = new Vec2(tex.getWidth(), tex.getHeight()); + else + wh = new Vec2(30, 30); + + rotation = 0.0; + scale = 1.0; + alpha = 1.0; + } + + //--------------------------------------------------------------- + //--------------------------------------------------------------- + // setter + public void setRotation(double rotation) { + this.rotation = rotation; + } + + //--------------------------------------------------------------- + //--------------------------------------------------------------- + // + public void draw() { + // テクスチャの結合 + glBindTexture(GL_TEXTURE_2D, id); + + // 変換行列の追加 + glPushMatrix(); + + // モデルビューモード + glMatrixMode(GL_MODELVIEW); + // 行列の設定 + glLoadIdentity(); // 単位行列化 + glTranslated(position.getX(), position.getY(), 0); // 移動 + glRotated(rotation, 0, 0, 1); // 回転 + glScaled(scale, scale, 1); // 拡縮 + + // プロジェクションモード + glMatrixMode(GL_PROJECTION); + // 行列の設定 + glLoadIdentity(); // 単位行列化 + glOrtho(0, Const.WIDTH, 0, Const.HEIGHT, -Const.DEPTH, Const.DEPTH); // 正射影投影 + + // ビューポートの範囲 + glViewport(0, 0, Const.WIDTH, Const.HEIGHT); + + // ポリゴンの色 + glColor4d(color.getR(), color.getG(), color.getB(), alpha); + + // ポリゴンの作成とテクスチャの適応 + glBegin(GL_TRIANGLE_STRIP); + glTexCoord2d(0, 0); + glVertex2d(-wh.getX() / 2, wh.getY() / 2); + glTexCoord2d(0, 1); + glVertex2d(-wh.getX() / 2, -wh.getY() / 2); + glTexCoord2d(1, 0); + glVertex2d(wh.getX() / 2, wh.getY() / 2); + glTexCoord2d(1, 1); + glVertex2d(wh.getX() / 2, -wh.getY() / 2); + glEnd(); + + // 行列の破棄 + glPopMatrix(); + + // テクスチャの解除 + glBindTexture(GL_TEXTURE_2D, 0); + } + + //--------------------------------------------------------------- +} \ No newline at end of file diff --git a/src/main/java/entities/JumpGame.java b/src/main/java/entities/JumpGame.java new file mode 100644 index 0000000..1f93c45 --- /dev/null +++ b/src/main/java/entities/JumpGame.java @@ -0,0 +1,76 @@ +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/Mass.java b/src/main/java/entities/Mass.java new file mode 100644 index 0000000..f7d4012 --- /dev/null +++ b/src/main/java/entities/Mass.java @@ -0,0 +1,19 @@ +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/Move.java b/src/main/java/entities/Move.java new file mode 100644 index 0000000..18a5b6d --- /dev/null +++ b/src/main/java/entities/Move.java @@ -0,0 +1,23 @@ +package entities; + +public class Move { + private Velocity velocity; + private Pair value; + + 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 new file mode 100644 index 0000000..6b58b90 --- /dev/null +++ b/src/main/java/entities/Onground.java @@ -0,0 +1,14 @@ +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/Pair.java b/src/main/java/entities/Pair.java new file mode 100644 index 0000000..4f17624 --- /dev/null +++ b/src/main/java/entities/Pair.java @@ -0,0 +1,19 @@ +package entities; + +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; + } +} diff --git a/src/main/java/entities/Position.java b/src/main/java/entities/Position.java new file mode 100644 index 0000000..0dd45c9 --- /dev/null +++ b/src/main/java/entities/Position.java @@ -0,0 +1,24 @@ +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))) { + 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 Pair getValue() { + return value; + } +} \ No newline at end of file diff --git a/src/main/java/entities/Texture.java b/src/main/java/entities/Texture.java new file mode 100644 index 0000000..7bfb9c6 --- /dev/null +++ b/src/main/java/entities/Texture.java @@ -0,0 +1,107 @@ +package entities; + +import static org.lwjgl.opengl.GL11.*; + +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.nio.ByteBuffer; +import javax.imageio.ImageIO; + +import org.lwjgl.BufferUtils; + +//--------------------------------------------------------------- +// +public class Texture { + + private int id; + private int width; + private int height; + private String name; + + //--------------------------------------------------------------- + //--------------------------------------------------------------- + public Texture(String name, String path) { + this.name = name; + BufferedImage bi; + try { + // イメージファイルの読み込み + bi = ImageIO.read(new File(path)); + width = bi.getWidth(); + height = bi.getHeight(); + + // ピクセルを保存する配列の用意 + int[] pixelsRaw; + pixelsRaw = bi.getRGB(0, 0, width, height, null, 0, width); + ByteBuffer pixels = BufferUtils.createByteBuffer(width * height * 4); + + // 一ピクセルずつ読み込む + for (int i = 0; i < height; ++i) { + for (int j = 0; j < width; ++j) { + int p = pixelsRaw[i * width + j]; + pixels.put((byte) ((p >> 16) & 0xFF)); + pixels.put((byte) ((p >> 8) & 0xFF)); + pixels.put((byte) (p & 0xFF)); + pixels.put((byte) ((p >> 24) & 0xFF)); + } + } + pixels.flip(); + + // テクスチャの作成 + id = glGenTextures(); // IDの取得 + glBindTexture(GL_TEXTURE_2D, id); // IDとテクスチャデータを結合 + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); // 作成 + + // テクスチャの設定 + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + + // テクスチャの解除 + glBindTexture(GL_TEXTURE_2D, 0); + + } catch (IOException e) { + e.printStackTrace(); + } + } + + //--------------------------------------------------------------- + //--------------------------------------------------------------- + public int getHeight() { + return height; + } + + //--------------------------------------------------------------- + public int getWidth() { + return width; + } + + //--------------------------------------------------------------- + public int getId() { + return id; + } + + //--------------------------------------------------------------- + public String getName() { + return name; + } + + //--------------------------------------------------------------- + //--------------------------------------------------------------- + // テクスチャの使用 + public void bind() { + glBindTexture(GL_TEXTURE_2D, id); + } + + //--------------------------------------------------------------- + // テクスチャの解除 + public void debind() { + glBindTexture(GL_TEXTURE_2D, 0); + } + + //--------------------------------------------------------------- + // テクスチャの破棄 + public void delete() { + glDeleteTextures(id); + } + //--------------------------------------------------------------- +} \ No newline at end of file diff --git a/src/main/java/entities/Time.java b/src/main/java/entities/Time.java new file mode 100644 index 0000000..f08de37 --- /dev/null +++ b/src/main/java/entities/Time.java @@ -0,0 +1,13 @@ +package entities; + +public class Time { + private double value; + + 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/Vec2.java b/src/main/java/entities/Vec2.java new file mode 100644 index 0000000..3d7b0cd --- /dev/null +++ b/src/main/java/entities/Vec2.java @@ -0,0 +1,22 @@ +package entities; + +//--------------------------------------------------------------- +public class Vec2 extends Pair { + + //--------------------------------------------------------------- + //--------------------------------------------------------------- + public Vec2(double x, double y) { + super(x, y); + } + + //--------------------------------------------------------------- + //--------------------------------------------------------------- + public Double getX() { + return this.getFirst(); + } + + public Double getY() { + return this.getSecond(); + } + //--------------------------------------------------------------- +} diff --git a/src/main/java/entities/Velocity.java b/src/main/java/entities/Velocity.java new file mode 100644 index 0000000..eee5e77 --- /dev/null +++ b/src/main/java/entities/Velocity.java @@ -0,0 +1,43 @@ +package entities; + + +public class Velocity { + private Pair moveValue; + private Pair accelerationValue; + private Position position; + private Onground onground; + private Pair value; + + 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/entity/Acceleration.java b/src/main/java/entity/Acceleration.java deleted file mode 100644 index 9c8c010..0000000 --- a/src/main/java/entity/Acceleration.java +++ /dev/null @@ -1,42 +0,0 @@ -package entity; - -public class Acceleration { - private double massValue; - private Pair forceValue; - private Velocity velocity; - private Onground onground; - private Pair value; - - 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)); - } - 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; - } -} \ No newline at end of file diff --git a/src/main/java/entity/Clear.java b/src/main/java/entity/Clear.java deleted file mode 100644 index 67e876d..0000000 --- a/src/main/java/entity/Clear.java +++ /dev/null @@ -1,19 +0,0 @@ -package entity; - -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; - } -} \ No newline at end of file diff --git a/src/main/java/entity/Color.java b/src/main/java/entity/Color.java deleted file mode 100644 index 06e9572..0000000 --- a/src/main/java/entity/Color.java +++ /dev/null @@ -1,35 +0,0 @@ -package entity; - -public class Color { - private float r; - private float g; - private float b; - private float a; - - //--------------------------------------------------------------- - //--------------------------------------------------------------- - public Color(float r, float g, float b, float a) { - this.r = r; - this.g = g; - this.b = b; - this.a = a; - } - - //--------------------------------------------------------------- - //--------------------------------------------------------------- - public float getR() { - return r; - } - - public float getG() { - return g; - } - - public float getB() { - return b; - } - - public float getA() { - return a; - } -} diff --git a/src/main/java/entity/Const.java b/src/main/java/entity/Const.java deleted file mode 100644 index a877fc9..0000000 --- a/src/main/java/entity/Const.java +++ /dev/null @@ -1,11 +0,0 @@ -package entity; - -public class Const { - private Const() { - } - - public static final String TITLE_NAME = "JumpGame"; - public static final int WIDTH = 1280; - public static final int HEIGHT = 960; - public static final int DEPTH = 100; // 追加。深度 -} \ No newline at end of file diff --git a/src/main/java/entity/Force.java b/src/main/java/entity/Force.java deleted file mode 100644 index ba219f0..0000000 --- a/src/main/java/entity/Force.java +++ /dev/null @@ -1,19 +0,0 @@ -package entity; - -public class Force { - private Acceleration acceleration; - private Pair value; - - 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/entity/Gameover.java b/src/main/java/entity/Gameover.java deleted file mode 100644 index da3eace..0000000 --- a/src/main/java/entity/Gameover.java +++ /dev/null @@ -1,19 +0,0 @@ -package entity; - -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; - } -} \ No newline at end of file diff --git a/src/main/java/entity/Ground.java b/src/main/java/entity/Ground.java deleted file mode 100644 index 461b542..0000000 --- a/src/main/java/entity/Ground.java +++ /dev/null @@ -1,9 +0,0 @@ -package entity; - -public class Ground { - private boolean value; - - public boolean getValue() { - return value; - } -} \ No newline at end of file diff --git a/src/main/java/entity/Image2D.java b/src/main/java/entity/Image2D.java deleted file mode 100644 index 1a54575..0000000 --- a/src/main/java/entity/Image2D.java +++ /dev/null @@ -1,96 +0,0 @@ -package entity; - -import static org.lwjgl.opengl.GL11.*; - -//--------------------------------------------------------------- -// -public class Image2D { - - private int id; // テクスチャのID - private Vec2 wh; // スプライトの幅高 - private Vec2 position; // スプライトの座標(画面座標) - private Color color; // スプライトの色 - private double rotation; // 回転(度) - private double scale; // 拡大 - private double alpha; // 透明度 - - //--------------------------------------------------------------- - //--------------------------------------------------------------- - // - public Image2D(Texture tex, double x, double y) { - if (tex != null) - this.id = tex.getId(); - else - this.id = 0; - - this.position = new Vec2(x, y); - this.color = new Color(1, 1, 1, 1); - - if (tex != null) - wh = new Vec2(tex.getWidth(), tex.getHeight()); - else - wh = new Vec2(30, 30); - - rotation = 0.0; - scale = 1.0; - alpha = 1.0; - } - - //--------------------------------------------------------------- - //--------------------------------------------------------------- - // setter - public void setRotation(double rotation) { - this.rotation = rotation; - } - - //--------------------------------------------------------------- - //--------------------------------------------------------------- - // - public void draw() { - // テクスチャの結合 - glBindTexture(GL_TEXTURE_2D, id); - - // 変換行列の追加 - glPushMatrix(); - - // モデルビューモード - glMatrixMode(GL_MODELVIEW); - // 行列の設定 - glLoadIdentity(); // 単位行列化 - glTranslated(position.getX(), position.getY(), 0); // 移動 - glRotated(rotation, 0, 0, 1); // 回転 - glScaled(scale, scale, 1); // 拡縮 - - // プロジェクションモード - glMatrixMode(GL_PROJECTION); - // 行列の設定 - glLoadIdentity(); // 単位行列化 - glOrtho(0, Const.WIDTH, 0, Const.HEIGHT, -Const.DEPTH, Const.DEPTH); // 正射影投影 - - // ビューポートの範囲 - glViewport(0, 0, Const.WIDTH, Const.HEIGHT); - - // ポリゴンの色 - glColor4d(color.getR(), color.getG(), color.getB(), alpha); - - // ポリゴンの作成とテクスチャの適応 - glBegin(GL_TRIANGLE_STRIP); - glTexCoord2d(0, 0); - glVertex2d(-wh.getX() / 2, wh.getY() / 2); - glTexCoord2d(0, 1); - glVertex2d(-wh.getX() / 2, -wh.getY() / 2); - glTexCoord2d(1, 0); - glVertex2d(wh.getX() / 2, wh.getY() / 2); - glTexCoord2d(1, 1); - glVertex2d(wh.getX() / 2, -wh.getY() / 2); - glEnd(); - - // 行列の破棄 - glPopMatrix(); - - // テクスチャの解除 - glBindTexture(GL_TEXTURE_2D, 0); - } - - //--------------------------------------------------------------- -} \ No newline at end of file diff --git a/src/main/java/entity/JumpGame.java b/src/main/java/entity/JumpGame.java deleted file mode 100644 index 0733d58..0000000 --- a/src/main/java/entity/JumpGame.java +++ /dev/null @@ -1,76 +0,0 @@ -package entity; - -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/entity/Mass.java b/src/main/java/entity/Mass.java deleted file mode 100644 index cb2bc08..0000000 --- a/src/main/java/entity/Mass.java +++ /dev/null @@ -1,19 +0,0 @@ -package entity; - -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/entity/Move.java b/src/main/java/entity/Move.java deleted file mode 100644 index 4eb80f0..0000000 --- a/src/main/java/entity/Move.java +++ /dev/null @@ -1,23 +0,0 @@ -package entity; - -public class Move { - private Velocity velocity; - private Pair value; - - 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/entity/Onground.java b/src/main/java/entity/Onground.java deleted file mode 100644 index 3dff7b1..0000000 --- a/src/main/java/entity/Onground.java +++ /dev/null @@ -1,14 +0,0 @@ -package entity; - -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/entity/Pair.java b/src/main/java/entity/Pair.java deleted file mode 100644 index 46b8a22..0000000 --- a/src/main/java/entity/Pair.java +++ /dev/null @@ -1,19 +0,0 @@ -package entity; - -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; - } -} diff --git a/src/main/java/entity/Position.java b/src/main/java/entity/Position.java deleted file mode 100644 index dfff747..0000000 --- a/src/main/java/entity/Position.java +++ /dev/null @@ -1,24 +0,0 @@ -package entity; - -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))) { - 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 Pair getValue() { - return value; - } -} \ No newline at end of file diff --git a/src/main/java/entity/Texture.java b/src/main/java/entity/Texture.java deleted file mode 100644 index 28a422e..0000000 --- a/src/main/java/entity/Texture.java +++ /dev/null @@ -1,107 +0,0 @@ -package entity; - -import static org.lwjgl.opengl.GL11.*; - -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.IOException; -import java.nio.ByteBuffer; -import javax.imageio.ImageIO; - -import org.lwjgl.BufferUtils; - -//--------------------------------------------------------------- -// -public class Texture { - - private int id; - private int width; - private int height; - private String name; - - //--------------------------------------------------------------- - //--------------------------------------------------------------- - public Texture(String name, String path) { - this.name = name; - BufferedImage bi; - try { - // イメージファイルの読み込み - bi = ImageIO.read(new File(path)); - width = bi.getWidth(); - height = bi.getHeight(); - - // ピクセルを保存する配列の用意 - int[] pixelsRaw; - pixelsRaw = bi.getRGB(0, 0, width, height, null, 0, width); - ByteBuffer pixels = BufferUtils.createByteBuffer(width * height * 4); - - // 一ピクセルずつ読み込む - for (int i = 0; i < height; ++i) { - for (int j = 0; j < width; ++j) { - int p = pixelsRaw[i * width + j]; - pixels.put((byte) ((p >> 16) & 0xFF)); - pixels.put((byte) ((p >> 8) & 0xFF)); - pixels.put((byte) (p & 0xFF)); - pixels.put((byte) ((p >> 24) & 0xFF)); - } - } - pixels.flip(); - - // テクスチャの作成 - id = glGenTextures(); // IDの取得 - glBindTexture(GL_TEXTURE_2D, id); // IDとテクスチャデータを結合 - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); // 作成 - - // テクスチャの設定 - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - - // テクスチャの解除 - glBindTexture(GL_TEXTURE_2D, 0); - - } catch (IOException e) { - e.printStackTrace(); - } - } - - //--------------------------------------------------------------- - //--------------------------------------------------------------- - public int getHeight() { - return height; - } - - //--------------------------------------------------------------- - public int getWidth() { - return width; - } - - //--------------------------------------------------------------- - public int getId() { - return id; - } - - //--------------------------------------------------------------- - public String getName() { - return name; - } - - //--------------------------------------------------------------- - //--------------------------------------------------------------- - // テクスチャの使用 - public void bind() { - glBindTexture(GL_TEXTURE_2D, id); - } - - //--------------------------------------------------------------- - // テクスチャの解除 - public void debind() { - glBindTexture(GL_TEXTURE_2D, 0); - } - - //--------------------------------------------------------------- - // テクスチャの破棄 - public void delete() { - glDeleteTextures(id); - } - //--------------------------------------------------------------- -} \ No newline at end of file diff --git a/src/main/java/entity/Time.java b/src/main/java/entity/Time.java deleted file mode 100644 index 4765f75..0000000 --- a/src/main/java/entity/Time.java +++ /dev/null @@ -1,13 +0,0 @@ -package entity; - -public class Time { - private double value; - - 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/entity/Vec2.java b/src/main/java/entity/Vec2.java deleted file mode 100644 index 5c893f3..0000000 --- a/src/main/java/entity/Vec2.java +++ /dev/null @@ -1,22 +0,0 @@ -package entity; - -//--------------------------------------------------------------- -public class Vec2 extends Pair { - - //--------------------------------------------------------------- - //--------------------------------------------------------------- - public Vec2(double x, double y) { - super(x, y); - } - - //--------------------------------------------------------------- - //--------------------------------------------------------------- - public Double getX() { - return this.getFirst(); - } - - public Double getY() { - return this.getSecond(); - } - //--------------------------------------------------------------- -} diff --git a/src/main/java/entity/Velocity.java b/src/main/java/entity/Velocity.java deleted file mode 100644 index 98130b8..0000000 --- a/src/main/java/entity/Velocity.java +++ /dev/null @@ -1,43 +0,0 @@ -package entity; - - -public class Velocity { - private Pair moveValue; - private Pair accelerationValue; - private Position position; - private Onground onground; - private Pair value; - - 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/views/PlayerRenderer.java b/src/main/java/views/PlayerRenderer.java index 3526444..68e359b 100644 --- a/src/main/java/views/PlayerRenderer.java +++ b/src/main/java/views/PlayerRenderer.java @@ -1,14 +1,8 @@ package views; -import entity.Image2D; -import entity.Texture; -import entity.Vec2; - -import java.awt.*; - -import static org.lwjgl.glfw.GLFW.glfwMakeContextCurrent; -import static org.lwjgl.opengl.GL11.*; -import static org.lwjgl.opengl.GL11C.glEnable; +import entities.Image2D; +import entities.Texture; +import entities.Vec2; //--------------------------------------------------------------- //