From 1fd63e957963a2d23e2a299cde28a24143056652 Mon Sep 17 00:00:00 2001 From: Recrown Date: Sat, 15 Jul 2017 23:51:07 -0500 Subject: [PATCH] implemented new map structure --- .../polyjet/audio/map/GamePlayMap.java | 76 +++++++++++-------- .../polyjet/audio/map/MapWindowData.java | 19 +++++ .../polyjet/audio/map/RhythmMapAlgorithm.java | 4 +- .../polyjet/ui/stages/GamePlayArea.java | 13 +++- 4 files changed, 77 insertions(+), 35 deletions(-) create mode 100755 core/src/zero1hd/polyjet/audio/map/MapWindowData.java diff --git a/core/src/zero1hd/polyjet/audio/map/GamePlayMap.java b/core/src/zero1hd/polyjet/audio/map/GamePlayMap.java index aec4118..1308c4a 100755 --- a/core/src/zero1hd/polyjet/audio/map/GamePlayMap.java +++ b/core/src/zero1hd/polyjet/audio/map/GamePlayMap.java @@ -7,17 +7,18 @@ import zero1hd.polyjet.audio.AudioData; import zero1hd.polyjet.entity.Entities; public class GamePlayMap { - private AudioData playableClip; + private AudioData musicData; private float playTime; - private Array spawnList; + private Array spawnList; private boolean building; private int index; + private int absoluteIndex; /** * GamePlayMap is what the game area will use to generate entities and judge current audio data * @param audioData audio data */ public GamePlayMap(AudioData audioData) { - this.playableClip = audioData; + this.musicData = audioData; spawnList = new Array<>(); } @@ -26,7 +27,7 @@ public class GamePlayMap { * @return */ public Music getPlayableClip() { - return playableClip.getPlaybackMusic(); + return musicData.getPlaybackMusic(); } /** @@ -42,6 +43,10 @@ public class GamePlayMap { */ public void beginBuild() { building = true; + spawnList.clear(); + spawnList.add(new MapWindowData()); + index = 0; + absoluteIndex = 0; } /** @@ -49,6 +54,8 @@ public class GamePlayMap { */ public void endBuild() { building = false; + index = 0; + absoluteIndex = 0; } @@ -58,46 +65,47 @@ public class GamePlayMap { * @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, float... parameters) { if (building && entityType != null && parameters != null) { - spawnList.add(new EntitySpawnInfo(entityType, parameters)); + spawnList.get(index).addEntity(new EntitySpawnInfo(entityType, parameters)); } } + /** + * Moves onto the next window of the map for the song + */ + public void nextWindow() { + absoluteIndex++; + resetIndex(); + if (building) { + spawnList.add(new MapWindowData()); + } + } + + /** + * moves to the previous window to make edits to that frame. + */ + public void previousWindow() { + absoluteIndex--; + resetIndex(); + } /** * use this to add rest for current index position */ public void addNullToMap() { if (building) { - spawnList.add(null); + spawnList.set(index, null); } } - /** - * Only works when not started. - * retrieve next entity in list. - * @return - */ - public EntitySpawnInfo nextEntity(boolean indexUpdate) { - if (!building) { - if (indexUpdate) { - index++; - } - EntitySpawnInfo spawnInfo = spawnList.get(index); - return spawnInfo; - } else { - return null; - } - } - - public EntitySpawnInfo safeNextEntity() { - playableClip.readIndexUpdate(); - if (index != playableClip.getReadIndex()) { - index = playableClip.getReadIndex(); - return nextEntity(false); - } else { - return null; + public MapWindowData nextWindowData() { + if (index != musicData.getReadIndex()) { + absoluteIndex = musicData.getReadIndex(); + resetIndex(); + return spawnList.get(index); } + return null; } /** @@ -107,4 +115,12 @@ public class GamePlayMap { public void setIndex(int index) { this.index = index; } + + public boolean isCurrentNull() { + return spawnList.get(index) == null ? true : false; + } + + public void resetIndex() { + index = absoluteIndex; + } } diff --git a/core/src/zero1hd/polyjet/audio/map/MapWindowData.java b/core/src/zero1hd/polyjet/audio/map/MapWindowData.java new file mode 100755 index 0000000..716172f --- /dev/null +++ b/core/src/zero1hd/polyjet/audio/map/MapWindowData.java @@ -0,0 +1,19 @@ +package zero1hd.polyjet.audio.map; + +import com.badlogic.gdx.utils.Array; + + +public class MapWindowData { + Array entityDatas; + public MapWindowData() { + entityDatas = new Array<>(EntitySpawnInfo.class); + } + + public void addEntity(EntitySpawnInfo entity) { + entityDatas.add(entity); + } + + public EntitySpawnInfo[] getArray() { + return entityDatas.toArray(); + } +} \ No newline at end of file diff --git a/core/src/zero1hd/polyjet/audio/map/RhythmMapAlgorithm.java b/core/src/zero1hd/polyjet/audio/map/RhythmMapAlgorithm.java index 37f02e2..84755f3 100755 --- a/core/src/zero1hd/polyjet/audio/map/RhythmMapAlgorithm.java +++ b/core/src/zero1hd/polyjet/audio/map/RhythmMapAlgorithm.java @@ -83,11 +83,11 @@ public class RhythmMapAlgorithm implements Runnable { (Polyjet.GAME_AREA_HEIGHT/4f)/avgSPB); } } - } else { map.addNullToMap(); } - + map.nextWindow(); + progress = MathUtils.round(100f*index/bassPeaks.size); sender.send(MiniEvents.MAPGEN_ITERATED); diff --git a/core/src/zero1hd/polyjet/ui/stages/GamePlayArea.java b/core/src/zero1hd/polyjet/ui/stages/GamePlayArea.java index 7463ee9..5fb4b23 100755 --- a/core/src/zero1hd/polyjet/ui/stages/GamePlayArea.java +++ b/core/src/zero1hd/polyjet/ui/stages/GamePlayArea.java @@ -9,7 +9,9 @@ import com.badlogic.gdx.scenes.scene2d.Stage; import com.badlogic.gdx.utils.viewport.FitViewport; import zero1hd.polyjet.Polyjet; +import zero1hd.polyjet.audio.map.EntitySpawnInfo; import zero1hd.polyjet.audio.map.GamePlayMap; +import zero1hd.polyjet.audio.map.MapWindowData; import zero1hd.polyjet.controls.KeyMap; import zero1hd.polyjet.entity.CollisionDetector; import zero1hd.polyjet.entity.Entities; @@ -114,9 +116,14 @@ public class GamePlayArea extends Stage { @Override public void act(float delta) { - if (audioMap != null) { - time = audioMap.getPlayableClip().getPosition(); - ec.spawnEntity(this, audioMap.safeNextEntity()); + MapWindowData mwd; + if (audioMap != null && audioMap.getPlayableClip().isPlaying() && (mwd = audioMap.nextWindowData()) != null) { + EntitySpawnInfo[] currentSpawnInfo = mwd.getArray(); + if (currentSpawnInfo != null) { + for (int i = 0; i < currentSpawnInfo.length; i++) { + ec.spawnEntity(this, currentSpawnInfo[i]); + } + } } collisionDetector.collisionCheck(); ec.deathClean();