From 26e3b5f9ad4cf969c546e9781ca7928ec0fce905 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laure=CE=B7t?= Date: Fri, 9 Apr 2021 15:49:33 +0200 Subject: [PATCH] feat: changed Planet to Group Moons now go in Planet's Group --- core/src/sagittarius/model/Moon.java | 6 +++--- core/src/sagittarius/model/MouseInfo.java | 6 ++---- core/src/sagittarius/model/Planet.java | 10 ++++++++-- core/src/sagittarius/view/GameScreen.java | 19 ++++++++++++++----- 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/core/src/sagittarius/model/Moon.java b/core/src/sagittarius/model/Moon.java index 51b92df..8573b44 100644 --- a/core/src/sagittarius/model/Moon.java +++ b/core/src/sagittarius/model/Moon.java @@ -1,6 +1,9 @@ package sagittarius.model; +import javax.print.attribute.standard.PrinterLocation; + import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.Vector2; @@ -21,12 +24,9 @@ public class Moon extends Planet { @Override public void act(float dt) { - this.rotateBy(10.0f / this.altitude); - this.setX(sun.getX() + this.altitude*MathUtils.cosDeg(this.getRotation())); this.setY(sun.getY() + this.altitude*MathUtils.sinDeg(this.getRotation())); - } /** diff --git a/core/src/sagittarius/model/MouseInfo.java b/core/src/sagittarius/model/MouseInfo.java index 20b67f0..1793788 100644 --- a/core/src/sagittarius/model/MouseInfo.java +++ b/core/src/sagittarius/model/MouseInfo.java @@ -1,11 +1,9 @@ package sagittarius.model; -import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.scenes.scene2d.Actor; -import sagittarius.SagittariusGame; import sagittarius.view.GameScreen; public class MouseInfo extends Actor { @@ -22,10 +20,10 @@ public class MouseInfo extends Actor { font.draw(batch, "screen=" + (int)GameScreen.screenCursor.x + "," + (int)GameScreen.screenCursor.y, GameScreen.worldCursor.x, GameScreen.worldCursor.y + font.getCapHeight()); - + font.draw(batch, "world=" + (int)GameScreen.worldCursor.x + "," + (int)GameScreen.worldCursor.y, GameScreen.worldCursor.x, GameScreen.worldCursor.y + font.getCapHeight()*2); - + } } diff --git a/core/src/sagittarius/model/Planet.java b/core/src/sagittarius/model/Planet.java index 4f379d0..e768df0 100644 --- a/core/src/sagittarius/model/Planet.java +++ b/core/src/sagittarius/model/Planet.java @@ -5,9 +5,9 @@ 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 Actor { +public class Planet extends Group { // ---------- ATTRIBUTEs ---------- @@ -33,6 +33,7 @@ public class Planet extends Actor { 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); } @Override @@ -40,6 +41,7 @@ public class Planet extends Actor { super.drawDebug(shapes); shapes.setColor(this.getColor()); shapes.circle(this.getX(), this.getY(), this.radius); + drawDebugChildren(shapes); } /** @@ -49,4 +51,8 @@ public class Planet extends Actor { return this.radius; } + public void addMoon(Moon moon) { + this.addActor(moon); + } + } diff --git a/core/src/sagittarius/view/GameScreen.java b/core/src/sagittarius/view/GameScreen.java index 7390d90..b0671aa 100644 --- a/core/src/sagittarius/view/GameScreen.java +++ b/core/src/sagittarius/view/GameScreen.java @@ -4,6 +4,7 @@ import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector3; +import com.badlogic.gdx.scenes.scene2d.Group; import sagittarius.model.*; @@ -26,18 +27,26 @@ public class GameScreen extends BaseScreen { mainStage.setDebugAll(true); // TODO: disable later + // planets + + Group planets = new Group(); + Planet planet1 = new Planet(new Vector2(400, 400), 1000, 50, Color.BLUE); - mainStage.addActor(planet1); - + planets.addActor(planet1); + Planet planet2 = new Planet(new Vector2(1400, 700), 1000, 100, Color.ORANGE); - mainStage.addActor(planet2); + planet2.addMoon(new Moon(planet2, 100, 10, 300, Color.MAGENTA)); + planets.addActor(planet2); - Moon moon2_1 = new Moon(planet2, 100, 10, 300, Color.MAGENTA); - mainStage.addActor(moon2_1); + mainStage.addActor(planets); + + // players Player player1 = new Player(planet1, Color.WHITE); mainStage.addActor(player1); + // others + FPS fpsCounter = new FPS(); uiStage.addActor(fpsCounter);