From 0942dae1de314281dd643d555d659510af03db0e Mon Sep 17 00:00:00 2001 From: Jonathan Hager Date: Wed, 3 Jun 2020 21:49:22 +0200 Subject: [PATCH] lol --- core/src/com/throwgame/main/ThrowMath.java | 18 ++++++++++++++++-- core/src/model/Level.java | 14 ++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/core/src/com/throwgame/main/ThrowMath.java b/core/src/com/throwgame/main/ThrowMath.java index 60484c7..70aebec 100644 --- a/core/src/com/throwgame/main/ThrowMath.java +++ b/core/src/com/throwgame/main/ThrowMath.java @@ -2,10 +2,13 @@ package com.throwgame.main; import com.badlogic.gdx.math.Vector2; +import model.Projectile; + public class ThrowMath { private double tanA; private double coefficient; private double y0; + private int xPos0; private boolean initialised; public ThrowMath(){ @@ -15,16 +18,17 @@ public class ThrowMath { this.initialised = false; } - public void initThrow(double alpha, double g, double v0, double y0){ + public void initThrow(double alpha, double g, double v0, double y0, int xPos0){ 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; } public int calculateY(int xPos){ if(this.initialised){ - double res = this.y0 + this.tanA * xPos - this.coefficient * Math.pow(xPos, 2); + double res = 1* (this.y0 + this.tanA * (xPos - this.xPos0) - this.coefficient * Math.pow((xPos - this.xPos0), 2)); return (int) res; } else{ @@ -33,6 +37,16 @@ public class ThrowMath { } } + public Vector2 test(Projectile projectile, double g){ + Vector2 lol = new Vector2(); + + lol.x = (int) (projectile.getxPos() + projectile.getvX()); + projectile.setvY(projectile.getvY() - g); + lol.y = (int) (projectile.getyPos() + projectile.getvY()); + + return lol; + } + public Vector2 pivotGetNewPos(double alpha, int xPosPivot, int yPosPivot, int radius){ Vector2 vector = new Vector2(); vector.x = (float) (radius * Math.sin(alpha)); diff --git a/core/src/model/Level.java b/core/src/model/Level.java index 50776ca..f453ecc 100644 --- a/core/src/model/Level.java +++ b/core/src/model/Level.java @@ -14,7 +14,7 @@ import com.throwgame.main.ThrowMath; * @author Jan */ public class Level { - private final double G = 9.81; + private final double G = 0.01; private final int RADIUS = 100; private Goal goal; @@ -43,7 +43,10 @@ public class Level { public void projectileReleased(){ this.isReleased = true; double v0 = angleSpeed * RADIUS; - this.math.initThrow(angle, G, v0, projectile.getyPos()); + this.math.initThrow(Math.PI / 2 + angle, G, v0, projectile.getyPos(), projectile.getxPos()); + //double tempAngle = angle + Math.PI / 2; + //projectile.setvX(v0 * Math.sin(tempAngle)); + //projectile.setvY(v0 * Math.cos(tempAngle)); } public void step(){ @@ -59,6 +62,8 @@ public class Level { angleSpeed += 0.0001; angle += angleSpeed; + System.out.println(Math.toDegrees(angle)); + Vector2 newPosVector = math.pivotGetNewPos(this.angle, this.xPosPivot, this.yPosPivot, RADIUS); this.projectile.setxPos(xPosPivot + (int) newPosVector.x); this.projectile.setyPos(yPosPivot + (int) newPosVector.y); @@ -67,6 +72,11 @@ public class Level { private void stepAir(){ projectile.setxPos(projectile.getxPos() + 1); projectile.setyPos(math.calculateY(projectile.getxPos())); + /*Vector2 lol = math.test(projectile, G); + projectile.setxPos((int) lol.x); + projectile.setyPos((int) lol.y); + System.out.println(projectile.getxPos() + " " + projectile.getyPos()); + */ } public Goal getGoal() {