From 89ecbb6f4d89cd835bc4563657eac141aeb7b1e0 Mon Sep 17 00:00:00 2001 From: Recrown Date: Wed, 2 Aug 2017 23:30:29 -0500 Subject: [PATCH] better integration with new entity system --- .../entity/CollisionDetector.java | 2 +- .../zero1hd/rhythmbullet/entity/Entity.java | 25 +++++--------- .../rhythmbullet/entity/EntityIndex.java | 24 -------------- .../rhythmbullet/entity/ally/Laser.java | 19 +---------- .../entity/ally/PolyJetEntity.java | 22 +++---------- .../rhythmbullet/entity/enemies/Bar.java | 20 ++--------- .../rhythmbullet/entity/enemies/Flake.java | 33 ++++--------------- .../rhythmbullet/entity/enemies/Pellet.java | 18 +--------- .../rhythmbullet/entity/enemies/Shard.java | 27 +++------------ .../entity/enemies/VoidCircle.java | 23 ++----------- .../ui/windows/SpawnerWindow.java | 4 --- 11 files changed, 32 insertions(+), 185 deletions(-) delete mode 100755 core/src/zero1hd/rhythmbullet/entity/EntityIndex.java diff --git a/core/src/zero1hd/rhythmbullet/entity/CollisionDetector.java b/core/src/zero1hd/rhythmbullet/entity/CollisionDetector.java index 0ac69ae..dfbbd23 100755 --- a/core/src/zero1hd/rhythmbullet/entity/CollisionDetector.java +++ b/core/src/zero1hd/rhythmbullet/entity/CollisionDetector.java @@ -43,7 +43,7 @@ public class CollisionDetector { Entity ally = allies.get(s); if (ally.getHitZone() != null) { if (enemy.getHitZone().overlaps(ally.getHitZone())) { - Gdx.app.debug("Collision Detector", "Collision between entities: " + enemy.getEntityType() + " and " + ally.getEntityType()); + Gdx.app.debug("Collision Detector", "Collision between entities: " + enemy.getClass().getSimpleName() + " and " + ally.getClass().getSimpleName()); //Play FX; if (ally.playCollideSFX() && enemy.playCollideSFX()) { diff --git a/core/src/zero1hd/rhythmbullet/entity/Entity.java b/core/src/zero1hd/rhythmbullet/entity/Entity.java index b09031d..3ab3387 100755 --- a/core/src/zero1hd/rhythmbullet/entity/Entity.java +++ b/core/src/zero1hd/rhythmbullet/entity/Entity.java @@ -28,6 +28,7 @@ public class Entity extends Actor implements Poolable { protected boolean simple = true; protected boolean nonStnrd = false; protected boolean move = true; + protected boolean dead; protected Rectangle hitbox; protected Sprite sprite; @@ -77,23 +78,8 @@ public class Entity extends Actor implements Poolable { return hitbox; } - /** - * gets the type of entity this entity is - * @return the entity type - */ - public EntityIndex getEntityType() { - return null; - } - - /** - * 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() { - if (getX() > RhythmBullet.GAME_AREA_WIDTH || getY() > RhythmBullet.GAME_AREA_HEIGHT || getX() < 0-getWidth() || getY() < 0-getHeight()) { - return true; - } - return false; + return dead; } @Override @@ -106,7 +92,7 @@ public class Entity extends Actor implements Poolable { if (move) { move(delta, true); } - if (isDead()) { + if (dead) { ef.recycleEntity(this); } } @@ -114,6 +100,10 @@ public class Entity extends Actor implements Poolable { if (angle >= 360f) { angle -= 360f; } + + if (getX() > RhythmBullet.GAME_AREA_WIDTH || getY() > RhythmBullet.GAME_AREA_HEIGHT || getX() < 0-getWidth() || getY() < 0-getHeight()) { + dead = true; + } super.act(delta); } @@ -172,6 +162,7 @@ public class Entity extends Actor implements Poolable { center.set(0, 0); angle = 0; speed = 0; + dead = false; } public Vector2 getCenter() { diff --git a/core/src/zero1hd/rhythmbullet/entity/EntityIndex.java b/core/src/zero1hd/rhythmbullet/entity/EntityIndex.java deleted file mode 100755 index d51cbb0..0000000 --- a/core/src/zero1hd/rhythmbullet/entity/EntityIndex.java +++ /dev/null @@ -1,24 +0,0 @@ -package zero1hd.rhythmbullet.entity; - -import zero1hd.rhythmbullet.entity.ally.Laser; -import zero1hd.rhythmbullet.entity.ally.PolyJetEntity; -import zero1hd.rhythmbullet.entity.enemies.Bar; -import zero1hd.rhythmbullet.entity.enemies.Flake; -import zero1hd.rhythmbullet.entity.enemies.Pellet; -import zero1hd.rhythmbullet.entity.enemies.Shard; -import zero1hd.rhythmbullet.entity.enemies.VoidCircle; - -public enum EntityIndex { - POLYJET(PolyJetEntity.class), BAR(Bar.class), VOID_CIRCLE(VoidCircle.class), SHARD(Shard.class), LASER(Laser.class), PELLET(Pellet.class), FLAKE(Flake.class); - - private final Class classType; - - private EntityIndex(Class classType) { - this.classType = classType; - } - - public Class getClassType() { - return classType; - } - -} diff --git a/core/src/zero1hd/rhythmbullet/entity/ally/Laser.java b/core/src/zero1hd/rhythmbullet/entity/ally/Laser.java index 3e8c5a1..aee2962 100755 --- a/core/src/zero1hd/rhythmbullet/entity/ally/Laser.java +++ b/core/src/zero1hd/rhythmbullet/entity/ally/Laser.java @@ -9,10 +9,8 @@ import com.badlogic.gdx.graphics.g2d.Sprite; import zero1hd.rhythmbullet.RhythmBullet; import zero1hd.rhythmbullet.entity.Entity; -import zero1hd.rhythmbullet.entity.EntityIndex; public class Laser extends Entity { - boolean dead; Sound sfx; @Override @@ -60,27 +58,12 @@ public class Laser extends Entity { @Override public void reset() { - dead = false; super.reset(); } @Override public void collided(Entity entity) { - switch (entity.getEntityType()) { - default: - dead = true; - break; - } - } - - @Override - public EntityIndex getEntityType() { - return EntityIndex.LASER; - } - - @Override - public boolean isDead() { - return dead; + dead = true; } } diff --git a/core/src/zero1hd/rhythmbullet/entity/ally/PolyJetEntity.java b/core/src/zero1hd/rhythmbullet/entity/ally/PolyJetEntity.java index 44f59f7..c04306e 100755 --- a/core/src/zero1hd/rhythmbullet/entity/ally/PolyJetEntity.java +++ b/core/src/zero1hd/rhythmbullet/entity/ally/PolyJetEntity.java @@ -9,7 +9,6 @@ import com.badlogic.gdx.scenes.scene2d.actions.Actions; import zero1hd.rhythmbullet.RhythmBullet; import zero1hd.rhythmbullet.entity.Entity; -import zero1hd.rhythmbullet.entity.EntityIndex; public class PolyJetEntity extends Entity { public float health; @@ -68,7 +67,11 @@ public class PolyJetEntity extends Entity { if (moveDown && !moveUp) { moveBy(0, -rate*delta); } - + + if (health <= 0) { + dead = true; + } + super.act(delta); } @@ -79,24 +82,9 @@ public class PolyJetEntity extends Entity { super.draw(batch, parentAlpha); } - - @Override - public EntityIndex getEntityType() { - return EntityIndex.POLYJET; - } - @Override public void collided(Entity entity) { } - - @Override - public boolean isDead() { - if (health <= 0) { - return true; - } else { - return false; - } - } public Rectangle getHitbox() { return hitbox; diff --git a/core/src/zero1hd/rhythmbullet/entity/enemies/Bar.java b/core/src/zero1hd/rhythmbullet/entity/enemies/Bar.java index 6d8e24a..2210d12 100755 --- a/core/src/zero1hd/rhythmbullet/entity/enemies/Bar.java +++ b/core/src/zero1hd/rhythmbullet/entity/enemies/Bar.java @@ -8,10 +8,9 @@ import com.badlogic.gdx.math.Rectangle; import zero1hd.rhythmbullet.RhythmBullet; import zero1hd.rhythmbullet.entity.Entity; -import zero1hd.rhythmbullet.entity.EntityIndex; +import zero1hd.rhythmbullet.entity.ally.PolyJetEntity; public class Bar extends Entity { - private boolean dead; @Override public void preInit() { @@ -43,18 +42,13 @@ public class Bar extends Entity { @Override public void reset() { - dead = false; super.reset(); } @Override public void collided(Entity entity) { - switch (entity.getEntityType()) { - case POLYJET: + if (entity.getClass() == PolyJetEntity.class) { dead = true; - break; - default: - break; } } @@ -63,14 +57,4 @@ public class Bar extends Entity { return hitbox; } - @Override - public EntityIndex getEntityType() { - return EntityIndex.BAR; - } - - @Override - public boolean isDead() { - return dead; - } - } diff --git a/core/src/zero1hd/rhythmbullet/entity/enemies/Flake.java b/core/src/zero1hd/rhythmbullet/entity/enemies/Flake.java index 410363d..d7f4a5d 100755 --- a/core/src/zero1hd/rhythmbullet/entity/enemies/Flake.java +++ b/core/src/zero1hd/rhythmbullet/entity/enemies/Flake.java @@ -7,9 +7,8 @@ import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.math.Rectangle; -import zero1hd.rhythmbullet.RhythmBullet; import zero1hd.rhythmbullet.entity.Entity; -import zero1hd.rhythmbullet.entity.EntityIndex; +import zero1hd.rhythmbullet.entity.ally.Laser; public class Flake extends Entity { private float timer; @@ -74,8 +73,11 @@ public class Flake extends Entity { shards[i].move(delta, true); } - if (getX() > RhythmBullet.GAME_AREA_WIDTH || getY() > RhythmBullet.GAME_AREA_HEIGHT || getX() < 0-getWidth() || getY() < 0-getHeight()) { - timer = 0; + if (timer <= 0) { + for (int i = 0; i < shards.length; i++) { + shards[i].setSpeed(45f); + } + dead = true; } super.act(delta); @@ -89,12 +91,8 @@ public class Flake extends Entity { @Override public void collided(Entity entity) { - switch (entity.getEntityType()) { - case LASER: + if (entity.getClass() == Laser.class) { timer --; - break; - default: - break; } } @@ -103,23 +101,6 @@ public class Flake extends Entity { return hitbox; } - @Override - public EntityIndex getEntityType() { - return EntityIndex.FLAKE; - } - - @Override - public boolean isDead() { - if (timer <= 0) { - for (int i = 0; i < shards.length; i++) { - shards[i].setSpeed(45f); - } - return true; - } else { - return false; - } - } - @Override public void reset() { timer = 0; diff --git a/core/src/zero1hd/rhythmbullet/entity/enemies/Pellet.java b/core/src/zero1hd/rhythmbullet/entity/enemies/Pellet.java index 05841be..f33a7cb 100755 --- a/core/src/zero1hd/rhythmbullet/entity/enemies/Pellet.java +++ b/core/src/zero1hd/rhythmbullet/entity/enemies/Pellet.java @@ -6,9 +6,7 @@ import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.utils.Pool.Poolable; -import zero1hd.rhythmbullet.RhythmBullet; import zero1hd.rhythmbullet.entity.Entity; -import zero1hd.rhythmbullet.entity.EntityIndex; public class Pellet extends Entity implements Poolable { private boolean dead; @@ -47,24 +45,10 @@ public class Pellet extends Entity implements Poolable { @Override public void collided(Entity entity) { - switch (entity.getEntityType()) { - default: - dead = true; - break; - } + dead = true; super.collided(entity); } - @Override - public EntityIndex getEntityType() { - return EntityIndex.PELLET; - } - - @Override - public boolean isDead() { - return dead; - } - @Override public void reset() { dead = false; diff --git a/core/src/zero1hd/rhythmbullet/entity/enemies/Shard.java b/core/src/zero1hd/rhythmbullet/entity/enemies/Shard.java index 7a2a005..90f6b3b 100755 --- a/core/src/zero1hd/rhythmbullet/entity/enemies/Shard.java +++ b/core/src/zero1hd/rhythmbullet/entity/enemies/Shard.java @@ -7,9 +7,8 @@ import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.math.Rectangle; -import zero1hd.rhythmbullet.RhythmBullet; import zero1hd.rhythmbullet.entity.Entity; -import zero1hd.rhythmbullet.entity.EntityIndex; +import zero1hd.rhythmbullet.entity.ally.Laser; public class Shard extends Entity { private int hp; @@ -57,8 +56,8 @@ public class Shard extends Entity { @Override public void act(float delta) { - if (getX() > RhythmBullet.GAME_AREA_WIDTH || getY() > RhythmBullet.GAME_AREA_HEIGHT || getX() < 0-getWidth() || getY() < 0-getHeight()) { - hp = 0; + if (hp <= 0) { + dead = true; } super.act(delta); } @@ -71,12 +70,8 @@ public class Shard extends Entity { @Override public void collided(Entity entity) { - switch (entity.getEntityType()) { - case LASER: - hp--; - break; - default: - break; + if (entity.getClass() == Laser.class) { + hp --; } } @@ -85,16 +80,4 @@ public class Shard extends Entity { return hitbox; } - @Override - public EntityIndex getEntityType() { - return EntityIndex.SHARD; - } - - @Override - public boolean isDead() { - if (hp <= 0) { - return true; - } - return false; - } } diff --git a/core/src/zero1hd/rhythmbullet/entity/enemies/VoidCircle.java b/core/src/zero1hd/rhythmbullet/entity/enemies/VoidCircle.java index c4c212c..e4a785c 100755 --- a/core/src/zero1hd/rhythmbullet/entity/enemies/VoidCircle.java +++ b/core/src/zero1hd/rhythmbullet/entity/enemies/VoidCircle.java @@ -7,14 +7,12 @@ import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.Sprite; import zero1hd.rhythmbullet.entity.Entity; -import zero1hd.rhythmbullet.entity.EntityIndex; public class VoidCircle extends Entity { private float timer; private float endRadius; private float currentRadius; private float growthRate; - private boolean done; private boolean begin; private float maxTime; private Sound sound; @@ -75,7 +73,7 @@ public class VoidCircle extends Entity { if (currentRadius > 0) { growCurrentRadius(delta*-growthRate); } else { - done = true; + dead = true; } } } @@ -90,7 +88,6 @@ public class VoidCircle extends Entity { timer = 0; maxTime = 0; endRadius = 0; - done = false; begin = false; setSize(0, 0); super.reset(); @@ -102,25 +99,9 @@ public class VoidCircle extends Entity { hitbox.setSize(length, length); } - @Override - public EntityIndex getEntityType() { - return EntityIndex.VOID_CIRCLE; - } - @Override public void collided(Entity entity) { - switch (entity.getEntityType()) { - case LASER: - sound.play(prefs.getFloat("fx vol")); - break; - default: - break; - } - } - - @Override - public boolean isDead() { - return done; + sound.play(prefs.getFloat("fx vol")); } @Override diff --git a/core/src/zero1hd/rhythmbullet/ui/windows/SpawnerWindow.java b/core/src/zero1hd/rhythmbullet/ui/windows/SpawnerWindow.java index 5617ae0..44dbd1b 100755 --- a/core/src/zero1hd/rhythmbullet/ui/windows/SpawnerWindow.java +++ b/core/src/zero1hd/rhythmbullet/ui/windows/SpawnerWindow.java @@ -1,7 +1,5 @@ package zero1hd.rhythmbullet.ui.windows; -import java.util.HashMap; - import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input.Keys; import com.badlogic.gdx.math.Vector2; @@ -29,8 +27,6 @@ import zero1hd.rhythmbullet.entity.enemies.VoidCircle; public class SpawnerWindow extends Window { private Stage stage; - private HashMap params = new HashMap<>(); - private Array> entityFrames = new Array<>(); private List> listOfEntities; private ScrollPane entityListScroller;