new texture added and everything resized; worked on spawning and collision checking

This commit is contained in:
2017-05-31 13:49:18 -05:00
parent 5776586458
commit 70bf120a5f
67 changed files with 73 additions and 33 deletions

View File

@@ -1,24 +1,31 @@
package zero1hd.polyjet.entity;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.utils.Array;
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() {
while (firstGroup.iterator().hasNext()) {
Entity firstEntity = firstGroup.iterator().next();
while (secondGroup.iterator().hasNext()) {
Entity secondEntity = secondGroup.iterator().next();
if (firstEntity.getHitZone().overlaps(secondEntity.getHitZone())) {
firstEntity.collided(secondEntity);
secondEntity.collided(firstEntity);
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));
}
}
}

View File

@@ -1,5 +1,6 @@
package zero1hd.polyjet.entity;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
@@ -23,6 +24,8 @@ public class EntityController {
public EntityController(ShapeRenderer shapeRenderer, AssetManager assetManager) {
ACTIVE_ALLIES = new Array<Entity>();
ACTIVE_ENEMIES = new Array<Entity>();
this.assets = assetManager;
this.shapes = shapeRenderer;
//Enemy pool initialization;
VOID_CIRCLE_POOL = new Pool<VoidCircle>() {
@@ -43,6 +46,7 @@ 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();

View File

@@ -24,7 +24,7 @@ public class Laser extends Actor implements Entity, Poolable {
setX(x);
setY(y);
this.rate = rate;
setSize(0.25f, 2f);
setSize(0.25f, 1f);
hitBox = new Rectangle();
hitBox.setSize(getWidth(), getHeight());
}

View File

@@ -1,5 +1,6 @@
package zero1hd.polyjet.entity.enemies;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
@@ -12,20 +13,21 @@ import zero1hd.polyjet.entity.Entities;
import zero1hd.polyjet.entity.Entity;
public class VoidCircle extends Actor implements Entity, Poolable {
float timer;
float endRadius;
private float timer;
private float endRadius;
private float currentRadius;
Rectangle hitBox;
ShapeRenderer shapeRenderer;
float growthRate;
boolean done;
public VoidCircle(ShapeRenderer shapeRenderer) {
private Rectangle hitBox;
private ShapeRenderer shapeRenderer;
private float growthRate;
private boolean done;
private boolean begin;
public VoidCircle(ShapeRenderer shapeRenderer) {
hitBox = new Rectangle();
this.shapeRenderer = shapeRenderer;
}
public void init(float endRadius, float x, float y, float growthRate, float warningTime) {
Gdx.app.debug("Void Circle", "Initiated.");
timer = warningTime;
this.endRadius = endRadius;
setSize(2*endRadius, 2*endRadius);
@@ -40,6 +42,7 @@ public class VoidCircle extends Actor implements Entity, Poolable {
if (timer > 0) {
timer -= delta;
} else {
begin = true;
if (currentRadius < endRadius) {
growCurrentRadius(delta*growthRate);
} else {
@@ -56,7 +59,9 @@ public class VoidCircle extends Actor implements Entity, Poolable {
@Override
public void draw(Batch batch, float parentAlpha) {
if (timer <= 0) {
batch.end();
shapeRenderer.begin();
if (begin) {
shapeRenderer.set(ShapeType.Filled);
shapeRenderer.setColor(Color.BLACK);
shapeRenderer.circle(getX(), getY(), currentRadius);
@@ -64,6 +69,10 @@ public class VoidCircle extends Actor implements Entity, Poolable {
shapeRenderer.set(ShapeType.Line);
shapeRenderer.setColor(Color.RED);
shapeRenderer.circle(getX(), getY(), endRadius);
shapeRenderer.end();
batch.begin();
super.draw(batch, parentAlpha);
}
@@ -75,6 +84,7 @@ public class VoidCircle extends Actor implements Entity, Poolable {
timer = 0;
endRadius = 0;
done = false;
begin = false;
}
public void setCurrentRadius(float currentRadius) {