From cfe5e3592bb80cac1bfa277d51769a085551f5dd Mon Sep 17 00:00:00 2001 From: Recrown Date: Wed, 2 Aug 2017 22:06:10 -0500 Subject: [PATCH] entity coordinator integration works --- .../zero1hd/rhythmbullet/entity/Entity.java | 19 +++- .../rhythmbullet/entity/EntityFrame.java | 8 +- .../rhythmbullet/entity/EntityManager.java | 12 +- .../entity/coordinator/Coordinator.java | 4 + .../entity/coordinator/CoordinatorFrame.java | 9 +- .../entity/coordinator/CoordinatorIndex.java | 5 - .../coordinator/CoordinatorManager.java | 4 +- .../coordinator/SlowLeftCoordinator.java | 2 +- .../coordinator/SlowRightCoordinator.java | 2 +- .../rhythmbullet/entity/enemies/Bar.java | 3 - .../rhythmbullet/entity/enemies/Flake.java | 6 +- .../rhythmbullet/entity/enemies/Pellet.java | 4 - .../rhythmbullet/ui/stages/CreativeHUD.java | 2 +- .../ui/windows/SpawnerWindow.java | 107 +++++++++++------- 14 files changed, 111 insertions(+), 76 deletions(-) delete mode 100755 core/src/zero1hd/rhythmbullet/entity/coordinator/CoordinatorIndex.java diff --git a/core/src/zero1hd/rhythmbullet/entity/Entity.java b/core/src/zero1hd/rhythmbullet/entity/Entity.java index b412e2e..b09031d 100755 --- a/core/src/zero1hd/rhythmbullet/entity/Entity.java +++ b/core/src/zero1hd/rhythmbullet/entity/Entity.java @@ -13,6 +13,7 @@ import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.utils.Pool.Poolable; +import zero1hd.rhythmbullet.RhythmBullet; import zero1hd.rhythmbullet.entity.coordinator.Coordinator; public class Entity extends Actor implements Poolable { @@ -58,6 +59,7 @@ public class Entity extends Actor implements Poolable { } public void init(HashMap params) { + params.clear(); } /** @@ -88,13 +90,18 @@ public class Entity extends Actor implements Poolable { * @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; } @Override public void act(float delta) { if (!nonStnrd) { - coordinator.coordinate(delta); + if (coordinator != null) { + coordinator.coordinate(delta); + } if (move) { move(delta, true); @@ -104,6 +111,9 @@ public class Entity extends Actor implements Poolable { } } + if (angle >= 360f) { + angle -= 360f; + } super.act(delta); } @@ -150,8 +160,10 @@ public class Entity extends Actor implements Poolable { @Override public void reset() { - coordinator.clean(); - coordinator = null; + if (coordinator != null) { + coordinator.clean(); + coordinator = null; + } rotRatios.set(0, 0); sprite.setPosition(0, 0); hitbox.set(0, 0, 0, 0); @@ -180,5 +192,6 @@ public class Entity extends Actor implements Poolable { public void setCoordinator(Coordinator coordinator) { this.coordinator = coordinator; + coordinator.setEntity(this); } } diff --git a/core/src/zero1hd/rhythmbullet/entity/EntityFrame.java b/core/src/zero1hd/rhythmbullet/entity/EntityFrame.java index d5deeef..ec1f57d 100755 --- a/core/src/zero1hd/rhythmbullet/entity/EntityFrame.java +++ b/core/src/zero1hd/rhythmbullet/entity/EntityFrame.java @@ -7,7 +7,8 @@ public class EntityFrame { private EntityManager ec; Class ct; EntityFrame ef; - public EntityFrame(EntityManager entityController) { + public EntityFrame(EntityManager entityController, Class classType) { + this.ct = classType; ef = this; ec = entityController; pool = new Pool() { @@ -52,4 +53,9 @@ public class EntityFrame { entity.remove(); pool.free(ct.cast(entity)); } + + @Override + public String toString() { + return ct.getSimpleName(); + } } diff --git a/core/src/zero1hd/rhythmbullet/entity/EntityManager.java b/core/src/zero1hd/rhythmbullet/entity/EntityManager.java index b992c09..2efe9ee 100755 --- a/core/src/zero1hd/rhythmbullet/entity/EntityManager.java +++ b/core/src/zero1hd/rhythmbullet/entity/EntityManager.java @@ -39,12 +39,12 @@ public class EntityManager { } private void setup() { - voidCircle = new EntityFrame<>(this); - pellet = new EntityFrame<>(this); - shard = new EntityFrame<>(this); - bar = new EntityFrame<>(this); - flake = new EntityFrame<>(this); - laser = new EntityFrame<>(this); + voidCircle = new EntityFrame<>(this, VoidCircle.class); + pellet = new EntityFrame<>(this, Pellet.class); + shard = new EntityFrame<>(this, Shard.class); + bar = new EntityFrame<>(this, Bar.class); + flake = new EntityFrame<>(this, Flake.class); + laser = new EntityFrame<>(this, Laser.class); } diff --git a/core/src/zero1hd/rhythmbullet/entity/coordinator/Coordinator.java b/core/src/zero1hd/rhythmbullet/entity/coordinator/Coordinator.java index dd90f53..c74da92 100755 --- a/core/src/zero1hd/rhythmbullet/entity/coordinator/Coordinator.java +++ b/core/src/zero1hd/rhythmbullet/entity/coordinator/Coordinator.java @@ -26,6 +26,10 @@ public class Coordinator implements Poolable { cf.recycleCoordinator(this); } + public void setEntity(Entity entity) { + this.entity = entity; + } + @Override public void reset() { entity = null; diff --git a/core/src/zero1hd/rhythmbullet/entity/coordinator/CoordinatorFrame.java b/core/src/zero1hd/rhythmbullet/entity/coordinator/CoordinatorFrame.java index 24bff3d..e1e8531 100755 --- a/core/src/zero1hd/rhythmbullet/entity/coordinator/CoordinatorFrame.java +++ b/core/src/zero1hd/rhythmbullet/entity/coordinator/CoordinatorFrame.java @@ -9,8 +9,9 @@ public class CoordinatorFrame { private EntityManager em; CoordinatorFrame cf; Class coordinatorType; - public CoordinatorFrame(EntityManager entityManager) { + public CoordinatorFrame(EntityManager entityManager, Class classtype) { this.em = entityManager; + coordinatorType = classtype; cf = this; pool = new Pool() { @Override @@ -35,5 +36,9 @@ public class CoordinatorFrame { protected void recycleCoordinator(Coordinator coordinator) { pool.free(coordinatorType.cast(coordinator)); } - + + @Override + public String toString() { + return coordinatorType.getSimpleName(); + } } diff --git a/core/src/zero1hd/rhythmbullet/entity/coordinator/CoordinatorIndex.java b/core/src/zero1hd/rhythmbullet/entity/coordinator/CoordinatorIndex.java deleted file mode 100755 index 355b48f..0000000 --- a/core/src/zero1hd/rhythmbullet/entity/coordinator/CoordinatorIndex.java +++ /dev/null @@ -1,5 +0,0 @@ -package zero1hd.rhythmbullet.entity.coordinator; - -public enum CoordinatorIndex { - SLOW_RIGHT, SLOW_LEFT; -} diff --git a/core/src/zero1hd/rhythmbullet/entity/coordinator/CoordinatorManager.java b/core/src/zero1hd/rhythmbullet/entity/coordinator/CoordinatorManager.java index 6cfac4f..384b2a2 100755 --- a/core/src/zero1hd/rhythmbullet/entity/coordinator/CoordinatorManager.java +++ b/core/src/zero1hd/rhythmbullet/entity/coordinator/CoordinatorManager.java @@ -14,7 +14,7 @@ public class CoordinatorManager { } private void setup() { - slowLeft = new CoordinatorFrame<>(em); - slowRight = new CoordinatorFrame<>(em); + slowLeft = new CoordinatorFrame<>(em, SlowLeftCoordinator.class); + slowRight = new CoordinatorFrame<>(em, SlowRightCoordinator.class); } } diff --git a/core/src/zero1hd/rhythmbullet/entity/coordinator/SlowLeftCoordinator.java b/core/src/zero1hd/rhythmbullet/entity/coordinator/SlowLeftCoordinator.java index d3525de..26ffd52 100755 --- a/core/src/zero1hd/rhythmbullet/entity/coordinator/SlowLeftCoordinator.java +++ b/core/src/zero1hd/rhythmbullet/entity/coordinator/SlowLeftCoordinator.java @@ -3,7 +3,7 @@ package zero1hd.rhythmbullet.entity.coordinator; public class SlowLeftCoordinator extends Coordinator { @Override public void coordinate(float delta) { - entity.angle -= 8*delta; + entity.angle -= 32*delta; super.coordinate(delta); } } diff --git a/core/src/zero1hd/rhythmbullet/entity/coordinator/SlowRightCoordinator.java b/core/src/zero1hd/rhythmbullet/entity/coordinator/SlowRightCoordinator.java index e9bd933..7b7da40 100755 --- a/core/src/zero1hd/rhythmbullet/entity/coordinator/SlowRightCoordinator.java +++ b/core/src/zero1hd/rhythmbullet/entity/coordinator/SlowRightCoordinator.java @@ -3,7 +3,7 @@ package zero1hd.rhythmbullet.entity.coordinator; public class SlowRightCoordinator extends Coordinator { @Override public void coordinate(float delta) { - entity.angle += 8*delta; + entity.angle += 32*delta; super.coordinate(delta); } } diff --git a/core/src/zero1hd/rhythmbullet/entity/enemies/Bar.java b/core/src/zero1hd/rhythmbullet/entity/enemies/Bar.java index 26a5b68..6d8e24a 100755 --- a/core/src/zero1hd/rhythmbullet/entity/enemies/Bar.java +++ b/core/src/zero1hd/rhythmbullet/entity/enemies/Bar.java @@ -39,9 +39,6 @@ public class Bar extends Entity { public void act(float delta) { hitbox.setPosition(getX(), getY()); super.act(delta); - if (getY() < 0-getHeight()) { - dead = true; - } } @Override diff --git a/core/src/zero1hd/rhythmbullet/entity/enemies/Flake.java b/core/src/zero1hd/rhythmbullet/entity/enemies/Flake.java index 8fb817a..410363d 100755 --- a/core/src/zero1hd/rhythmbullet/entity/enemies/Flake.java +++ b/core/src/zero1hd/rhythmbullet/entity/enemies/Flake.java @@ -68,14 +68,10 @@ public class Flake extends Entity { timer -= delta; } - move(delta, false); - System.out.println("---Start----"); - System.out.println("Flake: " + center); + move(delta, true); for (int i = 0; i < shards.length; i++) { shards[i].setPosition(center.x-shards[i].getWidth()/2f, center.y-shards[i].getWidth()/2f); shards[i].move(delta, true); - System.out.println("Shard " + i + ": " + shards[i].getCenter()); - System.out.println("Sprite Pos: " + shards[i].getHitZone()); } if (getX() > RhythmBullet.GAME_AREA_WIDTH || getY() > RhythmBullet.GAME_AREA_HEIGHT || getX() < 0-getWidth() || getY() < 0-getHeight()) { diff --git a/core/src/zero1hd/rhythmbullet/entity/enemies/Pellet.java b/core/src/zero1hd/rhythmbullet/entity/enemies/Pellet.java index 7f1c500..05841be 100755 --- a/core/src/zero1hd/rhythmbullet/entity/enemies/Pellet.java +++ b/core/src/zero1hd/rhythmbullet/entity/enemies/Pellet.java @@ -43,10 +43,6 @@ public class Pellet extends Entity implements Poolable { @Override public void act(float delta) { super.act(delta); - - if (getX() > RhythmBullet.GAME_AREA_WIDTH || getY() > RhythmBullet.GAME_AREA_HEIGHT || getX() < 0-getWidth() || getY() < 0-getHeight()) { - dead = true; - } } @Override diff --git a/core/src/zero1hd/rhythmbullet/ui/stages/CreativeHUD.java b/core/src/zero1hd/rhythmbullet/ui/stages/CreativeHUD.java index d0dfefe..2cd2826 100755 --- a/core/src/zero1hd/rhythmbullet/ui/stages/CreativeHUD.java +++ b/core/src/zero1hd/rhythmbullet/ui/stages/CreativeHUD.java @@ -56,7 +56,7 @@ public class CreativeHUD extends Stage implements MiniListener { bassUMgraphWindow = new BassUMGraphWindow("Bass/UM Peak Values", core.getDefaultSkin()); mGraphWindow = new MGraphWindow("Midrange Peak Values", core.getDefaultSkin()); volumeWindow = new VolumeWindow("Volume adjustments", core.getDefaultSkin(), core.getPrefs()); - spawnerWindow = new SpawnerWindow("Spawn Tool", core.getDefaultSkin(), gpa.em, gpa); + spawnerWindow = new SpawnerWindow("Spawn Tool", core.getDefaultSkin(), gpa.em, gpa.cm, gpa); diffWindow = new DifficultyWindow(core.getDefaultSkin()); //Back button diff --git a/core/src/zero1hd/rhythmbullet/ui/windows/SpawnerWindow.java b/core/src/zero1hd/rhythmbullet/ui/windows/SpawnerWindow.java index 106ed6b..974804c 100755 --- a/core/src/zero1hd/rhythmbullet/ui/windows/SpawnerWindow.java +++ b/core/src/zero1hd/rhythmbullet/ui/windows/SpawnerWindow.java @@ -1,5 +1,7 @@ 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; @@ -9,10 +11,16 @@ import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane; import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.ui.Slider; import com.badlogic.gdx.scenes.scene2d.ui.Window; +import com.badlogic.gdx.utils.Array; -import zero1hd.rhythmbullet.entity.EntityManager; +import zero1hd.rhythmbullet.entity.Entity; +import zero1hd.rhythmbullet.entity.EntityFrame; import zero1hd.rhythmbullet.entity.EntityIndex; +import zero1hd.rhythmbullet.entity.EntityManager; import zero1hd.rhythmbullet.entity.ally.Laser; +import zero1hd.rhythmbullet.entity.coordinator.Coordinator; +import zero1hd.rhythmbullet.entity.coordinator.CoordinatorFrame; +import zero1hd.rhythmbullet.entity.coordinator.CoordinatorManager; import zero1hd.rhythmbullet.entity.enemies.Bar; import zero1hd.rhythmbullet.entity.enemies.Flake; import zero1hd.rhythmbullet.entity.enemies.Pellet; @@ -23,17 +31,24 @@ public class SpawnerWindow extends Window { private EntityManager ec; private Stage stage; - private List listOfEntities; - private ScrollPane scroller; + private HashMap params = new HashMap<>(); + private Array> entityFrames = new Array<>(); + private List> listOfEntities; + private ScrollPane entityListScroller; + + private Array> coordinatorFrames = new Array<>(); + private List> listOfCoordinators; + private ScrollPane coordinatorListScroller; + private Slider mod1; private Slider mod2; private Slider mod3; private Slider mod4; - public SpawnerWindow(String title, Skin skin, EntityManager ec, Stage stageForEntities) { + public SpawnerWindow(String title, Skin skin, EntityManager em, CoordinatorManager cm, Stage stageForEntities) { super(title, skin, "tinted"); - this.ec = ec; + this.ec = em; stage = stageForEntities; mod1 = new Slider(0.1f, 50f, 0.01f, true, skin); @@ -42,14 +57,29 @@ public class SpawnerWindow extends Window { mod4 = new Slider(1f, 12f, 0.01f, true, skin); listOfEntities = new List<>(skin); - listOfEntities.setItems(EntityIndex.values()); + entityFrames.add(em.bar); + entityFrames.add(em.flake); + entityFrames.add(em.laser); + entityFrames.add(em.pellet); + entityFrames.add(em.shard); + entityFrames.add(em.voidCircle); - scroller = new ScrollPane(listOfEntities); - add(scroller).expandY().fillY().spaceRight(15f); + listOfEntities.setItems(entityFrames); + entityListScroller = new ScrollPane(listOfEntities, skin); + add(entityListScroller).height(350f).width(200f); + + listOfCoordinators = new List<>(skin); + coordinatorFrames.add(cm.slowLeft); + coordinatorFrames.add(cm.slowRight); + + listOfCoordinators.setItems(coordinatorFrames); + coordinatorListScroller = new ScrollPane(listOfCoordinators, skin); + add(coordinatorListScroller).height(350f).width(200f); + add(mod1, mod2, mod3, mod4); - setSize(300f, 375f); + pack(); } @@ -65,40 +95,33 @@ public class SpawnerWindow extends Window { coords.set(Gdx.input.getX(), Gdx.input.getY()); stage.screenToStageCoordinates(coords); - - switch(listOfEntities.getSelected()) { - case LASER: - Laser laser = ec.laser.buildEntity(); - laser.init(coords.x, coords.y, mod1.getValue()); - stage.addActor(laser); - break; - case PELLET: - Pellet pellet = ec.pellet.buildEntity(); - pellet.init(coords.x, coords.y, mod2.getValue()/mod2.getMaxValue()*360f, mod1.getValue()); - stage.addActor(pellet); - break; - case VOID_CIRCLE: - VoidCircle voidCircle = ec.voidCircle.buildEntity(); - voidCircle.init(mod2.getValue(), coords.x, coords.y, mod1.getValue(), mod3.getValue()); - stage.addActor(voidCircle); - break; - case SHARD: - Shard shard = ec.shard.buildEntity(); - shard.init(coords.x, coords.y, mod2.getValue()/mod2.getMaxValue()*360f, mod1.getValue(), (int) mod3.getValue()); - stage.addActor(shard); - break; - case BAR: - Bar bar = ec.bar.buildEntity(); - bar.init(coords.x, mod1.getValue()); - stage.addActor(bar); - break; - case FLAKE: - Flake flake = ec.flake.buildEntity(); - flake.init(coords.x, coords.y, mod1.getValue(), mod3.getValue(), mod2.getValue()/mod2.getMaxValue()*360f, (int) mod4.getValue()); - stage.addActor(flake); - default: - break; + Entity entity = listOfEntities.getSelected().buildEntity(); + + if (Gdx.input.isKeyPressed(Keys.ALT_LEFT)) { + entity.setCoordinator(listOfCoordinators.getSelected().buildCoordinator()); } + + if (entity.getClass() == Laser.class) { + Laser laser = (Laser) entity; + laser.init(coords.x, coords.y, mod1.getValue()); + } else if (entity.getClass() == Pellet.class) { + Pellet pellet = (Pellet) entity; + pellet.init(coords.x, coords.y, mod2.getValue()/mod2.getMaxValue()*360f, mod1.getValue()); + } else if (entity.getClass() == VoidCircle.class) { + VoidCircle voidCircle = (VoidCircle) entity; + voidCircle.init(mod2.getValue(), coords.x, coords.y, mod1.getValue(), mod3.getValue()); + } else if (entity.getClass() == Shard.class) { + Shard shard = (Shard) entity; + shard.init(coords.x, coords.y, mod2.getValue()/mod2.getMaxValue()*360f, mod1.getValue(), (int) mod3.getValue()); + } else if (entity.getClass() == Bar.class) { + Bar bar = (Bar) entity; + bar.init(coords.x, mod1.getValue()); + } else if (entity.getClass() == Flake.class) { + Flake flake = (Flake) entity; + flake.init(coords.x, coords.y, mod1.getValue(), mod3.getValue(), mod2.getValue()/mod2.getMaxValue()*360f, (int) mod4.getValue()); + } + + stage.addActor(entity); } super.act(delta); }