playable game

This commit is contained in:
Remco
2015-06-02 15:47:23 +02:00
parent 6a356982a6
commit 76a41dbbd1
10 changed files with 105 additions and 23 deletions
+21 -7
View File
@@ -1,13 +1,13 @@
package model;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import main.Window;
import audio.AudioPlayer;
import audio.Song;
import audio.SongInstance;
import audio.io.DirScanner;
public class SongHandler {
@@ -15,6 +15,7 @@ public class SongHandler {
private List<Song> songs;
private Song currentSong;
private SongInstance currentSongInstance;
private int currentIndex;
private File dir;
@@ -26,16 +27,19 @@ public class SongHandler {
songs = new ArrayList<Song>();
currentSong = null;
currentIndex = -1;
currentSongInstance = null;
currentIndex = 0;
p = new AudioPlayer();
if(Window.ON_RASP)
dir = new File(System.getProperty( "user.home" ) + "/ColorStrike/Songs");
dir = new File(System.getProperty( "user.home" ) + "/ColorStrike/Songs/");
else
dir = new File("Songs");
dir = new File(System.getProperty( "user.home" ) + "/Documents/songs/");
songs = DirScanner.scanDirectories(dir);
System.out.println(songs.size());
updatePlayer();
}
public void next()
@@ -56,15 +60,21 @@ public class SongHandler {
updatePlayer();
}
}
public void set(SongInstance si)
{
currentSongInstance = si;
}
private void updatePlayer()
{
if(currentIndex < 0)
currentIndex = songs.size() + currentIndex;
currentIndex%=songs.size();
if(currentIndex >= songs.size())
currentIndex = currentIndex - songs.size();
currentSong = songs.get(currentIndex);
currentSongInstance = currentSong.getSongs().get(0);
p.stop();
p.setClip(currentSong);
@@ -83,6 +93,10 @@ public class SongHandler {
{
return currentSong;
}
public SongInstance getCurrentSongInstance()
{
return currentSongInstance;
}
public void close()
{
@@ -102,7 +116,7 @@ public class SongHandler {
{
if(b)
{
p.play((int)currentSong.getSampleStart()*10000);
p.play((int)currentSong.getSampleStart()*10);
}
}