entity spawning added
This commit is contained in:
@@ -197,6 +197,7 @@ public class AudioAnalyzer {
|
||||
int lastID = 0;
|
||||
float bassBeats = 0;
|
||||
float umBeats = 0;
|
||||
avgBPS = -1f;
|
||||
for (int i = 0; i < umPrunned.size-1 && work; i++) {
|
||||
bassPeaks.add((bassPrunned.get(i) > bassPrunned.get(i+1) ? bassPrunned.get(i) : 0));
|
||||
if (bassPeaks.get(i) > bassMaxValue) {
|
||||
@@ -215,7 +216,6 @@ public class AudioAnalyzer {
|
||||
overlappedPeaks.add(0);
|
||||
}
|
||||
|
||||
avgBPS = -1f;
|
||||
|
||||
if (avgBPS != -1) {
|
||||
if (bassPeaks.get(i) == 0) {
|
||||
@@ -235,13 +235,15 @@ public class AudioAnalyzer {
|
||||
umAvg += umPeaks.get(i);
|
||||
umBeats++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//then we minus one from the beats so it actually works out
|
||||
avgBPS -= umPrunned.size-lastID;
|
||||
avgBPS *= secondsPerWindow;
|
||||
avgBPS /= bassBeats;
|
||||
|
||||
Gdx.app.debug("Audio Analyzer", "Avg BPS: " + avgBPS);
|
||||
|
||||
bassAvg /= bassBeats;
|
||||
umBeats /= umBeats;
|
||||
|
||||
|
@@ -34,7 +34,7 @@ public class WavAudioData implements AudioData {
|
||||
|
||||
@Override
|
||||
public void readIndexUpdate() {
|
||||
readIndex = (int) (playbackMusic.getPosition() * decoder.getSampleRate() / readWindowSize);
|
||||
readIndex = (int) (playbackMusic.getPosition() * decoder.getSampleRate() / (float)readWindowSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -4,9 +4,9 @@ import zero1hd.polyjet.entity.Entities;
|
||||
|
||||
public class EntitySpawnInfo {
|
||||
private Entities entityType;
|
||||
private double[] parameters;
|
||||
private float[] parameters;
|
||||
|
||||
public EntitySpawnInfo(Entities entityType, double... parameters) {
|
||||
public EntitySpawnInfo(Entities entityType, float... parameters) {
|
||||
this.entityType = entityType;
|
||||
this.parameters = parameters;
|
||||
}
|
||||
@@ -19,4 +19,8 @@ public class EntitySpawnInfo {
|
||||
public String toString() {
|
||||
return entityType.name() + ": " + parameters.length;
|
||||
}
|
||||
|
||||
public float[] getParameters() {
|
||||
return parameters;
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package zero1hd.polyjet.audio.map;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.audio.Music;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
@@ -7,19 +8,17 @@ import zero1hd.polyjet.audio.AudioData;
|
||||
import zero1hd.polyjet.entity.Entities;
|
||||
|
||||
public class GamePlayMap {
|
||||
private Music playableClip;
|
||||
private AudioData playableClip;
|
||||
private float playTime;
|
||||
private Array<EntitySpawnInfo> 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();
|
||||
this.playableClip = audioData;
|
||||
spawnList = new Array<>();
|
||||
}
|
||||
|
||||
@@ -28,7 +27,7 @@ public class GamePlayMap {
|
||||
* @return
|
||||
*/
|
||||
public Music getPlayableClip() {
|
||||
return playableClip;
|
||||
return playableClip.getPlaybackMusic();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,7 +59,7 @@ 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, double... parameters) {
|
||||
public void addToMap(Entities entityType, float... parameters) {
|
||||
if (building && entityType != null && parameters != null) {
|
||||
spawnList.add(new EntitySpawnInfo(entityType, parameters));
|
||||
}
|
||||
@@ -80,10 +79,11 @@ public class GamePlayMap {
|
||||
* retrieve next entity in list.
|
||||
* @return
|
||||
*/
|
||||
public EntitySpawnInfo nextEntity() {
|
||||
public EntitySpawnInfo nextEntity(boolean indexUpdate) {
|
||||
if (!building) {
|
||||
index++;
|
||||
|
||||
if (indexUpdate) {
|
||||
index++;
|
||||
}
|
||||
EntitySpawnInfo spawnInfo = spawnList.get(index);
|
||||
return spawnInfo;
|
||||
} else {
|
||||
@@ -91,6 +91,16 @@ public class GamePlayMap {
|
||||
}
|
||||
}
|
||||
|
||||
public EntitySpawnInfo safeNextEntity() {
|
||||
playableClip.readIndexUpdate();
|
||||
if (index != playableClip.getReadIndex()) {
|
||||
index = playableClip.getReadIndex();
|
||||
return nextEntity(false);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* set retrieve entity index position.
|
||||
* @param index
|
||||
|
@@ -60,17 +60,21 @@ public class RhythmMapAlgorithm implements Runnable {
|
||||
);
|
||||
}
|
||||
if (bassPeaks.get(index) != 0) {
|
||||
// float xSpawnLocation = (rand.nextFloat()*(Polyjet.GAME_AREA_WIDTH-2))+1;
|
||||
// map.addToMap(Entities.PELLET,
|
||||
// xSpawnLocation,
|
||||
// Polyjet.GAME_AREA_HEIGHT-0.25f,
|
||||
// 180*rand.nextFloat()+90,
|
||||
// speedMod*(1f/avgBPS));
|
||||
|
||||
map.addToMap(Entities.BAR,
|
||||
MathUtils.round(rand.nextFloat()*Polyjet.GAME_AREA_WIDTH),
|
||||
((Polyjet.GAME_AREA_HEIGHT-bassPeaks.get(index)*Polyjet.GAME_AREA_HEIGHT)/avgBPS)*speedMod);
|
||||
MathUtils.round(3),
|
||||
(1.5f/avgBPS)*speedMod);
|
||||
} else {
|
||||
if (UMPeaks.get(index) != 0) {
|
||||
float xSpawnLocation = (rand.nextFloat()*(Polyjet.GAME_AREA_WIDTH-2))+1;
|
||||
map.addToMap(Entities.PELLET,
|
||||
xSpawnLocation,
|
||||
Polyjet.GAME_AREA_HEIGHT-0.25f,
|
||||
180+180*rand.nextFloat(),
|
||||
speedMod*(Polyjet.GAME_AREA_HEIGHT/3)/avgBPS);
|
||||
// map.addToMap(Entities.BAR,
|
||||
// MathUtils.round(3),
|
||||
// (1.5f/avgBPS)*speedMod);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user