From 329ff21c751d25e54b192dd72e719eb748492fce Mon Sep 17 00:00:00 2001 From: Recrown Date: Fri, 23 Jun 2017 15:31:36 -0500 Subject: [PATCH] progress working on rhythm map --- .../zero1hd/polyjet/audio/AudioAnalyzer.java | 12 ++- .../zero1hd/polyjet/audio/GamePlayMap.java | 21 ---- .../polyjet/audio/RhythmMapAlgorithm.java | 16 --- .../polyjet/audio/map/EntitySpawnInfo.java | 22 ++++ .../polyjet/audio/map/GamePlayMap.java | 100 ++++++++++++++++++ .../polyjet/audio/map/RhythmMapAlgorithm.java | 36 +++++++ .../polyjet/entity/enemies/VoidCircle.java | 3 - .../zero1hd/polyjet/screens/GameScreen.java | 2 +- .../polyjet/ui/stages/GamePlayArea.java | 2 +- 9 files changed, 168 insertions(+), 46 deletions(-) delete mode 100755 core/src/zero1hd/polyjet/audio/GamePlayMap.java delete mode 100755 core/src/zero1hd/polyjet/audio/RhythmMapAlgorithm.java create mode 100755 core/src/zero1hd/polyjet/audio/map/EntitySpawnInfo.java create mode 100755 core/src/zero1hd/polyjet/audio/map/GamePlayMap.java create mode 100755 core/src/zero1hd/polyjet/audio/map/RhythmMapAlgorithm.java diff --git a/core/src/zero1hd/polyjet/audio/AudioAnalyzer.java b/core/src/zero1hd/polyjet/audio/AudioAnalyzer.java index 50a3d44..140558f 100755 --- a/core/src/zero1hd/polyjet/audio/AudioAnalyzer.java +++ b/core/src/zero1hd/polyjet/audio/AudioAnalyzer.java @@ -36,7 +36,7 @@ public class AudioAnalyzer { private FloatArray UMPeaks = new FloatArray(); private float UMMaxValue; - private FloatArray overlappedBeats = new FloatArray(); + private FloatArray overlappedPeaks = new FloatArray(); float bassThresholdMultiplier; float UMThresholdMultiplier; @@ -204,9 +204,9 @@ public class AudioAnalyzer { //overlapping beats for (int i = 0; i < UMPeaks.size && work; i++) { if (bassPeaks.get(i) != 0 && UMPeaks.get(i) != 0) { - overlappedBeats.add(bassPeaks.get(i)+UMPeaks.get(i)/2); + overlappedPeaks.add(bassPeaks.get(i)+UMPeaks.get(i)/2); } else { - overlappedBeats.add(0); + overlappedPeaks.add(0); } } @@ -233,7 +233,7 @@ public class AudioAnalyzer { UMPrunned.shrink(); UMPeaks.shrink(); - overlappedBeats.shrink(); + overlappedPeaks.shrink(); } public void startAnalyticalThread(AudioData audiofile) { @@ -306,4 +306,8 @@ public class AudioAnalyzer { public int getPUID() { return PUID; } + + public FloatArray getOverlappedPeaks() { + return overlappedPeaks; + } } diff --git a/core/src/zero1hd/polyjet/audio/GamePlayMap.java b/core/src/zero1hd/polyjet/audio/GamePlayMap.java deleted file mode 100755 index 343d0ea..0000000 --- a/core/src/zero1hd/polyjet/audio/GamePlayMap.java +++ /dev/null @@ -1,21 +0,0 @@ -package zero1hd.polyjet.audio; - -import com.badlogic.gdx.audio.Music; - -public class GamePlayMap { - private Music playableClip; - private float playTime; - - public GamePlayMap(AudioData audioData) { - playableClip = audioData.getPlaybackMusic(); - playTime = audioData.getDuration(); - } - - public Music getPlayableClip() { - return playableClip; - } - - public float getPlayTime() { - return playTime; - } -} diff --git a/core/src/zero1hd/polyjet/audio/RhythmMapAlgorithm.java b/core/src/zero1hd/polyjet/audio/RhythmMapAlgorithm.java deleted file mode 100755 index 8554b1e..0000000 --- a/core/src/zero1hd/polyjet/audio/RhythmMapAlgorithm.java +++ /dev/null @@ -1,16 +0,0 @@ -package zero1hd.polyjet.audio; - -import org.apache.commons.math3.random.MersenneTwister; - -public class RhythmMapAlgorithm implements Runnable { - AudioAnalyzer analyzer; - MersenneTwister rand; - public RhythmMapAlgorithm(AudioAnalyzer analyzer) { - this.analyzer = analyzer; - rand = new MersenneTwister(analyzer.getPUID()); - } - - @Override - public void run() { - } -} diff --git a/core/src/zero1hd/polyjet/audio/map/EntitySpawnInfo.java b/core/src/zero1hd/polyjet/audio/map/EntitySpawnInfo.java new file mode 100755 index 0000000..9ccbef3 --- /dev/null +++ b/core/src/zero1hd/polyjet/audio/map/EntitySpawnInfo.java @@ -0,0 +1,22 @@ +package zero1hd.polyjet.audio.map; + +import zero1hd.polyjet.entity.Entities; + +public class EntitySpawnInfo { + private Entities entityType; + private double[] parameters; + + public EntitySpawnInfo(Entities entityType, double... parameters) { + this.entityType = entityType; + this.parameters = parameters; + } + + public Entities getEntityType() { + return entityType; + } + + @Override + public String toString() { + return entityType.name() + ": " + parameters.length; + } +} diff --git a/core/src/zero1hd/polyjet/audio/map/GamePlayMap.java b/core/src/zero1hd/polyjet/audio/map/GamePlayMap.java new file mode 100755 index 0000000..64521f6 --- /dev/null +++ b/core/src/zero1hd/polyjet/audio/map/GamePlayMap.java @@ -0,0 +1,100 @@ +package zero1hd.polyjet.audio.map; + +import com.badlogic.gdx.audio.Music; +import com.badlogic.gdx.utils.Array; + +import zero1hd.polyjet.audio.AudioData; +import zero1hd.polyjet.entity.Entities; + +public class GamePlayMap { + private Music playableClip; + private float playTime; + private Array spawnList; + private boolean building; + private int index; + + /** + * GamePlayMap is what the game area will use to generate entities and judge current audio data + * @param audioData audio data + */ + public GamePlayMap(AudioData audioData) { + playableClip = audioData.getPlaybackMusic(); + playTime = audioData.getDuration(); + } + + /** + * returns audio data + * @return + */ + public Music getPlayableClip() { + return playableClip; + } + + /** + * returns the runtime time of the overall song + * @return + */ + public float getPlayTime() { + return playTime; + } + + /** + * call this when beginning to build map + */ + public void start() { + building = true; + } + + /** + * call this when finishing building map + */ + public void end() { + building = false; + } + + + /** + * used to add data types for what entity to spawn at that index position + * cannot be null. + * @param entityType what type of entity to spawn + * @param parameters the arguments for the entity. It is important to have the same amount of parameters the entity requires to spawn + */ + public void addToMap(Entities entityType, double... parameters) { + if (building && entityType != null && parameters != null) { + spawnList.add(new EntitySpawnInfo(entityType, parameters)); + } + } + + /** + * use this to add rest for current index position + */ + public void addRestToMap() { + if (building) { + spawnList.add(null); + } + } + + /** + * Only works when not started. + * retrieve next entity in list. + * @return + */ + public EntitySpawnInfo nextEntity() { + if (!building) { + index++; + + EntitySpawnInfo spawnInfo = spawnList.get(index); + return spawnInfo; + } else { + return null; + } + } + + /** + * set retrieve entity index position. + * @param index + */ + public void setIndex(int index) { + this.index = index; + } +} diff --git a/core/src/zero1hd/polyjet/audio/map/RhythmMapAlgorithm.java b/core/src/zero1hd/polyjet/audio/map/RhythmMapAlgorithm.java new file mode 100755 index 0000000..ec37f8f --- /dev/null +++ b/core/src/zero1hd/polyjet/audio/map/RhythmMapAlgorithm.java @@ -0,0 +1,36 @@ +package zero1hd.polyjet.audio.map; + +import org.apache.commons.math3.random.MersenneTwister; + +import com.badlogic.gdx.utils.FloatArray; + +import zero1hd.polyjet.audio.AudioAnalyzer; + +public class RhythmMapAlgorithm implements Runnable { + private FloatArray bassPeaks; + private FloatArray UMPeaks; + private FloatArray overlappedPeaks; + private MersenneTwister rand; + public RhythmMapAlgorithm(AudioAnalyzer analyzer) { + bassPeaks = analyzer.getBassPeaks(); + UMPeaks = analyzer.getUMPeaks(); + overlappedPeaks = analyzer.getOverlappedPeaks(); + rand = new MersenneTwister(analyzer.getPUID()); + } + + @Override + public void run() { + for (int index = 0; index < bassPeaks.size; index++) { + if (overlappedPeaks.get(index) != 0) { + //TODO basic void spawning + } else if (bassPeaks.get(index) != 0) { + //TODO basic bar spawning + } else { + if (UMPeaks.get(index) != 0) { + //TODO basic pellet scatter spawn + } + //TODO rest of the basic generation + } + } + } +} diff --git a/core/src/zero1hd/polyjet/entity/enemies/VoidCircle.java b/core/src/zero1hd/polyjet/entity/enemies/VoidCircle.java index 29fdd63..fad0c75 100755 --- a/core/src/zero1hd/polyjet/entity/enemies/VoidCircle.java +++ b/core/src/zero1hd/polyjet/entity/enemies/VoidCircle.java @@ -13,7 +13,6 @@ import zero1hd.polyjet.entity.Entities; import zero1hd.polyjet.entity.Entity; public class VoidCircle extends Actor implements Entity, Poolable { - private float warnTime; private float timer; private float endRadius; private float currentRadius; @@ -32,7 +31,6 @@ public VoidCircle(Texture voidTexture) { public void init(float endRadius, float x, float y, float growthRate, float warningTime) { timer = warningTime; - warnTime = warningTime; this.endRadius = endRadius; setSize(2f*endRadius, 2f*endRadius); center.set(getWidth()/2f, getHeight()/2f); @@ -89,7 +87,6 @@ public VoidCircle(Texture voidTexture) { endRadius = 0; done = false; begin = false; - warnTime = 0; center.set(0, 0); voidCircleTexture.setPosition(0, 0); setSize(0, 0); diff --git a/core/src/zero1hd/polyjet/screens/GameScreen.java b/core/src/zero1hd/polyjet/screens/GameScreen.java index d11ca5b..e1d4606 100755 --- a/core/src/zero1hd/polyjet/screens/GameScreen.java +++ b/core/src/zero1hd/polyjet/screens/GameScreen.java @@ -19,7 +19,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; import zero1hd.polyjet.Polyjet; import zero1hd.polyjet.audio.AudioData; -import zero1hd.polyjet.audio.GamePlayMap; +import zero1hd.polyjet.audio.map.GamePlayMap; import zero1hd.polyjet.ui.stages.GamePlayArea; import zero1hd.polyjet.ui.windows.FPSWindow; diff --git a/core/src/zero1hd/polyjet/ui/stages/GamePlayArea.java b/core/src/zero1hd/polyjet/ui/stages/GamePlayArea.java index 930bb33..24dc947 100755 --- a/core/src/zero1hd/polyjet/ui/stages/GamePlayArea.java +++ b/core/src/zero1hd/polyjet/ui/stages/GamePlayArea.java @@ -9,7 +9,7 @@ import com.badlogic.gdx.scenes.scene2d.Stage; import com.badlogic.gdx.utils.viewport.FitViewport; import zero1hd.polyjet.Polyjet; -import zero1hd.polyjet.audio.GamePlayMap; +import zero1hd.polyjet.audio.map.GamePlayMap; import zero1hd.polyjet.controls.KeyMap; import zero1hd.polyjet.entity.CollisionDetector; import zero1hd.polyjet.entity.Entities;