began map implementing
This commit is contained in:
parent
627a631f41
commit
fb10f2081e
@ -49,8 +49,14 @@ public interface AudioData extends Disposable {
|
||||
public AudioFormat getFormat();
|
||||
|
||||
/**
|
||||
* Returns object containing basic audio data;
|
||||
* returns sample count
|
||||
* @return
|
||||
*/
|
||||
public int getSampleCount();
|
||||
|
||||
/**
|
||||
* returns duration of song in seconds
|
||||
* @return
|
||||
*/
|
||||
public float getDuration();
|
||||
}
|
||||
|
21
core/src/zero1hd/polyjet/audio/GamePlayMap.java
Executable file
21
core/src/zero1hd/polyjet/audio/GamePlayMap.java
Executable 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;
|
||||
}
|
||||
}
|
@ -31,13 +31,17 @@ public class Mp3AudioData implements AudioData {
|
||||
private int readIndex;
|
||||
|
||||
private int sampleCount;
|
||||
private float durationInSeconds;
|
||||
|
||||
private AudioInputStream in;
|
||||
|
||||
Decoder decoder = new Decoder();
|
||||
public Mp3AudioData(FileHandle audioFile) {
|
||||
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) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
@ -149,4 +153,9 @@ public class Mp3AudioData implements AudioData {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDuration() {
|
||||
return durationInSeconds;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -80,4 +80,9 @@ public class WavAudioData implements AudioData {
|
||||
playbackMusic.dispose();
|
||||
decoder.cleanAndClose();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDuration() {
|
||||
return decoder.getDurationInSeconds();
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
||||
|
||||
import zero1hd.polyjet.Polyjet;
|
||||
import zero1hd.polyjet.audio.AudioData;
|
||||
import zero1hd.polyjet.audio.GamePlayMap;
|
||||
import zero1hd.polyjet.ui.stages.GamePlayArea;
|
||||
import zero1hd.polyjet.ui.windows.FPSWindow;
|
||||
|
||||
@ -37,7 +38,7 @@ public class GameScreen extends ScreenAdapter implements InputProcessor {
|
||||
|
||||
private AudioData music;
|
||||
|
||||
public GameScreen(Polyjet polyJet) {
|
||||
public GameScreen(Polyjet polyJet, GamePlayMap gpm) {
|
||||
core = polyJet;
|
||||
|
||||
// Overlay stuff
|
||||
@ -98,6 +99,7 @@ public class GameScreen extends ScreenAdapter implements InputProcessor {
|
||||
|
||||
// Continue to add things to input multiplexer
|
||||
gameArea = new GamePlayArea(polyJet.getAssetManager(), core.getPrefs());
|
||||
gameArea.setAudioMap(gpm);
|
||||
|
||||
inputs = new InputMultiplexer();
|
||||
inputs.addProcessor(this);
|
||||
|
@ -6,10 +6,10 @@ import com.badlogic.gdx.assets.AssetManager;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
|
||||
import com.badlogic.gdx.scenes.scene2d.Stage;
|
||||
import com.badlogic.gdx.utils.TimeUtils;
|
||||
import com.badlogic.gdx.utils.viewport.FitViewport;
|
||||
|
||||
import zero1hd.polyjet.Polyjet;
|
||||
import zero1hd.polyjet.audio.GamePlayMap;
|
||||
import zero1hd.polyjet.controls.KeyMap;
|
||||
import zero1hd.polyjet.entity.CollisionDetector;
|
||||
import zero1hd.polyjet.entity.Entities;
|
||||
@ -20,7 +20,7 @@ import zero1hd.polyjet.entity.ally.PolyJetEntity;
|
||||
|
||||
public class GamePlayArea extends Stage {
|
||||
public PolyJetEntity polyjet;
|
||||
|
||||
private GamePlayMap audioMap;
|
||||
|
||||
public EntityController ec;
|
||||
private CollisionDetector collisionDetector;
|
||||
@ -39,7 +39,6 @@ public class GamePlayArea extends Stage {
|
||||
public GamePlayArea(AssetManager assetManager, Preferences prefs) {
|
||||
super(new FitViewport(Polyjet.GAME_AREA_WIDTH, Polyjet.GAME_AREA_HEIGHT));
|
||||
Gdx.app.debug("Game Area", "new area created");
|
||||
|
||||
background = assetManager.get("star_bg.png");
|
||||
|
||||
polyjet = new PolyJetEntity(assetManager, 25f, 25f, "standard");
|
||||
@ -49,6 +48,11 @@ public class GamePlayArea extends Stage {
|
||||
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).
|
||||
* @param prefs
|
||||
@ -108,7 +112,9 @@ public class GamePlayArea extends Stage {
|
||||
|
||||
@Override
|
||||
public void act(float delta) {
|
||||
time = TimeUtils.millis()/10f;
|
||||
if (audioMap != null && time < audioMap.getPlayTime()) {
|
||||
time += delta;
|
||||
}
|
||||
|
||||
collisionDetector.collisionCheck();
|
||||
ec.deathClean();
|
||||
|
Loading…
x
Reference in New Issue
Block a user