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.MathUtils;
|
||||||
import com.badlogic.gdx.math.Polygon;
|
import com.badlogic.gdx.math.Polygon;
|
||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
import com.me.common.Random;
|
|
||||||
|
import static com.me.asteroids.Constants.rand;
|
||||||
|
|
||||||
public final class AsteroidFactory {
|
public final class AsteroidFactory {
|
||||||
|
|
||||||
public static final Random rand = new Random();
|
private int vertexCount;
|
||||||
|
private float size;
|
||||||
|
|
||||||
int vertexCount;
|
private float sizeVariation;
|
||||||
float size;
|
private float angleVariation;
|
||||||
|
|
||||||
float sizeVariation;
|
private boolean sizeRelativeToLast;
|
||||||
float angleVariation;
|
|
||||||
|
|
||||||
boolean sizeRelativeToLast;
|
|
||||||
|
|
||||||
public AsteroidFactory setVertexCount(int vertexCount) {
|
public AsteroidFactory setVertexCount(int vertexCount) {
|
||||||
this.vertexCount = vertexCount;
|
this.vertexCount = vertexCount;
|
||||||
@ -97,20 +96,20 @@ public final class AsteroidFactory {
|
|||||||
|
|
||||||
// Pick a random starting angle
|
// Pick a random starting angle
|
||||||
float startAngle = rand.nextFloat() * MathUtils.PI2;
|
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 lastSize = size;
|
||||||
float[] vertices = new float[vertexCount * 2];
|
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();
|
Vector2 vertex = dir.cpy();
|
||||||
|
|
||||||
vertex = applyAngleVariation(vertex);
|
vertex = applyAngleVariation(vertex);
|
||||||
lastSize = applySizeVariation(lastSize);
|
lastSize = applySizeVariation(lastSize);
|
||||||
|
|
||||||
vertex.scl(lastSize);
|
vertex.scl(lastSize);
|
||||||
vertices[i * 2] = vertex.x;
|
vertices[i] = vertex.x;
|
||||||
vertices[(i * 2) + 1] = vertex.y;
|
vertices[i + 1] = vertex.y;
|
||||||
|
|
||||||
dir.rotateRad(angleStep);
|
dir.rotateRad(angleStep);
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,19 @@
|
|||||||
package com.me.asteroids;
|
package com.me.asteroids;
|
||||||
|
|
||||||
|
import com.me.common.Random;
|
||||||
|
|
||||||
public class Constants {
|
public class Constants {
|
||||||
|
|
||||||
public static final boolean DEBUG = false;
|
public static final boolean DEBUG = false;
|
||||||
|
|
||||||
|
public static final Random rand = new Random();
|
||||||
|
|
||||||
public static final int WIDTH = 800;
|
public static final int WIDTH = 800;
|
||||||
public static final int HEIGHT = 600;
|
public static final int HEIGHT = 600;
|
||||||
|
|
||||||
public static final int HALF_WIDTH = WIDTH / 2;
|
public static final int HALF_WIDTH = WIDTH / 2;
|
||||||
public static final int HALF_HEIGHT = HEIGHT / 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