From 0301d8af719da2199d976f71b89b6764f1a55e50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laure=CE=B7t?= Date: Fri, 9 Apr 2021 16:45:43 +0200 Subject: [PATCH] fix: almost working, physics is still broken --- core/src/sagittarius/model/Arrow.java | 10 +++++++++- core/src/sagittarius/model/Bow.java | 17 +++++++++-------- core/src/sagittarius/view/GameScreen.java | 11 +++++++---- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/core/src/sagittarius/model/Arrow.java b/core/src/sagittarius/model/Arrow.java index 880eb0f..b1caf52 100644 --- a/core/src/sagittarius/model/Arrow.java +++ b/core/src/sagittarius/model/Arrow.java @@ -5,6 +5,7 @@ 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; +import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.scenes.scene2d.Actor; @@ -34,10 +35,13 @@ public class Arrow extends Actor { */ Arrow(float angle, float power, Player shooter) { 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.acceleration = new Vector2(); this.force = computeForce(); + this.setSize(100, 0); + this.setOrigin(50, 0); } // ---------- METHODs ---------- @@ -72,6 +76,10 @@ public class Arrow extends Actor { this.TTL -= dt; this.setRotation(this.velocity.angleDeg()); + if (TTL <= 0) { + GameScreen.arrows.removeActor(this); + } + } /** diff --git a/core/src/sagittarius/model/Bow.java b/core/src/sagittarius/model/Bow.java index 2782455..67378b0 100644 --- a/core/src/sagittarius/model/Bow.java +++ b/core/src/sagittarius/model/Bow.java @@ -44,19 +44,20 @@ class Bow extends Actor { computeArrow(); } else if (pressed) { // Sagittarius.arrowList.add(getArrow()); + GameScreen.arrows.addActor(getArrow()); pressed = false; } } - // /** - // * Generates an Arrow according to the Bow's attributes. - // * - // * @return an Arrow. - // */ - // private Arrow getArrow() { - // return new Arrow(angle, power, shooter); - // } + /** + * Generates an Arrow according to the Bow's attributes. + * + * @return an Arrow. + */ + private Arrow getArrow() { + return new Arrow(angle, power, shooter); + } /** * Converts the Bow's attributes to apply it diff --git a/core/src/sagittarius/view/GameScreen.java b/core/src/sagittarius/view/GameScreen.java index 9846f30..87d3092 100644 --- a/core/src/sagittarius/view/GameScreen.java +++ b/core/src/sagittarius/view/GameScreen.java @@ -17,8 +17,9 @@ public class GameScreen extends BaseScreen { private static Vector3 unprojectedCursor; public static Vector2 worldCursor; - // planets = attractors for arrows - public static Group planets; // TODO: move this in SagittariusGame ? + // Groups // TODO: move this in SagittariusGame ? + public static Group planets; + public static Group arrows; // ---------- METHODs ---------- @@ -40,12 +41,14 @@ public class GameScreen extends BaseScreen { mainStage.addActor(planets); // players - Player player1 = new Player(planet1, Color.WHITE); mainStage.addActor(player1); - // others + // arrows + arrows = new Group(); + mainStage.addActor(arrows); + // others FPS fpsCounter = new FPS(); uiStage.addActor(fpsCounter);