fix: disabled pixmapping for arrow trajectory prediction

This commit is contained in:
Laureηt 2021-05-12 21:54:34 +02:00
parent 61924b85b6
commit e047063e7e
2 changed files with 23 additions and 21 deletions

View file

@ -41,7 +41,7 @@ public class Arrow extends EntityQuad {
* @param power power given to the Arrow by the Bow.
* @param shooter Bow's shooter.
*/
Arrow(float angle, float power, Player shooter) {
Arrow(float angle, float power, Player shooter, boolean preview) {
super(0, 1, shooter.getColor(), shooter.getPosition());
this.velocity = new Vector2(power, 0).setAngleDeg(angle);
this.acceleration = new Vector2();
@ -49,27 +49,29 @@ public class Arrow extends EntityQuad {
this.setSize(100, 4);
this.force = computeForce();
this.landed = false;
Random random = new Random();
Pixmap pm = new Pixmap(new FileHandle("core/assets/arrow" + (random.nextInt(2) + 1) + ".png"));
pm.setBlending(Pixmap.Blending.None);
for (int x = 0; x < pm.getWidth(); x++) {
for (int y = 0; y < pm.getHeight(); y++) {
Color pc = new Color();
Color.rgba8888ToColor(pc, pm.getPixel(x, y));
if (pc.r == 1 && pc.g == 1 && pc.b == 1) {
pc.r = getColor().r;
pc.g = getColor().g;
pc.b = getColor().b;
if (!preview) {
Random random = new Random();
Pixmap pm = new Pixmap(new FileHandle("core/assets/arrow" + (random.nextInt(2) + 1) + ".png"));
pm.setBlending(Pixmap.Blending.None);
for (int x = 0; x < pm.getWidth(); x++) {
for (int y = 0; y < pm.getHeight(); y++) {
Color pc = new Color();
Color.rgba8888ToColor(pc, pm.getPixel(x, y));
if (pc.r == 1 && pc.g == 1 && pc.b == 1) {
pc.r = getColor().r;
pc.g = getColor().g;
pc.b = getColor().b;
}
pm.drawPixel(x, y, Color.rgba8888(pc));
}
pm.drawPixel(x, y, Color.rgba8888(pc));
}
texture = new Texture(pm);
}
texture = new Texture(pm);
}
// ---------- METHODs ----------
@ -215,7 +217,7 @@ public class Arrow extends EntityQuad {
*/
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);
Arrow dummyArrow = new Arrow(angle, power, shooter, true);
for (int i = 0; i < iterations; i++) {
dummyArrow.integrationVerlet(timeStep);
path.add(dummyArrow.getX());

View file

@ -45,7 +45,7 @@ public class Bow extends Actor {
} else if (pressed && power > 50) {
pressed = false;
GameScreen.playerCurrent.setActive(false);
Arrow arrowShot = new Arrow(angle, power, GameScreen.playerCurrent);
Arrow arrowShot = new Arrow(angle, power, GameScreen.playerCurrent, false);
GameScreen.setFocus(arrowShot); // do not use constructor 2 times
GameScreen.arrows.addActor(arrowShot);
} else {