successfully added debug spawning system and finished void circle enemy
This commit is contained in:
@@ -7,25 +7,24 @@ public class CollisionDetector {
|
||||
Array<Entity> firstGroup;
|
||||
Array<Entity> secondGroup;
|
||||
|
||||
private boolean debug = true;
|
||||
|
||||
public CollisionDetector(Array<Entity> firstGroup, Array<Entity> secondGroup) {
|
||||
this.firstGroup = firstGroup;
|
||||
this.secondGroup = secondGroup;
|
||||
}
|
||||
|
||||
public void collisionCheck() {
|
||||
if (debug) {
|
||||
Gdx.app.debug("collision check", "First group size: " + firstGroup.size);
|
||||
Gdx.app.debug("collision check", "Second group size: " + secondGroup.size);
|
||||
}
|
||||
|
||||
|
||||
for (int firstEID = 0; firstEID < firstGroup.size; firstEID++) {
|
||||
for (int secondEID = 0; secondEID < secondGroup.size; secondEID++) {
|
||||
if (firstGroup.get(firstEID).getHitZone().overlaps(secondGroup.get(secondEID).getHitZone())) {
|
||||
firstGroup.get(firstEID).collided(secondGroup.get(secondEID));
|
||||
secondGroup.get(secondEID).collided(firstGroup.get(firstEID));
|
||||
if ((firstGroup.size != 0) && (secondGroup.size != 0)) {
|
||||
for (int f = 0; f < firstGroup.size; f++) {
|
||||
Entity fe = firstGroup.get(f);
|
||||
for (int s = 0; s < secondGroup.size; s++) {
|
||||
Entity se = secondGroup.get(s);
|
||||
|
||||
if (fe.getHitZone().overlaps(se.getHitZone())) {
|
||||
Gdx.app.debug("Collision Detector", "Collision between entities: " + fe.getEntityType() + " and " + se.getEntityType());
|
||||
|
||||
fe.collided(se);
|
||||
se.collided(fe);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -14,21 +14,23 @@ public class EntityController {
|
||||
AssetManager assets;
|
||||
ShapeRenderer shapes;
|
||||
|
||||
public final Array<Entity> ACTIVE_ALLIES;
|
||||
public final Array<Entity> ACTIVE_ENEMIES;
|
||||
public Array<Entity> activeAllies;
|
||||
public Array<Entity> activeEnemies;
|
||||
//Enemy pool declaration;
|
||||
private final Pool<VoidCircle> VOID_CIRCLE_POOL;
|
||||
private Pool<VoidCircle> voidCirclePool;
|
||||
|
||||
//Ally pool declaration;
|
||||
private final Pool<Laser> LASER_POOL;
|
||||
public EntityController(ShapeRenderer shapeRenderer, AssetManager assetManager) {
|
||||
ACTIVE_ALLIES = new Array<Entity>();
|
||||
ACTIVE_ENEMIES = new Array<Entity>();
|
||||
private Pool<Laser> laserPool;
|
||||
public EntityController(AssetManager assetManager, ShapeRenderer shapeRenderer) {
|
||||
activeAllies = new Array<Entity>();
|
||||
activeEnemies = new Array<Entity>();
|
||||
this.assets = assetManager;
|
||||
|
||||
this.shapes = shapeRenderer;
|
||||
shapes.setAutoShapeType(true);
|
||||
|
||||
//Enemy pool initialization;
|
||||
VOID_CIRCLE_POOL = new Pool<VoidCircle>() {
|
||||
voidCirclePool = new Pool<VoidCircle>() {
|
||||
@Override
|
||||
protected VoidCircle newObject() {
|
||||
return new VoidCircle(shapes);
|
||||
@@ -36,7 +38,7 @@ public class EntityController {
|
||||
};
|
||||
|
||||
//Ally pool initialization;
|
||||
LASER_POOL = new Pool<Laser>() {
|
||||
laserPool = new Pool<Laser>() {
|
||||
@Override
|
||||
protected Laser newObject() {
|
||||
return new Laser(assets.get("laser.png", Texture.class));
|
||||
@@ -46,19 +48,18 @@ public class EntityController {
|
||||
}
|
||||
|
||||
public Entity retrieveEntity(Entities entity) {
|
||||
Gdx.app.debug("EntityController", "spawning entity " + entity.name());
|
||||
switch (entity) {
|
||||
case VOID_CIRCLE:
|
||||
VoidCircle voidCircle = VOID_CIRCLE_POOL.obtain();
|
||||
ACTIVE_ENEMIES.add(voidCircle);
|
||||
VoidCircle voidCircle = voidCirclePool.obtain();
|
||||
activeEnemies.add(voidCircle);
|
||||
return voidCircle;
|
||||
case BAR_BEAT:
|
||||
return null;
|
||||
case SHARDS:
|
||||
return null;
|
||||
case LASER:
|
||||
Laser laser = LASER_POOL.obtain();
|
||||
ACTIVE_ALLIES.add(laser);
|
||||
Laser laser = laserPool.obtain();
|
||||
activeAllies.add(laser);
|
||||
return laser;
|
||||
default:
|
||||
return null;
|
||||
@@ -74,14 +75,14 @@ public class EntityController {
|
||||
case VOID_CIRCLE:
|
||||
VoidCircle voidCircle = (VoidCircle) entity;
|
||||
voidCircle.remove();
|
||||
ACTIVE_ENEMIES.removeValue(entity, true);
|
||||
VOID_CIRCLE_POOL.free(voidCircle);
|
||||
activeEnemies.removeValue(entity, true);
|
||||
voidCirclePool.free(voidCircle);
|
||||
break;
|
||||
case LASER:
|
||||
Laser laser = (Laser) entity;
|
||||
laser.remove();
|
||||
ACTIVE_ALLIES.removeValue(entity, true);
|
||||
LASER_POOL.free(laser);
|
||||
activeAllies.removeValue(entity, true);
|
||||
laserPool.free(laser);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package zero1hd.polyjet.entity.ally;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
@@ -18,13 +19,15 @@ public class Laser extends Actor implements Entity, Poolable {
|
||||
|
||||
public Laser(Texture laserTexture) {
|
||||
this.laserTexture = laserTexture;
|
||||
setSize(0.25f, 1f);
|
||||
}
|
||||
|
||||
public void init(float x, float y, float rate) {
|
||||
Gdx.app.debug("Laser", "Pos: " + x + "," + y);
|
||||
|
||||
setX(x);
|
||||
setY(y);
|
||||
this.rate = rate;
|
||||
setSize(0.25f, 1f);
|
||||
hitBox = new Rectangle();
|
||||
hitBox.setSize(getWidth(), getHeight());
|
||||
}
|
||||
@@ -51,7 +54,6 @@ public class Laser extends Actor implements Entity, Poolable {
|
||||
public void reset() {
|
||||
setX(0);
|
||||
setY(0);
|
||||
setSize(0, 0);
|
||||
rate = 0;
|
||||
hitBox.set(0, 0, 0, 0);
|
||||
dead = false;
|
||||
|
@@ -6,6 +6,7 @@ import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.utils.Pool.Poolable;
|
||||
|
||||
@@ -13,6 +14,7 @@ import zero1hd.polyjet.entity.Entities;
|
||||
import zero1hd.polyjet.entity.Entity;
|
||||
|
||||
public class VoidCircle extends Actor implements Entity, Poolable {
|
||||
private float warnTime;
|
||||
private float timer;
|
||||
private float endRadius;
|
||||
private float currentRadius;
|
||||
@@ -21,24 +23,29 @@ public class VoidCircle extends Actor implements Entity, Poolable {
|
||||
private float growthRate;
|
||||
private boolean done;
|
||||
private boolean begin;
|
||||
private Vector2 center;
|
||||
public VoidCircle(ShapeRenderer shapeRenderer) {
|
||||
hitBox = new Rectangle();
|
||||
this.shapeRenderer = shapeRenderer;
|
||||
center = new Vector2();
|
||||
}
|
||||
|
||||
public void init(float endRadius, float x, float y, float growthRate, float warningTime) {
|
||||
Gdx.app.debug("Void Circle", "Initiated.");
|
||||
timer = warningTime;
|
||||
warnTime = warningTime;
|
||||
this.endRadius = endRadius;
|
||||
setSize(2*endRadius, 2*endRadius);
|
||||
setX(x);
|
||||
setY(y);
|
||||
setSize(2f*endRadius, 2f*endRadius);
|
||||
setX(x - getWidth()/2f);
|
||||
setY(y - getWidth()/2f);
|
||||
this.growthRate = growthRate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void act(float delta) {
|
||||
hitBox.setPosition(getX(), getY());
|
||||
center.x = getX()+getWidth()/2f;
|
||||
center.y = getY()+getHeight()/2f;
|
||||
hitBox.setCenter(center.x, center.y);
|
||||
|
||||
if (timer > 0) {
|
||||
timer -= delta;
|
||||
} else {
|
||||
@@ -57,6 +64,7 @@ public VoidCircle(ShapeRenderer shapeRenderer) {
|
||||
super.act(delta);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void draw(Batch batch, float parentAlpha) {
|
||||
batch.end();
|
||||
@@ -64,11 +72,12 @@ public VoidCircle(ShapeRenderer shapeRenderer) {
|
||||
if (begin) {
|
||||
shapeRenderer.set(ShapeType.Filled);
|
||||
shapeRenderer.setColor(Color.BLACK);
|
||||
shapeRenderer.circle(getX(), getY(), currentRadius);
|
||||
shapeRenderer.circle(center.x, center.y, currentRadius, 48);
|
||||
} else {
|
||||
shapeRenderer.set(ShapeType.Line);
|
||||
shapeRenderer.setColor(1 - timer/warnTime, 1 - timer/warnTime, 1 - timer/warnTime, 1f);
|
||||
shapeRenderer.circle(center.x, center.y, endRadius, 48);
|
||||
}
|
||||
shapeRenderer.set(ShapeType.Line);
|
||||
shapeRenderer.setColor(Color.RED);
|
||||
shapeRenderer.circle(getX(), getY(), endRadius);
|
||||
shapeRenderer.end();
|
||||
batch.begin();
|
||||
|
||||
@@ -85,18 +94,15 @@ public VoidCircle(ShapeRenderer shapeRenderer) {
|
||||
endRadius = 0;
|
||||
done = false;
|
||||
begin = false;
|
||||
warnTime = 0;
|
||||
center.set(0, 0);
|
||||
setSize(0, 0);
|
||||
}
|
||||
|
||||
public void setCurrentRadius(float currentRadius) {
|
||||
this.currentRadius = currentRadius;
|
||||
hitBox.setSize(2*(currentRadius*currentRadius));
|
||||
hitBox.setCenter(getX(), getY());
|
||||
}
|
||||
|
||||
public void growCurrentRadius(float currentRadius) {
|
||||
this.currentRadius += currentRadius;
|
||||
hitBox.setSize(2*(currentRadius*currentRadius));
|
||||
hitBox.setCenter(getX(), getY());
|
||||
public void growCurrentRadius(float radius) {
|
||||
currentRadius += radius;
|
||||
float length = (float) Math.sqrt(2*(currentRadius*currentRadius));
|
||||
hitBox.setSize(length, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user