began adding mirror visualizer

This commit is contained in:
Harrison Deng 2017-09-22 15:19:55 -05:00
parent b5e16188de
commit 4f58a43b79
2 changed files with 68 additions and 0 deletions

View File

@ -9,6 +9,7 @@ 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 zero1hd.rhythmbullet.audio.MusicManager;
@ -25,6 +26,7 @@ public class BasicVisualizer extends VisualizerCore {
private float rotation;
private Vector2 angleRot;
private boolean flip;
private Array<MirrorVisualizer> mirrors;
public BasicVisualizer() {
super(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()/2, 0, 0);
@ -137,4 +139,12 @@ public class BasicVisualizer extends VisualizerCore {
public boolean isFlipped() {
return flip;
}
public void addMirrorVisualizer(MirrorVisualizer mirror) {
mirrors.add(mirror);
}
public void removeMirrorVisualizer(MirrorVisualizer mirror) {
mirrors.removeValue(mirror, true);
}
}

View File

@ -0,0 +1,58 @@
package zero1hd.rhythmbullet.audio.visualizer;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
public class MirrorVisualizer {
private Sprite[] bars;
private float rotation;
private int xPos, yPos;
private Vector2 angleRot;
private boolean flip;
protected void setup(Sprite[] sprites, float rotation, int x, int y, Vector2 angleRot) {
this.xPos = x;
this.yPos = y;
this.angleRot = angleRot;
bars = new Sprite[sprites.length];
for (int i = 0; i < bars.length; i++) {
bars[i] = new Sprite(sprites[i]);
}
}
protected void updateSpriteSize(Sprite[] sprites) {
for (int i = 0; i < sprites.length; i++) {
bars[i].setSize(bars[i].getWidth(), sprites[i].getHeight());
}
}
public void updatePositioning(Sprite[] sprites, int barSpace) {
angleRot.set(MathUtils.cosDeg(rotation), MathUtils.sinDeg(rotation));
for (int i = 0; i < sprites.length; i++) {
bars[i].set(sprites[i]);
bars[i].setPosition(xPos + barSpace*angleRot.x, yPos + barSpace*angleRot.y);
if (flip) {
bars[i].setRotation(rotation+180);
} else {
bars[i].setRotation(rotation);
}
}
}
public void flip() {
flip = flip ? false : true;
}
public boolean isFlipped() {
return flip;
}
public void setxPos(int xPos) {
this.xPos = xPos;
}
public void setyPos(int yPos) {
this.yPos = yPos;
}
}