removed old, unused code; music controls now updated to use new

framework; circular visualizer updated; moved visualizers to core for
all platforms and accounted for different platform PCM reading with
interface for visualizer in core;
This commit is contained in:
Harrison Deng 2018-08-03 22:21:39 -05:00
parent a39f3a25ac
commit 59cfa277ab
20 changed files with 159 additions and 1152 deletions

View File

@ -49,8 +49,6 @@ public class MusicController extends Observable implements OnCompletionListener,
music.play(); music.play();
music.setVolume(prefs.getFloat("music vol", 1f)); music.setVolume(prefs.getFloat("music vol", 1f));
notifyObservers(states.PLAYING); notifyObservers(states.PLAYING);
} else {
Gdx.app.debug("MusicListController", "failed to begin playing. Load the music!!!");
} }
} }
@ -224,7 +222,7 @@ public class MusicController extends Observable implements OnCompletionListener,
/** /**
* Returns the current music. In no circumstances should this be used to begin playing or it would be playing independent of the controller. * Returns the current music. In no circumstances should this be used to begin playing or it would be playing independent of the controller.
* Doing otherwise would mean you are playing the music separately of the controller. * Doing otherwise would mean you are playing the music separately of the controller.
* @return * @return the {@link Music} that is currently "loaded" and ready to play.
*/ */
public Music getCurrentMusic() { public Music getCurrentMusic() {
return music; return music;
@ -233,4 +231,11 @@ public class MusicController extends Observable implements OnCompletionListener,
public int getCurrentlyPlayingIndex() { public int getCurrentlyPlayingIndex() {
return currentlyPlayingIndex; return currentlyPlayingIndex;
} }
public boolean hasSongLoaded() {
if (music != null) {
return true;
}
return false;
}
} }

View File

