changed entity setup to extend actor from the entity class

This commit is contained in:
Harrison Deng 2017-07-22 08:35:34 -05:00
parent 7e1c955c8b
commit de3a64551d
11 changed files with 31 additions and 26 deletions

View File

@ -1,15 +1,30 @@
package zero1hd.polyjet.entity;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.g2d.ParticleEffect;
import com.badlogic.gdx.graphics.g2d.ParticleEffectPool;
import com.badlogic.gdx.utils.Array;
public class CollisionDetector {
Array<Entity> firstGroup;
Array<Entity> secondGroup;
public CollisionDetector(Array<Entity> firstGroup, Array<Entity> secondGroup) {
AssetManager assets;
Preferences prefs;
//Particle pools;
ParticleEffectPool explosionEffectPool;
Sound explosionSFX;
public CollisionDetector(Array<Entity> firstGroup, Array<Entity> secondGroup, AssetManager assetManager, Preferences prefs) {
this.firstGroup = firstGroup;
this.secondGroup = secondGroup;
assets = assetManager;
this.prefs = prefs;
explosionEffectPool = new ParticleEffectPool(assets.get("explosion-s.p", ParticleEffect.class), 1, 64);
explosionSFX = assets.get("explosion.ogg", Sound.class);
}
public void collisionCheck() {

View File

@ -1,29 +1,31 @@
package zero1hd.polyjet.entity;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.scenes.scene2d.Actor;
public interface Entity {
public abstract class Entity extends Actor {
/**
* Called whenever a collision is detected
* @param entity is the entity that hit this one.
*/
public void collided(Entity entity);
public abstract void collided(Entity entity);
/**
* gets the box that represents the hit box to calculate whether there is a collision or not
* @return the object that represents the hit box
*/
public Rectangle getHitZone();
public abstract Rectangle getHitZone();
/**
* gets the type of entity this entity is
* @return the entity type
*/
public Entities getEntityType();
public abstract 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();
public abstract boolean isDead();
}

View File

@ -7,8 +7,6 @@ import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.ParticleEffect;
import com.badlogic.gdx.graphics.g2d.ParticleEffectPool;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Pool;
@ -28,9 +26,6 @@ public class EntityController {
public Array<Entity> activeAllies;
public Array<Entity> activeEnemies;
//Particle pools;
ParticleEffectPool explosionEffectPool;
//Enemy pool declaration;
private Pool<VoidCircle> voidCirclePool;
private Pool<Pellet> pelletPool;
@ -47,8 +42,6 @@ public class EntityController {
this.assets = assetManager;
this.prefs = preferences;
explosionEffectPool = new ParticleEffectPool(assets.get("explosion-s.p", ParticleEffect.class), 1, 64);
//Enemy pool initialization;
voidCirclePool = new Pool<VoidCircle>() {
@Override

View File

@ -12,7 +12,7 @@ import zero1hd.polyjet.Polyjet;
import zero1hd.polyjet.entity.Entities;
import zero1hd.polyjet.entity.Entity;
public class Laser extends Actor implements Entity, Poolable {
public class Laser extends Entity implements Poolable {
private Rectangle hitBox;
private float rate;
boolean dead;

View File

@ -5,14 +5,13 @@ import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.ParticleEffect;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import zero1hd.polyjet.Polyjet;
import zero1hd.polyjet.entity.Entities;
import zero1hd.polyjet.entity.Entity;
public class PolyJetEntity extends Actor implements Entity {
public class PolyJetEntity extends Entity {
public float health;
private ParticleEffect thrust;
private Texture polyjet;

View File

@ -3,14 +3,13 @@ package zero1hd.polyjet.entity.enemies;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
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 Bar extends Actor implements Entity, Poolable {
public class Bar extends Entity implements Poolable {
private boolean dead;
private Texture texture;
private float rate;

View File

@ -6,14 +6,13 @@ import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.math.MathUtils;
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;
import zero1hd.polyjet.Polyjet;
import zero1hd.polyjet.entity.Entities;
import zero1hd.polyjet.entity.Entity;
public class Flake extends Actor implements Poolable, Entity {
public class Flake extends Entity implements Poolable {
private Texture texture;
private float rate;
private float timer;

View File

@ -13,7 +13,7 @@ import zero1hd.polyjet.Polyjet;
import zero1hd.polyjet.entity.Entities;
import zero1hd.polyjet.entity.Entity;
public class Pellet extends Actor implements Entity, Poolable {
public class Pellet extends Entity implements Poolable {
private boolean dead;
private Texture texture;
private Rectangle hitBox;

View File

@ -7,14 +7,13 @@ import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.MathUtils;
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;
import zero1hd.polyjet.Polyjet;
import zero1hd.polyjet.entity.Entities;
import zero1hd.polyjet.entity.Entity;
public class Shard extends Actor implements Entity, Poolable {
public class Shard extends Entity implements Poolable {
private Sprite sprite;
private Rectangle hitbox;
private Vector2 angle;

View File

@ -8,13 +8,12 @@ import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.Sprite;
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;
import zero1hd.polyjet.entity.Entities;
import zero1hd.polyjet.entity.Entity;
public class VoidCircle extends Actor implements Entity, Poolable {
public class VoidCircle extends Entity implements Poolable {
private float timer;
private float endRadius;
private float currentRadius;

View File

@ -52,7 +52,7 @@ public class GamePlayArea extends Stage {
polyjet = new PolyJetEntity(assetManager, 25f, 25f, "standard");
ec = new EntityController(assetManager, prefs);
collisionDetector = new CollisionDetector(ec.activeAllies, ec.activeEnemies);
collisionDetector = new CollisionDetector(ec.activeAllies, ec.activeEnemies, assetManager, prefs);
ec.activeAllies.add(polyjet);
addActor(polyjet);
}