new entity management and hit detection concepts, began implementing in game play area

This commit is contained in:
2017-05-30 16:23:08 -05:00
parent 562dbb8117
commit 4894d6eea8
9 changed files with 174 additions and 115 deletions

View File

@@ -20,4 +20,10 @@ public interface Entity {
* @return the entity type
*/
public Entities getEntityType();
/**
* If this entity's life span is over, it should be considered dead. Useful for knowing what can be freed in a pool scenario.
* @return if this entity is dead or not.
*/
public boolean isDead();
}

View File

@@ -0,0 +1,82 @@
package zero1hd.polyjet.entity;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Pool;
import zero1hd.polyjet.entity.ally.Laser;
import zero1hd.polyjet.entity.enemies.VoidCircle;
public class EntityController {
AssetManager assets;
ShapeRenderer shapes;
public final Array<Entity> ACTIVE_ALLIES;
public final Array<Entity> ACTIVE_ENEMIES;
//Enemy pool declaration;
private final Pool<VoidCircle> VOID_CIRCLE_POOL;
//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>();
//Enemy pool initialization;
VOID_CIRCLE_POOL = new Pool<VoidCircle>() {
@Override
protected VoidCircle newObject() {
return new VoidCircle(shapes);
}
};
//Ally pool initialization;
LASER_POOL = new Pool<Laser>() {
@Override
protected Laser newObject() {
return new Laser(assets.get("laser.png", Texture.class));
}
};
}
public Entity retrieveEntity(Entities entity) {
switch (entity) {
case VOID_CIRCLE:
VoidCircle voidCircle = VOID_CIRCLE_POOL.obtain();
ACTIVE_ENEMIES.add(voidCircle);
return voidCircle;
case BAR_BEAT:
return null;
case SHARDS:
return null;
case LASER:
Laser laser = LASER_POOL.obtain();
ACTIVE_ALLIES.add(laser);
return laser;
default:
return null;
}
}
public void free(Entity entity, Entities type) {
switch (type) {
case BAR_BEAT:
break;
case SHARDS:
break;
case VOID_CIRCLE:
ACTIVE_ENEMIES.removeValue(entity, true);
VOID_CIRCLE_POOL.free((VoidCircle) entity);
break;
case LASER:
ACTIVE_ALLIES.removeValue(entity, true);
LASER_POOL.free((Laser) entity);
break;
default:
break;
}
}
}

View File

@@ -6,12 +6,14 @@ import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.utils.Pool.Poolable;
import zero1hd.polyjet.Polyjet;
import zero1hd.polyjet.entity.Entities;
import zero1hd.polyjet.entity.Entity;
public class Laser extends Actor implements Entity, Poolable {
private Rectangle hitBox;
private float rate;
boolean dead;
Texture laserTexture;
public Laser(Texture laserTexture) {
@@ -33,6 +35,10 @@ public class Laser extends Actor implements Entity, Poolable {
hitBox.setX(getX());
hitBox.setY(getY());
super.act(delta);
if (getY() > Polyjet.GAME_AREA_HEIGHT) {
dead = true;
}
}
@Override
@@ -48,6 +54,7 @@ public class Laser extends Actor implements Entity, Poolable {
setSize(0, 0);
rate = 0;
hitBox.set(0, 0, 0, 0);
dead = false;
}
@Override
@@ -64,4 +71,9 @@ public class Laser extends Actor implements Entity, Poolable {
return Entities.LASER;
}
@Override
public boolean isDead() {
return dead;
}
}

View File

@@ -1,5 +1,6 @@
package zero1hd.polyjet.entity.ally;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.ParticleEffect;
@@ -12,7 +13,7 @@ import zero1hd.polyjet.entity.Entities;
import zero1hd.polyjet.entity.Entity;
public class PolyJetEntity extends Actor implements Entity {
public float health;
private ParticleEffect thrust;
private Texture polyjet;
private ParticleEffect teleportCloak;
@@ -20,17 +21,17 @@ public class PolyJetEntity extends Actor implements Entity {
public boolean moveLeft, moveRight, moveUp, moveDown, teleporting;
private float rate;
public PolyJetEntity(Polyjet core, float rate, String jet) {
public PolyJetEntity(AssetManager assets, float rate, String jet) {
this.rate = rate;
setSize(1.5f, 1.5f);
setPosition(Polyjet.GAME_AREA_WIDTH/2 - getWidth()/2, -4f);
hitbox = new Rectangle(getX(), getY(), getWidth(), getHeight());
polyjet = core.getAssetManager().get("polyjet-" + jet + ".png", Texture.class);
thrust = core.getAssetManager().get("standard_thrust.p", ParticleEffect.class);
polyjet = assets.get("polyjet-" + jet + ".png", Texture.class);
thrust = assets.get("standard_thrust.p", ParticleEffect.class);
thrust.start();
teleportCloak = core.getAssetManager().get("teleport-cloak.p", ParticleEffect.class);
teleportCloak = assets.get("teleport-cloak.p", ParticleEffect.class);
addAction(Actions.moveTo(getX(), 4f, 0.5f));
}
@@ -82,4 +83,13 @@ public class PolyJetEntity extends Actor implements Entity {
@Override
public void collided(Entity entity) {
}
@Override
public boolean isDead() {
if (health <= 0) {
return true;
} else {
return false;
}
}
}

View File

@@ -1,5 +0,0 @@
package zero1hd.polyjet.entity.boxes;
public class BoxOfAllies {
}

View File

@@ -1,57 +0,0 @@
package zero1hd.polyjet.entity.boxes;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Pool;
import zero1hd.polyjet.entity.Entities;
import zero1hd.polyjet.entity.Entity;
import zero1hd.polyjet.entity.enemies.VoidCircle;
public class BoxOfEnemies {
private final Array<Entity> ActiveEnemies;
private final Pool<VoidCircle> voidCirclePool;
public BoxOfEnemies(final ShapeRenderer shapeRenderer) {
ActiveEnemies = new Array<Entity>();
voidCirclePool = new Pool<VoidCircle>() {
@Override
protected VoidCircle newObject() {
return new VoidCircle(shapeRenderer);
}
};
}
public Entity getEntity(Entities entity) {
switch (entity) {
case VOID_CIRCLE:
VoidCircle voidCircle = voidCirclePool.obtain();
ActiveEnemies.add(voidCircle);
return voidCircle;
case BAR_BEAT:
return null;
case SHARDS:
return null;
default:
return null;
}
}
public void free(Entity entity, Entities type) {
switch (type) {
case BAR_BEAT:
break;
case SHARDS:
break;
case VOID_CIRCLE:
ActiveEnemies.removeValue(entity, true);
voidCirclePool.free((VoidCircle) entity);
break;
default:
break;
}
}
}

View File

@@ -102,4 +102,9 @@ public class VoidCircle extends Actor implements Entity, Poolable {
@Override
public void collided(Entity entity) {
}
@Override
public boolean isDead() {
return done;
}
}