change way of entity spawning

This commit is contained in:
2017-07-15 14:56:25 -05:00
parent 1fce870503
commit 1af7457b00
6 changed files with 47 additions and 38 deletions

View File

@@ -5,10 +5,12 @@ import zero1hd.polyjet.entity.Entities;
public class EntitySpawnInfo {
private Entities entityType;
private float[] parameters;
private int spawnWindowID;
public EntitySpawnInfo(Entities entityType, float... parameters) {
public EntitySpawnInfo(Entities entityType, int spawnWindowID, float... parameters) {
this.entityType = entityType;
this.parameters = parameters;
this.spawnWindowID = spawnWindowID;
}
public Entities getEntityType() {
@@ -23,4 +25,8 @@ public class EntitySpawnInfo {
public float[] getParameters() {
return parameters;
}
public int getSpawnWindowID() {
return spawnWindowID;
}
}

View File

@@ -1,6 +1,5 @@
package zero1hd.polyjet.audio.map;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.utils.Array;
import zero1hd.polyjet.audio.AudioData;
@@ -11,6 +10,7 @@ public class GamePlayMap {
private float playTime;
private Array<EntitySpawnInfo> spawnList;
private boolean building;
private int constIndex;
private int index;
/**
* GamePlayMap is what the game area will use to generate entities and judge current audio data
@@ -25,8 +25,8 @@ public class GamePlayMap {
* returns audio data
* @return
*/
public Music getPlayableClip() {
return playableClip.getPlaybackMusic();
public AudioData getMusicData() {
return playableClip;
}
/**
@@ -42,6 +42,8 @@ public class GamePlayMap {
*/
public void beginBuild() {
building = true;
index = 0;
constIndex = 0;
}
/**
@@ -49,6 +51,8 @@ public class GamePlayMap {
*/
public void endBuild() {
building = false;
index = 0;
constIndex = 0;
}
@@ -60,17 +64,13 @@ public class GamePlayMap {
*/
public void addToMap(Entities entityType, float... parameters) {
if (building && entityType != null && parameters != null) {
spawnList.add(new EntitySpawnInfo(entityType, parameters));
spawnList.add(new EntitySpawnInfo(entityType, index, parameters));
}
}
/**
* use this to add rest for current index position
*/
public void addNullToMap() {
if (building) {
spawnList.add(null);
}
public void nextWindow() {
constIndex++;
index++;
}
/**
@@ -78,9 +78,10 @@ public class GamePlayMap {
* retrieve next entity in list.
* @return
*/
public EntitySpawnInfo nextEntity(boolean indexUpdate) {
public EntitySpawnInfo nextEntityBatch(boolean indexUpdate) {
if (!building) {
if (indexUpdate) {
constIndex++;
index++;
}
EntitySpawnInfo spawnInfo = spawnList.get(index);
@@ -90,11 +91,11 @@ public class GamePlayMap {
}
}
public EntitySpawnInfo safeNextEntity() {
public EntitySpawnInfo safeNextEntityBatch() {
playableClip.readIndexUpdate();
if (index != playableClip.getReadIndex()) {
index = playableClip.getReadIndex();
return nextEntity(false);
return nextEntityBatch(false);
} else {
return null;
}
@@ -107,4 +108,12 @@ public class GamePlayMap {
public void setIndex(int index) {
this.index = index;
}
public void restoreIndex() {
this.index = constIndex;
}
public int getIndex() {
return index;
}
}

View File

@@ -56,10 +56,9 @@ public class RhythmMapAlgorithm implements Runnable {
map.beginBuild();
for (int index = 0; index < bassPeaks.size; index++) {
if (bassPeaks.get(index) != 0 || UMPeaks.get(index) != 0) {
int warningTime = (int) ((3/speedMod)*windowPerSecond);
if ((index+warningTime < bassPeaks.size) && bassPeaks.get(index + warningTime) != 0) {
if (bassPeaks.get(index) > avgBass) {
//TODO basic void circle spawning
float endRadius = (bassPeaks.get(index + warningTime)/bassMax)*(Polyjet.GAME_AREA_HEIGHT/2f);
float endRadius = (bassPeaks.get(index)/bassMax)*(Polyjet.GAME_AREA_HEIGHT/2f);
map.addToMap(Entities.VOID_CIRCLE,
endRadius,
@@ -84,12 +83,10 @@ public class RhythmMapAlgorithm implements Runnable {
}
}
} else {
map.addNullToMap();
}
progress = MathUtils.round(100f*index/bassPeaks.size);
map.nextWindow();
sender.send(MiniEvents.MAPGEN_ITERATED);
}
map.endBuild();