Added some shit

master
Jonathan Hager 6 years ago
parent 7e130888ed
commit 89a4b5aaa7

@ -1,5 +1,7 @@
package com.throwgame.main;
import com.badlogic.gdx.math.Vector2;
public class ThrowMath {
private double tanA;
private double coefficient;
@ -30,4 +32,12 @@ public class ThrowMath {
return -1;
}
}
public Vector2 pivotGetNewPos(double alpha, int xPosPivot, int yPosPivot, int radius){
Vector2 vector = new Vector2();
vector.x = (float) (radius * Math.sin(alpha));
vector.y = (float) (radius * Math.cos(alpha));
return vector;
}
}

@ -5,6 +5,8 @@
*/
package model;
import com.badlogic.gdx.math.Circle;
import com.badlogic.gdx.math.Vector2;
import com.throwgame.main.ThrowMath;
/**
@ -12,23 +14,57 @@ import com.throwgame.main.ThrowMath;
* @author Jan
*/
public class Level {
private final double G = 9.81;
private final int RADIUS = 5;
private Goal goal;
private Projectile projectile;
private ThrowMath math;
private double angle;
private int xPosPivot;
private int yPosPivot;
private double angleSpeed;
private boolean isReleased;
public Level(Goal goal, Projectile projectile){
public Level(Goal goal, Projectile projectile, int xPosPivot, int yPosPivot){
this.goal = goal;
this.projectile = projectile;
this.math = new ThrowMath();
this.isReleased = false;
this.xPosPivot = xPosPivot;
this.yPosPivot = yPosPivot;
this.angle = 0;
this.angleSpeed = 0;
}
public void projectileReleased(){
this.isReleased = true;
double v0 = angleSpeed * RADIUS;
this.math.initThrow(angle, G, v0, projectile.getyPos());
}
public void step(){
if(this.isReleased){
stepAir();
}
else{
stepPivot();
}
}
private void stepPivot(){
angleSpeed += 0.1;
angle += angleSpeed;
Vector2 newPosVector = math.pivotGetNewPos(this.angle, this.xPosPivot, this.yPosPivot, RADIUS);
this.projectile.setxPos((int) newPosVector.x);
this.projectile.setyPos((int) newPosVector.y);
}
private void stepAir(){
projectile.setxPos(projectile.getxPos() + 1);
projectile.setyPos(math.calculateY(projectile.getxPos()));
}
public Goal getGoal() {

Loading…
Cancel
Save