cleaning for beginning of physics implementation

This commit is contained in:
Harrison Deng 2017-05-29 12:50:27 -05:00
parent 2821db605e
commit d6b6829023
7 changed files with 11 additions and 254 deletions

View File

@ -86,11 +86,7 @@ public class AudioAnalyzer {
fft.realForward(audioPCM); fft.realForward(audioPCM);
System.arraycopy(spectrum, 0, lastSpectrum, 0, spectrum.length);
System.arraycopy(audioPCM, 0, spectrum, 0, spectrum.length);
//Building a PUID (Pseudo unique ID) //Building a PUID (Pseudo unique ID)
if (tasksDone == (seedDigit*totalTasks/9)) { if (tasksDone == (seedDigit*totalTasks/9)) {
float avg = 0; float avg = 0;
for (int frame = 0; frame < spectrum.length; frame++) { for (int frame = 0; frame < spectrum.length; frame++) {
@ -104,20 +100,23 @@ public class AudioAnalyzer {
seedDigit ++; seedDigit ++;
} }
System.arraycopy(spectrum, 0, lastSpectrum, 0, spectrum.length);
System.arraycopy(audioPCM, 0, spectrum, 0, spectrum.length);
float fluxVal = 0; float fluxVal = 0;
//bass detection //bass detection
fluxVal = 0; fluxVal = 0;
for (int i = bassBinBegin; i < bassBinEnd && work; i++) { for (int i = bassBinBegin; i < bassBinEnd && work; i++) {
fluxVal += ((int) (spectrum[i] - lastSpectrum[i])) > 0 fluxVal += ((spectrum[i] - lastSpectrum[i])) > 0
? (int) (spectrum[i] - lastSpectrum[i]) : 0; ? (spectrum[i] - lastSpectrum[i]) : 0;
} }
bassSpectralFlux.add(fluxVal); bassSpectralFlux.add(fluxVal);
//main detection //main detection
fluxVal = 0; fluxVal = 0;
for (int i = UMBinBegin; i < UMBinEnd && work; i++) { for (int i = UMBinBegin; i < UMBinEnd && work; i++) {
fluxVal += ((int) (spectrum[i] - lastSpectrum[i])) > 0 fluxVal += ((spectrum[i] - lastSpectrum[i])) > 0
? (int) (spectrum[i] - lastSpectrum[i]) : 0; ? (spectrum[i] - lastSpectrum[i]) : 0;
} }
UMSpectralFlux.add(fluxVal); UMSpectralFlux.add(fluxVal);
tasksDone++; tasksDone++;

View File

@ -12,6 +12,5 @@ public class RhythmMapAlgorithm implements Runnable {
@Override @Override
public void run() { public void run() {
} }
} }

View File

@ -1,44 +0,0 @@
package zero1hd.polyjet.entity;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.NinePatch;
import zero1hd.polyjet.Polyjet;
public class BarBeat extends Entity {
NinePatch texture;
float rate;
public void initiate(float size, float rate, float spawnX, float spawnY, NinePatch texture) {
hitpoints = 1;
this.rate = rate;
setPosition(spawnX, spawnY);
this.texture = texture;
}
@Override
public void act(float delta) {
if (getY() + getHeight() < Polyjet.GAME_AREA_HEIGHT) {
hitpoints = 0;
}
moveBy(0, -rate*delta);
super.act(delta);
}
@Override
public void draw(Batch batch, float parentAlpha) {
texture.draw(batch, getX(), getY(), getWidth(), getHeight());
super.draw(batch, parentAlpha);
}
@Override
public int getDamageDealt() {
return 10;
}
@Override
public void reset() {
texture = null;
super.reset();
}
}

View File

@ -2,4 +2,8 @@ package zero1hd.polyjet.entity;
public enum Entities { public enum Entities {
Bar_Beat, Void_Circle; Bar_Beat, Void_Circle;
public float x;
public float y;
public float velocity;
} }

View File

@ -1,71 +0,0 @@
package zero1hd.polyjet.entity;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.utils.Pool.Poolable;
public class Entity extends Actor implements Poolable {
private Rectangle hitbox;
protected int hitpoints;
public Entity() {
hitbox = new Rectangle();
}
@Override
public void setSize(float width, float height) {
hitbox.setSize(width, height);
super.setSize(width, height);
}
@Override
public void act(float delta) {
hitbox.setPosition(getX(), getY());
super.act(delta);
}
/**
* @return amount of hp this entity has left.
*/
public int getHitPoints() {
return hitpoints;
}
/**
* used as a hitbox.
* @return a rectangle used for hit detection
*/
public Rectangle getHitbox() {
return hitbox;
}
/**
* Returns 0 if not overridden.
* @return the amount of damage dealt.
*/
public int getDamageDealt() {
return 0;
}
/**
* Doesn't do anything if not overridden.
* @param damageToDeal the amount of damage to deal to this entity.
*/
public void dealDamage(int damageToDeal) {
}
/**
* Default value is 0 if not overridden and setup properly.
* Note: this method is called whether or not this entity is dead. whenever two entities cross, this will be called.
* @return the amount of points this entity is worth
*/
public int getPoints() {
return 0;
}
@Override
public void reset() {
setPosition(0, 0);
setSize(0, 0);
hitpoints = 0;
}
}

View File

@ -1,75 +0,0 @@
package zero1hd.polyjet.entity;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import zero1hd.polyjet.Polyjet;
public class Projectile extends Entity {
float rate;
int damage;
Texture texture;
int hp;
int storedPoints;
public Projectile() {
super();
Gdx.app.debug("Projectile", "A new projectile was created.");
}
/**
*
* @param spawnX x spawn location
* @param spawnY y spawn location
* @param rate r/second
* @param hp health this projectile should have
* @param texture texture this projectile should render.
*/
public void initiate(float spawnX, float spawnY, float rate, int hp, Texture texture, float width, float height) {
this.hp = hp;
setX(spawnX);
setY(spawnY);
this.texture = texture;
this.rate = rate;
setSize(width, height);
damage = 1;
}
public void setDamage(int damage) {
this.damage = damage;
}
public void printDebug() {
Gdx.app.debug("Projectile", "Coordinates (X,Y): (" + getX() + ", " + getY() + ") Current parent: " + getParent().getName());
Gdx.app.debug("Projectile", "Width and height: " + getWidth() + "x" + getHeight());
}
@Override
public void act(float delta) {
moveBy(0, delta*rate);
if (getY() > Polyjet.GAME_AREA_HEIGHT) {
hp = 0;
}
super.act(delta);
}
@Override
public void draw(Batch batch, float parentAlpha) {
batch.draw(texture, getX(), getY(), getWidth(), getHeight());
super.draw(batch, parentAlpha);
}
@Override
public void reset() {
texture = null;
storedPoints = 0;
rate = 0;
damage = 0;
setDebug(false);
}
@Override
public int getHitPoints() {
return hp;
}
}

View File

@ -4,17 +4,12 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Pixmap; import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Pixmap.Format; import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.Stage; import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.utils.Pool;
import com.badlogic.gdx.utils.Pools;
import com.badlogic.gdx.utils.viewport.FitViewport; import com.badlogic.gdx.utils.viewport.FitViewport;
import zero1hd.polyjet.Polyjet; import zero1hd.polyjet.Polyjet;
import zero1hd.polyjet.controls.KeyMap; import zero1hd.polyjet.controls.KeyMap;
import zero1hd.polyjet.entity.BarBeat;
import zero1hd.polyjet.entity.PolyJetEntity; import zero1hd.polyjet.entity.PolyJetEntity;
import zero1hd.polyjet.entity.Projectile;
public class GamePlayArea extends Stage { public class GamePlayArea extends Stage {
@ -29,13 +24,6 @@ public class GamePlayArea extends Stage {
private float yTeleport = Polyjet.GAME_AREA_HEIGHT/2; private float yTeleport = Polyjet.GAME_AREA_HEIGHT/2;
private int score; private int score;
private final Pool<Projectile> projectilePool = Pools.get(Projectile.class, 50);
private final Pool<BarBeat> barBeatPool = Pools.get(BarBeat.class);
Group projectile;
Group foes;
Texture basicLaserTexture; Texture basicLaserTexture;
public GamePlayArea(Polyjet core) { public GamePlayArea(Polyjet core) {
super(new FitViewport(Polyjet.GAME_AREA_WIDTH, Polyjet.GAME_AREA_HEIGHT)); super(new FitViewport(Polyjet.GAME_AREA_WIDTH, Polyjet.GAME_AREA_HEIGHT));
@ -55,13 +43,6 @@ public class GamePlayArea extends Stage {
polyJet = new PolyJetEntity(core, 54, "standard"); polyJet = new PolyJetEntity(core, 54, "standard");
addActor(polyJet); addActor(polyJet);
projectile = new Group();
projectile.setName("basic Projectiles");
addActor(projectile);
foes = new Group();
addActor(foes);
} }
public void init() { public void init() {
@ -72,23 +53,6 @@ public class GamePlayArea extends Stage {
public void act(float delta) { public void act(float delta) {
timeCounter+=delta; timeCounter+=delta;
for (int projectileID = 0; projectileID < projectile.getChildren().size; projectileID++) {
Projectile currentProjectile = (Projectile) projectile.getChildren().get(projectileID);
if (currentProjectile.getHitPoints() <= 0) {
currentProjectile.printDebug();
currentProjectile.remove();
projectilePool.free(currentProjectile);
}
}
for (int barBeatID = 0; barBeatID < foes.getChildren().size; barBeatID++) {
BarBeat currentBarBeat = (BarBeat) foes.getChildren().get(barBeatID);
if (currentBarBeat.getHitPoints() <= 0) {
currentBarBeat.remove();
barBeatPool.free(currentBarBeat);
}
}
health -= 2*delta; health -= 2*delta;
if (health <= 0) { if (health <= 0) {
@ -128,24 +92,6 @@ public class GamePlayArea extends Stage {
} }
} }
public void spawnProjectile(int ID) {
switch (ID) {
case 0:
Projectile currentProjectile = projectilePool.obtain();
currentProjectile.initiate(
polyJet.getX()+polyJet.getWidth()/2-(0.125f)/2,
polyJet.getY()+polyJet.getHeight()+0.5f,
100,
1,
basicLaserTexture, 0.125f, 2f);
projectile.addActor(currentProjectile);
health -= 5;
break;
}
}
@Override @Override
public boolean keyDown(int keycode) { public boolean keyDown(int keycode) {
if (keycode == KeyMap.left) { if (keycode == KeyMap.left) {
@ -180,7 +126,6 @@ public class GamePlayArea extends Stage {
polyJet.moveDown = false; polyJet.moveDown = false;
} }
if (keycode == KeyMap.shoot) { if (keycode == KeyMap.shoot) {
spawnProjectile(0);
} }
return false; return false;
} }