playable game
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package audio;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
import control.button.Button;
|
||||
import control.button.ButtonHandler;
|
||||
|
||||
@@ -53,6 +55,11 @@ public class ObjectInstance {
|
||||
this.button = ButtonHandler.getButton(buttonID);
|
||||
}
|
||||
}
|
||||
|
||||
public Color getColor()
|
||||
{
|
||||
return button.getColor();
|
||||
}
|
||||
|
||||
public Button getButton() {
|
||||
return button;
|
||||
@@ -67,7 +74,10 @@ public class ObjectInstance {
|
||||
}
|
||||
|
||||
public long getLength() {
|
||||
return length;
|
||||
if(hold)
|
||||
return length;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
public void setLength(long length) {
|
||||
|
||||
@@ -42,4 +42,22 @@ public class SongInstance {
|
||||
public void setDifficulty(String difficulty) {
|
||||
this.difficulty = difficulty;
|
||||
}
|
||||
|
||||
public List<ObjectInstance> getBetween(long oldProgress, long progress) {
|
||||
List<ObjectInstance> b = new ArrayList<ObjectInstance>();
|
||||
|
||||
for(ObjectInstance i : objects)
|
||||
{
|
||||
if(i.getTime() > progress)
|
||||
{
|
||||
return b;
|
||||
}
|
||||
if(i.getTime() > oldProgress && i.getTime() <= progress)
|
||||
{
|
||||
b.add(i);
|
||||
}
|
||||
}
|
||||
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ public class DirScanner {
|
||||
Song s = JSONReader.readSong(file2);
|
||||
songs.add(s);
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -43,4 +43,8 @@ public class Button {
|
||||
{
|
||||
return buttonID;
|
||||
}
|
||||
public int getLedID()
|
||||
{
|
||||
return ledID;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,12 +78,23 @@ public class ButtonHandler implements KeyListener{
|
||||
}
|
||||
|
||||
public void buttonPress(Button b) {
|
||||
if(Window.ON_RASP)
|
||||
{
|
||||
Color c = b.getColor().brighter().brighter();
|
||||
led.setLed(b.getLedID(), c.getGreen(), c.getRed(), c.getBlue());
|
||||
led.show();
|
||||
}
|
||||
ButtonEvent e = new ButtonEvent(b, System.currentTimeMillis());
|
||||
for (ButtonListener bt : listeners)
|
||||
bt.buttonPressed(e);
|
||||
}
|
||||
|
||||
public void buttonRelease(Button b) {
|
||||
if(Window.ON_RASP)
|
||||
{
|
||||
led.setLed(b.getLedID(), b.getColor().getGreen(), b.getColor().getRed(), b.getColor().getBlue());
|
||||
led.show();
|
||||
}
|
||||
ButtonEvent e = new ButtonEvent(b, System.currentTimeMillis());
|
||||
for (ButtonListener bt : listeners)
|
||||
bt.buttonReleased(e);
|
||||
|
||||
+2
-2
@@ -58,7 +58,7 @@ public class Window extends JFrame {
|
||||
JoystickHandler jsh = new JoystickHandler();
|
||||
|
||||
//Create Instances
|
||||
SongHandler sh = null; //new SongHandler();
|
||||
SongHandler sh = new SongHandler();
|
||||
GameStateManager gsm = new GameStateManager(sh);
|
||||
GameView view = new GameView(led,gsm);
|
||||
GameModel model = new GameModel(sh, gsm);
|
||||
@@ -69,7 +69,7 @@ public class Window extends JFrame {
|
||||
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
||||
addWindowListener(new WindowAdapter(){
|
||||
public void windowClosing(WindowEvent e) {
|
||||
// sh.close();
|
||||
sh.close();
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
|
||||
+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