From de3a64551dffa1eff3e778e8ba61d64ab950840d Mon Sep 17 00:00:00 2001 From: Recrown Date: Sat, 22 Jul 2017 08:35:34 -0500 Subject: [PATCH] changed entity setup to extend actor from the entity class --- .../polyjet/entity/CollisionDetector.java | 17 ++++++++++++++++- core/src/zero1hd/polyjet/entity/Entity.java | 12 +++++++----- .../polyjet/entity/EntityController.java | 7 ------- core/src/zero1hd/polyjet/entity/ally/Laser.java | 2 +- .../polyjet/entity/ally/PolyJetEntity.java | 3 +-- .../src/zero1hd/polyjet/entity/enemies/Bar.java | 3 +-- .../zero1hd/polyjet/entity/enemies/Flake.java | 3 +-- .../zero1hd/polyjet/entity/enemies/Pellet.java | 2 +- .../zero1hd/polyjet/entity/enemies/Shard.java | 3 +-- .../polyjet/entity/enemies/VoidCircle.java | 3 +-- .../zero1hd/polyjet/ui/stages/GamePlayArea.java | 2 +- 11 files changed, 31 insertions(+), 26 deletions(-) diff --git a/core/src/zero1hd/polyjet/entity/CollisionDetector.java b/core/src/zero1hd/polyjet/entity/CollisionDetector.java index 07c566b..ad9c493 100755 --- a/core/src/zero1hd/polyjet/entity/CollisionDetector.java +++ b/core/src/zero1hd/polyjet/entity/CollisionDetector.java @@ -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 firstGroup; Array secondGroup; - public CollisionDetector(Array firstGroup, Array secondGroup) { + AssetManager assets; + Preferences prefs; + //Particle pools; + ParticleEffectPool explosionEffectPool; + Sound explosionSFX; + public CollisionDetector(Array firstGroup, Array 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() { diff --git a/core/src/zero1hd/polyjet/entity/Entity.java b/core/src/zero1hd/polyjet/entity/Entity.java index 95d10dd..2cfd5ac 100755 --- a/core/src/zero1hd/polyjet/entity/Entity.java +++ b/core/src/zero1hd/polyjet/entity/Entity.java @@ -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(); + } diff --git a/core/src/zero1hd/polyjet/entity/EntityController.java b/core/src/zero1hd/polyjet/entity/EntityController.java index 50cb294..70e54f5 100755 --- a/core/src/zero1hd/polyjet/entity/EntityController.java +++ b/core/src/zero1hd/polyjet/entity/EntityController.java @@ -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 activeAllies; public Array activeEnemies; - //Particle pools; - ParticleEffectPool explosionEffectPool; - //Enemy pool declaration; private Pool voidCirclePool; private Pool 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() { @Override diff --git a/core/src/zero1hd/polyjet/entity/ally/Laser.java b/core/src/zero1hd/polyjet/entity/ally/Laser.java index 41dc0fa..581689c 100755 --- a/core/src/zero1hd/polyjet/entity/ally/Laser.java +++ b/core/src/zero1hd/polyjet/entity/ally/Laser.java @@ -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; diff --git a/core/src/zero1hd/polyjet/entity/ally/PolyJetEntity.java b/core/src/zero1hd/polyjet/entity/ally/PolyJetEntity.java index a129657..91324f1 100755 --- a/core/src/zero1hd/polyjet/entity/ally/PolyJetEntity.java +++ b/core/src/zero1hd/polyjet/entity/ally/PolyJetEntity.java @@ -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; diff --git a/core/src/zero1hd/polyjet/entity/enemies/Bar.java b/core/src/zero1hd/polyjet/entity/enemies/Bar.java index fa5399d..ef7a637 100755 --- a/core/src/zero1hd/polyjet/entity/enemies/Bar.java +++ b/core/src/zero1hd/polyjet/entity/enemies/Bar.java @@ -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; diff --git a/core/src/zero1hd/polyjet/entity/enemies/Flake.java b/core/src/zero1hd/polyjet/entity/enemies/Flake.java index 99d8629..d5beba2 100755 --- a/core/src/zero1hd/polyjet/entity/enemies/Flake.java +++ b/core/src/zero1hd/polyjet/entity/enemies/Flake.java @@ -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; diff --git a/core/src/zero1hd/polyjet/entity/enemies/Pellet.java b/core/src/zero1hd/polyjet/entity/enemies/Pellet.java index 81835f8..0d88fcf 100755 --- a/core/src/zero1hd/polyjet/entity/enemies/Pellet.java +++ b/core/src/zero1hd/polyjet/entity/enemies/Pellet.java @@ -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; diff --git a/core/src/zero1hd/polyjet/entity/enemies/Shard.java b/core/src/zero1hd/polyjet/entity/enemies/Shard.java index ad4f7f8..694a4f2 100755 --- a/core/src/zero1hd/polyjet/entity/enemies/Shard.java +++ b/core/src/zero1hd/polyjet/entity/enemies/Shard.java @@ -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; diff --git a/core/src/zero1hd/polyjet/entity/enemies/VoidCircle.java b/core/src/zero1hd/polyjet/entity/enemies/VoidCircle.java index ef40869..4800f3d 100755 --- a/core/src/zero1hd/polyjet/entity/enemies/VoidCircle.java +++ b/core/src/zero1hd/polyjet/entity/enemies/VoidCircle.java @@ -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; diff --git a/core/src/zero1hd/polyjet/ui/stages/GamePlayArea.java b/core/src/zero1hd/polyjet/ui/stages/GamePlayArea.java index c98e265..81f90f7 100755 --- a/core/src/zero1hd/polyjet/ui/stages/GamePlayArea.java +++ b/core/src/zero1hd/polyjet/ui/stages/GamePlayArea.java @@ -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); }