From 013e3d7d996ef53d60828aae1f0c422ec45740dc Mon Sep 17 00:00:00 2001 From: Recrown Date: Wed, 26 Jul 2017 02:24:23 -0500 Subject: [PATCH] fixed dumb math mistake and changes to map gen index control --- .../polyjet/audio/map/RhythmMapAlgorithm.java | 57 ++++++++++++------- core/src/zero1hd/polyjet/entity/Entities.java | 20 ++++++- .../polyjet/entity/EntityController.java | 19 ++++--- .../zero1hd/polyjet/entity/enemies/Flake.java | 16 ++++-- .../polyjet/entity/enemies/Pellet.java | 3 +- .../zero1hd/polyjet/entity/enemies/Shard.java | 4 +- .../polyjet/ui/stages/GamePlayArea.java | 2 +- .../polyjet/ui/windows/SpawnerWindow.java | 8 +-- 8 files changed, 81 insertions(+), 48 deletions(-) diff --git a/core/src/zero1hd/polyjet/audio/map/RhythmMapAlgorithm.java b/core/src/zero1hd/polyjet/audio/map/RhythmMapAlgorithm.java index 963fd7a..f43009c 100755 --- a/core/src/zero1hd/polyjet/audio/map/RhythmMapAlgorithm.java +++ b/core/src/zero1hd/polyjet/audio/map/RhythmMapAlgorithm.java @@ -57,34 +57,51 @@ public class RhythmMapAlgorithm implements Runnable { map.beginBuild(); for (int index = 0; index < bassPeaks.size; index++) { if (bassPeaks.get(index) != 0 || UMPeaks.get(index) != 0) { - //If there is a value of some sorts that is not zero, we generate some beat for the map - if (bassPeaks.get(index) >= avgBass) { - float warningTime = map.goBack((int) (windowPerSecond*1.5f))/windowPerSecond; - float endRadius = (bassPeaks.get(index)/bassMax)*(Main.GAME_AREA_HEIGHT/4f); - map.addToMap(Entities.VOID_CIRCLE, - endRadius, - rand.nextFloat()*Main.GAME_AREA_WIDTH, - rand.nextFloat()*Main.GAME_AREA_HEIGHT, - endRadius/(avgSPB*0.7f), - warningTime - ); - map.resetIndex(); + if (bassPeaks.get(index) != 0) { + //If there is a value of some sorts that is not zero, we generate some beat for the map + if (bassPeaks.get(index) >= avgBass) { + //If bass peak is greater than the bass peak average, then: + int indexMoved = map.goBack((int) (windowPerSecond*1.5f)); + float waitTime = indexMoved/windowPerSecond; + float endRadius = (bassPeaks.get(index)/bassMax)*(Main.GAME_AREA_HEIGHT/4f); + map.addToMap(Entities.VOID_CIRCLE, + endRadius, + rand.nextFloat()*Main.GAME_AREA_WIDTH, + rand.nextFloat()*Main.GAME_AREA_HEIGHT, + endRadius/(avgSPB*0.7f), + waitTime + ); + map.goForward(indexMoved); + } } - if (UMPeaks.get(index) >= avgUM) { - int spawnLocations = (Main.GAME_AREA_WIDTH-8)/8; - map.addToMap(Entities.BAR, - MathUtils.round(rand.nextFloat()*spawnLocations)*8, - (8f/avgSPB)*speedMod); - } else { - if (UMPeaks.get(index) != 0) { + + if (UMPeaks.get(index) != 0) { + if (UMPeaks.get(index) >= avgUM) { + //If upper midrange peaks are greater than average, the: + int spawnLocations = (Main.GAME_AREA_WIDTH-8)/8; + map.addToMap(Entities.BAR, + MathUtils.round(rand.nextFloat()*spawnLocations)*8, + (8f/avgSPB)*speedMod); + } else { float xSpawnLocation = (rand.nextFloat()*(Main.GAME_AREA_WIDTH-2))+1; map.addToMap(Entities.PELLET, xSpawnLocation, Main.GAME_AREA_HEIGHT-0.25f, - 140*rand.nextFloat()+110f, + 140*rand.nextFloat()+110f, (Main.GAME_AREA_HEIGHT/4f)/avgSPB); } } + + if (overlappedPeaks.get(index) != 0) { + + } + + if (rand.nextFloat() < 0.15f) { + switch(rand.nextInt(10)) { + case 0: + break; + } + } } else { map.addNullToMap(); } diff --git a/core/src/zero1hd/polyjet/entity/Entities.java b/core/src/zero1hd/polyjet/entity/Entities.java index 63f7df9..5438093 100755 --- a/core/src/zero1hd/polyjet/entity/Entities.java +++ b/core/src/zero1hd/polyjet/entity/Entities.java @@ -1,15 +1,29 @@ package zero1hd.polyjet.entity; +import zero1hd.polyjet.entity.ally.Laser; +import zero1hd.polyjet.entity.ally.PolyJetEntity; +import zero1hd.polyjet.entity.enemies.Bar; +import zero1hd.polyjet.entity.enemies.Flake; +import zero1hd.polyjet.entity.enemies.Pellet; +import zero1hd.polyjet.entity.enemies.Shard; +import zero1hd.polyjet.entity.enemies.VoidCircle; + public enum Entities { - POLYJET(false), BAR(true), VOID_CIRCLE(true), SHARD(true), LASER(false), PELLET(true), FLAKE(true); + POLYJET(false, PolyJetEntity.class), BAR(true, Bar.class), VOID_CIRCLE(true, VoidCircle.class), SHARD(true, Shard.class), LASER(false, Laser.class), PELLET(true, Pellet.class), FLAKE(true, Flake.class); - private boolean enemy; + private final boolean enemy; + private final Class classType; - private Entities(boolean enemy) { + private Entities(boolean enemy, Class classType) { this.enemy = enemy; + this.classType = classType; } public boolean isEnemy() { return enemy; } + + public Class getClassType() { + return classType; + } } diff --git a/core/src/zero1hd/polyjet/entity/EntityController.java b/core/src/zero1hd/polyjet/entity/EntityController.java index 70e54f5..93ba6c9 100755 --- a/core/src/zero1hd/polyjet/entity/EntityController.java +++ b/core/src/zero1hd/polyjet/entity/EntityController.java @@ -33,14 +33,18 @@ public class EntityController { private Pool barPool; private Pool flakePool; + private EntityController ec = this; + //Ally pool declaration; private Pool laserPool; - public EntityController(AssetManager assetManager, Preferences preferences) { + private Stage stage; + public EntityController(AssetManager assetManager, Preferences preferences, Stage stage) { activeAllies = new Array(); activeEnemies = new Array(); this.assets = assetManager; this.prefs = preferences; + this.stage = stage; //Enemy pool initialization; voidCirclePool = new Pool() { @@ -74,7 +78,7 @@ public class EntityController { flakePool = new Pool() { @Override protected Flake newObject() { - return new Flake(assets.get("flake.png", Texture.class)); + return new Flake(assets.get("flake.png", Texture.class), ec); } }; @@ -155,13 +159,7 @@ public class EntityController { return bar; case FLAKE: Flake flake = flakePool.obtain(); - Shard[] shards = new Shard[(int) param[0]]; - for (int i = 0; i < shards.length; i++) { - shards[i] = (Shard) retrieveEntity(Entities.SHARD); - shards[i].init(param[6], param[7], param[8], param[9], (int) param[10]); - stage.addActor(shards[i]); - } - flake.init(param[1], param[2], param[3], param[4], param[5], shards); + flake.init(param[1], param[2], param[3], param[4], param[5], (int) param[0]); activeEnemies.add(flake); stage.addActor(flake); return flake; @@ -228,4 +226,7 @@ public class EntityController { } } + public Stage getStage() { + return stage; + } } diff --git a/core/src/zero1hd/polyjet/entity/enemies/Flake.java b/core/src/zero1hd/polyjet/entity/enemies/Flake.java index 84f888a..d3a0eb2 100755 --- a/core/src/zero1hd/polyjet/entity/enemies/Flake.java +++ b/core/src/zero1hd/polyjet/entity/enemies/Flake.java @@ -11,6 +11,7 @@ import com.badlogic.gdx.utils.Pool.Poolable; import zero1hd.polyjet.Main; import zero1hd.polyjet.entity.Entities; import zero1hd.polyjet.entity.Entity; +import zero1hd.polyjet.entity.EntityController; public class Flake extends Entity implements Poolable { private Texture texture; @@ -21,16 +22,23 @@ public class Flake extends Entity implements Poolable { private Rectangle hitbox; private Vector2 center; private Vector2 rot; + private EntityController ec; - public Flake(Texture texture) { + public Flake(Texture texture, EntityController ec) { + this.ec = ec; this.texture = texture; hitbox = new Rectangle(); center = new Vector2(); rot = new Vector2(); } - public void init(float x, float y, float rate, float fuse, float angle, Shard... shards) { - this.shards = shards; + public void init(float x, float y, float rate, float fuse, float angle, int shardCount) { + this.shards = new Shard[shardCount]; + for (int i = 0; i < shards.length; i++) { + shards[i] = (Shard) ec.retrieveEntity(Entities.SHARD); + shards[i].init(x, y, 360/shards.length*i, 0, 2); + ec.getStage().addActor(shards[i]); + } setSize(3f, 3f); this.rate = rate; this.timer = fuse; @@ -38,7 +46,7 @@ public class Flake extends Entity implements Poolable { hitbox.setSize(getWidth(), getHeight()); center.set(getWidth()/2f, getHeight()/2f); setPosition(x-center.x, y-center.y); - rot.set(MathUtils.sinDeg(angle), MathUtils.cosDeg(angle)); + rot.set(MathUtils.cosDeg(angle), MathUtils.sinDeg(angle)); } @Override diff --git a/core/src/zero1hd/polyjet/entity/enemies/Pellet.java b/core/src/zero1hd/polyjet/entity/enemies/Pellet.java index abf5a53..dd3cdc7 100755 --- a/core/src/zero1hd/polyjet/entity/enemies/Pellet.java +++ b/core/src/zero1hd/polyjet/entity/enemies/Pellet.java @@ -6,7 +6,6 @@ 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.Main; @@ -28,7 +27,7 @@ public class Pellet extends Entity implements Poolable { public void init(float x, float y, float angle, float rate) { setPosition(x, y); - direction.set(MathUtils.sinDeg(angle), MathUtils.cosDeg(angle)); + direction.set(MathUtils.cosDeg(angle), MathUtils.sinDeg(angle)); setSize(0.5f, 0.5f); hitBox.setSize(getWidth(), getHeight()); this.rate = rate; diff --git a/core/src/zero1hd/polyjet/entity/enemies/Shard.java b/core/src/zero1hd/polyjet/entity/enemies/Shard.java index bd92fd6..c48b63d 100755 --- a/core/src/zero1hd/polyjet/entity/enemies/Shard.java +++ b/core/src/zero1hd/polyjet/entity/enemies/Shard.java @@ -34,8 +34,8 @@ public class Shard extends Entity implements Poolable { this.rate = rate; this.hp = hp; maxHp = hp; - this.angle.set(MathUtils.sinDeg(angle), MathUtils.cosDeg(angle)); - sprite.setRotation(-angle); + this.angle.set(MathUtils.cosDeg(angle), MathUtils.sinDeg(angle)); + sprite.setRotation(angle+90); setSize(2f, 2f); hitbox.setSize(getWidth(), getHeight()); center.set(getWidth()/2f, getHeight()/2f); diff --git a/core/src/zero1hd/polyjet/ui/stages/GamePlayArea.java b/core/src/zero1hd/polyjet/ui/stages/GamePlayArea.java index d3d9bd7..3a6cfc4 100755 --- a/core/src/zero1hd/polyjet/ui/stages/GamePlayArea.java +++ b/core/src/zero1hd/polyjet/ui/stages/GamePlayArea.java @@ -46,7 +46,7 @@ public class GamePlayArea extends Stage { Gdx.app.debug("Game Area", "new area created"); polyjet = new PolyJetEntity(assetManager, 25f, 25f, "standard"); - ec = new EntityController(assetManager, prefs); + ec = new EntityController(assetManager, prefs, this); collisionDetector = new CollisionDetector(ec.activeAllies, ec.activeEnemies, assetManager, prefs); ec.activeAllies.add(polyjet); addActor(polyjet); diff --git a/core/src/zero1hd/polyjet/ui/windows/SpawnerWindow.java b/core/src/zero1hd/polyjet/ui/windows/SpawnerWindow.java index b220c35..1fdb916 100755 --- a/core/src/zero1hd/polyjet/ui/windows/SpawnerWindow.java +++ b/core/src/zero1hd/polyjet/ui/windows/SpawnerWindow.java @@ -96,14 +96,8 @@ public class SpawnerWindow extends Window { break; case FLAKE: Flake flake = (Flake) entity; - Shard[] shards = new Shard[(int) mod4.getValue()]; - for (int i = 0; i < shards.length; i++) { - shards[i] = (Shard) ec.retrieveEntity(Entities.SHARD); - shards[i].init(coords.x, coords.y, 360f/shards.length*i, 0f, (int) 2); - stage.addActor(shards[i]); - } stage.addActor(flake); - flake.init(coords.x, coords.y, mod1.getValue(), mod3.getValue(), mod2.getValue()/mod2.getMaxValue()*360f, shards); + flake.init(coords.x, coords.y, mod1.getValue(), mod3.getValue(), mod2.getValue()/mod2.getMaxValue()*360f, (int) mod4.getValue()); default: break; }