better control system; album art loading more efficient;
This commit is contained in:
@@ -21,6 +21,7 @@ public class MusicController extends Observable implements OnCompletionListener,
|
||||
public final class States {
|
||||
public final Integer LOADED = new Integer(0), PLAYING = new Integer(1);
|
||||
}
|
||||
|
||||
public final States states = new States();
|
||||
private MusicList musicList;
|
||||
private MinimalAudioHeader musicHeader;
|
||||
@@ -191,12 +192,16 @@ public class MusicController extends Observable implements OnCompletionListener,
|
||||
@Override
|
||||
public void update(Observable o, Object arg) {
|
||||
if (o == musicList) {
|
||||
if (shuffle) {
|
||||
shuffle();
|
||||
}
|
||||
loadMusic();
|
||||
if (autoPlay) {
|
||||
play();
|
||||
if (arg == musicList.states.LOADING) {
|
||||
pause();
|
||||
} else if (arg == musicList.states.COMPLETE) {
|
||||
if (shuffle) {
|
||||
shuffle();
|
||||
}
|
||||
loadMusic();
|
||||
if (autoPlay) {
|
||||
play();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -17,6 +17,10 @@ import zero1hd.rhythmbullet.audio.processor.WAVAudioProcessor;
|
||||
* @author yunya
|
||||
*/
|
||||
public class MusicList extends Observable {
|
||||
public final class States {
|
||||
public final Integer LOADING = new Integer(0), COMPLETE = new Integer(1);
|
||||
}
|
||||
public States states = new States();
|
||||
private Array<FileHandle> musicList;
|
||||
private RecursiveMusicSearchThread searchThread;
|
||||
private AudioProcessorFactory audioProcFactory;
|
||||
@@ -45,7 +49,7 @@ public class MusicList extends Observable {
|
||||
*/
|
||||
public void asyncSearch(boolean refresh) {
|
||||
if (refresh) {
|
||||
|
||||
notifyObservers(states.LOADING);
|
||||
if (searchThread != null) {
|
||||
if (!searchThread.start()) {
|
||||
searchThread.stop();
|
||||
@@ -57,9 +61,7 @@ public class MusicList extends Observable {
|
||||
searchThread.start();
|
||||
}
|
||||
} else {
|
||||
if (searched && !hasChanged()) {
|
||||
notifyObservers();
|
||||
} else {
|
||||
if (!searched || hasChanged()) {
|
||||
asyncSearch(true);
|
||||
}
|
||||
}
|
||||
@@ -154,7 +156,7 @@ public class MusicList extends Observable {
|
||||
searched = true;
|
||||
Gdx.app.debug("MusicList", "recursive async search completed.");
|
||||
setChanged();
|
||||
notifyObservers();
|
||||
notifyObservers(states.COMPLETE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -25,7 +25,7 @@ public class MP3Metadata implements AudioMetadata {
|
||||
private int length;
|
||||
private Texture albumCover;
|
||||
private FileHandle fileHandle;
|
||||
private byte[] imageData;
|
||||
private Pixmap pixmap;
|
||||
|
||||
public MP3Metadata(FileHandle fileHandle) {
|
||||
this.fileHandle = fileHandle;
|
||||
@@ -65,8 +65,8 @@ public class MP3Metadata implements AudioMetadata {
|
||||
mp3file = (MP3File) AudioFileIO.read(fileHandle.file());
|
||||
Artwork art = mp3file.getTag().getFirstArtwork();
|
||||
if (art != null) {
|
||||
imageData = art.getBinaryData();
|
||||
|
||||
byte[] imageData = art.getBinaryData();
|
||||
pixmap = new Pixmap(imageData, 0, imageData.length);
|
||||
}
|
||||
|
||||
} catch (CannotReadException | IOException | TagException | ReadOnlyFileException | InvalidAudioFrameException e) {
|
||||
@@ -109,11 +109,10 @@ public class MP3Metadata implements AudioMetadata {
|
||||
|
||||
@Override
|
||||
public Texture getAlbumCover() {
|
||||
if (albumCover == null && imageData != null) {
|
||||
Pixmap pixmap = new Pixmap(imageData, 0, imageData.length);
|
||||
if (pixmap != null && albumCover == null) {
|
||||
albumCover = new Texture(pixmap);
|
||||
pixmap.dispose();
|
||||
imageData = null;
|
||||
pixmap = null;
|
||||
}
|
||||
return albumCover;
|
||||
}
|
||||
|
@@ -24,7 +24,7 @@ public class WAVMetadata implements AudioMetadata {
|
||||
private int length;
|
||||
private Texture albumCover;
|
||||
private FileHandle fileHandle;
|
||||
private byte[] imageData;
|
||||
private Pixmap pixmap;
|
||||
|
||||
public WAVMetadata(FileHandle fileHandle) {
|
||||
this.fileHandle = fileHandle;
|
||||
@@ -52,10 +52,11 @@ public class WAVMetadata implements AudioMetadata {
|
||||
try {
|
||||
AudioFile wav = AudioFileIO.read(fileHandle.file());
|
||||
Artwork art = wav.getTag().getFirstArtwork();
|
||||
if (art != null) {
|
||||
imageData = art.getBinaryData();
|
||||
}
|
||||
|
||||
if (art != null) {
|
||||
byte[] imageData = art.getBinaryData();
|
||||
pixmap = new Pixmap(imageData, 0, imageData.length);
|
||||
}
|
||||
} catch (CannotReadException | IOException | TagException | ReadOnlyFileException | InvalidAudioFrameException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -88,11 +89,10 @@ public class WAVMetadata implements AudioMetadata {
|
||||
|
||||
@Override
|
||||
public Texture getAlbumCover() {
|
||||
if (albumCover == null && imageData != null) {
|
||||
Pixmap pixmap = new Pixmap(imageData, 0, imageData.length);
|
||||
if (pixmap != null && albumCover == null) {
|
||||
albumCover = new Texture(pixmap);
|
||||
pixmap.dispose();
|
||||
imageData = null;
|
||||
pixmap = null;
|
||||
}
|
||||
return albumCover;
|
||||
}
|
||||
|
@@ -1,149 +0,0 @@
|
||||
package zero1hd.rhythmbullet.controls;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input.Keys;
|
||||
import com.badlogic.gdx.Preferences;
|
||||
import com.badlogic.gdx.assets.AssetManager;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
|
||||
public class KeyMap {
|
||||
TextureAtlas keyTextures;
|
||||
private Preferences keyBindPrefs;
|
||||
|
||||
public static final String UP = "up";
|
||||
public static final String DOWN = "down";
|
||||
public static final String LEFT = "left";
|
||||
public static final String RIGHT = "right";
|
||||
|
||||
public static final String SHOOT = "shoot";
|
||||
|
||||
public static final String FIRSTTHIRDTELEPORT = "firstThirdTP";
|
||||
public static final String SECONDTHIRDTELEPORT = "secondThirdTP";
|
||||
public static final String THIRDTHIRDTELEPORT = "thirdThirdTP";
|
||||
|
||||
public static final String ACCELERATE = "accelerate";
|
||||
|
||||
/**
|
||||
* forward binding.
|
||||
*/
|
||||
public static int up;
|
||||
/**
|
||||
* backward binding.
|
||||
*/
|
||||
public static int down;
|
||||
/**
|
||||
* left binding.
|
||||
*/
|
||||
public static int left;
|
||||
/**
|
||||
* right binding.
|
||||
*/
|
||||
public static int right;
|
||||
/**
|
||||
* shoot binding
|
||||
*/
|
||||
public static int shoot;
|
||||
/**
|
||||
* teleport first third binding
|
||||
*/
|
||||
public static int firstThirdTeleport;
|
||||
/**
|
||||
* teleport second third binding
|
||||
*/
|
||||
public static int secondThirdTeleport;
|
||||
/**
|
||||
* teleport third third binding
|
||||
*/
|
||||
public static int thirdThirdTeleport;
|
||||
|
||||
public static int accelerate;
|
||||
|
||||
|
||||
public KeyMap(AssetManager assets) {
|
||||
keyTextures = assets.get("keyboard.atlas", TextureAtlas.class);
|
||||
|
||||
setKeys(Gdx.app.getPreferences("PolyJet_Controls"));
|
||||
updateKeys();
|
||||
}
|
||||
|
||||
public Preferences getKeys() {
|
||||
return keyBindPrefs;
|
||||
}
|
||||
|
||||
public void setKeys(Preferences keys) {
|
||||
this.keyBindPrefs = keys;
|
||||
}
|
||||
|
||||
public TextureRegion getIcon(int keycode) {
|
||||
// Gdx.app.debug("Keycode texture name", Keys.toString(keycode));
|
||||
|
||||
switch (keycode) {
|
||||
case Keys.ALT_LEFT:
|
||||
case Keys.ALT_RIGHT:
|
||||
return keyTextures.findRegion("Keyboard_Black_Alt");
|
||||
case Keys.SHIFT_LEFT:
|
||||
case Keys.SHIFT_RIGHT:
|
||||
return keyTextures.findRegion("Keyboard_Black_Shift");
|
||||
case Keys.LEFT_BRACKET:
|
||||
return keyTextures.findRegion("Keyboard_Black_Bracket_Left");
|
||||
case Keys.RIGHT_BRACKET:
|
||||
return keyTextures.findRegion("Keyboard_Black_Bracket_Right");
|
||||
case Keys.SEMICOLON:
|
||||
return keyTextures.findRegion("Keyboard_Black_Semicolon");
|
||||
case Keys.SLASH:
|
||||
return keyTextures.findRegion("Keyboard_Black_Slash");
|
||||
case Keys.NUM:
|
||||
return keyTextures.findRegion("Keyboard_Black_Num_Lock");
|
||||
default:
|
||||
return keyTextures.findRegion("Keyboard_Black_" + Keys.toString(keycode).replace(' ', '_'));
|
||||
}
|
||||
}
|
||||
|
||||
public void updateKeys() {
|
||||
up = keyBindPrefs.getInteger(KeyMap.UP, Keys.UP);
|
||||
down = keyBindPrefs.getInteger(KeyMap.DOWN, Keys.DOWN);
|
||||
left = keyBindPrefs.getInteger(KeyMap.LEFT, Keys.LEFT);
|
||||
right = keyBindPrefs.getInteger(KeyMap.RIGHT, Keys.RIGHT);
|
||||
|
||||
shoot = keyBindPrefs.getInteger(KeyMap.SHOOT, Keys.SPACE);
|
||||
|
||||
firstThirdTeleport = keyBindPrefs.getInteger(KeyMap.FIRSTTHIRDTELEPORT, Keys.Q);
|
||||
secondThirdTeleport = keyBindPrefs.getInteger(KeyMap.SECONDTHIRDTELEPORT, Keys.W);
|
||||
thirdThirdTeleport = keyBindPrefs.getInteger(KeyMap.THIRDTHIRDTELEPORT, Keys.E);
|
||||
|
||||
accelerate = keyBindPrefs.getInteger(KeyMap.ACCELERATE, Keys.SHIFT_LEFT);
|
||||
}
|
||||
|
||||
/**
|
||||
* resets all binding to default;
|
||||
*/
|
||||
public void resetAllBinding() {
|
||||
keyBindPrefs.clear();
|
||||
keyBindPrefs.flush();
|
||||
}
|
||||
|
||||
public int stringToID(String control) {
|
||||
if (control == KeyMap.UP) {
|
||||
return KeyMap.up;
|
||||
} else if (control == KeyMap.DOWN) {
|
||||
return KeyMap.down;
|
||||
} else if (control == KeyMap.LEFT) {
|
||||
return KeyMap.left;
|
||||
} else if (control == KeyMap.RIGHT) {
|
||||
return KeyMap.right;
|
||||
} else if (control == KeyMap.SHOOT) {
|
||||
return KeyMap.shoot;
|
||||
} else if (control == KeyMap.FIRSTTHIRDTELEPORT) {
|
||||
return KeyMap.firstThirdTeleport;
|
||||
} else if (control == KeyMap.SECONDTHIRDTELEPORT) {
|
||||
return KeyMap.secondThirdTeleport;
|
||||
} else if (control == KeyMap.THIRDTHIRDTELEPORT) {
|
||||
return KeyMap.thirdThirdTeleport;
|
||||
} else if (control == KeyMap.ACCELERATE) {
|
||||
return KeyMap.accelerate;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,148 +0,0 @@
|
||||
package zero1hd.rhythmbullet.game;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.InputProcessor;
|
||||
import com.badlogic.gdx.Preferences;
|
||||
import com.badlogic.gdx.assets.AssetManager;
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.utils.Disposable;
|
||||
|
||||
import zero1hd.rhythmbullet.controls.KeyMap;
|
||||
import zero1hd.rhythmbullet.entity.CollisionDetector;
|
||||
import zero1hd.rhythmbullet.entity.EntityManager;
|
||||
import zero1hd.rhythmbullet.entity.ally.Laser;
|
||||
import zero1hd.rhythmbullet.entity.ally.PolyjetEntity;
|
||||
import zero1hd.rhythmbullet.entity.coordinator.CoordinatorManager;
|
||||
|
||||
|
||||
public class GameController implements Disposable, InputProcessor {
|
||||
public PolyjetEntity polyjet;
|
||||
|
||||
public CoordinatorManager cm;
|
||||
public EntityManager em;
|
||||
private CollisionDetector collisionDetector;
|
||||
|
||||
public ScoreManager score = new ScoreManager();
|
||||
|
||||
public GameController(AssetManager assetManager, Preferences prefs) {
|
||||
Gdx.app.debug("Game Area", "new area created");
|
||||
|
||||
polyjet = new PolyjetEntity(assetManager, 25f, 25f, 100, "standard");
|
||||
em = new EntityManager(assetManager, prefs);
|
||||
cm = new CoordinatorManager(em);
|
||||
|
||||
collisionDetector = new CollisionDetector(em.activeEnemies, em.activeAllies, assetManager, prefs);
|
||||
em.activeAllies.add(polyjet);
|
||||
}
|
||||
|
||||
public void draw(Batch batch) {
|
||||
batch.begin();
|
||||
for (int i = 0; i < em.activeEnemies.size; i++) {
|
||||
em.activeEnemies.get(i).draw(batch);
|
||||
}
|
||||
for (int i = 0; i < em.activeAllies.size; i++) {
|
||||
em.activeAllies.get(i).draw(batch);
|
||||
}
|
||||
batch.end();
|
||||
}
|
||||
|
||||
public void prepare(float delta) {
|
||||
for (int i = 0; i < em.activeEnemies.size; i++) {
|
||||
em.activeEnemies.get(i).updatePosition();
|
||||
}
|
||||
for (int i = 0; i < em.activeAllies.size; i++) {
|
||||
em.activeAllies.get(i).updatePosition();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyDown(int keycode) {
|
||||
if (keycode == KeyMap.left) {
|
||||
polyjet.moveLeft = true;
|
||||
}
|
||||
if (keycode == KeyMap.right) {
|
||||
polyjet.moveRight = true;
|
||||
}
|
||||
|
||||
if (keycode == KeyMap.up) {
|
||||
polyjet.moveUp = true;
|
||||
}
|
||||
|
||||
if (keycode == KeyMap.down) {
|
||||
polyjet.moveDown = true;
|
||||
}
|
||||
|
||||
if (keycode == KeyMap.accelerate) {
|
||||
polyjet.accelerate = true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyUp(int keycode) {
|
||||
if (keycode == KeyMap.left) {
|
||||
polyjet.moveLeft = false;
|
||||
}
|
||||
if (keycode == KeyMap.right) {
|
||||
polyjet.moveRight = false;
|
||||
}
|
||||
if (keycode == KeyMap.up) {
|
||||
polyjet.moveUp = false;
|
||||
}
|
||||
if (keycode == KeyMap.down) {
|
||||
polyjet.moveDown = false;
|
||||
}
|
||||
|
||||
if (keycode == KeyMap.accelerate) {
|
||||
polyjet.accelerate = false;
|
||||
}
|
||||
|
||||
if (keycode == KeyMap.shoot) {
|
||||
Laser laser = em.laser.buildEntity();
|
||||
laser.init(polyjet.getX() + polyjet.getWidth()/2f, polyjet.getY() + polyjet.getHeight()+1f, 60f);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public PolyjetEntity getPolyjetEntity() {
|
||||
return polyjet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
}
|
||||
|
||||
public CollisionDetector getCollisionDetector() {
|
||||
return collisionDetector;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyTyped(char character) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean touchDragged(int screenX, int screenY, int pointer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseMoved(int screenX, int screenY) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean scrolled(int amount) {
|
||||
return false;
|
||||
}
|
||||
}
|
71
core/src/zero1hd/rhythmbullet/graphics/ui/components/HealthBar.java
Executable file
71
core/src/zero1hd/rhythmbullet/graphics/ui/components/HealthBar.java
Executable file
@@ -0,0 +1,71 @@
|
||||
package zero1hd.rhythmbullet.graphics.ui.components;
|
||||
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
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 zero1hd.rhythmbullet.entity.ally.PolyjetEntity;
|
||||
|
||||
public class HealthBar extends WidgetGroup {
|
||||
Image empty;
|
||||
Image filler;
|
||||
float health;
|
||||
float maxHealth;
|
||||
|
||||
PolyjetEntity pje;
|
||||
public HealthBar(Skin skin, float maxHealth) {
|
||||
super();
|
||||
filler = new Image(skin.getPatch("bar-fill"));
|
||||
addActor(filler);
|
||||
|
||||
empty = new Image(skin.getPatch("bar-empty"));
|
||||
addActor(empty);
|
||||
|
||||
this.maxHealth = maxHealth;
|
||||
|
||||
}
|
||||
|
||||
public void setPolyjetEntity(PolyjetEntity pje) {
|
||||
this.pje = pje;
|
||||
}
|
||||
|
||||
public void setHealth(float health) {
|
||||
this.health = health;
|
||||
|
||||
filler.addAction(Actions.sizeTo(getWidth(), MathUtils.round((health/maxHealth)*getHeight()), 0.1f));;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void act(float delta) {
|
||||
if (pje != null) {
|
||||
health = pje.health;
|
||||
}
|
||||
super.act(delta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSize(float width, float height) {
|
||||
empty.setSize(width, height);
|
||||
filler.setSize(width, height);
|
||||
super.setSize(width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWidth(float width) {
|
||||
empty.setWidth(width);
|
||||
filler.setWidth(width);
|
||||
super.setWidth(width);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHeight(float height) {
|
||||
empty.setHeight(height);
|
||||
super.setHeight(height);
|
||||
}
|
||||
|
||||
public float getMaxHealth() {
|
||||
return maxHealth;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user