entity spawning added
This commit is contained in:
@@ -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