Jonathan Hager 6 years ago
parent fee0678d59
commit 4971f42fe2

@ -8,7 +8,9 @@ public class ThrowMath {
private double tanA; private double tanA;
private double coefficient; private double coefficient;
private double y0; private double y0;
private int xPos0; private double xPos0;
private double v;
private double vX;
private boolean initialised; private boolean initialised;
public ThrowMath(){ public ThrowMath(){
@ -18,25 +20,43 @@ public class ThrowMath {
this.initialised = false; this.initialised = false;
} }
public void initThrow(double alpha, double g, double v0, double y0, int xPos0){ public void initThrow(double alpha, double g, double v0, double y0, double xPos0, double vX){
this.tanA = Math.tan(alpha); this.tanA = Math.tan(alpha);
this.coefficient = g / (2 * Math.pow(v0, 2) * Math.pow(Math.cos(alpha), 2)); this.coefficient = g / (2 * Math.pow(v0, 2) * Math.pow(Math.cos(alpha), 2));
this.y0 = y0; this.y0 = y0;
this.initialised = true; this.initialised = true;
this.xPos0 = xPos0; this.xPos0 = xPos0;
this.vX = vX;
} }
public int calculateY(int xPos){ public Vector2 calculateY(double xPos){
if(this.initialised){ if(this.initialised){
double res = 1* (this.y0 + this.tanA * (xPos - this.xPos0) - this.coefficient * Math.pow((xPos - this.xPos0), 2)); Vector2 newPos = new Vector2();
return (int) res;
//this.v = getV(xPos);
//System.out.println("V: " + this.v);
double newXPos = (xPos + this.vX);
newPos.x = (float) newXPos;
double newYPos = 1* (this.y0 + this.tanA * (newXPos - this.xPos0) - this.coefficient * Math.pow((newXPos - this.xPos0), 2));
//System.out.println("Neue x: Position " + newXPos);
//System.out.println("Neue y: Position " + newYPos);
newPos.y = (float) newYPos;
return newPos;
} }
else{ else{
System.out.println("Der Wurf wurde nicht initialisiert!"); System.out.println("Der Wurf wurde nicht initialisiert!");
return -1; return new Vector2();
} }
} }
public double getV(double xPos){
double v = 1* (this.tanA - this.coefficient * 2 * (xPos - this.xPos0));
return v;
}
public Vector2 test(Projectile projectile, double g){ public Vector2 test(Projectile projectile, double g){
Vector2 lol = new Vector2(); Vector2 lol = new Vector2();

@ -5,7 +5,6 @@
*/ */
package model; package model;
import com.badlogic.gdx.math.Circle;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
import com.throwgame.main.ThrowMath; import com.throwgame.main.ThrowMath;
@ -14,7 +13,7 @@ import com.throwgame.main.ThrowMath;
* @author Jan * @author Jan
*/ */
public class Level { public class Level {
private final double G = 0.01; private final double G = 0.05;
private final int RADIUS = 100; private final int RADIUS = 100;
private Goal goal; private Goal goal;
@ -43,8 +42,9 @@ public class Level {
public void projectileReleased(){ public void projectileReleased(){
this.isReleased = true; this.isReleased = true;
double v0 = angleSpeed * RADIUS; double v0 = angleSpeed * RADIUS;
this.math.initThrow(Math.PI / 2 + angle, G, v0, projectile.getyPos(), projectile.getxPos()); double tempAngle = angle - Math.PI / 2;
//double tempAngle = angle + Math.PI / 2; double vX = v0 * Math.sin(tempAngle);
this.math.initThrow(Math.PI / 2 + angle, G, v0, projectile.getyPos(), projectile.getxPos(), vX);
//projectile.setvX(v0 * Math.sin(tempAngle)); //projectile.setvX(v0 * Math.sin(tempAngle));
//projectile.setvY(v0 * Math.cos(tempAngle)); //projectile.setvY(v0 * Math.cos(tempAngle));
} }
@ -60,7 +60,7 @@ public class Level {
private void stepPivot(){ private void stepPivot(){
angleSpeed += 0.0001; angleSpeed += 0.0001;
angle += angleSpeed; angle -= angleSpeed;
System.out.println(Math.toDegrees(angle)); System.out.println(Math.toDegrees(angle));
@ -70,8 +70,9 @@ public class Level {
} }
private void stepAir(){ private void stepAir(){
projectile.setxPos(projectile.getxPos() + 1); Vector2 newPos = math.calculateY(projectile.getxPos());
projectile.setyPos(math.calculateY(projectile.getxPos())); projectile.setxPos(newPos.x);
projectile.setyPos(newPos.y);
/*Vector2 lol = math.test(projectile, G); /*Vector2 lol = math.test(projectile, G);
projectile.setxPos((int) lol.x); projectile.setxPos((int) lol.x);
projectile.setyPos((int) lol.y); projectile.setyPos((int) lol.y);

@ -2,8 +2,8 @@ package model;
public class Projectile { public class Projectile {
private int xPos; private double xPos;
private int yPos; private double yPos;
private int mass; private int mass;
private int radius; private int radius;
private double vX; private double vX;
@ -25,19 +25,19 @@ public class Projectile {
} }
} }
public int getxPos() { public double getxPos() {
return xPos; return xPos;
} }
public void setxPos(int xPos) { public void setxPos(double xPos) {
this.xPos = xPos; this.xPos = xPos;
} }
public int getyPos() { public double getyPos() {
return yPos; return yPos;
} }
public void setyPos(int yPos) { public void setyPos(double yPos) {
this.yPos = yPos; this.yPos = yPos;
} }

@ -5,16 +5,10 @@
*/ */
package view; package view;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Rectangle;
import model.Goal; import model.Goal;
import model.Level; import model.Level;
import model.Projectile; import model.Projectile;
@ -63,7 +57,7 @@ public class Gamescreen{
shapeRenderer.rect(g.getxPos(), g.getyPos(), 0.2f * g.getSizeX(), g.getSizeY()); shapeRenderer.rect(g.getxPos(), g.getyPos(), 0.2f * g.getSizeX(), g.getSizeY());
shapeRenderer.rect(g.getxPos() + 0.2f * g.getSizeX(), g.getyPos(), 0.6f * g.getSizeX(),0.2f * g.getSizeY()); shapeRenderer.rect(g.getxPos() + 0.2f * g.getSizeX(), g.getyPos(), 0.6f * g.getSizeX(),0.2f * g.getSizeY());
shapeRenderer.rect(g.getxPos() + 0.2f * g.getSizeX() + 0.6f * g.getSizeX(), g.getyPos(), 0.2f * g.getSizeX(),g.getSizeY()); shapeRenderer.rect(g.getxPos() + 0.2f * g.getSizeX() + 0.6f * g.getSizeX(), g.getyPos(), 0.2f * g.getSizeX(),g.getSizeY());
shapeRenderer.circle(p.getxPos(), p.getyPos(), p.getRadius()); shapeRenderer.circle((float) p.getxPos(), (float) p.getyPos(), p.getRadius());
shapeRenderer.setColor(Color.GRAY); shapeRenderer.setColor(Color.GRAY);
shapeRenderer.circle(pivotX, pivotY, 5); shapeRenderer.circle(pivotX, pivotY, 5);
shapeRenderer.end(); shapeRenderer.end();

Loading…
Cancel
Save