feat: changed Planet to Group

Moons now go in Planet's Group
This commit is contained in:
Laureηt 2021-04-09 15:49:33 +02:00
parent c56c5e92df
commit 26e3b5f9ad
4 changed files with 27 additions and 14 deletions

View file

@ -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()));
}
/**

View file

@ -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 {

View file

@ -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);
}
}

View file

@ -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);