began map implementing

This commit is contained in:
Harrison Deng 2017-06-19 14:44:31 -05:00
parent 627a631f41
commit fb10f2081e
6 changed files with 58 additions and 9 deletions

View File

@ -49,8 +49,14 @@ public interface AudioData extends Disposable {
public AudioFormat getFormat(); public AudioFormat getFormat();
/** /**
* Returns object containing basic audio data; * returns sample count
* @return * @return
*/ */
public int getSampleCount(); public int getSampleCount();
/**
* returns duration of song in seconds
* @return
*/
public float getDuration();
} }

View File

@ -0,0 +1,21 @@
package zero1hd.polyjet.audio;
import com.badlogic.gdx.audio.Music;
public class GamePlayMap {
private Music playableClip;
private float playTime;
public GamePlayMap(AudioData audioData) {
playableClip = audioData.getPlaybackMusic();
playTime = audioData.getDuration();
}
public Music getPlayableClip() {
return playableClip;
}
public float getPlayTime() {
return playTime;
}
}

View File

@ -31,13 +31,17 @@ public class Mp3AudioData implements AudioData {
private int readIndex; private int readIndex;
private int sampleCount; private int sampleCount;
private float durationInSeconds;
private AudioInputStream in; private AudioInputStream in;
Decoder decoder = new Decoder(); Decoder decoder = new Decoder();
public Mp3AudioData(FileHandle audioFile) { public Mp3AudioData(FileHandle audioFile) {
try { try {
sampleCount = (int) new MP3File(audioFile.file()).getMP3AudioHeader().getNumberOfFrames(); MP3File mp3File = new MP3File(audioFile.file());
sampleCount = (int) mp3File.getMP3AudioHeader().getNumberOfFrames();
durationInSeconds = mp3File.getMP3AudioHeader().getNumberOfFrames()/readWindowSize;
} catch (IOException | TagException | ReadOnlyFileException | InvalidAudioFrameException e1) { } catch (IOException | TagException | ReadOnlyFileException | InvalidAudioFrameException e1) {
e1.printStackTrace(); e1.printStackTrace();
} }
@ -149,4 +153,9 @@ public class Mp3AudioData implements AudioData {
} }
} }
@Override
public float getDuration() {
return durationInSeconds;
}
} }

View File

@ -80,4 +80,9 @@ public class WavAudioData implements AudioData {
playbackMusic.dispose(); playbackMusic.dispose();
decoder.cleanAndClose(); decoder.cleanAndClose();
} }
@Override
public float getDuration() {
return decoder.getDurationInSeconds();
}
} }

View File

@ -19,6 +19,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import zero1hd.polyjet.Polyjet; import zero1hd.polyjet.Polyjet;
import zero1hd.polyjet.audio.AudioData; import zero1hd.polyjet.audio.AudioData;
import zero1hd.polyjet.audio.GamePlayMap;
import zero1hd.polyjet.ui.stages.GamePlayArea; import zero1hd.polyjet.ui.stages.GamePlayArea;
import zero1hd.polyjet.ui.windows.FPSWindow; import zero1hd.polyjet.ui.windows.FPSWindow;
@ -37,7 +38,7 @@ public class GameScreen extends ScreenAdapter implements InputProcessor {
private AudioData music; private AudioData music;
public GameScreen(Polyjet polyJet) { public GameScreen(Polyjet polyJet, GamePlayMap gpm) {
core = polyJet; core = polyJet;
// Overlay stuff // Overlay stuff
@ -98,6 +99,7 @@ public class GameScreen extends ScreenAdapter implements InputProcessor {
// Continue to add things to input multiplexer // Continue to add things to input multiplexer
gameArea = new GamePlayArea(polyJet.getAssetManager(), core.getPrefs()); gameArea = new GamePlayArea(polyJet.getAssetManager(), core.getPrefs());
gameArea.setAudioMap(gpm);
inputs = new InputMultiplexer(); inputs = new InputMultiplexer();
inputs.addProcessor(this); inputs.addProcessor(this);

View File

@ -6,10 +6,10 @@ import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.glutils.ShaderProgram; import com.badlogic.gdx.graphics.glutils.ShaderProgram;
import com.badlogic.gdx.scenes.scene2d.Stage; import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.utils.TimeUtils;
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.audio.GamePlayMap;
import zero1hd.polyjet.controls.KeyMap; import zero1hd.polyjet.controls.KeyMap;
import zero1hd.polyjet.entity.CollisionDetector; import zero1hd.polyjet.entity.CollisionDetector;
import zero1hd.polyjet.entity.Entities; import zero1hd.polyjet.entity.Entities;
@ -20,7 +20,7 @@ import zero1hd.polyjet.entity.ally.PolyJetEntity;
public class GamePlayArea extends Stage { public class GamePlayArea extends Stage {
public PolyJetEntity polyjet; public PolyJetEntity polyjet;
private GamePlayMap audioMap;
public EntityController ec; public EntityController ec;
private CollisionDetector collisionDetector; private CollisionDetector collisionDetector;
@ -39,7 +39,6 @@ public class GamePlayArea extends Stage {
public GamePlayArea(AssetManager assetManager, Preferences prefs) { public GamePlayArea(AssetManager assetManager, Preferences prefs) {
super(new FitViewport(Polyjet.GAME_AREA_WIDTH, Polyjet.GAME_AREA_HEIGHT)); super(new FitViewport(Polyjet.GAME_AREA_WIDTH, Polyjet.GAME_AREA_HEIGHT));
Gdx.app.debug("Game Area", "new area created"); Gdx.app.debug("Game Area", "new area created");
background = assetManager.get("star_bg.png"); background = assetManager.get("star_bg.png");
polyjet = new PolyJetEntity(assetManager, 25f, 25f, "standard"); polyjet = new PolyJetEntity(assetManager, 25f, 25f, "standard");
@ -49,6 +48,11 @@ public class GamePlayArea extends Stage {
addActor(polyjet); addActor(polyjet);
} }
public void setAudioMap(GamePlayMap audioMap) {
time = 0;
this.audioMap = audioMap;
}
/** /**
* needs to be called right after set (should be called in show method). * needs to be called right after set (should be called in show method).
* @param prefs * @param prefs
@ -108,7 +112,9 @@ public class GamePlayArea extends Stage {
@Override @Override
public void act(float delta) { public void act(float delta) {
time = TimeUtils.millis()/10f; if (audioMap != null && time < audioMap.getPlayTime()) {
time += delta;
}
collisionDetector.collisionCheck(); collisionDetector.collisionCheck();
ec.deathClean(); ec.deathClean();