fix: almost working, physics is still broken
This commit is contained in:
parent
6a95fe7d3a
commit
0301d8af71
|
@ -5,6 +5,7 @@ import java.util.ArrayList;
|
||||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||||
|
import com.badlogic.gdx.math.MathUtils;
|
||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||||
|
|
||||||
|
@ -34,10 +35,13 @@ public class Arrow extends Actor {
|
||||||
*/
|
*/
|
||||||
Arrow(float angle, float power, Player shooter) {
|
Arrow(float angle, float power, Player shooter) {
|
||||||
super();
|
super();
|
||||||
this.setPosition(shooter.getX(), shooter.getY());
|
this.setPosition(shooter.getX() + shooter.getWidth() * MathUtils.cosDeg(shooter.getRotation()),
|
||||||
|
shooter.getY() + shooter.getWidth() * MathUtils.sinDeg(shooter.getRotation()));
|
||||||
this.velocity = new Vector2(power, 0).setAngleDeg(angle);
|
this.velocity = new Vector2(power, 0).setAngleDeg(angle);
|
||||||
this.acceleration = new Vector2();
|
this.acceleration = new Vector2();
|
||||||
this.force = computeForce();
|
this.force = computeForce();
|
||||||
|
this.setSize(100, 0);
|
||||||
|
this.setOrigin(50, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------- METHODs ----------
|
// ---------- METHODs ----------
|
||||||
|
@ -72,6 +76,10 @@ public class Arrow extends Actor {
|
||||||
this.TTL -= dt;
|
this.TTL -= dt;
|
||||||
this.setRotation(this.velocity.angleDeg());
|
this.setRotation(this.velocity.angleDeg());
|
||||||
|
|
||||||
|
if (TTL <= 0) {
|
||||||
|
GameScreen.arrows.removeActor(this);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -44,19 +44,20 @@ class Bow extends Actor {
|
||||||
computeArrow();
|
computeArrow();
|
||||||
} else if (pressed) {
|
} else if (pressed) {
|
||||||
// Sagittarius.arrowList.add(getArrow());
|
// Sagittarius.arrowList.add(getArrow());
|
||||||
|
GameScreen.arrows.addActor(getArrow());
|
||||||
pressed = false;
|
pressed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Generates an Arrow according to the Bow's attributes.
|
* Generates an Arrow according to the Bow's attributes.
|
||||||
// *
|
*
|
||||||
// * @return an Arrow.
|
* @return an Arrow.
|
||||||
// */
|
*/
|
||||||
// private Arrow getArrow() {
|
private Arrow getArrow() {
|
||||||
// return new Arrow(angle, power, shooter);
|
return new Arrow(angle, power, shooter);
|
||||||
// }
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts the Bow's attributes to apply it
|
* Converts the Bow's attributes to apply it
|
||||||
|
|
|
@ -17,8 +17,9 @@ public class GameScreen extends BaseScreen {
|
||||||
private static Vector3 unprojectedCursor;
|
private static Vector3 unprojectedCursor;
|
||||||
public static Vector2 worldCursor;
|
public static Vector2 worldCursor;
|
||||||
|
|
||||||
// planets = attractors for arrows
|
// Groups // TODO: move this in SagittariusGame ?
|
||||||
public static Group planets; // TODO: move this in SagittariusGame ?
|
public static Group planets;
|
||||||
|
public static Group arrows;
|
||||||
|
|
||||||
// ---------- METHODs ----------
|
// ---------- METHODs ----------
|
||||||
|
|
||||||
|
@ -40,12 +41,14 @@ public class GameScreen extends BaseScreen {
|
||||||
mainStage.addActor(planets);
|
mainStage.addActor(planets);
|
||||||
|
|
||||||
// players
|
// players
|
||||||
|
|
||||||
Player player1 = new Player(planet1, Color.WHITE);
|
Player player1 = new Player(planet1, Color.WHITE);
|
||||||
mainStage.addActor(player1);
|
mainStage.addActor(player1);
|
||||||
|
|
||||||
// others
|
// arrows
|
||||||
|
arrows = new Group();
|
||||||
|
mainStage.addActor(arrows);
|
||||||
|
|
||||||
|
// others
|
||||||
FPS fpsCounter = new FPS();
|
FPS fpsCounter = new FPS();
|
||||||
uiStage.addActor(fpsCounter);
|
uiStage.addActor(fpsCounter);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue