implemented new map structure

This commit is contained in:
Harrison Deng 2017-07-15 23:51:07 -05:00
parent 1fce870503
commit 1fd63e9579
4 changed files with 77 additions and 35 deletions

View File

@ -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<EntitySpawnInfo> spawnList;
private Array<MapWindowData> 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;
}
}

View File

@ -0,0 +1,19 @@
package zero1hd.polyjet.audio.map;
import com.badlogic.gdx.utils.Array;
public class MapWindowData {
Array<EntitySpawnInfo> entityDatas;
public MapWindowData() {
entityDatas = new Array<>(EntitySpawnInfo.class);
}
public void addEntity(EntitySpawnInfo entity) {
entityDatas.add(entity);
}
public EntitySpawnInfo[] getArray() {
return entityDatas.toArray();
}
}

View File

@ -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);

View File

@ -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();