From 0c843bdea1fc8251f8e42d8cad3ca239e4227718 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laure=CE=B7t?= Date: Thu, 8 Apr 2021 22:13:03 +0200 Subject: [PATCH] refactor: rewriting of Planet, now extends Actor --- core/src/sagittarius/model/Planet.java | 41 +++++++++++++++----------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/core/src/sagittarius/model/Planet.java b/core/src/sagittarius/model/Planet.java index ec8cf2b..341e42b 100644 --- a/core/src/sagittarius/model/Planet.java +++ b/core/src/sagittarius/model/Planet.java @@ -5,42 +5,49 @@ 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; -public class Planet extends Entity { +public class Planet extends Actor { // ---------- ATTRIBUTEs ---------- - private float radius = 10; + private BitmapFont fontDebug; + private float radius; + private float mass; // ---------- CONSTRUCTORs ---------- - public Planet(Vector2 position, float mass, float radius) { - super(position, mass); - this.radius = radius; - } - public Planet(Vector2 position, float mass, float radius, Color color) { - this(position, mass, radius); - this.color = color; + super(); + this.setPosition(position.x, position.y); + this.radius = radius; + this.mass = mass; + this.setColor(color); } // ---------- METHODs ---------- - void render(ShapeRenderer shapeRenderer) { - shapeRenderer.setColor(color); - shapeRenderer.circle(this.position.x, this.position.y, radius); - } + @Override + public void draw(Batch batch, float parentAlpha) { + super.draw(batch, parentAlpha); + fontDebug.draw(batch, "mass = " + mass, this.getX(), this.getY() + 15); + fontDebug.draw(batch, "x = " + (int) this.getX() + ", y = " + (int) this.getY(), this.getX(), this.getY()); + } - void renderDebug(Batch batch, BitmapFont font) { - font.draw(batch, "mass = " + mass, position.x, position.y + 15); - font.draw(batch, "x = " + (int) position.x + ", y = " + (int) position.y, position.x, position.y); + @Override + public void drawDebug(ShapeRenderer shapes) { + super.drawDebug(shapes); + shapes.setColor(this.getColor()); + shapes.circle(this.getX(), this.getY(), this.radius); } /** * @return the radius of the Planet. */ - float getRadius() { + public float getRadius() { return this.radius; } + + }