Jonathan Hager 6 years ago
parent fee0678d59
commit 4971f42fe2

@ -8,7 +8,9 @@ public class ThrowMath {
private double tanA;
private double coefficient;
private double y0;
private int xPos0;
private double xPos0;
private double v;
private double vX;
private boolean initialised;
public ThrowMath(){
@ -18,25 +20,43 @@ public class ThrowMath {
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.coefficient = g / (2 * Math.pow(v0, 2) * Math.pow(Math.cos(alpha), 2));
this.y0 = y0;
this.initialised = true;
this.xPos0 = xPos0;
this.vX = vX;
}
public int calculateY(int xPos){
public Vector2 calculateY(double xPos){
if(this.initialised){
double res = 1* (this.y0 + this.tanA * (xPos - this.xPos0) - this.coefficient * Math.pow((xPos - this.xPos0), 2));
return (int) res;
Vector2 newPos = new Vector2();
//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{
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){
Vector2 lol = new Vector2();

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

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

@ -5,16 +5,10 @@
*/
package view;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
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.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Rectangle;
import model.Goal;
import model.Level;
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() + 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.circle(p.getxPos(), p.getyPos(), p.getRadius());
shapeRenderer.circle((float) p.getxPos(), (float) p.getyPos(), p.getRadius());
shapeRenderer.setColor(Color.GRAY);
shapeRenderer.circle(pivotX, pivotY, 5);
shapeRenderer.end();

Loading…
Cancel
Save