@ -19,6 +19,7 @@ import com.badlogic.gdx.utils.Disposable;
import zero1hd.rhythmbullet.RhythmBullet; import zero1hd.rhythmbullet.RhythmBullet;
public class CircularVisualizer implements Disposable { public class CircularVisualizer implements Disposable {
private PCMSystem pcm;
private int centerX, centerY; private int centerX, centerY;
private int r; private int r;
private int componentCount = 2 + 1; private int componentCount = 2 + 1;
@ -27,21 +28,19 @@ public class CircularVisualizer implements Disposable {
private float color; private float color;
private Mesh mesh; private Mesh mesh;
private ShaderProgram shader; private ShaderProgram shader;
private Visualizer visualizer;
private int barCount = 180; private int barCount = 180;
private float barHeightMultiplier = 1.5f; private float barHeightMultiplier = 1.5f;
private float[] audioSpectrum; private float[] audioSpectrum;
private Camera camera; private Camera camera;
public CircularVisualizer(Visualizer visualizer) { public CircularVisualizer(PCMSystem PCMSystem) {
this.pcm = PCMSystem;
shader = new ShaderProgram(Gdx.files.internal("shaders/mesh.vsh"), Gdx.files.internal("shaders/mesh.fsh")); shader = new ShaderProgram(Gdx.files.internal("shaders/mesh.vsh"), Gdx.files.internal("shaders/mesh.fsh"));
if (!shader.isCompiled() || shader.getLog().length() != 0) { if (!shader.isCompiled() || shader.getLog().length() != 0) {
Gdx.app.debug("Circular visualizer shader", shader.getLog()); Gdx.app.debug("Circular visualizer shader", shader.getLog());
Gdx.app.exit(); Gdx.app.exit();
} }
r = RhythmBullet.pixels_per_unit*RhythmBullet.SPAWN_CIRCLE_RADIUS; r = RhythmBullet.pixels_per_unit*RhythmBullet.SPAWN_CIRCLE_RADIUS;
this.visualizer = visualizer;
} }
/** /**

View File

@ -1,4 +1,4 @@
package zero1hd.rhythmbullet.desktop.audio.visualizer; package zero1hd.rhythmbullet.audio.visualizer;
import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
@ -11,7 +11,7 @@ public class DoubleHorizontalVisualizer {
private int x, y; private int x, y;
private float barRate = 0.75f; private float barRate = 0.75f;
private ShapeRenderer shapeRenderer; private ShapeRenderer shapeRenderer;
private PCMMachine pcm; private PCMSystem pcm;
private int smoothRange; private int smoothRange;
private int multiplier = 300; private int multiplier = 300;
private int[] amplitudes; private int[] amplitudes;
@ -24,7 +24,7 @@ public class DoubleHorizontalVisualizer {
* @param width the width of the visualizer. * @param width the width of the visualizer.
* @param spacePercentage the percentage of a bar that should be space. * @param spacePercentage the percentage of a bar that should be space.
*/ */
public DoubleHorizontalVisualizer(int barCount, int width, int height, float spacePercentage, MusicController musicController) { public DoubleHorizontalVisualizer(int barCount, int width, int height, float spacePercentage, MusicController musicController, PCMSystem PCMSystem) {
this.barCount = barCount; this.barCount = barCount;
this.barWidth = width/barCount; this.barWidth = width/barCount;
this.spaceBetweenBars = (int) (barWidth * spacePercentage); this.spaceBetweenBars = (int) (barWidth * spacePercentage);
@ -33,7 +33,7 @@ public class DoubleHorizontalVisualizer {
binsPerBar = (pcm.getWindowSize()/barCount); binsPerBar = (pcm.getWindowSize()/barCount);
this.width = width; this.width = width;
this.height = height; this.height = height;
pcm = new PCMMachine(musicController); pcm = PCMSystem;
amplitudes = new int[barCount]; amplitudes = new int[barCount];
barHeights = new int[barCount]; barHeights = new int[barCount];
shapeRenderer = new ShapeRenderer(); shapeRenderer = new ShapeRenderer();

View File

@ -1,280 +0,0 @@
package zero1hd.rhythmbullet.audio.visualizer;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Pixmap.Format;
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.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Disposable;
public class HorizontalVisualizer implements Disposable {
private Pixmap pixmap;
private Texture barTexture;
private int barWidth;
private int binsPerBar;
private int spaceBetweenBars;
private Sprite[] bars;
private float[] barHeights;
private int smoothRange;
private float barHeightMultiplier;
private float rotation;
private Vector2 angleRot;
private boolean flip;
private Array<MirrorVisualizer> mirrors;
private boolean reverse;
private float maxAvgHeight;
private float currentAvg;
private int barCount;
private float width, height, x, y;
private Visualizer visualizer;
public HorizontalVisualizer(Visualizer visualizer) {
super();
mirrors = new Array<>();
pixmap = new Pixmap(2, 2, Format.RGBA8888);
pixmap.setColor(Color.WHITE);
pixmap.fill();
barCount = 68;
width = Gdx.graphics.getWidth();
height = Gdx.graphics.getHeight()/2f;
x = 0;
y = 0;
this.visualizer = visualizer;
smoothRange = 2;
angleRot = new Vector2(MathUtils.cosDeg(rotation), MathUtils.sinDeg(rotation));
bars = new Sprite[barCount];
barHeights = new float[barCount];
barTexture = new Texture(pixmap);
for (int i = 0; i < bars.length; i++) {
bars[i] = new Sprite(barTexture);
}
updatePositionInfo();
pixmap.dispose();
}
public void render(Batch batch, float parentAlpha) {
if (visualizer.getMM() != null) {
for (int i = 0; i < bars.length; i++) {
bars[i].draw(batch);
for (int j = 0; j < mirrors.size; j++) {
mirrors.get(j).render(i, batch, parentAlpha, bars);
}
}
}
}
public void update(float delta) {
if (visualizer.getMM() != null) {
//Averaging bins together
for (int i = 0; i < barCount; i++) {
float barHeight = 0;
for (int j = 0; j < binsPerBar; j++) {
barHeight += Math.abs(visualizer.getAudioPCMData()[j+i*binsPerBar +1]);
}
barHeight /= binsPerBar;
barHeight *= barHeightMultiplier;
barHeights[i] = barHeight;
}
currentAvg = 0;
for (int i = 0; i < barCount; i++) {
int avg = 0;
//Averaging the bars
for (int range = 0; range < smoothRange; range++) {
if (i+range < barCount) {
avg += barHeights[i+range];
}
if (i-range >= 0) {
avg += barHeights[i-range];
}
}
avg /= smoothRange*2;
barHeights[i] = avg;
currentAvg += barHeights[i];
if (bars[i].getHeight() > barHeights[i]) {
bars[i].setSize(barWidth, bars[i].getHeight() - (15f*delta*(bars[i].getHeight()-barHeights[i])));
} else {
bars[i].setSize(barWidth, bars[i].getHeight() + (20f*delta*(barHeights[i] - bars[i].getHeight())));
}
}
currentAvg /= barHeights.length;
if (currentAvg > maxAvgHeight) {
maxAvgHeight = currentAvg;
}
}
}
public void setMM(MusicManager mm) {
maxAvgHeight = 0;
currentAvg = 0;
float validBins = (4200/((mm.getSampleRate()/2)/((mm.getReadWindowSize()/2)+1)));
Gdx.app.debug("Visualizer", "valid frequency bins " + validBins);
binsPerBar = MathUtils.round((validBins/barCount));
barHeights = new float[barCount];
visualizer.setMM(mm);
}
public void dispose() {
barTexture.dispose();
visualizer.dispose();
}
public void updatePositionInfo() {
barHeightMultiplier = height;
int barSpace = 0;
angleRot.set(MathUtils.cosDeg(rotation), MathUtils.sinDeg(rotation));
barWidth = MathUtils.round((float) width/(float) barCount);
barWidth -= spaceBetweenBars;
for (int i = 0; i < bars.length; i++) {
barSpace = i*(barWidth+spaceBetweenBars);
if (flip) {
bars[i].setRotation(rotation+180);
} else {
bars[i].setRotation(rotation);
}
if (reverse) {
bars[bars.length-i-1].setPosition(x + barSpace*angleRot.x, y + barSpace*angleRot.y);
} else {
bars[i].setPosition(x + barSpace*angleRot.x, y + barSpace*angleRot.y);
}
for (int mirrorIndex = 0; mirrorIndex < mirrors.size; mirrorIndex++) {
mirrors.get(mirrorIndex).position(i, barWidth, spaceBetweenBars);
}
}
}
public float getActualWidth() {
return (barWidth+spaceBetweenBars)*(barCount - 1);
}
public void setColor(Color color) {
for (int i = 0; i < bars.length; i++) {
bars[i].setColor(color);
}
for (int i = 0; i < mirrors.size; i++) {
mirrors.get(i).setColor(color);
}
}
public void setColor(float r, float g, float b, float a) {
for (int i = 0; i < bars.length; i++) {
bars[i].setColor(r, g, b, a);
}
for (int i = 0; i < mirrors.size; i++) {
mirrors.get(i).setColor(r, g, b, a);
}
}
public void setRotation(float rotation) {
this.rotation = rotation;
}
public void flip() {
flip = !flip;
}
public boolean isFlipped() {
return flip;
}
public void addMirrorVisualizer(MirrorVisualizer mirror) {
updatePositionInfo();
mirror.setup(bars, x, y, rotation);
mirrors.add(mirror);
x = (int) (((width - getActualWidth())/2f));
}
public void removeMirrorVisualizer(MirrorVisualizer mirror) {
mirrors.removeValue(mirror, true);
}
public void setSpaceBetweenBars(int spaceBetweenBars) {
this.spaceBetweenBars = spaceBetweenBars;
}
public int getBarWidth() {
return barWidth;
}
public void reverse() {
reverse = reverse ? false : true;
}
public boolean isReversed() {
return reverse;
}
public Sprite[] getBars() {
return bars;
}
public float getCurrentAvg() {
return currentAvg;
}
public float getMaxAvgHeight() {
return maxAvgHeight;
}
public int getSpaceBetweenBars() {
return spaceBetweenBars;
}
public void setX(float x) {
this.x = x;
}
public float getX() {
return x;
}
public void setY(float y) {
this.y = y;
}
public float getY() {
return y;
}
public void setWidth(float width) {
this.width = width;
}
public float getWidth() {
return width;
}
public void setHeight(float height) {
this.height = height;
}
public float getHeight() {
return height;
}
public void calcPCMData() {
visualizer.calcPCMData();
}
public void calculate() {
visualizer.fft();
}
public Visualizer getVisualizer() {
return visualizer;
}
}

View File

@ -0,0 +1,9 @@
package zero1hd.rhythmbullet.audio.visualizer;
public interface PCMSystem {
float[] getFrequencyBins();
int getWindowSize();
}

View File

@ -1,106 +0,0 @@
package zero1hd.rhythmbullet.game;
import zero1hd.rhythmbullet.audio.MusicManager;
import zero1hd.rhythmbullet.entity.Entity;
import zero1hd.rhythmbullet.entity.EntityFrame;
import zero1hd.rhythmbullet.entity.coordinator.Coordinator;
import zero1hd.rhythmbullet.entity.coordinator.CoordinatorFrame;
public class GamePlayMap {
private MusicManager musicData;
private MapWindowData[] spawnList;
private boolean building;
private int index;
private byte[] hudType;
/**
* GamePlayMap is what the game area will use to generate entities and judge current audio data
* @param audioData audio data
*/
public GamePlayMap(MusicManager audioData, int totalWindows) {
this.musicData = audioData;
spawnList = new MapWindowData[totalWindows];
hudType = new byte[totalWindows];
}
public int setIndex(int index) {
int previousIndex = this.index;
if (index < 0) {
this.index = 0;
} else if (index >= spawnList.length) {
toHead();
} else {
this.index = index;
}
return previousIndex;
}
public void setHUDType(byte data) {
hudType[index] = data;
}
public byte[] getHudType() {
return hudType;
}
public EntitySpawnInfo addEntity(EntityFrame<? extends Entity> entityType, CoordinatorFrame<? extends Coordinator> coordinator) {
if (building) {
if (spawnList[index] == null) {
spawnList[index] = new MapWindowData();
}
EntitySpawnInfo esi = new EntitySpawnInfo(entityType, coordinator);
spawnList[index].addEntity(esi);
return esi;
} else {
throw new IllegalStateException("Stupid, you need to call begin building first first.");
}
}
public void nextWindowData() {
if (building) {
index++;
} else {
throw new IllegalStateException("Stupid, you need to call begin building first first.");
}
}
public void toHead() {
index = spawnList.length-1;
}
public MusicManager getMusicData() {
return musicData;
}
public void beginBuild() {
if (!building) {
index = 0;
building = true;
} else {
throw new IllegalStateException("Excuse me, but your already building...");
}
}
public void endBuild() {
if (building) {
index = 0;
building = false;
} else {
throw new IllegalStateException("Nothings being built...");
}
}
public MapWindowData getCurrentWindowBasedOnIndex() {
if (index != musicData.getPlaybackIndexPosition()) {
index = musicData.getPlaybackIndexPosition();
if (index < spawnList.length) {
return spawnList[index];
}
}
return null;
}
public int getIndex() {
return index;
}
}

View File

@ -10,7 +10,6 @@ import java.util.Observer;
import org.lwjgl.openal.AL11; import org.lwjgl.openal.AL11;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.assets.AssetLoaderParameters.LoadedCallback;
import com.badlogic.gdx.backends.lwjgl.audio.OpenALMusic; import com.badlogic.gdx.backends.lwjgl.audio.OpenALMusic;
import com.badlogic.gdx.utils.Disposable; import com.badlogic.gdx.utils.Disposable;
import com.badlogic.gdx.utils.TimeUtils; import com.badlogic.gdx.utils.TimeUtils;
@ -20,8 +19,9 @@ import com.badlogic.gdx.utils.reflect.ReflectionException;
import zero1hd.rhythmbullet.audio.MusicController; import zero1hd.rhythmbullet.audio.MusicController;
import zero1hd.rhythmbullet.audio.visualizer.BasicFFT; import zero1hd.rhythmbullet.audio.visualizer.BasicFFT;
import zero1hd.rhythmbullet.audio.visualizer.PCMSystem;
public class PCMMachine implements Observer, Disposable { public class PCMObtainer implements Observer, Disposable, PCMSystem {
private int windowSize = 1024; private int windowSize = 1024;
private float[] PCM = new float[windowSize]; private float[] PCM = new float[windowSize];
private float[] frequencyBins = new float[windowSize / 2]; private float[] frequencyBins = new float[windowSize / 2];
@ -38,7 +38,7 @@ public class PCMMachine implements Observer, Disposable {
private int currentPlaybackWindow; private int currentPlaybackWindow;
private volatile boolean updated; private volatile boolean updated;
public PCMMachine(MusicController musicController) { public PCMObtainer(MusicController musicController) {
this.mc = musicController; this.mc = musicController;
mc.addObserver(this); mc.addObserver(this);
try { try {
@ -141,6 +141,7 @@ public class PCMMachine implements Observer, Disposable {
buffer.rewind(); buffer.rewind();
} }
@Override
public float[] getFrequencyBins() { public float[] getFrequencyBins() {
if (updated) { if (updated) {
synchronized (PCM) { synchronized (PCM) {
@ -151,6 +152,7 @@ public class PCMMachine implements Observer, Disposable {
return frequencyBins; return frequencyBins;
} }
@Override
public int getWindowSize() { public int getWindowSize() {
return windowSize; return windowSize;
} }

View File

@ -12,32 +12,25 @@ import zero1hd.rhythmbullet.audio.MusicController;
public class MusicControls extends HorizontalGroup { public class MusicControls extends HorizontalGroup {
private ImageButton reverse, forward; private ImageButton reverse, forward;
private CheckBox shuffle, play; private CheckBox shuffle, play;
private float disableTimer;
public MusicControls(Skin skin, final MusicController sc) { public MusicControls(Skin skin, final MusicController sc) {
reverse = new ImageButton(skin, "rewind-button"); reverse = new ImageButton(skin, "rewind-button");
reverse.addListener(new ChangeListener() { reverse.addListener(new ChangeListener() {
@Override @Override
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
if (sc.getCurrentMusicManager() != null) { boolean wasPlaying = sc.isPlaying();
boolean wasPlaying = sc.getCurrentMusicManager().isPlaying();
sc.previous(); sc.previous();
if (wasPlaying) { if (wasPlaying) {
sc.play(); sc.play();
} }
} }
forward.setDisabled(true);
reverse.setDisabled(true);
disableTimer = 0.75f;
}
}); });
addActor(reverse); addActor(reverse);
play = new CheckBox(null, skin, "play-button") { play = new CheckBox(null, skin, "play-button") {
@Override @Override
public void act(float delta) { public void act(float delta) {
if (sc.getCurrentMusicManager() != null) { if (sc.hasSongLoaded()) {
play.setChecked(sc.getCurrentMusicManager().isPlaying()); play.setChecked(sc.isPlaying());
} else { } else {
play.setChecked(false); play.setChecked(false);
} }
@ -47,12 +40,10 @@ public class MusicControls extends HorizontalGroup {
play.addListener(new ChangeListener() { play.addListener(new ChangeListener() {
@Override @Override
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
if (sc.getCurrentMusicManager() != null) {
if (play.isChecked()) { if (play.isChecked()) {
sc.getCurrentMusicManager().play(); sc.play();
} else { } else {
sc.getCurrentMusicManager().pause(); sc.pause();
}
} }
} }
}); });
@ -62,18 +53,12 @@ public class MusicControls extends HorizontalGroup {
forward.addListener(new ChangeListener() { forward.addListener(new ChangeListener() {
@Override @Override
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
if (sc.getCurrentMusicManager() != null) { boolean wasPlaying = sc.isPlaying();
boolean wasPlaying = sc.getCurrentMusicManager().isPlaying();
sc.skip(); sc.skip();
if (wasPlaying) { if (wasPlaying) {
sc.play(); sc.play();
} }
} }
forward.setDisabled(true);
reverse.setDisabled(true);
disableTimer = 0.75f;
}
}); });
addActor(forward); addActor(forward);
shuffle = new CheckBox(null, skin, "shuffle-button") { shuffle = new CheckBox(null, skin, "shuffle-button") {
@ -98,20 +83,4 @@ public class MusicControls extends HorizontalGroup {
invalidate(); invalidate();
} }
@Override
public void act(float delta) {
setWidth(getMinWidth());
setHeight(getMinHeight());
if (disableTimer > 0) {
disableTimer -= delta;
if (disableTimer <= 0) {
forward.setDisabled(false);
reverse.setDisabled(false);
disableTimer = 0;
}
}
super.act(delta);
}
} }

View File

@ -1,44 +0,0 @@
package zero1hd.rhythmbullet.desktop.graphics.ui.pages;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
public class StatPage extends Page {
private Table table;
private Label winLabel;
private Label finalScore, damageTaken, enemiesKilled, shotsTaken, shotsMissed, accuracy;
public StatPage(Skin skin, int score, int damageTake, int enemiesKilled, int shotsTaken, int shotsMissed, int accuracy) {
table = new Table(skin);
addActor(table);
table.setFillParent(true);
winLabel = new Label("Win!", skin);
table.add(winLabel);
table.row();
this.finalScore = new Label("Your score: " + score, skin, "sub-font", skin.getColor("default"));
table.add(this.finalScore);
table.row();
this.damageTaken = new Label("Damage Taken: " + damageTake, skin, "sub-font", skin.getColor("default"));
table.add(this.damageTaken);
table.row();
this.enemiesKilled = new Label("Enemies slayed: " + enemiesKilled, skin, "sub-font", skin.getColor("default"));
table.add(this.enemiesKilled);
table.row();
this.shotsTaken = new Label("Shots taken: " + shotsTaken, skin, "sub-font", skin.getColor("default"));
table.add(this.shotsTaken);
table.row();
this.shotsMissed = new Label("Shots missed: " + shotsMissed, skin, "sub-font", skin.getColor("default"));
table.add(this.shotsMissed);
table.row();
this.accuracy = new Label("Accuracy: " + accuracy, skin, "sub-font", skin.getColor("default"));
table.add(this.accuracy);
}
}

View File

@ -1,132 +0,0 @@
package zero1hd.rhythmbullet.desktop.graphics.ui.windows;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.WidgetGroup;
import com.badlogic.gdx.scenes.scene2d.ui.Window;
import zero1hd.rhythmbullet.audio.AudioDataPackage;
import zero1hd.rhythmbullet.audio.MusicManager;
public class BeatViewer extends Window {
Pixmap lights;
int songIndex;
MusicManager music;
Texture lightOn;
private AudioDataPackage data;
public BeatViewer(String title, Skin skin) {
super(title, skin, "tinted");
defaults().space(5f);
setSize(64, 100);
//Draw the 'lights'
lights = new Pixmap(16, 16, Format.RGBA8888);
lights.setColor(1, 0.2f, 0.2f, 1f);
lights.fillCircle(lights.getWidth()/2, lights.getHeight()/2, 7);
lightOn = new Texture(lights);
WidgetGroup bassBar = new WidgetGroup();
final Image bgBassBar = new Image(skin.getPatch("bar-empty"));
bgBassBar.setHeight(50f);
bassBar.setSize(bgBassBar.getWidth(), bgBassBar.getHeight());
final Image bassBarFill = new Image(skin.getPatch("bar-fill")) {
@Override
public void act(float delta) {
try {
if (music != null && data.getBassPeaks().get(songIndex) != 0) {
clearActions();
addAction(Actions.sequence(Actions.sizeTo(getWidth(), (data.getBassPeaks().get(songIndex)/data.getBassMaxVal())*bgBassBar.getHeight()), Actions.sizeTo(getWidth(), 0, 0.3f)));
}
} catch (IndexOutOfBoundsException e) {
}
super.act(delta);
}
};
bassBarFill.setHeight(0f);
bassBar.addActor(bgBassBar);
bassBar.addActor(bassBarFill);
add(bassBar).minSize(bassBar.getWidth(), bassBar.getHeight());
WidgetGroup UMBar = new WidgetGroup();
final Image bgUMBar = new Image(skin.getPatch("bar-empty"));
bgUMBar.setHeight(50f);
UMBar.setSize(bgUMBar.getWidth(), bgUMBar.getHeight());
Image UMBarFill = new Image(skin.getPatch("bar-fill")) {
@Override
public void act(float delta) {
try {
if (music != null && data.getBassPeaks().get(songIndex) != 0) {
clearActions();
addAction(Actions.sequence(Actions.sizeTo(getWidth(), (data.getuMPeaks().get(songIndex)/data.getuMMaxval())*bgUMBar.getHeight()), Actions.sizeTo(getWidth(), 0f, 0.3f)));
}
} catch (IndexOutOfBoundsException e) {
}
super.act(delta);
}
};
UMBarFill.setHeight(0f);
UMBar.addActor(bgUMBar);
UMBar.addActor(UMBarFill);
add(UMBar).minSize(UMBar.getWidth(), UMBar.getHeight());
row();
Image bassIndicator = new Image(lightOn) {
@Override
public void act(float delta) {
try {
if (music != null && data.getBassPeaks().get(songIndex) != 0) {
clearActions();
addAction(Actions.sequence(Actions.alpha(1f), Actions.fadeOut(0.15f)));
}
} catch (IndexOutOfBoundsException e) {
}
super.act(delta);
}
};
bassIndicator.setColor(1f, 1f, 1f, 0f);
add(bassIndicator).center();
Image UMIndicator = new Image(lightOn) {
@Override
public void act(float delta) {
try {
if (music != null && data.getuMPeaks().get(songIndex) != 0) {
clearActions();
addAction(Actions.sequence(Actions.alpha(1f), Actions.fadeOut(0.15f)));
}
} catch (IndexOutOfBoundsException e) {
}
super.act(delta);
}
};
UMIndicator.setColor(1f, 1f, 1f, 0f);
add(UMIndicator).center();
}
@Override
public void act(float delta) {
if (music != null) {
songIndex = music.getPlaybackIndexPosition();
}
super.act(delta);
}
public void setMusic(MusicManager audioData, AudioDataPackage adp) {
this.music = audioData;
this.data = adp;
}
}

View File

@ -1,77 +0,0 @@
package zero1hd.rhythmbullet.desktop.graphics.ui.windows;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Slider;
import com.badlogic.gdx.scenes.scene2d.ui.Window;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
public class DifficultyWindow extends Window {
private Slider sensitivityRating;
private Label sensitivityRatingTitle;
private Slider speedModifier;
private Label speedModifierTitle;
private Slider healthModifier;
private Label healthModifierTitle;
public DifficultyWindow(Skin skin) {
super("Difficulty Adjuster", skin, "tinted");
sensitivityRating = new Slider(0f, 100f, 1f, false, skin);
sensitivityRating.setValue(0f);
sensitivityRating.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
sensitivityRatingTitle.setText("Base Difficulty: " + sensitivityRating.getValue());
}
});
sensitivityRatingTitle = new Label("Base Difficulty: " + sensitivityRating.getValue(), skin, "sub-font", skin.getColor("default"));
add(sensitivityRatingTitle);
add(sensitivityRating);
row();
speedModifier = new Slider(1f, 3f, 0.25f, false, skin);
speedModifier.setValue(1f);
speedModifier.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
speedModifierTitle.setText("Speed Modifier: " + speedModifier.getValue());
}
});
speedModifierTitle = new Label("Speed Modifier: " + speedModifier.getValue(), skin, "sub-font", skin.getColor("default"));
add(speedModifierTitle);
add(speedModifier);
row();
healthModifier = new Slider(0f, 5f, 1f, false, skin);
healthModifier.setValue(0f);
healthModifier.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
healthModifierTitle.setText("Health modifier: " + healthModifier.getValue());
}
});
healthModifierTitle = new Label("Health modifier: " + healthModifier.getValue(), skin, "sub-font", skin.getColor("default"));
add(healthModifierTitle);
add(healthModifier);
pack();
}
public float getOverallDiffMod() {
return sensitivityRating.getValue();
}
public float getSpeedModifier() {
return speedModifier.getValue();
}
public float getHealthModifier() {
return healthModifier.getValue();
}
}

View File

@ -1,21 +0,0 @@
package zero1hd.rhythmbullet.desktop.graphics.ui.windows;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Window;
public class FPSWindow extends Window {
public FPSWindow(String title, Skin skin) {
super(title, skin, "tinted");
Label FPS = new Label("FPS: ", skin, "window-font", skin.getColor("default")) {
@Override
public void act(float delta) {
setText("FPS: " + Gdx.graphics.getFramesPerSecond());
super.act(delta);
}
};
add(FPS).center();
setSize(70, 70);
}
}

View File

@ -1,85 +0,0 @@
package zero1hd.rhythmbullet.desktop.graphics.ui.windows;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Window;
import com.badlogic.gdx.utils.Disposable;
public class LoadingWindow extends Window implements Disposable {
private Label status;
private Sound closeSound;
private Sound openSound;
private float vol;
public LoadingWindow(Skin skin, boolean progress, AssetManager assets, float vol) {
super("loading...", skin, "tinted");
this.openSound = assets.get("pop_open.ogg", Sound.class);
this.closeSound = assets.get("pop_close.ogg", Sound.class);
this.vol = vol;
Image loading = new Image(skin, "loading");
loading.addAction(Actions.forever(Actions.rotateBy(-360f, 2f)));
add(loading).left();
setSize(loading.getWidth()+20f, loading.getHeight()+40f);
loading.setOrigin(loading.getWidth()/2, loading.getHeight()/2);
if (progress) {
status = new Label("[ ]", skin, "sub-font", skin.getColor("default"));
add(status).spaceLeft(10f).expandX().right();
setSize(getWidth() + status.getWidth() + 45f, (loading.getHeight() >= status.getHeight() ? loading.getHeight() : status.getHeight()) + 74);
}
}
public LoadingWindow(Skin skin, String styleName, boolean progress, AssetManager assets, float vol) {
super("loading...", skin, styleName);
this.openSound = assets.get("pop_open.ogg", Sound.class);
this.closeSound = assets.get("pop_close.ogg", Sound.class);
this.vol = vol;
Image loading = new Image(skin, "loading");
loading.addAction(Actions.forever(Actions.rotateBy(-360f, 2f)));
add(loading).left();
setSize(loading.getWidth()+20f, loading.getHeight()+40f);
loading.setOrigin(loading.getWidth()/2, loading.getHeight()/2);
if (progress) {
status = new Label("[ ]", skin, "sub-font", skin.getColor("default"));
add(status).spaceLeft(10f).expandX().right();
setSize(getWidth() + status.getWidth() + 45f, (loading.getHeight() >= status.getHeight() ? loading.getHeight() : status.getHeight()) + 74);
}
}
public void playOpenSound() {
openSound.play(vol/100f);
}
@Override
public boolean remove() {
closeSound.play(vol/100f);
return super.remove();
}
public void setProgress(float progress) {
status.setText(String.valueOf((int) progress) + '%');
}
@Override
public void dispose() {
openSound.dispose();
closeSound.dispose();
}
}

View File

@ -1,63 +0,0 @@
package zero1hd.rhythmbullet.desktop.graphics.ui.windows;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.Window;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.utils.Align;
public class NoticeWindow extends Window {
private Label noticeText;
private Skin skin;
private Sound closeSound;
private Sound openSound;
private float vol;
public NoticeWindow(Skin skin, String styleName, String text, float vol, AssetManager assets) {
super("Notice", skin, "tinted");
this.skin = skin;
this.openSound = assets.get("pop_open.ogg", Sound.class);
this.closeSound = assets.get("pop_close.ogg", Sound.class);
this.vol = vol;
noticeText = new Label(text, skin, "sub-font", skin.getColor("default"));
noticeText.setWrap(true);
noticeText.setAlignment(Align.center);
add(noticeText).expandX().fill().center().padLeft(20f).padRight(20f);
}
public NoticeWindow(Skin skin, String styleName, String title, String text, float vol, AssetManager assets) {
super(title, skin, styleName);
this.skin = skin;
this.openSound = assets.get("pop_open.ogg", Sound.class);
this.closeSound = assets.get("pop_close.ogg", Sound.class);
this.vol = vol;
noticeText = new Label(text, skin, "sub-font", skin.getColor("default"));
noticeText.setWrap(true);
noticeText.setAlignment(Align.center);
add(noticeText).expandX().fill().center().padLeft(20f).padRight(20f);
}
public void setupButton(String text, ChangeListener changeListener, int alignment) {
TextButton button = new TextButton(text, skin, "sub");
button.addListener(changeListener);
add(button).align(alignment);
}
public void playOpenSound() {
openSound.play(vol/100f);
}
@Override
public boolean remove() {
closeSound.play(vol/100f);
return super.remove();
}
}

View File

@ -1,35 +0,0 @@
package zero1hd.rhythmbullet.desktop.graphics.ui.windows;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.Window;
public class PauseMenu extends Window {
private Label label;
private TextButton resumeButton;
private TextButton quit;
public PauseMenu(Skin skin) {
super("Paused", skin, "tinted");
defaults().pad(25f);
label = new Label("Game is paused.", skin);
add(label).spaceBottom(15f);
row();
resumeButton = new TextButton("Resume", skin, "sub");
add(resumeButton).spaceBottom(8f);
quit = new TextButton("Quit", skin, "sub");
add(quit);
pack();
setModal(true);
}
public TextButton getResumeButton() {
return resumeButton;
}
public TextButton getQuitButton() {
return quit;
}
}

View File

@ -1,20 +0,0 @@
package zero1hd.rhythmbullet.desktop.graphics.ui.windows;
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.Window;
public class Spawnables extends Window {
public Spawnables(String title, Skin skin) {
super(title, skin, "tinted");
Table spawnButtons = new Table(skin);
ScrollPane entityListScroller = new ScrollPane(spawnButtons);
entityListScroller.setSize(180, 80);
add(entityListScroller);
setSize(185, 85);
}
}

View File

@ -1,76 +0,0 @@
package zero1hd.rhythmbullet.desktop.graphics.ui.windows;
import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Slider;
import com.badlogic.gdx.scenes.scene2d.ui.Window;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import zero1hd.rhythmbullet.audio.MusicManager;
public class VolumeWindow extends Window {
private Slider fxVolSlider;
private Slider musicVolSlider;
private Preferences prefs;
private MusicManager music;
public VolumeWindow(String title, Skin skin, Preferences prefs) {
super(title, skin, "tinted");
this.prefs = prefs;
setSize(360f, 100f);
Label musicVolSliderLabel = new Label("Music Volume: ", skin, "window-font", skin.getColor("default"));
add(musicVolSliderLabel).left().padLeft(5f);
musicVolSlider = new Slider(0, 100, 0.1f, false, skin);
musicVolSlider.setValue(prefs.getFloat("music vol", 100f));
add(musicVolSlider).width(200f);
final Label musicVolPercentage = new Label(MathUtils.round(musicVolSlider.getValue()) + "%", skin, "window-font", skin.getColor("default"));
musicVolSlider.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
save();
musicVolPercentage.setText(MathUtils.round(musicVolSlider.getValue()) + "%");
if (music != null) {
music.setVolume(musicVolSlider.getValue());
}
}
});
add(musicVolPercentage).spaceLeft(10f).expandX().left();
row();
Label fxVolSliderLabel = new Label("FX Volume: ", skin, "window-font", skin.getColor("default"));
add(fxVolSliderLabel).left().padLeft(5f);
fxVolSlider = new Slider(0, 100, 1, false, skin);
fxVolSlider.setValue(prefs.getFloat("fx vol", 100f));
add(fxVolSlider).width(200f);
final Label fxVolPercentage = new Label(MathUtils.round(fxVolSlider.getValue()) + "%", skin, "window-font", skin.getColor("default"));
fxVolSlider.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
save();
fxVolPercentage.setText(MathUtils.round(fxVolSlider.getValue()) + "%");
}
});
add(fxVolPercentage).spaceLeft(10f).expandX().left();
}
public void save() {
prefs.putFloat("music vol", musicVolSlider.getValue());
prefs.putFloat("fx vol", fxVolSlider.getValue());
prefs.flush();
}
public void setMusic(MusicManager music) {
this.music = music;
if (music != null) {
music.setVolume(prefs.getFloat("music vol"));
}
}
}

View File

@ -10,8 +10,9 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.utils.viewport.ExtendViewport; import com.badlogic.gdx.utils.viewport.ExtendViewport;
import zero1hd.rhythmbullet.RhythmBullet; import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.audio.MusicController;
import zero1hd.rhythmbullet.audio.visualizer.CircularVisualizer; import zero1hd.rhythmbullet.audio.visualizer.CircularVisualizer;
import zero1hd.rhythmbullet.desktop.audio.visualizer.PCMMachine; import zero1hd.rhythmbullet.desktop.audio.visualizer.PCMObtainer;
import zero1hd.rhythmbullet.game.GameController; import zero1hd.rhythmbullet.game.GameController;
public class GameScreen extends ScreenAdapter { public class GameScreen extends ScreenAdapter {
@ -21,11 +22,11 @@ public class GameScreen extends ScreenAdapter {
private GameController gc; private GameController gc;
private CircularVisualizer circleVisualizer; private CircularVisualizer circleVisualizer;
public GameScreen(AssetManager assets, Preferences prefs) { public GameScreen(AssetManager assets, Preferences prefs, MusicController musicController) {
this.assets = assets; this.assets = assets;
batch = new SpriteBatch(); batch = new SpriteBatch();
viewport = new ExtendViewport(RhythmBullet.WORLD_WIDTH, RhythmBullet.WORLD_HEIGHT); viewport = new ExtendViewport(RhythmBullet.WORLD_WIDTH, RhythmBullet.WORLD_HEIGHT);
circleVisualizer = new CircularVisualizer(new PCMMachine()); circleVisualizer = new CircularVisualizer(new PCMObtainer(musicController));
circleVisualizer.setCenter(Gdx.graphics.getWidth()/2, Gdx.graphics.getHeight()/2); circleVisualizer.setCenter(Gdx.graphics.getWidth()/2, Gdx.graphics.getHeight()/2);
circleVisualizer.setCamera(viewport.getCamera()); circleVisualizer.setCamera(viewport.getCamera());
circleVisualizer.setColor(Color.CYAN.toFloatBits()); circleVisualizer.setColor(Color.CYAN.toFloatBits());

View File

@ -18,7 +18,8 @@ import com.badlogic.gdx.utils.Align;
import zero1hd.rhythmbullet.RhythmBullet; import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.audio.MusicController; import zero1hd.rhythmbullet.audio.MusicController;
import zero1hd.rhythmbullet.desktop.audio.visualizer.DoubleHorizontalVisualizer; import zero1hd.rhythmbullet.audio.visualizer.DoubleHorizontalVisualizer;
import zero1hd.rhythmbullet.desktop.audio.visualizer.PCMObtainer;
import zero1hd.rhythmbullet.desktop.graphics.ui.components.MusicControls; import zero1hd.rhythmbullet.desktop.graphics.ui.components.MusicControls;
import zero1hd.rhythmbullet.desktop.graphics.ui.pages.Page; import zero1hd.rhythmbullet.desktop.graphics.ui.pages.Page;
import zero1hd.rhythmbullet.graphics.ui.components.ScrollText; import zero1hd.rhythmbullet.graphics.ui.components.ScrollText;
@ -43,7 +44,7 @@ public class MainPage extends Page implements Observer {
super(0, 0); super(0, 0);
this.mc = musicController; this.mc = musicController;
dhv = new DoubleHorizontalVisualizer(70, (int) getWidth(), (int) (getHeight()*0.3), 0.3f, mc); dhv = new DoubleHorizontalVisualizer(70, (int) getWidth(), (int) (getHeight()*0.3), 0.3f, mc, new PCMObtainer(mc));
dhv.setPosition(0, (int) ((getHeight() - dhv.getHeight())/2f)); dhv.setPosition(0, (int) ((getHeight() - dhv.getHeight())/2f));
title = new Image(assetManager.get("title.png", Texture.class)); title = new Image(assetManager.get("title.png", Texture.class));

View File

@ -1,40 +0,0 @@
package zero1hd.rhythmbullet.desktop.screens.main;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.ui.Button;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import zero1hd.rhythmbullet.desktop.graphics.ui.pages.Page;
public class MusicStatusPage extends Page {
Label statusText;
Image loading;
Button back;
public MusicStatusPage(Skin skin, final Vector3 v3) {
super("Info", skin);
back = new Button(skin, "arrow-button");
back.setPosition(15f, (getHeight()-back.getHeight())/2 -15);
back.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
v3.x = 0.5f*getWidth();
}
});
addActor(back);
loading = new Image(skin, "loading");
loading.setPosition((getWidth()-loading.getWidth())/2, (getHeight()-loading.getHeight())/2);
loading.setOrigin(loading.getWidth()/2, loading.getHeight()/2);
loading.addAction(Actions.forever(Actions.rotateBy(-360f, 2f)));
addActor(loading);
}
}