slightly different approach to map storing
This commit is contained in:
parent
5ec04f0f27
commit
053f4fb40e
@ -1,16 +1,11 @@
|
||||
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.EntityIndex;
|
||||
|
||||
public class GamePlayMap {
|
||||
|
||||
private AudioData musicData;
|
||||
private float playTime;
|
||||
private Array<MapWindowData> spawnList;
|
||||
private MapWindowData[] spawnList;
|
||||
private boolean building;
|
||||
private int index;
|
||||
|
||||
@ -18,135 +13,77 @@ public class GamePlayMap {
|
||||
* GamePlayMap is what the game area will use to generate entities and judge current audio data
|
||||
* @param audioData audio data
|
||||
*/
|
||||
public GamePlayMap(AudioData audioData) {
|
||||
public GamePlayMap(AudioData audioData, int totalWindows) {
|
||||
this.musicData = audioData;
|
||||
spawnList = new Array<>();
|
||||
spawnList = new MapWindowData[totalWindows];
|
||||
}
|
||||
|
||||
/**
|
||||
* returns audio data
|
||||
* @return
|
||||
*/
|
||||
public Music getPlayableClip() {
|
||||
return musicData.getPlaybackMusic();
|
||||
public int setIndex(int index) {
|
||||
int previousIndex = this.index;
|
||||
if (index < 0) {
|
||||
this.index = 0;
|
||||
} else if (index >= spawnList.length) {
|
||||
toHead();
|
||||
} else {
|
||||
this.index = index;
|
||||
}
|
||||
return previousIndex;
|
||||
}
|
||||
|
||||
public EntitySpawnInfo addEntity(EntityIndex entityType) {
|
||||
if (building) {
|
||||
if (spawnList[index] == null) {
|
||||
spawnList[index] = new MapWindowData();
|
||||
}
|
||||
EntitySpawnInfo esi = new EntitySpawnInfo(entityType);
|
||||
spawnList[index].addEntity(esi);
|
||||
return esi;
|
||||
} else {
|
||||
throw new IllegalStateException("Stupid, you need to call begin building first first.");
|
||||
}
|
||||
}
|
||||
|
||||
public void nextWindowData() {
|
||||
if (building) {
|
||||
index++;
|
||||
} else {
|
||||
throw new IllegalStateException("Stupid, you need to call begin building first first.");
|
||||
}
|
||||
}
|
||||
|
||||
public void toHead() {
|
||||
index = spawnList.length-1;
|
||||
}
|
||||
|
||||
public AudioData getMusicData() {
|
||||
return musicData;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the runtime time of the overall song
|
||||
* @return
|
||||
*/
|
||||
public float getPlayTime() {
|
||||
return playTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* call this when beginning to build map
|
||||
*/
|
||||
public void beginBuild() {
|
||||
building = true;
|
||||
spawnList.clear();
|
||||
spawnList.add(new MapWindowData());
|
||||
index = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* call this when finishing building map
|
||||
*/
|
||||
public void endBuild() {
|
||||
building = false;
|
||||
index = 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* adds a new entity to the map for the current window.
|
||||
* @param entityType what type of entity it should be
|
||||
* @return the object.
|
||||
*/
|
||||
public EntitySpawnInfo nextEntitySpawnInfo(EntityIndex entityType) {
|
||||
EntitySpawnInfo esi = new EntitySpawnInfo(entityType);
|
||||
if (spawnList.get(index) == null) {
|
||||
spawnList.set(index, new MapWindowData());
|
||||
}
|
||||
spawnList.get(index).addEntity(esi);
|
||||
return esi;
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves onto the next window of the map for the song
|
||||
*/
|
||||
public void nextWindow() {
|
||||
if (building) {
|
||||
spawnList.add(new MapWindowData());
|
||||
resetIndex();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* moves to the previous window to make edits to that frame.
|
||||
*/
|
||||
public void previousWindow() {
|
||||
if (building) {
|
||||
index--;
|
||||
}
|
||||
}
|
||||
|
||||
public int goBack(int amount) {
|
||||
if (index-amount < 0) {
|
||||
int howMuchLess = -(index - amount);
|
||||
if (!building) {
|
||||
index = 0;
|
||||
return howMuchLess;
|
||||
building = true;
|
||||
} else {
|
||||
index -= amount;
|
||||
return amount;
|
||||
throw new IllegalStateException("Excuse me, but your already building...");
|
||||
}
|
||||
}
|
||||
|
||||
public void goForward(int amount) {
|
||||
if (index+amount > spawnList.size-1) {
|
||||
index += amount;
|
||||
} else {
|
||||
index += amount;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* use this to add rest for current index position
|
||||
*/
|
||||
public void addNullToMap() {
|
||||
public void endBuild() {
|
||||
if (building) {
|
||||
spawnList.add(null);
|
||||
index = 0;
|
||||
building = false;
|
||||
} else {
|
||||
throw new IllegalStateException("Nothings being built...");
|
||||
}
|
||||
}
|
||||
public MapWindowData nextWindowData() {
|
||||
|
||||
public MapWindowData getCurrentWindowBasedOnIndex() {
|
||||
if (index != musicData.getReadIndex()) {
|
||||
index = musicData.getReadIndex();
|
||||
return spawnList.get(index);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* set retrieve entity index position.
|
||||
* @param index
|
||||
*/
|
||||
public void setIndex(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public boolean isCurrentNull() {
|
||||
return spawnList.get(index) == null ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the current index to the end of the array
|
||||
*/
|
||||
public void resetIndex() {
|
||||
if (building) {
|
||||
index = spawnList.size-1;
|
||||
return spawnList[index];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public class RhythmMapAlgorithm implements Runnable {
|
||||
bassPeaks = analyzer.getBassPeaks();
|
||||
UMPeaks = analyzer.getUMPeaks();
|
||||
overlappedPeaks = analyzer.getOverlappedPeaks();
|
||||
map = new GamePlayMap(analyzer.getAudioData());
|
||||
map = new GamePlayMap(analyzer.getAudioData(), UMPeaks.size);
|
||||
rand = new MersenneTwister(analyzer.getPUID());
|
||||
avgSPB = analyzer.getAvgSPB();
|
||||
windowPerSecond = 1/analyzer.getsecondsPerWindow();
|
||||
@ -63,18 +63,18 @@ public class RhythmMapAlgorithm implements Runnable {
|
||||
//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));
|
||||
int indexMoved = map.setIndex((int) (windowPerSecond*1.5f));
|
||||
float waitTime = indexMoved/windowPerSecond;
|
||||
float endRadius = (bassPeaks.get(index)/bassMax)*(Main.GAME_AREA_HEIGHT/4f);
|
||||
|
||||
esi = map.nextEntitySpawnInfo(EntityIndex.VOID_CIRCLE);
|
||||
esi = map.addEntity(EntityIndex.VOID_CIRCLE);
|
||||
esi.parameters.put("warningTime", waitTime);
|
||||
esi.parameters.put("endRadius", endRadius);
|
||||
esi.parameters.put("growthRate", endRadius/(avgSPB*0.7f));
|
||||
esi.parameters.put("x", rand.nextFloat()*Main.GAME_AREA_WIDTH);
|
||||
esi.parameters.put("y", rand.nextFloat()*Main.GAME_AREA_HEIGHT);
|
||||
|
||||
map.goForward(indexMoved);
|
||||
map.setIndex(indexMoved);
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,14 +83,14 @@ public class RhythmMapAlgorithm implements Runnable {
|
||||
//If upper midrange peaks are greater than average, the:
|
||||
int spawnLocations = (Main.GAME_AREA_WIDTH-8)/8;
|
||||
|
||||
esi = map.nextEntitySpawnInfo(EntityIndex.BAR);
|
||||
esi = map.addEntity(EntityIndex.BAR);
|
||||
esi.parameters.put("x", (float) (MathUtils.round(rand.nextFloat()*spawnLocations)*8));
|
||||
esi.parameters.put("rate", (8f/avgSPB)*speedMod);
|
||||
|
||||
} else {
|
||||
float xSpawnLocation = (rand.nextFloat()*(Main.GAME_AREA_WIDTH-2))+1;
|
||||
|
||||
esi = map.nextEntitySpawnInfo(EntityIndex.PELLET);
|
||||
esi = map.addEntity(EntityIndex.PELLET);
|
||||
esi.parameters.put("x", xSpawnLocation);
|
||||
esi.parameters.put("y", Main.GAME_AREA_HEIGHT-0.25f);
|
||||
esi.parameters.put("angle", 140*rand.nextFloat()+110f);
|
||||
@ -109,10 +109,8 @@ public class RhythmMapAlgorithm implements Runnable {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
map.addNullToMap();
|
||||
}
|
||||
map.nextWindow();
|
||||
map.nextWindowData();
|
||||
|
||||
progress = MathUtils.round(100f*index/bassPeaks.size);
|
||||
|
||||
|
@ -50,7 +50,7 @@ public class GameScreen extends ScreenAdapter {
|
||||
|
||||
gameArea = new GamePlayArea(polyJet.getAssetManager(), core.getPrefs());
|
||||
gameArea.setAudioMap(gpm);
|
||||
gameHUD = new GameHUD(polyJet.getDefaultSkin(), gpm.getPlayableClip(), gameArea.getMaxHealth());
|
||||
gameHUD = new GameHUD(polyJet.getDefaultSkin(), gpm.getMusicData().getPlaybackMusic(), gameArea.getMaxHealth());
|
||||
|
||||
inputs = new InputMultiplexer();
|
||||
inputs.addProcessor(gameHUD);
|
||||
|
@ -121,9 +121,9 @@ public class GamePlayArea extends Stage {
|
||||
@Override
|
||||
public void act(float delta) {
|
||||
MapWindowData mwd;
|
||||
if (audioMap != null && audioMap.getPlayableClip().isPlaying()) {
|
||||
if (audioMap != null && audioMap.getMusicData().getPlaybackMusic().isPlaying()) {
|
||||
audioMap.getMusicData().readIndexUpdate();
|
||||
if ((mwd = audioMap.nextWindowData()) != null) {
|
||||
if ((mwd = audioMap.getCurrentWindowBasedOnIndex()) != null) {
|
||||
EntitySpawnInfo[] currentSpawnInfo = mwd.getArray();
|
||||
if (currentSpawnInfo != null) {
|
||||
for (int i = 0; i < currentSpawnInfo.length; i++) {
|
||||
|
Loading…
Reference in New Issue
Block a user