changed entity setup to extend actor from the entity class
This commit is contained in:
parent
7e1c955c8b
commit
de3a64551d
@ -1,15 +1,30 @@
|
|||||||
package zero1hd.polyjet.entity;
|
package zero1hd.polyjet.entity;
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
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;
|
import com.badlogic.gdx.utils.Array;
|
||||||
|
|
||||||
public class CollisionDetector {
|
public class CollisionDetector {
|
||||||
Array<Entity> firstGroup;
|
Array<Entity> firstGroup;
|
||||||
Array<Entity> secondGroup;
|
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.firstGroup = firstGroup;
|
||||||
this.secondGroup = secondGroup;
|
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() {
|
public void collisionCheck() {
|
||||||
|
@ -1,29 +1,31 @@
|
|||||||
package zero1hd.polyjet.entity;
|
package zero1hd.polyjet.entity;
|
||||||
|
|
||||||
import com.badlogic.gdx.math.Rectangle;
|
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
|
* Called whenever a collision is detected
|
||||||
* @param entity is the entity that hit this one.
|
* @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
|
* 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
|
* @return the object that represents the hit box
|
||||||
*/
|
*/
|
||||||
public Rectangle getHitZone();
|
public abstract Rectangle getHitZone();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gets the type of entity this entity is
|
* gets the type of entity this entity is
|
||||||
* @return the entity type
|
* @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.
|
* 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.
|
* @return if this entity is dead or not.
|
||||||
*/
|
*/
|
||||||
public boolean isDead();
|
public abstract boolean isDead();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,6 @@ import com.badlogic.gdx.Preferences;
|
|||||||
import com.badlogic.gdx.assets.AssetManager;
|
import com.badlogic.gdx.assets.AssetManager;
|
||||||
import com.badlogic.gdx.audio.Sound;
|
import com.badlogic.gdx.audio.Sound;
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
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.scenes.scene2d.Stage;
|
||||||
import com.badlogic.gdx.utils.Array;
|
import com.badlogic.gdx.utils.Array;
|
||||||
import com.badlogic.gdx.utils.Pool;
|
import com.badlogic.gdx.utils.Pool;
|
||||||
@ -28,9 +26,6 @@ public class EntityController {
|
|||||||
public Array<Entity> activeAllies;
|
public Array<Entity> activeAllies;
|
||||||
public Array<Entity> activeEnemies;
|
public Array<Entity> activeEnemies;
|
||||||
|
|
||||||
//Particle pools;
|
|
||||||
ParticleEffectPool explosionEffectPool;
|
|
||||||
|
|
||||||
//Enemy pool declaration;
|
//Enemy pool declaration;
|
||||||
private Pool<VoidCircle> voidCirclePool;
|
private Pool<VoidCircle> voidCirclePool;
|
||||||
private Pool<Pellet> pelletPool;
|
private Pool<Pellet> pelletPool;
|
||||||
@ -47,8 +42,6 @@ public class EntityController {
|
|||||||
this.assets = assetManager;
|
this.assets = assetManager;
|
||||||
this.prefs = preferences;
|
this.prefs = preferences;
|
||||||
|
|
||||||
explosionEffectPool = new ParticleEffectPool(assets.get("explosion-s.p", ParticleEffect.class), 1, 64);
|
|
||||||
|
|
||||||
//Enemy pool initialization;
|
//Enemy pool initialization;
|
||||||
voidCirclePool = new Pool<VoidCircle>() {
|
voidCirclePool = new Pool<VoidCircle>() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -12,7 +12,7 @@ import zero1hd.polyjet.Polyjet;
|
|||||||
import zero1hd.polyjet.entity.Entities;
|
import zero1hd.polyjet.entity.Entities;
|
||||||
import zero1hd.polyjet.entity.Entity;
|
import zero1hd.polyjet.entity.Entity;
|
||||||
|
|
||||||
public class Laser extends Actor implements Entity, Poolable {
|
public class Laser extends Entity implements Poolable {
|
||||||
private Rectangle hitBox;
|
private Rectangle hitBox;
|
||||||
private float rate;
|
private float rate;
|
||||||
boolean dead;
|
boolean dead;
|
||||||
|
@ -5,14 +5,13 @@ import com.badlogic.gdx.graphics.Texture;
|
|||||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||||
import com.badlogic.gdx.graphics.g2d.ParticleEffect;
|
import com.badlogic.gdx.graphics.g2d.ParticleEffect;
|
||||||
import com.badlogic.gdx.math.Rectangle;
|
import com.badlogic.gdx.math.Rectangle;
|
||||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
|
||||||
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
|
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
|
||||||
|
|
||||||
import zero1hd.polyjet.Polyjet;
|
import zero1hd.polyjet.Polyjet;
|
||||||
import zero1hd.polyjet.entity.Entities;
|
import zero1hd.polyjet.entity.Entities;
|
||||||
import zero1hd.polyjet.entity.Entity;
|
import zero1hd.polyjet.entity.Entity;
|
||||||
|
|
||||||
public class PolyJetEntity extends Actor implements Entity {
|
public class PolyJetEntity extends Entity {
|
||||||
public float health;
|
public float health;
|
||||||
private ParticleEffect thrust;
|
private ParticleEffect thrust;
|
||||||
private Texture polyjet;
|
private Texture polyjet;
|
||||||
|
@ -3,14 +3,13 @@ package zero1hd.polyjet.entity.enemies;
|
|||||||
import com.badlogic.gdx.graphics.Texture;
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||||
import com.badlogic.gdx.math.Rectangle;
|
import com.badlogic.gdx.math.Rectangle;
|
||||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
|
||||||
import com.badlogic.gdx.utils.Pool.Poolable;
|
import com.badlogic.gdx.utils.Pool.Poolable;
|
||||||
|
|
||||||
import zero1hd.polyjet.Polyjet;
|
import zero1hd.polyjet.Polyjet;
|
||||||
import zero1hd.polyjet.entity.Entities;
|
import zero1hd.polyjet.entity.Entities;
|
||||||
import zero1hd.polyjet.entity.Entity;
|
import zero1hd.polyjet.entity.Entity;
|
||||||
|
|
||||||
public class Bar extends Actor implements Entity, Poolable {
|
public class Bar extends Entity implements Poolable {
|
||||||
private boolean dead;
|
private boolean dead;
|
||||||
private Texture texture;
|
private Texture texture;
|
||||||
private float rate;
|
private float rate;
|
||||||
|
@ -6,14 +6,13 @@ import com.badlogic.gdx.graphics.g2d.Batch;
|
|||||||
import com.badlogic.gdx.math.MathUtils;
|
import com.badlogic.gdx.math.MathUtils;
|
||||||
import com.badlogic.gdx.math.Rectangle;
|
import com.badlogic.gdx.math.Rectangle;
|
||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
|
||||||
import com.badlogic.gdx.utils.Pool.Poolable;
|
import com.badlogic.gdx.utils.Pool.Poolable;
|
||||||
|
|
||||||
import zero1hd.polyjet.Polyjet;
|
import zero1hd.polyjet.Polyjet;
|
||||||
import zero1hd.polyjet.entity.Entities;
|
import zero1hd.polyjet.entity.Entities;
|
||||||
import zero1hd.polyjet.entity.Entity;
|
import zero1hd.polyjet.entity.Entity;
|
||||||
|
|
||||||
public class Flake extends Actor implements Poolable, Entity {
|
public class Flake extends Entity implements Poolable {
|
||||||
private Texture texture;
|
private Texture texture;
|
||||||
private float rate;
|
private float rate;
|
||||||
private float timer;
|
private float timer;
|
||||||
|
@ -13,7 +13,7 @@ import zero1hd.polyjet.Polyjet;
|
|||||||
import zero1hd.polyjet.entity.Entities;
|
import zero1hd.polyjet.entity.Entities;
|
||||||
import zero1hd.polyjet.entity.Entity;
|
import zero1hd.polyjet.entity.Entity;
|
||||||
|
|
||||||
public class Pellet extends Actor implements Entity, Poolable {
|
public class Pellet extends Entity implements Poolable {
|
||||||
private boolean dead;
|
private boolean dead;
|
||||||
private Texture texture;
|
private Texture texture;
|
||||||
private Rectangle hitBox;
|
private Rectangle hitBox;
|
||||||
|
@ -7,14 +7,13 @@ import com.badlogic.gdx.graphics.g2d.Sprite;
|
|||||||
import com.badlogic.gdx.math.MathUtils;
|
import com.badlogic.gdx.math.MathUtils;
|
||||||
import com.badlogic.gdx.math.Rectangle;
|
import com.badlogic.gdx.math.Rectangle;
|
||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
|
||||||
import com.badlogic.gdx.utils.Pool.Poolable;
|
import com.badlogic.gdx.utils.Pool.Poolable;
|
||||||
|
|
||||||
import zero1hd.polyjet.Polyjet;
|
import zero1hd.polyjet.Polyjet;
|
||||||
import zero1hd.polyjet.entity.Entities;
|
import zero1hd.polyjet.entity.Entities;
|
||||||
import zero1hd.polyjet.entity.Entity;
|
import zero1hd.polyjet.entity.Entity;
|
||||||
|
|
||||||
public class Shard extends Actor implements Entity, Poolable {
|
public class Shard extends Entity implements Poolable {
|
||||||
private Sprite sprite;
|
private Sprite sprite;
|
||||||
private Rectangle hitbox;
|
private Rectangle hitbox;
|
||||||
private Vector2 angle;
|
private Vector2 angle;
|
||||||
|
@ -8,13 +8,12 @@ import com.badlogic.gdx.graphics.g2d.Batch;
|
|||||||
import com.badlogic.gdx.graphics.g2d.Sprite;
|
import com.badlogic.gdx.graphics.g2d.Sprite;
|
||||||
import com.badlogic.gdx.math.Rectangle;
|
import com.badlogic.gdx.math.Rectangle;
|
||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
|
||||||
import com.badlogic.gdx.utils.Pool.Poolable;
|
import com.badlogic.gdx.utils.Pool.Poolable;
|
||||||
|
|
||||||
import zero1hd.polyjet.entity.Entities;
|
import zero1hd.polyjet.entity.Entities;
|
||||||
import zero1hd.polyjet.entity.Entity;
|
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 timer;
|
||||||
private float endRadius;
|
private float endRadius;
|
||||||
private float currentRadius;
|
private float currentRadius;
|
||||||
|
@ -52,7 +52,7 @@ public class GamePlayArea extends Stage {
|
|||||||
|
|
||||||
polyjet = new PolyJetEntity(assetManager, 25f, 25f, "standard");
|
polyjet = new PolyJetEntity(assetManager, 25f, 25f, "standard");
|
||||||
ec = new EntityController(assetManager, prefs);
|
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);
|
ec.activeAllies.add(polyjet);
|
||||||
addActor(polyjet);
|
addActor(polyjet);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user