change way of entity spawning

This commit is contained in:
Harrison Deng 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 { public class EntitySpawnInfo {
private Entities entityType; private Entities entityType;
private float[] parameters; private float[] parameters;
private int spawnWindowID;
public EntitySpawnInfo(Entities entityType, float... parameters) { public EntitySpawnInfo(Entities entityType, int spawnWindowID, float... parameters) {
this.entityType = entityType; this.entityType = entityType;
this.parameters = parameters; this.parameters = parameters;
this.spawnWindowID = spawnWindowID;
} }
public Entities getEntityType() { public Entities getEntityType() {
@ -23,4 +25,8 @@ public class EntitySpawnInfo {
public float[] getParameters() { public float[] getParameters() {
return parameters; return parameters;
} }
public int getSpawnWindowID() {
return spawnWindowID;
}
} }

View File

@ -1,6 +1,5 @@
package zero1hd.polyjet.audio.map; package zero1hd.polyjet.audio.map;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Array;
import zero1hd.polyjet.audio.AudioData; import zero1hd.polyjet.audio.AudioData;
@ -11,6 +10,7 @@ public class GamePlayMap {
private float playTime; private float playTime;
private Array<EntitySpawnInfo> spawnList; private Array<EntitySpawnInfo> spawnList;
private boolean building; private boolean building;
private int constIndex;
private int index; private int index;
/** /**
* GamePlayMap is what the game area will use to generate entities and judge current audio data * 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 * returns audio data
* @return * @return
*/ */
public Music getPlayableClip() { public AudioData getMusicData() {
return playableClip.getPlaybackMusic(); return playableClip;
} }
/** /**
@ -42,6 +42,8 @@ public class GamePlayMap {
*/ */
public void beginBuild() { public void beginBuild() {
building = true; building = true;
index = 0;
constIndex = 0;
} }
/** /**
@ -49,6 +51,8 @@ public class GamePlayMap {
*/ */
public void endBuild() { public void endBuild() {
building = false; building = false;
index = 0;
constIndex = 0;
} }
@ -60,17 +64,13 @@ public class GamePlayMap {
*/ */
public void addToMap(Entities entityType, float... parameters) { public void addToMap(Entities entityType, float... parameters) {
if (building && entityType != null && parameters != null) { if (building && entityType != null && parameters != null) {
spawnList.add(new EntitySpawnInfo(entityType, parameters)); spawnList.add(new EntitySpawnInfo(entityType, index, parameters));
} }
} }
/** public void nextWindow() {
* use this to add rest for current index position constIndex++;
*/ index++;
public void addNullToMap() {
if (building) {
spawnList.add(null);
}
} }
/** /**
@ -78,9 +78,10 @@ public class GamePlayMap {
* retrieve next entity in list. * retrieve next entity in list.
* @return * @return
*/ */
public EntitySpawnInfo nextEntity(boolean indexUpdate) { public EntitySpawnInfo nextEntityBatch(boolean indexUpdate) {
if (!building) { if (!building) {
if (indexUpdate) { if (indexUpdate) {
constIndex++;
index++; index++;
} }
EntitySpawnInfo spawnInfo = spawnList.get(index); EntitySpawnInfo spawnInfo = spawnList.get(index);
@ -90,11 +91,11 @@ public class GamePlayMap {
} }
} }
public EntitySpawnInfo safeNextEntity() { public EntitySpawnInfo safeNextEntityBatch() {
playableClip.readIndexUpdate(); playableClip.readIndexUpdate();
if (index != playableClip.getReadIndex()) { if (index != playableClip.getReadIndex()) {
index = playableClip.getReadIndex(); index = playableClip.getReadIndex();
return nextEntity(false); return nextEntityBatch(false);
} else { } else {
return null; return null;
} }
@ -107,4 +108,12 @@ public class GamePlayMap {
public void setIndex(int index) { public void setIndex(int index) {
this.index = 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(); map.beginBuild();
for (int index = 0; index < bassPeaks.size; index++) { for (int index = 0; index < bassPeaks.size; index++) {
if (bassPeaks.get(index) != 0 || UMPeaks.get(index) != 0) { if (bassPeaks.get(index) != 0 || UMPeaks.get(index) != 0) {
int warningTime = (int) ((3/speedMod)*windowPerSecond); if (bassPeaks.get(index) > avgBass) {
if ((index+warningTime < bassPeaks.size) && bassPeaks.get(index + warningTime) != 0) {
//TODO basic void circle spawning //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, map.addToMap(Entities.VOID_CIRCLE,
endRadius, endRadius,
@ -84,12 +83,10 @@ public class RhythmMapAlgorithm implements Runnable {
} }
} }
} else {
map.addNullToMap();
} }
progress = MathUtils.round(100f*index/bassPeaks.size); progress = MathUtils.round(100f*index/bassPeaks.size);
map.nextWindow();
sender.send(MiniEvents.MAPGEN_ITERATED); sender.send(MiniEvents.MAPGEN_ITERATED);
} }
map.endBuild(); map.endBuild();

View File

@ -111,41 +111,41 @@ public class EntityController {
} }
} }
public Entity spawnEntity(Stage stage, EntitySpawnInfo entitySpawnInfo) { public EntitySpawnInfo spawnEntity(Stage stage, EntitySpawnInfo entitySpawnInfo) {
if (entitySpawnInfo != null) { if (entitySpawnInfo != null) {
float[] param = entitySpawnInfo.getParameters(); float[] param = entitySpawnInfo.getParameters();
Gdx.app.debug("Spawning Entity", entitySpawnInfo.toString() + " parameters: " + Arrays.toString(param)); Gdx.app.debug("Spawning Entity", entitySpawnInfo.toString() + " parameters: " + Arrays.toString(param) + "Attributed spawn window: " + entitySpawnInfo.getSpawnWindowID());
switch (entitySpawnInfo.getEntityType()) { switch (entitySpawnInfo.getEntityType()) {
case VOID_CIRCLE: case VOID_CIRCLE:
VoidCircle voidCircle = voidCirclePool.obtain(); VoidCircle voidCircle = voidCirclePool.obtain();
voidCircle.init(param[0], param[1], param[2], param[3], param[4]); voidCircle.init(param[0], param[1], param[2], param[3], param[4]);
activeEnemies.add(voidCircle); activeEnemies.add(voidCircle);
stage.addActor(voidCircle); stage.addActor(voidCircle);
return voidCircle; break;
case LASER: case LASER:
Laser laser = laserPool.obtain(); Laser laser = laserPool.obtain();
laser.init(param[0], param[1], param[2]); laser.init(param[0], param[1], param[2]);
activeAllies.add(laser); activeAllies.add(laser);
stage.addActor(laser); stage.addActor(laser);
return laser; break;
case PELLET: case PELLET:
Pellet pellet = pelletPool.obtain(); Pellet pellet = pelletPool.obtain();
pellet.init(param[0], param[1], param[2], param[3]); pellet.init(param[0], param[1], param[2], param[3]);
activeEnemies.add(pellet); activeEnemies.add(pellet);
stage.addActor(pellet); stage.addActor(pellet);
return pellet; break;
case SHARD: case SHARD:
Shard shard = shardPool.obtain(); Shard shard = shardPool.obtain();
shard.init(param[0], param[1], param[2], param[3], (int) param[4]); shard.init(param[0], param[1], param[2], param[3], (int) param[4]);
activeEnemies.add(shard); activeEnemies.add(shard);
stage.addActor(shard); stage.addActor(shard);
return shard; break;
case BAR: case BAR:
Bar bar = barPool.obtain(); Bar bar = barPool.obtain();
bar.init(param[0], param[1]); bar.init(param[0], param[1]);
activeEnemies.add(bar); activeEnemies.add(bar);
stage.addActor(bar); stage.addActor(bar);
return bar; break;
case FLAKE: case FLAKE:
Flake flake = flakePool.obtain(); Flake flake = flakePool.obtain();
Shard[] shards = new Shard[(int) param[0]]; Shard[] shards = new Shard[(int) param[0]];
@ -157,13 +157,10 @@ public class EntityController {
flake.init(param[1], param[2], param[3], param[4], param[5], shards); flake.init(param[1], param[2], param[3], param[4], param[5], shards);
activeEnemies.add(flake); activeEnemies.add(flake);
stage.addActor(flake); stage.addActor(flake);
return flake; break;
default:
return null;
} }
} else {
return null;
} }
return entitySpawnInfo;
} }
public void free(Entity entity) { public void free(Entity entity) {

View File

@ -106,8 +106,6 @@ public class GamePlayArea extends Stage {
getBatch().draw(background, 0f, 0f, Polyjet.GAME_AREA_WIDTH, Polyjet.GAME_AREA_HEIGHT); getBatch().draw(background, 0f, 0f, Polyjet.GAME_AREA_WIDTH, Polyjet.GAME_AREA_HEIGHT);
getBatch().end(); getBatch().end();
getBatch().setShader(null); getBatch().setShader(null);
super.draw(); super.draw();
} }
@ -115,8 +113,11 @@ public class GamePlayArea extends Stage {
@Override @Override
public void act(float delta) { public void act(float delta) {
if (audioMap != null) { if (audioMap != null) {
time = audioMap.getPlayableClip().getPosition(); audioMap.getMusicData().readIndexUpdate();
ec.spawnEntity(this, audioMap.safeNextEntity()); time = audioMap.getMusicData().getPlaybackMusic().getPosition();
while (ec.spawnEntity(this, audioMap.nextEntityBatch(false)).getSpawnWindowID() == audioMap.getMusicData().getReadIndex()) {
audioMap.nextWindow();
};
} }
collisionDetector.collisionCheck(); collisionDetector.collisionCheck();
ec.deathClean(); ec.deathClean();

View File

@ -4,7 +4,6 @@ import java.io.DataInputStream;
import java.io.IOException; import java.io.IOException;
import java.security.InvalidParameterException; import java.security.InvalidParameterException;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.files.FileHandle;
public class WavDecoder { public class WavDecoder {