feat: added revolving planets (and moons)

This commit is contained in:
Laureηt 2021-04-23 16:17:09 +02:00
parent 5b591e3f8e
commit ed9e805c88
6 changed files with 34 additions and 14 deletions

View file

@ -4,6 +4,8 @@ import com.badlogic.gdx.Game;
import com.kotcrab.vis.ui.VisUI;
import sagittarius.view.BaseScreen;
import sagittarius.view.GameScreen;
import sagittarius.view.SettingsScreen;
import sagittarius.view.StartScreen;
public class SagittariusGame extends Game {
@ -29,7 +31,7 @@ public class SagittariusGame extends Game {
@Override
public void create() {
VisUI.load();
game.setScreen(new StartScreen());
game.setScreen(new GameScreen());
}
}

View file

@ -46,13 +46,13 @@ public abstract class EntityCircle extends Entity {
@Override
protected float[] getHitbox() { // peut être optimisé
int segments = 128;
int segments = 64;
float[] vertices = new float[2*segments];
float theta = 360.0f / segments;
for (int i = 0; i < segments; i++) {
vertices[2*i] = getX() + MathUtils.cosDeg(theta * (i+1))*radius;
vertices[2*i+1] = getY() + MathUtils.sinDeg(theta * (i+1))*radius;
vertices[2*i] = getX() + MathUtils.cosDeg(theta * (i+1) + getRotation())*radius;
vertices[2*i+1] = getY() + MathUtils.sinDeg(theta * (i+1) + getRotation())*radius;
}
return vertices;

View file

@ -14,6 +14,7 @@ public class Moon extends Planet {
public Moon(Planet sun, float mass, float radius, float altitude, Color color) {
super(new Vector2(), mass, radius, color);
this.angle = MathUtils.random(360);
this.sun = sun;
this.altitude = altitude;
}
@ -31,9 +32,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()));
this.angle += 10.0f / this.altitude;
this.setX(sun.getX() + this.altitude*MathUtils.cosDeg(this.angle));
this.setY(sun.getY() + this.altitude*MathUtils.sinDeg(this.angle));
super.act(dt);
}

View file

@ -1,10 +1,15 @@
package sagittarius.model;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
public class Planet extends EntityCircle {
// ---------- ATTRIBUTEs ----------
float revolutionRate = MathUtils.randomTriangular(1) + 1;
// ---------- CONSTRUCTORs ----------
public Planet(Vector2 position, float mass, float radius, Color color) {
@ -13,6 +18,12 @@ public class Planet extends EntityCircle {
// ---------- METHODs ----------
@Override
public void act(float dt) {
super.act(dt);
this.rotateBy(revolutionRate / this.radius);
}
@Override
protected String getInfo() {
return

View file

@ -17,7 +17,7 @@ public class Player extends EntityQuad {
public Player(Planet home, Color color) {
super(MathUtils.random(360), 0, color, home.getPosition());
this.setRotation(angle-90);
this.setRotation(home.getRotation() + angle - 90);
this.setSize(50, 100);
this.setOrigin(getWidth()/2, getHeight()/2);
@ -47,10 +47,10 @@ public class Player extends EntityQuad {
}
}
setX(home.getX() + (home.getRadius() + getHeight()/2)*MathUtils.cosDeg(angle));
setY(home.getY() + (home.getRadius() + getHeight()/2)*MathUtils.sinDeg(angle));
setX(home.getX() + (home.getRadius() + getHeight()/2)*MathUtils.cosDeg(home.getRotation() + angle));
setY(home.getY() + (home.getRadius() + getHeight()/2)*MathUtils.sinDeg(home.getRotation() + angle));
this.setRotation(angle-90);
this.setRotation(home.getRotation() + angle - 90);
}
@Override

View file

@ -37,15 +37,18 @@ public class GameScreen extends BaseScreen {
// planets & moons
attractors = new Group();
Planet planet1 = new Planet(new Vector2(400, 400), 1000, 50, Color.BLUE);
Planet planet1 = new Planet(new Vector2(300, 200), 1000, 50, Color.BLUE);
attractors.addActor(planet1);
Planet planet2 = new Planet(new Vector2(1400, 700), 1000, 100, Color.ORANGE);
Planet planet2 = new Planet(new Vector2(1200, 700), 4000, 200, Color.ORANGE);
attractors.addActor(planet2);
Moon moon2_1 = new Moon(planet2, 100, 10, 300, Color.MAGENTA);
Moon moon2_1 = new Moon(planet2, 100, 70, 500, Color.MAGENTA);
attractors.addActor(moon2_1);
Planet planet3 = new Planet(new Vector2(1500, 100), 1000, 70, Color.PINK);
attractors.addActor(planet3);
mainStage.addActor(attractors);
// players
@ -57,6 +60,9 @@ public class GameScreen extends BaseScreen {
Player player2 = new Player(planet2, Color.WHITE);
players.addActor(player2);
Player player3 = new Player(moon2_1, Color.YELLOW);
players.addActor(player3);
mainStage.addActor(players);
// arrows