playable game
This commit is contained in:
+21
-7
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ public class MenuState extends GameState {
|
||||
@Override
|
||||
public void init() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
sh.play(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,6 +16,7 @@ import model.drawObjects.enemy.Enemy;
|
||||
import model.objects.InfoPanel;
|
||||
import model.objects.Path;
|
||||
import model.objects.PlayArea;
|
||||
import audio.ObjectInstance;
|
||||
import control.GameStateManager;
|
||||
import control.button.ButtonEvent;
|
||||
import control.joystick.JoystickEvent;
|
||||
@@ -32,13 +33,15 @@ public class PlayState extends GameState{
|
||||
public static int currentScore = 0;
|
||||
public static int lifePoints = 100;
|
||||
|
||||
private long oldProgress = 0;
|
||||
|
||||
public PlayState(GameStateManager gsm, SongHandler sh) {
|
||||
super(gsm,sh);
|
||||
infoPanel = new InfoPanel(0, 0);
|
||||
area = new PlayArea(256, 1024, 1024, 100);
|
||||
for(int index = 0; index < 8; index++){
|
||||
addEnemy(index, GameModel.colors[index % 6]);
|
||||
}
|
||||
// for(int index = 0; index < 8; index++){
|
||||
// addEnemy(index, GameModel.colors[index % 6]);
|
||||
// }
|
||||
|
||||
player = new Player(1280-1024+1024/2, 1024/2);
|
||||
stroke = new BasicStroke(sizeOfEnemy,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND);
|
||||
@@ -46,15 +49,17 @@ public class PlayState extends GameState{
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
sh.stop();
|
||||
sh.play();
|
||||
|
||||
|
||||
System.out.println("Diff" + sh.getCurrentSongInstance().getDifficulty());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
player.update();
|
||||
for(Path path : area.paths){
|
||||
enemyIterator = enemys.iterator();
|
||||
Iterator<Enemy>enemyIterator = path.getEnemysInPath().iterator();
|
||||
while(enemyIterator.hasNext()){
|
||||
Enemy e = enemyIterator.next();
|
||||
Rectangle2D hitArea = area.hitAreas[e.getIndex()];
|
||||
@@ -67,7 +72,18 @@ public class PlayState extends GameState{
|
||||
e.update();
|
||||
}
|
||||
}
|
||||
infoPanel.updateIPanel();
|
||||
|
||||
infoPanel.updateIPanel();
|
||||
|
||||
long progress = sh.getProgress() / 1000;
|
||||
|
||||
for(ObjectInstance ob : sh.getCurrentSongInstance().getBetween(oldProgress, progress))
|
||||
{
|
||||
Path p = area.paths.get(ob.getDirection());
|
||||
p.addEnemy(ob.getColor(), ob.getDirection(), (int) ob.getLength());
|
||||
}
|
||||
|
||||
oldProgress = progress;
|
||||
}
|
||||
|
||||
|
||||
@@ -97,13 +113,15 @@ public class PlayState extends GameState{
|
||||
|
||||
@Override
|
||||
public void buttonPressed(ButtonEvent e) {
|
||||
// int index = player.getIndex();
|
||||
// int index = player.getIndex();
|
||||
Path currentPath = area.paths.get(player.getIndex());
|
||||
Enemy ce = currentPath.getEnemysInPath().getFirst();
|
||||
if(ce.isClickable()){
|
||||
if(ce.getColor().equals(e.getButton().getColor())){
|
||||
currentScore += ce.getTimeLeftToClick();
|
||||
currentPath.getEnemysInPath().remove(ce);
|
||||
if (!currentPath.getEnemysInPath().isEmpty()) {
|
||||
Enemy ce = currentPath.getEnemysInPath().getFirst();
|
||||
if (ce.isClickable()) {
|
||||
if (ce.getColor().equals(e.getButton().getColor())) {
|
||||
currentScore += ce.getTimeLeftToClick();
|
||||
currentPath.getEnemysInPath().remove(ce);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package model.objects;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.geom.Line2D;
|
||||
import java.util.ArrayDeque;
|
||||
|
||||
@@ -25,4 +26,9 @@ public class Path extends Line2D.Double {
|
||||
public void setEnemysInPath(ArrayDeque<Enemy> enemysInPath) {
|
||||
this.enemysInPath = enemysInPath;
|
||||
}
|
||||
|
||||
public void addEnemy(Color c, int pathID, int length)
|
||||
{
|
||||
enemysInPath.addLast(new Enemy(pathID, length, c, 100, getP1(), getP2()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user