diff --git a/src/Acceleration.java b/src/Acceleration.java index e44caaa..37babc8 100644 --- a/src/Acceleration.java +++ b/src/Acceleration.java @@ -1,23 +1,21 @@ -import java.util.*; - public class Acceleration { private double mass; - private Vector2 force; + private Pair force; private Velocity velocity; private Onground onground; - private Vector2 acceleration; + private Pair acceleration; public void updateMass(double mass) { this.mass = mass; - acceleration = (this.onground.getOnground() ? new AbstractMap.SimpleEntry<>((force.getKey() / mass), 0.0) - : new Vector2((force.getX() / mass), (force.getY() / mass))); + acceleration = (this.onground.getOnground() ? new Pair<>((force.getX() / mass), 0.0) + : new Pair<>((force.getX() / mass), (force.getY() / mass))); velocity.updateAcceleration(acceleration); } - public void updateForce(Vector2 force) { + public void updateForce(Pair force) { this.force = force; - acceleration = (this.onground.getOnground() ? new Vector2((force.getX() / mass), 0.0) - : new Vector2((force.getX() / mass), (force.getY() / mass))); + acceleration = (this.onground.getOnground() ? new Pair<>((force.getX() / mass), 0.0) + : new Pair<>((force.getX() / mass), (force.getY() / mass))); velocity.updateAcceleration(acceleration); } @@ -26,7 +24,7 @@ this.onground = onground; } - public Vector2 getAcceleration() { + public Pair getAcceleration() { return acceleration; } } \ No newline at end of file diff --git a/src/Force.java b/src/Force.java index ea94daa..a2aa9b3 100644 --- a/src/Force.java +++ b/src/Force.java @@ -1,8 +1,6 @@ -import java.util.*; - public class Force { private Acceleration acceleration; - private Vector2 force; + private Pair force; public Force(Acceleration acceleration) { this.acceleration = acceleration; @@ -13,7 +11,7 @@ acceleration.updateForce(force); } - public Vector2 getForce() { + public Pair getForce() { return force; } } \ No newline at end of file diff --git a/src/JumpGame.java b/src/JumpGame.java index 33afe0a..70f05c7 100644 --- a/src/JumpGame.java +++ b/src/JumpGame.java @@ -1,5 +1,3 @@ -import java.util.*; - public class JumpGame { private Time time = new Time(); private Position position = new Position(); @@ -30,11 +28,11 @@ this.mass.setMass(x); } - public Vector2 getAcceleration() { + public Pair getAcceleration() { return acceleration.getAcceleration(); } - public Map.Entry getMove() { + public Pair getMove() { return move.getMove(); } @@ -50,15 +48,15 @@ return ground.getGround(); } - public Vector2 getForce() { + public Pair getForce() { return force.getForce(); } - public Vector2 getVelocity() { + public Pair getVelocity() { return velocity.getVelocity(); } - public Vector2 getPosition() { + public Pair getPosition() { return position.getPosition(); } diff --git a/src/Move.java b/src/Move.java index 2c56556..cbbcbc6 100644 --- a/src/Move.java +++ b/src/Move.java @@ -1,8 +1,6 @@ -import java.util.*; - public class Move { private Velocity velocity; - private Vector2 move; + private Pair move; public Move(Velocity velocity) { this.velocity = velocity; @@ -17,7 +15,7 @@ this.move.setX(x); } - public Vector2 getMove() { + public Pair getMove() { return move; } } \ No newline at end of file diff --git a/src/Pair.java b/src/Pair.java new file mode 100644 index 0000000..95f6959 --- /dev/null +++ b/src/Pair.java @@ -0,0 +1,26 @@ +// 2 dim +public class Pair { + private Type x; + private Type y; + + public Pair(Type x, Type y) { + this.x = x; + this.y = y; + } + + public void setX(Type x) { + this.x = x; + } + + public void setY(Type y) { + this.y = y; + } + + public Type getX() { + return (this.x); + } + + public Type getY() { + return (this.y); + } +} diff --git a/src/Position.java b/src/Position.java index a7652e0..f185b73 100644 --- a/src/Position.java +++ b/src/Position.java @@ -1,27 +1,25 @@ -import java.util.*; - public class Position { - private Vector2 velocity; + private Pair velocity; private boolean ground; - private Vector2 position; + private Pair position; - public void updateVelocity(Vector2 velocity) { + public void updateVelocity(Pair velocity) { this.velocity = velocity; position = (((ground == true) && ((this.position.getY() + (0.01 * velocity.getY())) < 0.0)) - ? new Vector2(this.position.getX() + (0.01 * velocity.getX()), 0.0) - : new Vector2(this.position.getX() + (0.01 * velocity.getX()), + ? new Pair<>(this.position.getX() + (0.01 * velocity.getX()), 0.0) + : new Pair<>(this.position.getX() + (0.01 * velocity.getX()), (this.position.getY() + (0.01 * velocity.getY())))); } public void updateGround(boolean ground) { this.ground = ground; position = (((ground == true) && ((this.position.getY() + (0.01 * velocity.getY())) < 0.0)) - ? new Vector2(this.position.getX() + (0.01 * velocity.getX()), 0.0) - : new Vector2(this.position.getX() + (0.01 * velocity.getX()), + ? new Pair<>(this.position.getX() + (0.01 * velocity.getX()), 0.0) + : new Pair<>(this.position.getX() + (0.01 * velocity.getX()), this.position.getY() + (0.01 * velocity.getY()))); } - public Vector2 getPosition() { + public Pair getPosition() { return position; } } \ No newline at end of file diff --git a/src/Vector2.java b/src/Vector2.java deleted file mode 100644 index 3763446..0000000 --- a/src/Vector2.java +++ /dev/null @@ -1,28 +0,0 @@ -import java.util.*; - -// 2 dim -public class Vector2 { - private double x; - private double y; - - public Vector2(double x, double y) { - this.x = x; - this.y = y; - } - - public void setX(double x) { - this.x = x; - } - - public void setY(double y) { - this.y = y; - } - - public double getX() { - return (this.x); - } - - public double getY() { - return (this.y); - } -} diff --git a/src/Velocity.java b/src/Velocity.java index 204d67c..28f5d90 100644 --- a/src/Velocity.java +++ b/src/Velocity.java @@ -1,22 +1,20 @@ -import java.util.*; - public class Velocity { - private Vector2 acceleration; - private Vector2 move; + private Pair acceleration; + private Pair move; private Position position; private Onground onground; - private Vector2 velocity; + private Pair velocity; - public void updateAcceleration(Vector2 acceleration) { + public void updateAcceleration(Pair acceleration) { this.acceleration = acceleration; velocity = ((this.onground.getOnground() && (this.velocity.getY() < 0.0)) - ? new Vector2(this.velocity.getX() + (0.01 * acceleration.getX()), 0.0) - : new Vector2(this.velocity.getX() + (0.01 * acceleration.getX()), + ? new Pair<>(this.velocity.getX() + (0.01 * acceleration.getX()), 0.0) + : new Pair<>(this.velocity.getX() + (0.01 * acceleration.getX()), (this.velocity.getY() + (0.01 * acceleration.getY())))); position.updateVelocity(velocity); } - public void updateMove(Vector2 move) { + public void updateMove(Pair move) { this.move = move; velocity = ((this.onground.getOnground() && (move.getY() >= 0.0)) ? move : this.velocity); position.updateVelocity(velocity); @@ -27,7 +25,7 @@ this.onground = onground; } - public Vector2 getVelocity() { + public Pair getVelocity() { return velocity; } } \ No newline at end of file