Update AsteroidFactor to use rand from Constants
Made its members private, small changes to generation method.
This commit is contained in:
parent
97e79b93ea
commit
e6356e4210
@ -3,19 +3,18 @@ package com.me.asteroids;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.math.Polygon;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.me.common.Random;
|
||||
|
||||
import static com.me.asteroids.Constants.rand;
|
||||
|
||||
public final class AsteroidFactory {
|
||||
|
||||
public static final Random rand = new Random();
|
||||
private int vertexCount;
|
||||
private float size;
|
||||
|
||||
int vertexCount;
|
||||
float size;
|
||||
private float sizeVariation;
|
||||
private float angleVariation;
|
||||
|
||||
float sizeVariation;
|
||||
float angleVariation;
|
||||
|
||||
boolean sizeRelativeToLast;
|
||||
private boolean sizeRelativeToLast;
|
||||
|
||||
public AsteroidFactory setVertexCount(int vertexCount) {
|
||||
this.vertexCount = vertexCount;
|
||||
@ -97,20 +96,20 @@ public final class AsteroidFactory {
|
||||
|
||||
// Pick a random starting angle
|
||||
float startAngle = rand.nextFloat() * MathUtils.PI2;
|
||||
Vector2 dir = new Vector2(MathUtils.cos(startAngle), MathUtils.sin(startAngle));
|
||||
Vector2 dir = Utils.setUnitVectorAngleRad(new Vector2(), startAngle);
|
||||
|
||||
float lastSize = size;
|
||||
float[] vertices = new float[vertexCount * 2];
|
||||
|
||||
for (int i = 0; i < vertexCount; i++) {
|
||||
for (int i = 0; i < vertices.length; i += 2) {
|
||||
Vector2 vertex = dir.cpy();
|
||||
|
||||
vertex = applyAngleVariation(vertex);
|
||||
lastSize = applySizeVariation(lastSize);
|
||||
|
||||
vertex.scl(lastSize);
|
||||
vertices[i * 2] = vertex.x;
|
||||
vertices[(i * 2) + 1] = vertex.y;
|
||||
vertices[i] = vertex.x;
|
||||
vertices[i + 1] = vertex.y;
|
||||
|
||||
dir.rotateRad(angleStep);
|
||||
}
|
||||
|
@ -1,13 +1,19 @@
|
||||
package com.me.asteroids;
|
||||
|
||||
import com.me.common.Random;
|
||||
|
||||
public class Constants {
|
||||
|
||||
public static final boolean DEBUG = false;
|
||||
|
||||
public static final Random rand = new Random();
|
||||
|
||||
public static final int WIDTH = 800;
|
||||
public static final int HEIGHT = 600;
|
||||
|
||||
public static final int HALF_WIDTH = WIDTH / 2;
|
||||
public static final int HALF_HEIGHT = HEIGHT / 2;
|
||||
|
||||
public static final float ASTEROID_SPAWN_DELAY = 1f;
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user