planets random
This commit is contained in:
parent
919a9a6951
commit
0101996b91
|
@ -9,6 +9,7 @@ import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||||
import com.badlogic.gdx.math.MathUtils;
|
import com.badlogic.gdx.math.MathUtils;
|
||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
import com.badlogic.gdx.math.Vector3;
|
import com.badlogic.gdx.math.Vector3;
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||||
import com.badlogic.gdx.scenes.scene2d.Group;
|
import com.badlogic.gdx.scenes.scene2d.Group;
|
||||||
|
|
||||||
import sagittarius.SagittariusGame;
|
import sagittarius.SagittariusGame;
|
||||||
|
@ -16,6 +17,19 @@ import sagittarius.model.*;
|
||||||
|
|
||||||
public class GameScreen extends BaseScreen implements InputProcessor {
|
public class GameScreen extends BaseScreen implements InputProcessor {
|
||||||
|
|
||||||
|
// ---------- GENERATION ----------
|
||||||
|
|
||||||
|
public static int numberPlanets = 4;
|
||||||
|
public static int numberMoons = 2;
|
||||||
|
public static int minDistance = 400;
|
||||||
|
public static int maxDistance = 800;
|
||||||
|
public static int minMass = 500;
|
||||||
|
public static int maxMass = 1000;
|
||||||
|
public static int minRadius = 20;
|
||||||
|
public static int maxRadius = 150;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ---------- ATTRIBUTEs ----------
|
// ---------- ATTRIBUTEs ----------
|
||||||
|
|
||||||
public static BitmapFont fontDebug = new BitmapFont();
|
public static BitmapFont fontDebug = new BitmapFont();
|
||||||
|
@ -72,30 +86,51 @@ public class GameScreen extends BaseScreen implements InputProcessor {
|
||||||
// planets & moons
|
// planets & moons
|
||||||
attractors = new Group();
|
attractors = new Group();
|
||||||
|
|
||||||
Planet planet1 = new Planet(new Vector2(300, 200), 1000, 50, Color.BLUE);
|
for (int i = 0; i < numberPlanets; i++) {
|
||||||
attractors.addActor(planet1);
|
Vector2 position;
|
||||||
|
if (i == 0) {
|
||||||
|
position = new Vector2(0, 0);
|
||||||
|
} else {
|
||||||
|
int distance = minDistance + MathUtils.random(maxDistance - minDistance);
|
||||||
|
float angle = 2*MathUtils.PI*MathUtils.random();
|
||||||
|
float shortestDistance;
|
||||||
|
do {
|
||||||
|
int index = MathUtils.random(i-1);
|
||||||
|
Actor planet0 = attractors.getChild(index);
|
||||||
|
position = new Vector2(distance * (float) Math.cos(angle), distance * (float) Math.sin(angle));
|
||||||
|
position.add(planet0.getX(), planet0.getY());
|
||||||
|
|
||||||
Planet planet2 = new Planet(new Vector2(1200, 700), 3000, 200, Color.ORANGE);
|
shortestDistance = maxDistance;
|
||||||
attractors.addActor(planet2);
|
for (int j = 0; j < i-1; j++) {
|
||||||
|
Actor planet1 = attractors.getChild(j);
|
||||||
Moon moon2_1 = new Moon(planet2, 100, 70, 500, Color.MAGENTA);
|
float dx = planet1.getX() - position.x;
|
||||||
attractors.addActor(moon2_1);
|
float dy = planet1.getY() - position.y;
|
||||||
|
float distanceToPlanet1 = (float) Math.sqrt(dx*dx + dy*dy);
|
||||||
Planet planet3 = new Planet(new Vector2(1500, 100), 1000, 70, Color.PINK);
|
if (distanceToPlanet1 < shortestDistance) {
|
||||||
attractors.addActor(planet3);
|
shortestDistance = distanceToPlanet1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (shortestDistance < minDistance);
|
||||||
|
}
|
||||||
|
int mass = minMass + MathUtils.random(maxMass - minMass);
|
||||||
|
int radius = minRadius + MathUtils.random(maxRadius - minRadius);
|
||||||
|
Color color = new Color((int)(Math.random() * 0x1000000));
|
||||||
|
Planet planet = new Planet(position, mass, radius, color);
|
||||||
|
attractors.addActor(planet);
|
||||||
|
}
|
||||||
|
|
||||||
mainStage.addActor(attractors);
|
mainStage.addActor(attractors);
|
||||||
|
|
||||||
// players
|
// players
|
||||||
players = new Group();
|
players = new Group();
|
||||||
|
|
||||||
Player player1 = new Player(planet1, Color.RED);
|
Player player1 = new Player((Planet) attractors.getChild(0), Color.RED);
|
||||||
players.addActor(player1);
|
players.addActor(player1);
|
||||||
|
|
||||||
Player player2 = new Player(planet2, Color.WHITE);
|
Player player2 = new Player((Planet) attractors.getChild(1), Color.WHITE);
|
||||||
players.addActor(player2);
|
players.addActor(player2);
|
||||||
|
|
||||||
Player player3 = new Player(moon2_1, Color.YELLOW);
|
Player player3 = new Player((Planet) attractors.getChild(2), Color.YELLOW);
|
||||||
players.addActor(player3);
|
players.addActor(player3);
|
||||||
|
|
||||||
mainStage.addActor(players);
|
mainStage.addActor(players);
|
||||||
|
|
Loading…
Reference in a new issue