package com.lpatalas.spacegame;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector2;

import java.util.Random;

class Stars {
	private static final int MAX_STARS = 20;
	private static final int STAR_LENGTH = 10;

	private final Random random = new Random();
	private final Vector2[] stars = new Vector2[MAX_STARS];
	private final Texture texture;

	public Stars(Texture texture) {
		this.texture = texture;
	}

	public void initialize() {

		for (int i = 0; i < stars.length; i++) {
			float x = random.nextFloat() * Gdx.graphics.getWidth();
			float y = random.nextFloat() * Gdx.graphics.getHeight();

			stars[i] = new Vector2(x, y);
		}
	}

	public void render(SpriteBatch spriteBatch) {
		for (Vector2 star : stars) {
			spriteBatch.draw(texture, star.x, star.y, STAR_LENGTH, 1);
		}
	}

	public void update(float deltaTime, float moveSpeed) {
		for (Vector2 star : stars) {
			star.x -= deltaTime * moveSpeed;
			if (star.x < 0) {
				resetStar(star);
			}
		}
	}

	private void resetStar(Vector2 star) {
		star.x = Gdx.graphics.getWidth();
		star.y = random.nextFloat() * Gdx.graphics.getHeight();
	}
}
@@ -24,17 +24,19 @@
 acegame;
-%0A
+%0D%0A%0D
 %0Aimport 
@@ -56,16 +56,17 @@
 gdx.Gdx;
+%0D
 %0Aimport 
@@ -99,16 +99,17 @@
 Texture;
+%0D
 %0Aimport 
@@ -150,16 +150,58 @@
 teBatch;
+%0D%0Aimport com.badlogic.gdx.math.MathUtils;%0D
 %0Aimport 
@@ -230,17 +230,19 @@
 Vector2;
-%0A
+%0D%0A%0D
 %0Aimport 
@@ -258,17 +258,19 @@
 .Random;
-%0A
+%0D%0A%0D
 %0Aclass S
@@ -275,16 +275,17 @@
  Stars %7B
+%0D
 %0A%09privat
@@ -318,16 +318,17 @@
 RS = 20;
+%0D
 %0A%09privat
@@ -367,54 +367,11 @@
  10;
-%0A%0A%09private final Random random = new Random();
+%0D%0A%0D
 %0A%09pr
@@ -423,16 +423,17 @@
 _STARS%5D;
+%0D
 %0A%09privat
@@ -456,17 +456,19 @@
 texture;
-%0A
+%0D%0A%0D
 %0A%09public
@@ -492,16 +492,17 @@
 xture) %7B
+%0D
 %0A%09%09this.
@@ -519,20 +519,23 @@
 texture;
+%0D
 %0A%09%7D
-%0A
+%0D%0A%0D
 %0A%09public
@@ -554,17 +554,19 @@
 lize() %7B
-%0A
+%0D%0A%0D
 %0A%09%09for (
@@ -600,16 +600,17 @@
 ; i++) %7B
+%0D
 %0A%09%09%09floa
@@ -615,37 +615,33 @@
 oat x = 
-random.nextFloat() * 
+MathUtils.random(
 Gdx.grap
@@ -655,17 +655,19 @@
 tWidth()
-;
+);%0D
 %0A%09%09%09floa
@@ -672,37 +672,33 @@
 oat y = 
-random.nextFloat() * 
+MathUtils.random(
 Gdx.grap
@@ -713,18 +713,21 @@
 Height()
-;%0A
+);%0D%0A%0D
 %0A%09%09%09star
@@ -751,24 +751,28 @@
 2(x, y);
+%0D
 %0A%09%09%7D
+%0D
 %0A%09%7D
-%0A
+%0D%0A%0D
 %0A%09public
@@ -810,16 +810,17 @@
 Batch) %7B
+%0D
 %0A%09%09for (
@@ -838,24 +838,25 @@
 r : stars) %7B
+%0D
 %0A%09%09%09spriteBa
@@ -905,24 +905,28 @@
 GTH, 1);
+%0D
 %0A%09%09%7D
+%0D
 %0A%09%7D
-%0A
+%0D%0A%0D
 %0A%09public
@@ -973,16 +973,17 @@
 Speed) %7B
+%0D
 %0A%09%09for (
@@ -1005,16 +1005,17 @@
 stars) %7B
+%0D
 %0A%09%09%09star
@@ -1042,16 +1042,17 @@
 veSpeed;
+%0D
 %0A%09%09%09if (
@@ -1064,16 +1064,17 @@
 x %3C 0) %7B
+%0D
 %0A%09%09%09%09res
@@ -1090,21 +1090,26 @@
 ar);
+%0D
 %0A%09%09%09%7D
+%0D
 %0A%09%09%7D
+%0D
 %0A%09%7D
-%0A
+%0D%0A%0D
 %0A%09pr
@@ -1144,16 +1144,17 @@
  star) %7B
+%0D
 %0A%09%09star.
@@ -1157,16 +1157,33 @@
 tar.x = 
+MathUtils.random(
 Gdx.grap
@@ -1201,42 +1201,69 @@
 th()
-;%0A%09%09star.y = random.nextFloat() * 
+, Gdx.graphics.getWidth() * 2);%0D%0A%09%09star.y = MathUtils.random(
 Gdx.
@@ -1286,10 +1286,13 @@
 ht()
-;
+);%0D
 %0A%09%7D
+%0D
 %0A%7D

Fix star position generation to prevent clumping