reworked the entity framework (still in progress)

This commit is contained in:
2017-07-28 00:42:08 -05:00
parent 013e3d7d99
commit 66e82c0efe
18 changed files with 476 additions and 502 deletions

View File

@@ -1,26 +1,25 @@
package zero1hd.polyjet.audio.map;
import zero1hd.polyjet.entity.Entities;
import java.util.HashMap;
import zero1hd.polyjet.entity.EntityIndex;
public class EntitySpawnInfo {
private Entities entityType;
private float[] parameters;
private EntityIndex entityType;
// private float[] parameters;
public HashMap<String, Float> parameters;
public EntitySpawnInfo(Entities entityType, float... parameters) {
public EntitySpawnInfo(EntityIndex entityType) {
this.entityType = entityType;
this.parameters = parameters;
parameters = new HashMap<>();
}
public Entities getEntityType() {
public EntityIndex getEntityType() {
return entityType;
}
@Override
public String toString() {
return entityType.name() + ": " + parameters.length;
}
public float[] getParameters() {
return parameters;
return entityType.name() + ": " + parameters.size();
}
}

View File

@@ -4,14 +4,16 @@ import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.utils.Array;
import zero1hd.polyjet.audio.AudioData;
import zero1hd.polyjet.entity.Entities;
import zero1hd.polyjet.entity.EntityIndex;
public class GamePlayMap {
private AudioData musicData;
private float playTime;
private Array<MapWindowData> 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
@@ -61,19 +63,17 @@ public class GamePlayMap {
/**
* used to add data types for what entity to spawn at that index position
* cannot be null.
* @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
* adds a new entity to the map for the current window.
* @param entityType what type of entity it should be
* @return the object.
*/
public void addToMap(Entities entityType, float... parameters) {
if (building && entityType != null && parameters != null) {
if (spawnList.get(index) == null) {
spawnList.set(index, new MapWindowData());
}
spawnList.get(index).addEntity(new EntitySpawnInfo(entityType, parameters));
public EntitySpawnInfo nextEntitySpawnInfo(EntityIndex entityType) {
if (spawnList.get(index) == null) {
spawnList.set(index, new MapWindowData());
}
EntitySpawnInfo esi = new EntitySpawnInfo(entityType);
spawnList.get(index).addEntity(esi);
return esi;
}
/**
@@ -81,8 +81,7 @@ public class GamePlayMap {
*/
public void nextWindow() {
if (building) {
spawnList.add(new MapWindowData());
resetIndex();
index++;
}
}

View File

@@ -7,7 +7,7 @@ import com.badlogic.gdx.utils.FloatArray;
import zero1hd.polyjet.Main;
import zero1hd.polyjet.audio.AudioAnalyzer;
import zero1hd.polyjet.entity.Entities;
import zero1hd.polyjet.entity.EntityIndex;
import zero1hd.polyjet.util.MiniEvents;
import zero1hd.polyjet.util.MiniSender;
@@ -52,6 +52,8 @@ public class RhythmMapAlgorithm implements Runnable {
avgBass = analyzer.getBassAvg();
}
EntitySpawnInfo esi;
@Override
public void run() {
map.beginBuild();
@@ -64,13 +66,14 @@ public class RhythmMapAlgorithm implements Runnable {
int indexMoved = map.goBack((int) (windowPerSecond*1.5f));
float waitTime = indexMoved/windowPerSecond;
float endRadius = (bassPeaks.get(index)/bassMax)*(Main.GAME_AREA_HEIGHT/4f);
map.addToMap(Entities.VOID_CIRCLE,
endRadius,
rand.nextFloat()*Main.GAME_AREA_WIDTH,
rand.nextFloat()*Main.GAME_AREA_HEIGHT,
endRadius/(avgSPB*0.7f),
waitTime
);
esi = map.nextEntitySpawnInfo(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);
}
}
@@ -79,16 +82,20 @@ public class RhythmMapAlgorithm implements Runnable {
if (UMPeaks.get(index) >= avgUM) {
//If upper midrange peaks are greater than average, the:
int spawnLocations = (Main.GAME_AREA_WIDTH-8)/8;
map.addToMap(Entities.BAR,
MathUtils.round(rand.nextFloat()*spawnLocations)*8,
(8f/avgSPB)*speedMod);
esi = map.nextEntitySpawnInfo(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;
map.addToMap(Entities.PELLET,
xSpawnLocation,
Main.GAME_AREA_HEIGHT-0.25f,
140*rand.nextFloat()+110f,
(Main.GAME_AREA_HEIGHT/4f)/avgSPB);
esi = map.nextEntitySpawnInfo(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);
esi.parameters.put("speed", (Main.GAME_AREA_HEIGHT/4f)/avgSPB);
}
}