changing to a different way of handling entities (no longer using scene2d)

This commit is contained in:
2018-02-01 14:59:51 -06:00
parent 08fb879b1f
commit 1fbdefaecd
19 changed files with 138 additions and 1164 deletions

View File

@@ -46,7 +46,6 @@ public class AudioAnalyzer implements Disposable {
public boolean isDone() {
if ((sfar.isDone() && tcr.isDone() && pfr.isDone() && pdr.isDone())) {
dispose();
return true;
}
return false;

View File

@@ -109,8 +109,10 @@ public class PeakDetectionRunnable implements Runnable {
pack.setSecPerWin(secondsPerWindow);
pack.setMusicInfo(musicManager);
if (work) {
Gdx.app.debug("Audio Analyzer", "data cleaned and ready for map gen.");
Gdx.app.debug("Audio Analyzer", "Peak detection complete. Data ready for map gen.");
}
done = true;
}
public AudioDataPackage getPack() {

View File

@@ -35,8 +35,8 @@ public class SpectralFluxAnalysisRunnable implements Runnable {
float[] spectrum = new float[(musicManager.getReadWindowSize()/2)+1];
float[] lastSpectrum = new float[(musicManager.getReadWindowSize()/2)+1];
int bassBinBegin = 0;
int bassBinEnd = 12;
int bassBinBegin = 1;
int bassBinEnd = 11;
int mBinBegin = 50;
int mBinEnd = 250;
@@ -105,10 +105,10 @@ public class SpectralFluxAnalysisRunnable implements Runnable {
if (work) {
Gdx.app.debug("Audio Analyzer", "Done getting spectral flux.");
Gdx.app.debug("Audio Analyzer", "window count: " + bassSpectralFlux.size);
done = true;
Gdx.app.debug("Audio Analyzer", "USING SEED: " + PUID);
progress = 100;
}
done = true;
}
public synchronized int getProgress() {

View File

@@ -65,8 +65,8 @@ public class ThresholdCalcRunnable implements Runnable {
average /= (end - start);
umThreshold.add(average*umThresholdMultiplier);
}
done = true;
Gdx.app.debug("Audio Analyzer", "Threshold calculated.");
done = true;
}
private int thresholdRangeCalc(float durationOfRange) {

View File

@@ -1,7 +1,5 @@
package zero1hd.rhythmbullet.entity;
import java.util.HashMap;
import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.Color;
@@ -10,13 +8,12 @@ import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.utils.Pool.Poolable;
import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.entity.coordinator.Coordinator;
public class Entity extends Actor implements Poolable {
public class Entity implements Poolable {
private Coordinator coordinator;
private EntityFrame<?> ef;
@@ -32,10 +29,10 @@ public class Entity extends Actor implements Poolable {
protected Rectangle hitbox;
protected Sprite sprite;
protected Vector2 rotRatios;
protected Vector2 center;
public float angle;
public float speed;
protected float hitBoxScale;
protected int points;
/**
@@ -51,7 +48,6 @@ public class Entity extends Actor implements Poolable {
assets = ec.getAssets();
prefs = ec.getPrefs();
rotRatios = new Vector2();
center = new Vector2();
hitbox = new Rectangle();
preInit();
@@ -65,11 +61,8 @@ public class Entity extends Actor implements Poolable {
sprite.setOriginCenter();
}
/**
* used by the game stage to pass parameters for different types of entities.
* @param params a hashmap containing parameters necessary for different entities.
*/
public void init(HashMap<String, Float> params) {
public void init(float deg, float speed, int hp) {
}
/**
@@ -91,16 +84,12 @@ public class Entity extends Actor implements Poolable {
return dead;
}
@Override
public void act(float delta) {
public void calculate(float delta) {
if (!nonStnrd) {
if (coordinator != null) {
coordinator.coordinate(delta);
}
if (move) {
move(delta, true);
}
if (dead) {
ef.recycleEntity(this);
}
@@ -110,36 +99,29 @@ public class Entity extends Actor implements Poolable {
angle -= 360f;
}
if (getX() > RhythmBullet.GAME_AREA_WIDTH || getY() > RhythmBullet.GAME_AREA_HEIGHT || getX() < 0-getWidth() || getY() < 0-getHeight()) {
if (sprite.getX() > RhythmBullet.GAME_AREA_WIDTH || sprite.getY() > RhythmBullet.GAME_AREA_HEIGHT || sprite.getX() < 0-sprite.getWidth() || sprite.getX() < 0-sprite.getWidth()) {
dead = true;
}
super.act(delta);
updatePosition();
}
@Override
public void draw(Batch batch, float parentAlpha) {
public void draw(Batch batch) {
if (!nonStnrd) {
sprite.draw(batch);
}
batch.setColor(Color.WHITE);
super.draw(batch, parentAlpha);
}
public void move(float delta, boolean update) {
public void moveBy(float x, float y) {
rotRatios.set(MathUtils.cosDeg(angle), MathUtils.sinDeg(angle));
moveBy(rotRatios.x*speed*delta, rotRatios.y*speed*delta);
center.set(getX() + getWidth()/2f, getY() + getHeight()/2f);
if (update) {
updatePositionData();
}
sprite.setCenter(x, y);
}
public void updatePositionData() {
sprite.setCenter(center.x, center.y);
hitbox.setCenter(center);
public void updatePosition() {
sprite.setOriginCenter();
sprite.setRotation(angle);
hitbox.setCenter(sprite.getOriginX(), sprite.getOriginY());
}
@Override
@@ -153,18 +135,12 @@ public class Entity extends Actor implements Poolable {
hitbox.set(0, 0, 0, 0);
sprite.setRotation(0);
sprite.setColor(Color.WHITE);
setPosition(0, 0);
center.set(0, 0);
angle = 0;
speed = 0;
points = 0;
dead = false;
}
public Vector2 getCenter() {
return center;
}
public float getAngle() {
return angle;
}
@@ -189,4 +165,33 @@ public class Entity extends Actor implements Poolable {
public int getPoints() {
return points + (coordinator != null ? coordinator.getScoreBonus() : 0);
}
public float getX() {
return sprite.getX();
}
public float getY() {
return sprite.getY();
}
public void setPosition(float x, float y) {
sprite.setPosition(x, y);
updatePosition();
}
public float getWidth() {
return sprite.getWidth();
}
public float getHeight() {
return sprite.getHeight();
}
public void setSize(float width, float height) {
sprite.setSize(width, height);
}
public void setHitboxScale(float scale) {
hitbox.setSize(sprite.getWidth()*scale, sprite.getHeight()*scale);
}
}

View File

@@ -56,7 +56,6 @@ public class EntityFrame<T extends Entity> {
} else {
ec.activeAllies.removeValue(entity, true);
}
entity.remove();
pool.free(ct.cast(entity));
}

View File

@@ -2,53 +2,40 @@ package zero1hd.rhythmbullet.entity;
import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.utils.Array;
import zero1hd.rhythmbullet.entity.ally.Laser;
import zero1hd.rhythmbullet.entity.enemies.Flake;
import zero1hd.rhythmbullet.entity.enemies.Pellet;
import zero1hd.rhythmbullet.entity.enemies.Shard;
import zero1hd.rhythmbullet.entity.enemies.VoidCircle;
public class EntityManager {
private AssetManager assets;
private Preferences prefs;
private Stage stage;
public Array<Entity> activeAllies;
public Array<Entity> activeEnemies;
public EntityFrame<VoidCircle> voidCircle;
public EntityFrame<Pellet> pellet;
public EntityFrame<Shard> shard;
public EntityFrame<Flake> flake;
public EntityFrame<Laser> laser;
public EntityManager(AssetManager assetManager, Preferences preferences, Stage stage) {
public EntityManager(AssetManager assetManager, Preferences preferences) {
activeAllies = new Array<Entity>();
activeEnemies = new Array<Entity>();
this.assets = assetManager;
this.prefs = preferences;
this.stage = stage;
setup();
}
private void setup() {
voidCircle = new EntityFrame<>(this, VoidCircle.class);
pellet = new EntityFrame<>(this, Pellet.class);
shard = new EntityFrame<>(this, Shard.class);
flake = new EntityFrame<>(this, Flake.class);
laser = new EntityFrame<>(this, Laser.class);
}
public Stage getStage() {
return stage;
}
public AssetManager getAssets() {
return assets;
}

View File

@@ -1,7 +1,5 @@
package zero1hd.rhythmbullet.entity.ally;
import java.util.HashMap;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
@@ -25,35 +23,20 @@ public class Laser extends Entity {
setPosition(x-getWidth()/2f, y-getHeight()/2f);
speed = rate;
sfx.play(prefs.getFloat("fx vol")/100f);
toBack();
angle = 90f;
}
/**
* Vars: x, y, rate;
*/
@Override
public void init(HashMap<String, Float> params) {
setX(params.get("x") - getWidth()/2f);
setY(params.get("y") - getHeight()/2f);
speed = params.get("rate");
angle = 90f;
sfx.play(prefs.getFloat("fx vol")/100f);
super.init(params);
}
@Override
public void act(float delta) {
toBack();
public void calculate(float delta) {
if (getY() > RhythmBullet.GAME_AREA_HEIGHT) {
dead = true;
}
super.act(delta);
super.calculate(delta);
}
@Override
public void draw(Batch batch, float parentAlpha) {
super.draw(batch, parentAlpha);
public void draw(Batch batch) {
super.draw(batch);
}
@Override

View File

@@ -5,7 +5,6 @@ import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.ParticleEffect;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.entity.Entity;
@@ -34,11 +33,10 @@ public class PolyjetEntity extends Entity {
teleportCloak = assets.get("teleport-cloak.p", ParticleEffect.class);
addAction(Actions.moveTo(getX(), 4f, 0.5f));
}
@Override
public void act(float delta) {
public void calculate(float delta) {
hitbox.setPosition(getX(), getY());
thrust.setPosition(getX()+(getWidth())/2 - 1f/16f, getY()-0.2f);
@@ -74,34 +72,14 @@ public class PolyjetEntity extends Entity {
health = maxH;
}
if (getX() <= 1) {
moveLeft = false;
setX(1f);
}
if (getX() >= RhythmBullet.GAME_AREA_WIDTH-1-getWidth()) {
moveRight = false;
setX(RhythmBullet.GAME_AREA_WIDTH-1f-getWidth());
}
if (getY() >= RhythmBullet.GAME_AREA_HEIGHT - 1 - getHeight()) {
moveUp = false;
setY(RhythmBullet.GAME_AREA_HEIGHT - 1 - getHeight());
}
if (getY() <= 1) {
moveDown = false;
setY(1f);
}
super.act(delta);
super.calculate(delta);
}
@Override
public void draw(Batch batch, float parentAlpha) {
public void draw(Batch batch) {
thrust.draw(batch);
batch.draw(polyjet, getX(), getY(), getWidth(), getHeight());
super.draw(batch, parentAlpha);
super.draw(batch);
}
@Override

View File

@@ -1,115 +0,0 @@
package zero1hd.rhythmbullet.entity.enemies;
import java.util.HashMap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.Rectangle;
import zero1hd.rhythmbullet.entity.Entity;
import zero1hd.rhythmbullet.entity.ally.Laser;
public class Flake extends Entity {
private float timer;
private float totalTime;
private Shard[] shards;
@Override
public void preInit() {
sprite = new Sprite(assets.get("flake.png", Texture.class));
enemy = true;
move = false;
setSize(3f, 3f);
sprite.setSize(getWidth(), getHeight());
super.preInit();
}
public void init(float x, float y, float rate, float fuse, float angle, int shardCount) {
this.shards = new Shard[shardCount];
for (int i = 0; i < shards.length; i++) {
shards[i] = ec.shard.buildEntity();
shards[i].init(x, y, 360/shards.length*i, 0, 2);
ec.getStage().addActor(shards[i]);
}
this.speed = rate;
this.timer = fuse;
this.totalTime = fuse;
this.angle = angle;
setPosition(x-getWidth()/2f, y-getHeight()/2f);
}
/**
* params: shardCount, x, y, rate, fuse, angle;
*/
@Override
public void init(HashMap<String, Float> params) {
this.shards = new Shard[params.get("shardCount").intValue()];
for (int i = 0; i < shards.length; i++) {
shards[i] = ec.shard.buildEntity();
shards[i].init(params.get("x"), params.get("y"), 360/shards.length*i, 0, 1);
ec.getStage().addActor(shards[i]);
}
this.speed = params.get("rate");
this.timer = params.get("fuse");
this.totalTime = timer;
this.angle = params.get("angle");
hitbox.setSize(getWidth(), getHeight());
setPosition(params.get("x")-getWidth()/2f, params.get("y")-getHeight()/2f);
super.init(params);
}
@Override
public void act(float delta) {
if (timer > 0) {
timer -= delta;
}
move(delta, true);
for (int i = 0; i < shards.length; i++) {
shards[i].setPosition(center.x-shards[i].getWidth()/2f, center.y-shards[i].getWidth()/2f);
shards[i].move(delta, true);
}
if (timer <= 0) {
for (int i = 0; i < shards.length; i++) {
shards[i].setSpeed(30f);
}
dead = true;
}
super.act(delta);
}
@Override
public void draw(Batch batch, float parentAlpha) {
sprite.setColor(0f, 0f, 0f, 1-(timer/totalTime));
super.draw(batch, parentAlpha);
}
@Override
public void collided(Entity entity) {
if (entity.getClass() == Laser.class) {
dead = true;
for (int i = 0; i < shards.length; i++) {
shards[i].kill();
}
}
}
@Override
public Rectangle getHitZone() {
return hitbox;
}
@Override
public void reset() {
timer = 0;
shards = null;
totalTime = 0;
super.reset();
}
}

View File

@@ -1,7 +1,5 @@
package zero1hd.rhythmbullet.entity.enemies;
import java.util.HashMap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.utils.Pool.Poolable;
@@ -19,27 +17,13 @@ public class Pellet extends Entity implements Poolable {
super.preInit();
}
public void init(float x, float y, float angle, float rate) {
setPosition(x, y);
this.speed = rate;
this.angle = angle;
@Override
public void init(float deg, float speed, int hp) {
this.speed = speed;
this.angle = deg;
super.init(deg, speed, hp);
}
/**
* Vars: x, y, speed, angle;
*/
@Override
public void init(HashMap<String, Float> params) {
setPosition(params.get("x"), params.get("y"));
speed = params.get("speed");
angle = params.get("angle");
super.init(params);
}
@Override
public void act(float delta) {
super.act(delta);
}
@Override
public void collided(Entity entity) {

View File

@@ -1,7 +1,5 @@
package zero1hd.rhythmbullet.entity.enemies;
import java.util.HashMap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.Sprite;
@@ -23,26 +21,13 @@ public class Shard extends Entity {
super.preInit();
}
public void init(float x, float y, float angle, float rate, int hp) {
speed = rate;
@Override
public void init(float deg, float speed, int hp) {
this.speed = speed;
this.hp = hp;
maxHp = hp;
this.angle = angle;
setPosition(x-(getWidth()/2f), y-(getHeight()/2f));
hitbox.setSize(getWidth(), getHeight());
}
/**
* x, y, angle, rate, hp;
*/
@Override
public void init(HashMap<String, Float> params) {
setX(params.get("x"));
setY(params.get("y"));
angle = params.get("angle");
speed = params.get("rate");
hp = params.get("hp").intValue();
super.init(params);
this.angle = deg;
super.init(deg, speed, hp);
}
@Override
@@ -53,17 +38,17 @@ public class Shard extends Entity {
}
@Override
public void act(float delta) {
public void calculate(float delta) {
if (hp <= 0) {
dead = true;
}
super.act(delta);
super.calculate(delta);
}
@Override
public void draw(Batch batch, float parentAlpha) {
public void draw(Batch batch) {
sprite.setColor(((float)hp/(float)maxHp), ((float)hp/(float)maxHp), ((float)hp/(float)maxHp), 0.5f);
super.draw(batch, parentAlpha);
super.draw(batch);
}
@Override

View File

@@ -1,115 +0,0 @@
package zero1hd.rhythmbullet.entity.enemies;
import java.util.HashMap;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.Sprite;
import zero1hd.rhythmbullet.entity.Entity;
public class VoidCircle extends Entity {
private float timer;
private float endRadius;
private float currentRadius;
private float growthRate;
private boolean begin;
private float maxTime;
private Sound sound;
@Override
public void preInit() {
sprite = new Sprite(assets.get("void_circle.png", Texture.class));
enemy = true;
sound = assets.get("disintegrate.ogg", Sound.class);
super.preInit();
}
public void init(float endRadius, float x, float y, float growthRate, float warningTime) {
timer = warningTime;
maxTime = warningTime;
this.endRadius = endRadius;
setSize(2f*endRadius, 2f*endRadius);
setPosition(x-getWidth()/2f, y-getHeight()/2f);
this.growthRate = growthRate;
}
/**
* warningTime, endRadius, growthRate, x, y;
*/
@Override
public void init(HashMap<String, Float> params) {
timer = params.get("warningTime");
maxTime = timer;
endRadius = params.get("endRadius");
setSize(2f*endRadius, 2f*endRadius);
setPosition(params.get("x")-getWidth()/2f, params.get("y")-getHeight()/2f);
growthRate = params.get("growthRate");
super.init(params);
}
@Override
public void act(float delta) {
toFront();
if (begin) {
sprite.setSize(2*currentRadius, 2*currentRadius);
sprite.setColor(0f,0f,0f,1f);
} else {
sprite.setSize(2*endRadius, 2*endRadius);
sprite.setColor(1f,0.52f,0.32f,0.1f*(timer/maxTime));
}
if (timer > 0) {
timer -= delta;
} else {
begin = true;
if (currentRadius < endRadius) {
growCurrentRadius(delta*growthRate);
} else {
endRadius = -1f;
if (currentRadius > 0) {
growCurrentRadius(delta*-growthRate);
} else {
dead = true;
}
}
}
super.act(delta);
}
@Override
public void draw(Batch batch, float parentAlpha) {
super.draw(batch, parentAlpha);
}
@Override
public void reset() {
currentRadius = 0;
growthRate = 0;
timer = 0;
maxTime = 0;
endRadius = 0;
begin = false;
setSize(0, 0);
super.reset();
}
public void growCurrentRadius(float radius) {
currentRadius += radius;
float length = (float) Math.sqrt(2*(currentRadius*currentRadius));
if (length < 0) {
length = 0;
}
hitbox.setSize(length, length);
}
@Override
public void collided(Entity entity) {
if (begin) {
sound.play(prefs.getFloat("fx vol"));
}
}
}