From 2406453507b9fa842bb4288bcedcee225c19260c Mon Sep 17 00:00:00 2001 From: Damien Date: Sat, 29 May 2021 12:41:40 +0200 Subject: [PATCH] color fix --- core/src/sagittarius/SagittariusGame.java | 1 + core/src/sagittarius/view/GameScreen.java | 26 ++++++++++++----------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/core/src/sagittarius/SagittariusGame.java b/core/src/sagittarius/SagittariusGame.java index eaa4e4d..4b4d521 100644 --- a/core/src/sagittarius/SagittariusGame.java +++ b/core/src/sagittarius/SagittariusGame.java @@ -11,6 +11,7 @@ public class SagittariusGame extends Game { // Constants public static float G = 100; + public static int numberPlayers = 3; public static boolean debugMode = false; public static Music music; public static boolean disableMusic = true; diff --git a/core/src/sagittarius/view/GameScreen.java b/core/src/sagittarius/view/GameScreen.java index db79f0a..575e6d7 100644 --- a/core/src/sagittarius/view/GameScreen.java +++ b/core/src/sagittarius/view/GameScreen.java @@ -86,6 +86,7 @@ public class GameScreen extends BaseScreen implements InputProcessor { attractors = new Group(); for (int i = 0; i < numberPlanets; i++) { + // Position of the new planet Vector2 position; if (i == 0) { position = new Vector2(0, 0); @@ -111,19 +112,24 @@ public class GameScreen extends BaseScreen implements InputProcessor { } } while (shortestDistance < minDistance); } + + // other attributs int mass = minMass + MathUtils.random(maxMass - minMass); int radius = minRadius + MathUtils.random(maxRadius - minRadius); - Color color = new Color((int)(Math.random() * 0x1000000)); + Color color = new Color((float) Math.random(), (float) Math.random(), (float) Math.random(), 1); + + // create the planet Planet planet = new Planet(position, mass, radius, color); attractors.addActor(planet); } + // create a moon Moon moon = new Moon( (Planet) attractors.getChild( MathUtils.random(numberPlanets-1)), minMass / 2 + MathUtils.random(maxMass - minMass) / 2, minRadius / 2 + MathUtils.random(maxRadius - minRadius) / 2, minDistance / 2, - new Color((int)(Math.random() * 0x1000000)) + new Color((float) Math.random(), (float) Math.random(), (float) Math.random(), 1) ); attractors.addActor(moon); @@ -132,14 +138,10 @@ public class GameScreen extends BaseScreen implements InputProcessor { // players players = new Group(); - Player player1 = new Player((Planet) attractors.getChild(0), Color.RED); - players.addActor(player1); - - Player player2 = new Player((Planet) attractors.getChild(1), Color.WHITE); - players.addActor(player2); - - Player player3 = new Player((Planet) attractors.getChild(2), Color.YELLOW); - players.addActor(player3); + for (int i = 0; i < SagittariusGame.numberPlayers; i++) { + Player player = new Player((Planet) attractors.getChild(i), new Color((float) Math.random(), (float) Math.random(), (float) Math.random(), 1)); + players.addActor(player); + } mainStage.addActor(players); @@ -155,8 +157,8 @@ public class GameScreen extends BaseScreen implements InputProcessor { // game turns playerIndex = 0; - player1.setActive(true); - playerCurrent = player1; + ((Player) players.getChild(0)).setActive(true); + playerCurrent = (Player) players.getChild(0); // camera stuff mainCameraPosition = mainStage.getCamera().position;