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 {
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();

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) {
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()) {
case VOID_CIRCLE:
VoidCircle voidCircle = voidCirclePool.obtain();
voidCircle.init(param[0], param[1], param[2], param[3], param[4]);
activeEnemies.add(voidCircle);
stage.addActor(voidCircle);
return voidCircle;
break;
case LASER:
Laser laser = laserPool.obtain();
laser.init(param[0], param[1], param[2]);
activeAllies.add(laser);
stage.addActor(laser);
return laser;
break;
case PELLET:
Pellet pellet = pelletPool.obtain();
pellet.init(param[0], param[1], param[2], param[3]);
activeEnemies.add(pellet);
stage.addActor(pellet);
return pellet;
break;
case SHARD:
Shard shard = shardPool.obtain();
shard.init(param[0], param[1], param[2], param[3], (int) param[4]);
activeEnemies.add(shard);
stage.addActor(shard);
return shard;
break;
case BAR:
Bar bar = barPool.obtain();
bar.init(param[0], param[1]);
activeEnemies.add(bar);
stage.addActor(bar);
return bar;
break;
case FLAKE:
Flake flake = flakePool.obtain();
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);
activeEnemies.add(flake);
stage.addActor(flake);
return flake;
default:
return null;
break;
}
} else {
return null;
}
return entitySpawnInfo;
}
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().end();
getBatch().setShader(null);
super.draw();
}
@ -115,8 +113,11 @@ public class GamePlayArea extends Stage {
@Override
public void act(float delta) {
if (audioMap != null) {
time = audioMap.getPlayableClip().getPosition();
ec.spawnEntity(this, audioMap.safeNextEntity());
audioMap.getMusicData().readIndexUpdate();
time = audioMap.getMusicData().getPlaybackMusic().getPosition();
while (ec.spawnEntity(this, audioMap.nextEntityBatch(false)).getSpawnWindowID() == audioMap.getMusicData().getReadIndex()) {
audioMap.nextWindow();
};
}
collisionDetector.collisionCheck();
ec.deathClean();

View File

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