feat: added Bow's aimAssist

This commit is contained in:
Laureηt 2021-04-06 12:58:27 +02:00
parent 9f58fa4a33
commit 64b487f80d
4 changed files with 36 additions and 5 deletions

View file

@ -1,5 +1,7 @@
package bzh.fainsin.sagittarius;
import java.util.ArrayList;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
@ -51,7 +53,7 @@ class Arrow extends Entity {
if (!this.hasLanded()) {
integrationVerlet(deltaTime);
this.TTL -= deltaTime;
this.angle = this.velocity.angleRad();
this.angle = this.velocity.angleDeg();
}
}
@ -61,6 +63,8 @@ class Arrow extends Entity {
// TODO : vectorialiser
// System.out.println(deltaTime);
this.acceleration = this.force.cpy();
this.position.x += deltaTime * ( this.velocity.x + deltaTime * this.acceleration.x / 2 );
@ -73,7 +77,7 @@ class Arrow extends Entity {
}
void render(ShapeRenderer shapeRenderer) {
Vector2 tail = new Vector2(-this.length, 0).rotateRad(this.angle).add(this.position);
Vector2 tail = new Vector2(-this.length, 0).rotateDeg(this.angle).add(this.position);
shapeRenderer.line(this.position, tail);
}
@ -90,4 +94,27 @@ class Arrow extends Entity {
}
}
// ---------- STATIC METHODs ----------
static float[] traj(float angle, float power, Player shooter, int iterations, float timeStep) {
ArrayList<Float> path = new ArrayList<Float>();
Arrow dummyArrow = new Arrow(angle, power, shooter);
for (int i = 0; i < iterations; i++) {
if (dummyArrow.hasLanded()) { break; }
dummyArrow.integrationVerlet(timeStep);
path.add(dummyArrow.position.x);
path.add(dummyArrow.position.y);
}
// TODO : optimize, lots of useless stuff
final float[] arr = new float[path.size()]; // TODO : min with 2, Exception in thread "main" java.lang.IllegalArgumentException: Polylines must contain at least 2 points.
int index = 0;
for (final Float value: path) {
arr[index++] = value;
}
return arr;
}
}

View file

@ -56,7 +56,10 @@ class Bow {
public void render(ShapeRenderer shapeRenderer) {
if (pressed) {
shapeRenderer.line(this.anchor, SagittariusGame.worldCursor);
//shapeRenderer.polyline(traj);
float[] traj = Arrow.traj(angle, power, shooter, 250, 0.05f);
if (traj.length > 2) {
shapeRenderer.polyline(traj);
}
}
}

View file

@ -93,6 +93,9 @@ class GameScreen extends ScreenAdapter {
arrow.render(shapeRenderer);
}
// float[] vertices = {100, 100, 200, 200, 1000, 500};
// shapeRenderer.polyline(vertices);
shapeRenderer.end();
// HUD

View file

@ -1,14 +1,12 @@
package bzh.fainsin.sagittarius;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Buttons;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.ui.Button;
class Player extends Entity {