From eb0a6a62539f374ea0c61623178598cbd997c20b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laure=CE=B7t?= Date: Thu, 22 Apr 2021 17:43:41 +0200 Subject: [PATCH] feat: used Entities instead of Actors --- core/src/sagittarius/model/Arrow.java | 11 ++++------- core/src/sagittarius/model/BaseActor.java | 4 ++-- core/src/sagittarius/model/Bow.java | 2 +- core/src/sagittarius/model/Entity.java | 9 ++++----- core/src/sagittarius/model/FPS.java | 4 ++-- core/src/sagittarius/model/MouseInfo.java | 4 ++-- core/src/sagittarius/model/Player.java | 9 +++------ core/src/sagittarius/view/GameScreen.java | 2 +- 8 files changed, 19 insertions(+), 26 deletions(-) diff --git a/core/src/sagittarius/model/Arrow.java b/core/src/sagittarius/model/Arrow.java index 0172b1f..daf9b9b 100644 --- a/core/src/sagittarius/model/Arrow.java +++ b/core/src/sagittarius/model/Arrow.java @@ -9,9 +9,7 @@ import com.badlogic.gdx.scenes.scene2d.Actor; import sagittarius.SagittariusGame; import sagittarius.view.GameScreen; -public class Arrow extends BaseActor { - - public static final float initTTL = 20; +public class Arrow extends EntityQuad { // ---------- ATTRIBUTEs ---------- @@ -19,7 +17,7 @@ public class Arrow extends BaseActor { private Vector2 acceleration; private Vector2 force; - private float TTL = initTTL; + private float TTL = 20; private boolean landed; private Planet crash; @@ -35,8 +33,7 @@ public class Arrow extends BaseActor { * @param shooter Bow's shooter. */ Arrow(float angle, float power, Player shooter) { - super(); - this.setPosition(shooter.getX(), shooter.getY()); + super(0, 1, shooter.getColor(), shooter.getPosition()); this.velocity = new Vector2(power, 0).setAngleDeg(angle); this.acceleration = new Vector2(); this.setOrigin(80, 2); @@ -49,7 +46,7 @@ public class Arrow extends BaseActor { @Override public void act(float dt) { - + super.act(dt); if (!landed) { integrationVerlet(dt); this.TTL -= dt; diff --git a/core/src/sagittarius/model/BaseActor.java b/core/src/sagittarius/model/BaseActor.java index 5b3db67..1fb10ee 100644 --- a/core/src/sagittarius/model/BaseActor.java +++ b/core/src/sagittarius/model/BaseActor.java @@ -23,8 +23,8 @@ public abstract class BaseActor extends Actor { // ---------- METHODs ---------- @Override - public void act(float delta) { - super.act(delta); + public void act(float dt) { + super.act(dt); hitbox.setVertices(test()); } diff --git a/core/src/sagittarius/model/Bow.java b/core/src/sagittarius/model/Bow.java index 8769dba..3964b37 100644 --- a/core/src/sagittarius/model/Bow.java +++ b/core/src/sagittarius/model/Bow.java @@ -34,7 +34,7 @@ public class Bow extends Actor { @Override public void act(float dt) { - + super.act(dt); this.shooter = GameScreen.actualPlayer; // TODO: probably can do better with an eventListener diff --git a/core/src/sagittarius/model/Entity.java b/core/src/sagittarius/model/Entity.java index 54be816..17163ce 100644 --- a/core/src/sagittarius/model/Entity.java +++ b/core/src/sagittarius/model/Entity.java @@ -112,21 +112,20 @@ public abstract class Entity extends Actor { protected abstract float[] getHitbox(); @Override - public void act(float delta) { - super.act(delta); + public void act(float dt) { + super.act(dt); hitbox.setVertices(getHitbox()); } @Override public void draw(Batch batch, float parentAlpha) { super.draw(batch, parentAlpha); - //if (getDebug()) - fontDebug.draw(batch, getInfo(), getX(), getY()); + if (getDebug()) fontDebug.draw(batch, getInfo(), getX(), getY()); } @Override protected void drawDebugBounds(ShapeRenderer shapes) { - //if (!getDebug()) return; + if (!getDebug()) return; shapes.set(ShapeType.Line); if (getStage() != null) shapes.setColor(this.getColor()); shapes.polygon(hitbox.getVertices()); diff --git a/core/src/sagittarius/model/FPS.java b/core/src/sagittarius/model/FPS.java index f98ec9c..496bb3e 100644 --- a/core/src/sagittarius/model/FPS.java +++ b/core/src/sagittarius/model/FPS.java @@ -17,8 +17,8 @@ public class FPS extends BaseActor { } @Override - public void act(float delta) { - super.act(delta); + public void act(float dt) { + super.act(dt); frameRate = Gdx.graphics.getFramesPerSecond(); } diff --git a/core/src/sagittarius/model/MouseInfo.java b/core/src/sagittarius/model/MouseInfo.java index 851a829..025d9ba 100644 --- a/core/src/sagittarius/model/MouseInfo.java +++ b/core/src/sagittarius/model/MouseInfo.java @@ -7,8 +7,8 @@ public class MouseInfo extends BaseActor { // ---------- METHODs ---------- @Override - public void act(float delta) { - super.act(delta); + public void act(float dt) { + super.act(dt); setX(GameScreen.worldCursor.x); // use direct method setY(GameScreen.worldCursor.y); } diff --git a/core/src/sagittarius/model/Player.java b/core/src/sagittarius/model/Player.java index da85f7d..fc4ab48 100644 --- a/core/src/sagittarius/model/Player.java +++ b/core/src/sagittarius/model/Player.java @@ -6,7 +6,7 @@ import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.math.MathUtils; -public class Player extends BaseActor { +public class Player extends EntityQuad { // ---------- ATTRIBUTEs ---------- @@ -16,14 +16,11 @@ public class Player extends BaseActor { // ---------- CONSTRUCTORs ---------- public Player(Planet home, Color color) { - super(); + super(MathUtils.random(360), 0, color, home.getPosition()); + this.setRotation(angle-90); this.setSize(50, 100); this.setOrigin(getWidth()/2, getHeight()/2); - this.setColor(color); - - this.angle = MathUtils.random(360); - this.setRotation(angle-90); this.home = home; } diff --git a/core/src/sagittarius/view/GameScreen.java b/core/src/sagittarius/view/GameScreen.java index e1269ad..105fd82 100644 --- a/core/src/sagittarius/view/GameScreen.java +++ b/core/src/sagittarius/view/GameScreen.java @@ -48,7 +48,7 @@ public class GameScreen extends BaseScreen { // players players = new Group(); - Player player1 = new Player(planet1, Color.WHITE); + Player player1 = new Player(planet1, Color.RED); players.addActor(player1); Player player2 = new Player(planet2, Color.WHITE);