From f9c1f258bc3cb4e918e5c397879b2b377b8bff7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laure=CE=B7t?= Date: Sat, 10 Apr 2021 12:22:48 +0200 Subject: [PATCH] fix: arrow position --- README.md | 17 +++++----- core/src/sagittarius/model/Arrow.java | 28 +++++++++++++++-- core/src/sagittarius/model/Moon.java | 38 ++++++++++++++++++++--- core/src/sagittarius/model/Planet.java | 18 ++++++++--- core/src/sagittarius/model/Player.java | 2 +- core/src/sagittarius/view/GameScreen.java | 4 +-- 6 files changed, 84 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 39ca93e..1d89b13 100644 --- a/README.md +++ b/README.md @@ -25,15 +25,14 @@ To export the game to a .jar file: The resulting .jar files should be in `*/build/libs/` ## TODO LIST -1. player turn -2. kill player -3. move freely camera -4. lerp camera arrow -5. event based shit -6. menus test -7. améliorer trajectoires arrows en simulant tout n'univers -8. rotating planets and moons (on themselves) -9. faire des sous-packages, sgittarius.modele, sagittarius.view, saggitarius.control ... +* create BaseActor to concatenate code +* player turn +* kill player +* move freely camera +* lerp camera arrow +* menus test +* améliorer trajectoires arrows en simulant tout n'univers +* rotating planets and moons (on themselves) ## Contributing Please use [conventionnal commits](https://www.conventionalcommits.org/). diff --git a/core/src/sagittarius/model/Arrow.java b/core/src/sagittarius/model/Arrow.java index 131119b..46ebf80 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.graphics.glutils.ShapeRenderer.ShapeType; import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.scenes.scene2d.Actor; @@ -39,9 +40,9 @@ public class Arrow extends Actor { shooter.getY() + shooter.getWidth() * MathUtils.sinDeg(shooter.getRotation())); this.velocity = new Vector2(power, 0).setAngleDeg(angle); this.acceleration = new Vector2(); + this.setOrigin(80, 0); + this.setSize(100, 4); this.force = computeForce(); - this.setSize(100, 0); - this.setOrigin(50, 0); } // ---------- METHODs ---------- @@ -70,6 +71,27 @@ public class Arrow extends Actor { fontDebug.draw(batch, "angle=" + getRotation(), getX(), getY()); } + @Override + public void drawDebug(ShapeRenderer shapes) { + super.drawDebug(shapes); + for (Actor actor : GameScreen.planets.getChildren()) { + shapes.line(getX(), getY(), actor.getX(), actor.getY()); + } + } + + @Override + protected void drawDebugBounds(ShapeRenderer shapes) { + if (!getDebug()) return; + shapes.set(ShapeType.Line); + if (getStage() != null) shapes.setColor(getStage().getDebugColor()); + + shapes.rect(getX() - getOriginX(), getY(), + getOriginX(), getOriginY(), + getWidth(), getHeight(), + getScaleX(), getScaleY(), + getRotation()); + } + /** * Computes the {@link Arrow#force} exerted on the Arrow, * according to the other weighted entities. @@ -78,7 +100,7 @@ public class Arrow extends Actor { private Vector2 computeForce() { Vector2 force = new Vector2(); for (Actor actor : GameScreen.planets.getChildren()) { - + float dx = actor.getX() - this.getX(); float dy = actor.getY() - this.getY(); diff --git a/core/src/sagittarius/model/Moon.java b/core/src/sagittarius/model/Moon.java index 8573b44..f85d87d 100644 --- a/core/src/sagittarius/model/Moon.java +++ b/core/src/sagittarius/model/Moon.java @@ -1,23 +1,30 @@ package sagittarius.model; -import javax.print.attribute.standard.PrinterLocation; - import com.badlogic.gdx.graphics.Color; +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; -public class Moon extends Planet { +public class Moon extends Actor { + private BitmapFont fontDebug = new BitmapFont(); + private float mass; private Planet sun; private float altitude; + private float radius; // ---------- CONSTRUCTORs ---------- public Moon(Planet sun, float mass, float radius, float altitude, Color color) { - super(new Vector2(), mass, radius, color); + super(); this.sun = sun; + this.mass = mass; + this.setColor(color); this.altitude = altitude; + this.radius = radius; } // ---------- METHODs ---------- @@ -29,6 +36,21 @@ public class Moon extends Planet { this.setY(sun.getY() + this.altitude*MathUtils.sinDeg(this.getRotation())); } + @Override + public void draw(Batch batch, float parentAlpha) { + super.draw(batch, parentAlpha); + fontDebug.draw(batch, "radius=" + (int)radius, getX(), getY() + fontDebug.getCapHeight()*2); + fontDebug.draw(batch, "mass=" + (int)mass, getX(), getY() + fontDebug.getCapHeight()); + fontDebug.draw(batch, "pos=" + (int)getX() + "," + (int)getY(), getX(), getY()); + } + + @Override + public void drawDebug(ShapeRenderer shapes) { + super.drawDebug(shapes); + shapes.setColor(this.getColor()); + shapes.circle(this.getX(), this.getY(), this.radius); + } + /** * @return the Planet which the Moon orbits. */ @@ -36,4 +58,12 @@ public class Moon extends Planet { return this.sun; } + public float getMass() { + return mass; + } + + public Vector2 getPosition() { + return new Vector2( getX(), getY() ); + } + } diff --git a/core/src/sagittarius/model/Planet.java b/core/src/sagittarius/model/Planet.java index 27434ef..5dddc85 100644 --- a/core/src/sagittarius/model/Planet.java +++ b/core/src/sagittarius/model/Planet.java @@ -5,15 +5,17 @@ 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.Vector2; +import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.Group; -public class Planet extends Group { +public class Planet extends Actor { // ---------- ATTRIBUTEs ---------- private BitmapFont fontDebug = new BitmapFont(); private float radius; private float mass; + private Group moons; // ---------- CONSTRUCTORs ---------- @@ -23,17 +25,25 @@ public class Planet extends Group { this.radius = radius; this.mass = mass; this.setColor(color); + moons = new Group(); } // ---------- METHODs ---------- + @Override + public void act(float dt) { + super.act(dt); + moons.setDebug(getDebug(), true); + moons.act(dt); + } + @Override public void draw(Batch batch, float parentAlpha) { super.draw(batch, parentAlpha); fontDebug.draw(batch, "radius=" + (int)radius, getX(), getY() + fontDebug.getCapHeight()*2); fontDebug.draw(batch, "mass=" + (int)mass, getX(), getY() + fontDebug.getCapHeight()); fontDebug.draw(batch, "pos=" + (int)getX() + "," + (int)getY(), getX(), getY()); - drawChildren(batch, parentAlpha); + moons.draw(batch, parentAlpha); } @Override @@ -41,7 +51,7 @@ public class Planet extends Group { super.drawDebug(shapes); shapes.setColor(this.getColor()); shapes.circle(this.getX(), this.getY(), this.radius); - drawDebugChildren(shapes); + moons.drawDebug(shapes); } /** @@ -52,7 +62,7 @@ public class Planet extends Group { } public void addMoon(Moon moon) { - this.addActor(moon); + moons.addActor(moon); } public float getMass() { diff --git a/core/src/sagittarius/model/Player.java b/core/src/sagittarius/model/Player.java index 00c4b54..339af70 100644 --- a/core/src/sagittarius/model/Player.java +++ b/core/src/sagittarius/model/Player.java @@ -41,6 +41,7 @@ public class Player extends Actor { @Override public void drawDebug(ShapeRenderer shapes) { super.drawDebug(shapes); + bow.drawDebug(shapes); } @Override @@ -55,7 +56,6 @@ public class Player extends Actor { getScaleX(), getScaleY(), getRotation()); shapes.line(home.getX(), home.getY(), getX(), getY()); - bow.drawDebug(shapes); } @Override diff --git a/core/src/sagittarius/view/GameScreen.java b/core/src/sagittarius/view/GameScreen.java index 87d3092..00db15f 100644 --- a/core/src/sagittarius/view/GameScreen.java +++ b/core/src/sagittarius/view/GameScreen.java @@ -26,8 +26,6 @@ public class GameScreen extends BaseScreen { @Override public void initialize() { - mainStage.setDebugAll(true); // TODO: disable later - // planets planets = new Group(); @@ -55,6 +53,8 @@ public class GameScreen extends BaseScreen { MouseInfo mouseInfo = new MouseInfo(); uiStage.addActor(mouseInfo); + mainStage.setDebugAll(true); // TODO: disable later + } @Override