feat: used Entities instead of Actors

This commit is contained in:
Laureηt 2021-04-22 17:43:41 +02:00
parent 6cd727c09d
commit eb0a6a6253
8 changed files with 19 additions and 26 deletions

View file

@ -9,9 +9,7 @@ import com.badlogic.gdx.scenes.scene2d.Actor;
import sagittarius.SagittariusGame; import sagittarius.SagittariusGame;
import sagittarius.view.GameScreen; import sagittarius.view.GameScreen;
public class Arrow extends BaseActor { public class Arrow extends EntityQuad {
public static final float initTTL = 20;
// ---------- ATTRIBUTEs ---------- // ---------- ATTRIBUTEs ----------
@ -19,7 +17,7 @@ public class Arrow extends BaseActor {
private Vector2 acceleration; private Vector2 acceleration;
private Vector2 force; private Vector2 force;
private float TTL = initTTL; private float TTL = 20;
private boolean landed; private boolean landed;
private Planet crash; private Planet crash;
@ -35,8 +33,7 @@ public class Arrow extends BaseActor {
* @param shooter Bow's shooter. * @param shooter Bow's shooter.
*/ */
Arrow(float angle, float power, Player shooter) { Arrow(float angle, float power, Player shooter) {
super(); super(0, 1, shooter.getColor(), shooter.getPosition());
this.setPosition(shooter.getX(), shooter.getY());
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.setOrigin(80, 2); this.setOrigin(80, 2);
@ -49,7 +46,7 @@ public class Arrow extends BaseActor {
@Override @Override
public void act(float dt) { public void act(float dt) {
super.act(dt);
if (!landed) { if (!landed) {
integrationVerlet(dt); integrationVerlet(dt);
this.TTL -= dt; this.TTL -= dt;

View file

@ -23,8 +23,8 @@ public abstract class BaseActor extends Actor {
// ---------- METHODs ---------- // ---------- METHODs ----------
@Override @Override
public void act(float delta) { public void act(float dt) {
super.act(delta); super.act(dt);
hitbox.setVertices(test()); hitbox.setVertices(test());
} }

View file

@ -34,7 +34,7 @@ public class Bow extends Actor {
@Override @Override
public void act(float dt) { public void act(float dt) {
super.act(dt);
this.shooter = GameScreen.actualPlayer; this.shooter = GameScreen.actualPlayer;
// TODO: probably can do better with an eventListener // TODO: probably can do better with an eventListener

View file

@ -112,21 +112,20 @@ public abstract class Entity extends Actor {
protected abstract float[] getHitbox(); protected abstract float[] getHitbox();
@Override @Override
public void act(float delta) { public void act(float dt) {
super.act(delta); super.act(dt);
hitbox.setVertices(getHitbox()); hitbox.setVertices(getHitbox());
} }
@Override @Override
public void draw(Batch batch, float parentAlpha) { public void draw(Batch batch, float parentAlpha) {
super.draw(batch, parentAlpha); super.draw(batch, parentAlpha);
//if (getDebug()) if (getDebug()) fontDebug.draw(batch, getInfo(), getX(), getY());
fontDebug.draw(batch, getInfo(), getX(), getY());
} }
@Override @Override
protected void drawDebugBounds(ShapeRenderer shapes) { protected void drawDebugBounds(ShapeRenderer shapes) {
//if (!getDebug()) return; if (!getDebug()) return;
shapes.set(ShapeType.Line); shapes.set(ShapeType.Line);
if (getStage() != null) shapes.setColor(this.getColor()); if (getStage() != null) shapes.setColor(this.getColor());
shapes.polygon(hitbox.getVertices()); shapes.polygon(hitbox.getVertices());

View file

@ -17,8 +17,8 @@ public class FPS extends BaseActor {
} }
@Override @Override
public void act(float delta) { public void act(float dt) {
super.act(delta); super.act(dt);
frameRate = Gdx.graphics.getFramesPerSecond(); frameRate = Gdx.graphics.getFramesPerSecond();
} }

View file

@ -7,8 +7,8 @@ public class MouseInfo extends BaseActor {
// ---------- METHODs ---------- // ---------- METHODs ----------
@Override @Override
public void act(float delta) { public void act(float dt) {
super.act(delta); super.act(dt);
setX(GameScreen.worldCursor.x); // use direct method setX(GameScreen.worldCursor.x); // use direct method
setY(GameScreen.worldCursor.y); setY(GameScreen.worldCursor.y);
} }

View file

@ -6,7 +6,7 @@ import com.badlogic.gdx.graphics.Color;
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.MathUtils;
public class Player extends BaseActor { public class Player extends EntityQuad {
// ---------- ATTRIBUTEs ---------- // ---------- ATTRIBUTEs ----------
@ -16,14 +16,11 @@ public class Player extends BaseActor {
// ---------- CONSTRUCTORs ---------- // ---------- CONSTRUCTORs ----------
public Player(Planet home, Color color) { public Player(Planet home, Color color) {
super(); super(MathUtils.random(360), 0, color, home.getPosition());
this.setRotation(angle-90);
this.setSize(50, 100); this.setSize(50, 100);
this.setOrigin(getWidth()/2, getHeight()/2); this.setOrigin(getWidth()/2, getHeight()/2);
this.setColor(color);
this.angle = MathUtils.random(360);
this.setRotation(angle-90);
this.home = home; this.home = home;
} }

View file

@ -48,7 +48,7 @@ public class GameScreen extends BaseScreen {
// players // players
players = new Group(); players = new Group();
Player player1 = new Player(planet1, Color.WHITE); Player player1 = new Player(planet1, Color.RED);
players.addActor(player1); players.addActor(player1);
Player player2 = new Player(planet2, Color.WHITE); Player player2 = new Player(planet2, Color.WHITE);