Feature/json
# Conflicts: # control/GameStateManager.java # image/Images.java # main/Window.java # model/gameState/MenuState.java
@@ -1,2 +1,4 @@
|
||||
branch for the buttons and joystick for gpio raspberry
|
||||
|
||||
JSON Parser
|
||||
Add the libraries to your build path.
|
||||
Add all the folders EXCEPT the 'songs' folder to your source.
|
||||
The 'songs' folder should be in your project root.
|
||||
@@ -0,0 +1,80 @@
|
||||
package audio;
|
||||
|
||||
import javax.sound.sampled.AudioFormat;
|
||||
import javax.sound.sampled.AudioInputStream;
|
||||
import javax.sound.sampled.AudioSystem;
|
||||
import javax.sound.sampled.Clip;
|
||||
|
||||
public class AudioPlayer {
|
||||
|
||||
private Clip clip;
|
||||
|
||||
public AudioPlayer() {
|
||||
clip = null;
|
||||
}
|
||||
|
||||
public void setClip(Song s) {
|
||||
try {
|
||||
clip = null;
|
||||
AudioInputStream ais = s.getAudioStream();
|
||||
AudioFormat baseFormat = ais.getFormat();
|
||||
AudioFormat decodeFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, baseFormat.getSampleRate(), 16, baseFormat.getChannels(), baseFormat.getChannels() * 2, baseFormat.getSampleRate(), false);
|
||||
AudioInputStream dais = AudioSystem.getAudioInputStream(decodeFormat, ais);
|
||||
clip = AudioSystem.getClip();
|
||||
clip.open(dais);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void play() {
|
||||
if (clip == null)
|
||||
return;
|
||||
clip.start();
|
||||
}
|
||||
|
||||
public void pause()
|
||||
{
|
||||
if (clip == null)
|
||||
return;
|
||||
if (clip.isRunning())
|
||||
{
|
||||
clip.stop();
|
||||
}
|
||||
}
|
||||
|
||||
public void play(int framePosition) {
|
||||
if (clip == null)
|
||||
return;
|
||||
stop();
|
||||
clip.setFramePosition(framePosition);
|
||||
clip.start();
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
if (clip == null)
|
||||
return;
|
||||
if (clip.isRunning())
|
||||
{
|
||||
clip.stop();
|
||||
clip.setFramePosition(0);
|
||||
}
|
||||
}
|
||||
|
||||
public void close() {
|
||||
stop();
|
||||
if(clip != null)
|
||||
{
|
||||
clip.close();
|
||||
}
|
||||
}
|
||||
|
||||
public long getProgress()
|
||||
{
|
||||
if(clip != null)
|
||||
return clip.getMicrosecondPosition();
|
||||
else
|
||||
return 0L;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package audio;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
import control.button.Button;
|
||||
import control.button.ButtonHandler;
|
||||
|
||||
public class ButtonInstance {
|
||||
|
||||
private long time;
|
||||
private int buttonID;
|
||||
private Color color;
|
||||
private Button button;
|
||||
|
||||
public ButtonInstance()
|
||||
{
|
||||
time = 0;
|
||||
buttonID = 0;
|
||||
|
||||
color = null;
|
||||
|
||||
button = null;
|
||||
}
|
||||
|
||||
public Button getButton() {
|
||||
return button;
|
||||
}
|
||||
|
||||
public long getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(long time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public int getButtonID() {
|
||||
return buttonID;
|
||||
}
|
||||
|
||||
public void setButtonID(int buttonID) {
|
||||
if(buttonID < ButtonHandler.getButtons().size() - 1)
|
||||
{
|
||||
this.buttonID = buttonID;
|
||||
this.button = ButtonHandler.getButton(buttonID);
|
||||
}
|
||||
}
|
||||
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public void setColor(Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package audio;
|
||||
|
||||
import control.button.Button;
|
||||
import control.button.ButtonHandler;
|
||||
|
||||
public class ObjectInstance {
|
||||
|
||||
private long time;
|
||||
private int direction;
|
||||
|
||||
private int buttonID;
|
||||
private Button button;
|
||||
|
||||
private boolean hold;
|
||||
private long length;
|
||||
|
||||
public ObjectInstance()
|
||||
{
|
||||
time = 0;
|
||||
direction = 0;
|
||||
|
||||
buttonID = 0;
|
||||
button = null;
|
||||
|
||||
hold = false;
|
||||
length = 0;
|
||||
}
|
||||
|
||||
public long getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(long time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public int getDirection() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
public void setDirection(int direction) {
|
||||
this.direction = direction;
|
||||
}
|
||||
|
||||
public int getButtonID() {
|
||||
return buttonID;
|
||||
}
|
||||
|
||||
public void setButtonID(int buttonID) {
|
||||
if(buttonID < ButtonHandler.getButtons().size() - 1)
|
||||
{
|
||||
this.buttonID = buttonID;
|
||||
this.button = ButtonHandler.getButton(buttonID);
|
||||
}
|
||||
}
|
||||
|
||||
public Button getButton() {
|
||||
return button;
|
||||
}
|
||||
|
||||
public boolean isHold() {
|
||||
return hold;
|
||||
}
|
||||
|
||||
public void setHold(boolean hold) {
|
||||
this.hold = hold;
|
||||
}
|
||||
|
||||
public long getLength() {
|
||||
return length;
|
||||
}
|
||||
|
||||
public void setLength(long length) {
|
||||
this.length = length;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
package audio;
|
||||
|
||||
import image.Images;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.sound.sampled.AudioInputStream;
|
||||
import javax.sound.sampled.AudioSystem;
|
||||
import javax.sound.sampled.UnsupportedAudioFileException;
|
||||
|
||||
public class Song {
|
||||
|
||||
private String title;
|
||||
private String subtitle;
|
||||
private String author;
|
||||
private double sample_start;
|
||||
private double BPM;
|
||||
|
||||
private File audio;
|
||||
private File background;
|
||||
private File banner;
|
||||
private File file;
|
||||
|
||||
private BufferedImage backgroundImage;
|
||||
private BufferedImage bannerImage;
|
||||
private AudioInputStream audioStream;
|
||||
|
||||
private List<SongInstance> songs;
|
||||
|
||||
public Song() {
|
||||
title = "";
|
||||
subtitle = "";
|
||||
author = "";
|
||||
sample_start = 0;
|
||||
BPM = 0.0;
|
||||
|
||||
audio = null;
|
||||
background = null;
|
||||
banner = null;
|
||||
file = null;
|
||||
|
||||
backgroundImage = null;
|
||||
bannerImage = null;
|
||||
audioStream = null;
|
||||
|
||||
songs = new ArrayList<SongInstance>();
|
||||
}
|
||||
|
||||
public void addSongInstance(SongInstance s) {
|
||||
songs.add(s);
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getSubtitle() {
|
||||
return subtitle;
|
||||
}
|
||||
|
||||
public void setSubtitle(String subtitle) {
|
||||
this.subtitle = subtitle;
|
||||
}
|
||||
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public void setAuthor(String author) {
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
public double getSampleStart() {
|
||||
return sample_start;
|
||||
}
|
||||
|
||||
public void setSampleStart(double sample_start) {
|
||||
this.sample_start = sample_start;
|
||||
}
|
||||
|
||||
public double getBPM() {
|
||||
return BPM;
|
||||
}
|
||||
|
||||
public void setBPM(double bPM) {
|
||||
BPM = bPM;
|
||||
}
|
||||
|
||||
public File getAudio() {
|
||||
return audio;
|
||||
}
|
||||
|
||||
public AudioInputStream getAudioStream()
|
||||
{
|
||||
if(audioStream == null)
|
||||
{
|
||||
try {
|
||||
this.audioStream = AudioSystem.getAudioInputStream(audio);
|
||||
} catch (UnsupportedAudioFileException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
audioStream.reset();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return audioStream;
|
||||
}
|
||||
|
||||
public void setAudio(File audio) {
|
||||
this.audio = audio;
|
||||
}
|
||||
|
||||
public File getBackground() {
|
||||
return background;
|
||||
}
|
||||
|
||||
public void setBackground(File background) {
|
||||
this.background = background;
|
||||
|
||||
}
|
||||
|
||||
public BufferedImage getBackgroundImage()
|
||||
{
|
||||
if(backgroundImage == null)
|
||||
{
|
||||
this.backgroundImage = Images.readImage(background);
|
||||
}
|
||||
return backgroundImage;
|
||||
}
|
||||
|
||||
public File getBanner() {
|
||||
return banner;
|
||||
}
|
||||
|
||||
public BufferedImage getBannerImage()
|
||||
{
|
||||
if(bannerImage == null)
|
||||
{
|
||||
this.bannerImage = Images.readImage(banner);
|
||||
}
|
||||
return bannerImage;
|
||||
}
|
||||
|
||||
public void setBanner(File banner) {
|
||||
this.banner = banner;
|
||||
}
|
||||
|
||||
public File getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
public void setFile(File file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
public List<SongInstance> getSongs() {
|
||||
return songs;
|
||||
}
|
||||
|
||||
public void close()
|
||||
{
|
||||
if(audioStream != null)
|
||||
{
|
||||
try {
|
||||
audioStream.close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package audio;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SongInstance {
|
||||
|
||||
private String difficulty;
|
||||
|
||||
private List<ObjectInstance> objects;
|
||||
private List<ButtonInstance> buttons;
|
||||
|
||||
public SongInstance(String difficulty)
|
||||
{
|
||||
this.difficulty = difficulty;
|
||||
|
||||
objects = new ArrayList<ObjectInstance>();
|
||||
buttons = new ArrayList<ButtonInstance>();
|
||||
}
|
||||
|
||||
public void addObjectInstance(ObjectInstance obj)
|
||||
{
|
||||
objects.add(obj);
|
||||
}
|
||||
public void addButtonInstance(ButtonInstance btn)
|
||||
{
|
||||
buttons.add(btn);
|
||||
}
|
||||
|
||||
public List<ObjectInstance> getObjects() {
|
||||
return objects;
|
||||
}
|
||||
|
||||
public List<ButtonInstance> getButtons() {
|
||||
return buttons;
|
||||
}
|
||||
|
||||
public String getDifficulty() {
|
||||
return difficulty;
|
||||
}
|
||||
|
||||
public void setDifficulty(String difficulty) {
|
||||
this.difficulty = difficulty;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package audio.io;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import audio.Song;
|
||||
|
||||
public class DirScanner {
|
||||
|
||||
public static List<Song> scanDirectories(File f)
|
||||
{
|
||||
List<Song> songs = new ArrayList<Song>();
|
||||
|
||||
if(!f.isDirectory())
|
||||
return songs;
|
||||
|
||||
FileFilter dirs = new FileFilter()
|
||||
{
|
||||
public boolean accept(File e) {
|
||||
if(e.isDirectory())
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
};
|
||||
FileFilter csf = new FileFilter()
|
||||
{
|
||||
public boolean accept(File e) {
|
||||
if(e.isFile() && e.getName().endsWith(".csf"))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
for(File file : f.listFiles(dirs))
|
||||
{
|
||||
for(File file2 : file.listFiles(csf))
|
||||
{
|
||||
try {
|
||||
Song s = JSONReader.readSong(file2);
|
||||
songs.add(s);
|
||||
} catch (IOException e1) {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return songs;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
package audio.io;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonArray;
|
||||
import javax.json.JsonObject;
|
||||
import javax.json.JsonReader;
|
||||
|
||||
import model.GameModel;
|
||||
import audio.ButtonInstance;
|
||||
import audio.ObjectInstance;
|
||||
import audio.Song;
|
||||
import audio.SongInstance;
|
||||
|
||||
public class JSONReader {
|
||||
|
||||
public static Song readSong(File f) throws IOException {
|
||||
|
||||
if(!f.exists())
|
||||
throw new FileNotFoundException("CSF File does not exist");
|
||||
|
||||
// Get CSF File
|
||||
InputStream is = new FileInputStream(f);
|
||||
|
||||
// Read CSF Content
|
||||
JsonReader rdr = Json.createReader(is);
|
||||
JsonObject obj = rdr.readObject();
|
||||
rdr.close();
|
||||
is.close();
|
||||
|
||||
if(!obj.containsKey("meta") || !obj.containsKey("file") || !obj.containsKey("data"))
|
||||
throw new IOException("Corrupt CSF File");
|
||||
|
||||
// Create new Song
|
||||
Song s = new Song();
|
||||
|
||||
// Read META data
|
||||
JsonObject meta = obj.getJsonObject("meta");
|
||||
|
||||
s.setTitle(meta.getString("title"));
|
||||
s.setSubtitle(meta.getString("subtitle"));
|
||||
s.setAuthor(meta.getString("author"));
|
||||
s.setSampleStart(meta.getInt("sample_start"));
|
||||
s.setBPM(meta.getInt("BPM"));
|
||||
|
||||
//Read FILE data
|
||||
JsonObject file = obj.getJsonObject("file");
|
||||
|
||||
File audio = new File(f.getParent() + File.separator + file.getString("audio"));
|
||||
if(!audio.exists() || !audio.getName().toLowerCase().endsWith(".mp3"))
|
||||
throw new FileNotFoundException("Audio file does not exist: " + audio.getPath());
|
||||
s.setAudio(audio);
|
||||
|
||||
File background = new File(f.getParent() + File.separator + file.getString("background"));
|
||||
if(!background.exists() || !(background.getName().toLowerCase().endsWith(".jpg") || background.getName().toLowerCase().endsWith(".png")))
|
||||
throw new FileNotFoundException("Background image does not exist: " + background.getPath());
|
||||
s.setBackground(background);
|
||||
|
||||
File banner = new File(f.getParent() + File.separator + file.getString("banner"));
|
||||
if(!banner.exists() || !(banner.getName().toLowerCase().endsWith(".jpg") || banner.getName().toLowerCase().endsWith(".png")))
|
||||
throw new FileNotFoundException("Banner image does not exist: " + banner.getPath());
|
||||
s.setBanner(banner);
|
||||
|
||||
s.setFile(f);
|
||||
|
||||
//Read Data data
|
||||
JsonArray data = obj.getJsonArray("data");
|
||||
for(int i = 0; i < data.size(); i++)
|
||||
{
|
||||
s.addSongInstance( readSongInstance(data.getJsonObject(i)) );
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
private static SongInstance readSongInstance(JsonObject obj) throws IOException {
|
||||
String difficulty = obj.getString("difficulty");
|
||||
SongInstance si = new SongInstance(difficulty);
|
||||
|
||||
JsonArray object = obj.getJsonArray("objects");
|
||||
for(int i = 0; i < object.size(); i++)
|
||||
{
|
||||
si.addObjectInstance( readObjectInstance(object.getJsonObject(i)) );
|
||||
}
|
||||
|
||||
JsonArray buttons = obj.getJsonArray("buttons");
|
||||
for(int i = 0; i < buttons.size(); i++)
|
||||
{
|
||||
si.addButtonInstance( readButtonInstance(buttons.getJsonObject(i)) );
|
||||
}
|
||||
|
||||
return si;
|
||||
}
|
||||
|
||||
private static ObjectInstance readObjectInstance(JsonObject obj)
|
||||
{
|
||||
ObjectInstance oi = new ObjectInstance();
|
||||
|
||||
oi.setTime(obj.getInt("time"));
|
||||
oi.setDirection(obj.getInt("direction"));
|
||||
oi.setButtonID(obj.getInt("button"));
|
||||
|
||||
if(obj.containsKey("hold") && obj.getBoolean("hold"))
|
||||
{
|
||||
oi.setHold(obj.getBoolean("hold"));
|
||||
oi.setLength(obj.getInt("length"));
|
||||
}
|
||||
|
||||
return oi;
|
||||
}
|
||||
|
||||
private static ButtonInstance readButtonInstance(JsonObject obj)
|
||||
{
|
||||
ButtonInstance bi = new ButtonInstance();
|
||||
|
||||
bi.setTime(obj.getInt("time"));
|
||||
bi.setButtonID(obj.getInt("button"));
|
||||
|
||||
Color color = GameModel.colors[obj.getInt("color") % GameModel.colors.length];
|
||||
bi.setColor(color);
|
||||
|
||||
return bi;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package audio.io;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import audio.Song;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Song s = null;
|
||||
try {
|
||||
s = JSONReader.readSong(new File("C:\\Users\\Kenneth\\Development\\Java Development\\SimApplicatie\\Arcade\\songs\\NAME_OF_SONG\\NAME_OF_SONG.csf"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println("---");
|
||||
System.out.println(s);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,9 +3,11 @@ package control;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import model.SongHandler;
|
||||
import model.gameState.GameState;
|
||||
import model.gameState.MenuState;
|
||||
import model.gameState.TitleState;
|
||||
import model.gameState.PickSongState;
|
||||
import model.gameState.PlayState;
|
||||
|
||||
public class GameStateManager {
|
||||
@@ -14,18 +16,33 @@ public class GameStateManager {
|
||||
public GameState currentState;
|
||||
private int index = 0;
|
||||
|
||||
public GameStateManager(){
|
||||
public enum State {
|
||||
TITLE_STATE,
|
||||
MENU_STATE,
|
||||
PLAY_STATE,
|
||||
PICKSONG_STATE
|
||||
}
|
||||
|
||||
public GameStateManager(SongHandler sh){
|
||||
gamestates = new ArrayList<GameState>();
|
||||
gamestates.add(new TitleState(this));
|
||||
gamestates.add(new MenuState(this));
|
||||
gamestates.add(new PlayState(this));
|
||||
gamestates.add(new TitleState(this, sh));
|
||||
gamestates.add(new MenuState(this, sh));
|
||||
gamestates.add(new PlayState(this, sh));
|
||||
gamestates.add(new PickSongState(this, sh));
|
||||
currentState = gamestates.get(0);
|
||||
}
|
||||
|
||||
public void setState(State st)
|
||||
{
|
||||
currentState = gamestates.get(st.ordinal());
|
||||
currentState.init();
|
||||
}
|
||||
|
||||
public void next() {
|
||||
index++;
|
||||
index %= gamestates.size();
|
||||
currentState = gamestates.get(index);
|
||||
currentState.init();
|
||||
}
|
||||
|
||||
public void update(){
|
||||
|
||||
@@ -6,6 +6,8 @@ import java.awt.event.KeyListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import main.Window;
|
||||
|
||||
import com.pi4j.io.gpio.GpioController;
|
||||
import com.pi4j.io.gpio.GpioFactory;
|
||||
import com.pi4j.io.gpio.GpioPinDigitalInput;
|
||||
@@ -14,7 +16,6 @@ import com.pi4j.io.gpio.RaspiPin;
|
||||
import com.pi4j.io.gpio.event.GpioPinDigitalStateChangeEvent;
|
||||
import com.pi4j.io.gpio.event.GpioPinListenerDigital;
|
||||
|
||||
import main.Window;
|
||||
import control.LedHandler;
|
||||
|
||||
public class ButtonHandler implements KeyListener{
|
||||
@@ -37,12 +38,7 @@ public class ButtonHandler implements KeyListener{
|
||||
buttons.add(new Button(4, 3, led));
|
||||
buttons.add(new Button(5, 4, led));
|
||||
buttons.add(new Button(6, 5, led));
|
||||
|
||||
for(Button b : buttons)
|
||||
{
|
||||
b.setColor(new Color((int)(Math.random()*254+1),(int)(Math.random()*254+1),(int)(Math.random()*254+1)));
|
||||
}
|
||||
System.out.println(Window.ON_RASP);
|
||||
|
||||
if (Window.ON_RASP)
|
||||
addGpioListeners();
|
||||
|
||||
@@ -158,4 +154,16 @@ public class ButtonHandler implements KeyListener{
|
||||
{
|
||||
return buttons;
|
||||
}
|
||||
|
||||
public static Button getButton(int id)
|
||||
{
|
||||
for(Button b : buttons)
|
||||
{
|
||||
if(b.getButtonID() == id)
|
||||
{
|
||||
return b;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package image;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -8,34 +9,42 @@ import javax.imageio.ImageIO;
|
||||
|
||||
import main.Main;
|
||||
|
||||
public class Images{
|
||||
public class Images {
|
||||
|
||||
public static ArrayList<BufferedImage> images = new ArrayList<BufferedImage>();
|
||||
public static ArrayList<BufferedImage> images = new ArrayList<BufferedImage>();
|
||||
|
||||
public Images(){
|
||||
|
||||
}
|
||||
public Images() {
|
||||
|
||||
static{
|
||||
try{
|
||||
images.add(ImageIO.read(Main.class.getResource("/image/player.png")));
|
||||
images.add(ImageIO.read(Main.class.getResource("/image/player2.png")));
|
||||
images.add(ImageIO.read(Main.class.getResource("/image/pressstart.png")));
|
||||
images.add(ImageIO.read(Main.class.getResource("/image/colorstrike.png")));
|
||||
images.add(ImageIO.read(Main.class.getResource("/image/background.png")));
|
||||
|
||||
}catch(IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static BufferedImage getImage(ImageType img)
|
||||
{
|
||||
return images.get(img.ordinal());
|
||||
}
|
||||
static {
|
||||
try {
|
||||
images.add(ImageIO.read(Main.class.getResource("/image/player.png")));
|
||||
images.add(ImageIO.read(Main.class.getResource("/image/player2.png")));
|
||||
images.add(ImageIO.read(Main.class.getResource("/image/pressstart.png")));
|
||||
images.add(ImageIO.read(Main.class.getResource("/image/colorstrike.png")));
|
||||
images.add(ImageIO.read(Main.class.getResource("/image/background.png")));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public enum ImageType
|
||||
{
|
||||
player,player2,pressstart,colorstrike,background
|
||||
}
|
||||
public static BufferedImage getImage(ImageType img) {
|
||||
return images.get(img.ordinal());
|
||||
}
|
||||
|
||||
public enum ImageType {
|
||||
player,player2,pressstart,colorstrike,background
|
||||
}
|
||||
|
||||
public static BufferedImage readImage(File f) {
|
||||
BufferedImage bf = null;
|
||||
try {
|
||||
bf = ImageIO.read(f);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return bf;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,5 +12,4 @@ public class Main {
|
||||
new Window(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import java.awt.image.BufferedImage;
|
||||
import javax.swing.JFrame;
|
||||
|
||||
import model.GameModel;
|
||||
import model.SongHandler;
|
||||
import view.GameView;
|
||||
import control.GameControl;
|
||||
import control.GameStateManager;
|
||||
@@ -24,19 +25,14 @@ public class Window extends JFrame {
|
||||
private static final long serialVersionUID = -9222956702898533696L;
|
||||
public static boolean ON_RASP;
|
||||
|
||||
public final static int WIDTH = 1280;
|
||||
public final static int HEIGHT = 1024;
|
||||
|
||||
public Window(boolean ON_RASP)
|
||||
{
|
||||
//Create window
|
||||
super("Arcade");
|
||||
setSize(1280, 1024);
|
||||
|
||||
//Set window close listener
|
||||
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
||||
addWindowListener(new WindowAdapter(){
|
||||
public void windowClosing(WindowEvent e) {
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
setSize(WIDTH, HEIGHT);
|
||||
|
||||
//Create Events
|
||||
LedHandler led = null;
|
||||
@@ -62,12 +58,22 @@ public class Window extends JFrame {
|
||||
JoystickHandler jsh = new JoystickHandler();
|
||||
|
||||
//Create Instances
|
||||
GameStateManager gsm = new GameStateManager();
|
||||
SongHandler sh = new SongHandler();
|
||||
GameStateManager gsm = new GameStateManager(sh);
|
||||
GameView view = new GameView(led,gsm);
|
||||
GameModel model = new GameModel(gsm);
|
||||
GameModel model = new GameModel(sh, gsm);
|
||||
GameControl control = new GameControl(model, view,gsm);
|
||||
setContentPane(view);
|
||||
|
||||
//Set window close listener
|
||||
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
||||
addWindowListener(new WindowAdapter(){
|
||||
public void windowClosing(WindowEvent e) {
|
||||
sh.close();
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
|
||||
//Create EventListeners
|
||||
if(!Window.ON_RASP){
|
||||
addKeyListener(bth);
|
||||
|
||||
@@ -15,11 +15,14 @@ public class GameModel implements ActionListener{
|
||||
private Timer update;
|
||||
public static Color[] colors = {Color.MAGENTA,Color.RED,Color.GREEN,Color.YELLOW,Color.CYAN,Color.WHITE};
|
||||
private GameStateManager gsm;
|
||||
SongHandler sh;
|
||||
|
||||
public GameModel(GameStateManager gsm)
|
||||
public GameModel(SongHandler sh, GameStateManager gsm)
|
||||
{
|
||||
|
||||
this.gsm = gsm;
|
||||
|
||||
this.sh = sh;
|
||||
|
||||
update = new Timer(1000/30, this);
|
||||
update.start();
|
||||
|
||||
@@ -30,6 +33,6 @@ public class GameModel implements ActionListener{
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
gsm.update();
|
||||
gsm.update();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
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.io.DirScanner;
|
||||
|
||||
public class SongHandler {
|
||||
|
||||
private List<Song> songs;
|
||||
|
||||
private Song currentSong;
|
||||
private int currentIndex;
|
||||
|
||||
private File dir;
|
||||
|
||||
private AudioPlayer p;
|
||||
|
||||
public SongHandler()
|
||||
{
|
||||
songs = new ArrayList<Song>();
|
||||
|
||||
currentSong = null;
|
||||
currentIndex = -1;
|
||||
|
||||
p = new AudioPlayer();
|
||||
|
||||
if(Window.ON_RASP)
|
||||
dir = new File(System.getProperty( "user.home" ) + "/ColorStrike/Songs");
|
||||
else
|
||||
dir = new File("Songs");
|
||||
|
||||
songs = DirScanner.scanDirectories(dir);
|
||||
}
|
||||
|
||||
public void next()
|
||||
{
|
||||
currentIndex++;
|
||||
updatePlayer();
|
||||
}
|
||||
public void previous()
|
||||
{
|
||||
currentIndex--;
|
||||
updatePlayer();
|
||||
}
|
||||
public void set(int i)
|
||||
{
|
||||
if(currentIndex != i)
|
||||
{
|
||||
currentIndex = i;
|
||||
updatePlayer();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void updatePlayer()
|
||||
{
|
||||
if(currentIndex < 0)
|
||||
currentIndex = songs.size() + currentIndex;
|
||||
|
||||
currentIndex%=songs.size();
|
||||
currentSong = songs.get(currentIndex);
|
||||
|
||||
p.stop();
|
||||
p.setClip(currentSong);
|
||||
}
|
||||
|
||||
public long getProgress()
|
||||
{
|
||||
return p.getProgress();
|
||||
}
|
||||
|
||||
public List<Song> getSongs()
|
||||
{
|
||||
return songs;
|
||||
}
|
||||
public Song getCurrentSong()
|
||||
{
|
||||
return currentSong;
|
||||
}
|
||||
|
||||
public void close()
|
||||
{
|
||||
p.close();
|
||||
for(Song s : songs)
|
||||
{
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void play()
|
||||
{
|
||||
p.play();
|
||||
}
|
||||
|
||||
public void play(boolean b)
|
||||
{
|
||||
if(b)
|
||||
{
|
||||
p.play((int)currentSong.getSampleStart()*10000);
|
||||
}
|
||||
}
|
||||
|
||||
public void pause()
|
||||
{
|
||||
p.pause();
|
||||
}
|
||||
|
||||
public void stop()
|
||||
{
|
||||
p.stop();
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package model.gameState;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
|
||||
import model.SongHandler;
|
||||
import control.GameStateManager;
|
||||
import control.button.ButtonEvent;
|
||||
import control.joystick.JoystickEvent;
|
||||
@@ -9,10 +10,11 @@ import control.joystick.JoystickEvent;
|
||||
public abstract class GameState {
|
||||
|
||||
protected GameStateManager gsm;
|
||||
protected SongHandler sh;
|
||||
|
||||
public GameState(GameStateManager gsm) {
|
||||
super();
|
||||
public GameState(GameStateManager gsm, SongHandler sh) {
|
||||
this.gsm = gsm;
|
||||
this.sh = sh;
|
||||
}
|
||||
|
||||
public abstract void init();
|
||||
|
||||
@@ -5,12 +5,12 @@ import image.Images.ImageType;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import model.SongHandler;
|
||||
import model.objects.MenuButton;
|
||||
import control.GameStateManager;
|
||||
import control.button.Button;
|
||||
import control.GameStateManager.State;
|
||||
import control.button.ButtonEvent;
|
||||
import control.joystick.Joystick;
|
||||
import control.joystick.JoystickEvent;
|
||||
@@ -25,11 +25,11 @@ public class MenuState extends GameState {
|
||||
int maxFrames = 2560;
|
||||
int animationcounter;
|
||||
|
||||
public MenuState(GameStateManager gsm) {
|
||||
super(gsm);
|
||||
public MenuState(GameStateManager gsm, SongHandler sh) {
|
||||
super(gsm, sh);
|
||||
buttons = new ArrayList<MenuButton>();
|
||||
buttons.add(new MenuButton(-600, 50,1.7,"Genre", 0, Color.green));
|
||||
buttons.add(new MenuButton(-600, 150, 1.7, "Most played", 10, new Color(60,60,255)));
|
||||
buttons.add(new MenuButton(-600, 50,1.7, "Quick play", 0, Color.green));
|
||||
buttons.add(new MenuButton(-600, 150, 1.7, "Pick song", 10, new Color(60,60,255)));
|
||||
buttons.add(new MenuButton(-600, 250, 1.7, "Best played", 20, Color.red));
|
||||
buttons.add(new MenuButton(-600, 350, 1.7, "Last played", 30, Color.yellow));
|
||||
}
|
||||
@@ -57,6 +57,13 @@ public class MenuState extends GameState {
|
||||
|
||||
@Override
|
||||
public void buttonPressed(ButtonEvent e) {
|
||||
if(e.getButton().getButtonID() == 1){
|
||||
for(MenuButton b:buttons){
|
||||
if(b.isSelected()){
|
||||
gsm.setState(State.PLAY_STATE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void buttonReleased(ButtonEvent e) {
|
||||
@@ -95,7 +102,6 @@ public class MenuState extends GameState {
|
||||
}
|
||||
if(buttons.get(button).getX() >= -200){
|
||||
buttonInAnimation(button+1);
|
||||
System.out.println(buttons.get(button).getX());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package model.gameState;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Window;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import model.SongHandler;
|
||||
import control.GameStateManager;
|
||||
import control.button.ButtonEvent;
|
||||
import control.joystick.JoystickEvent;
|
||||
|
||||
public class PickSongState extends GameState {
|
||||
|
||||
public PickSongState(GameStateManager gsm, SongHandler sh) {
|
||||
super(gsm, sh);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
sh.set(0);
|
||||
sh.play(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Graphics2D g2d) {
|
||||
g2d.drawImage(sh.getCurrentSong().getBackgroundImage(), null, 0, 0);
|
||||
g2d.drawImage(sh.getCurrentSong().getBannerImage(), null, 400, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buttonPressed(ButtonEvent e) {}
|
||||
|
||||
@Override
|
||||
public void buttonReleased(ButtonEvent e) {}
|
||||
|
||||
@Override
|
||||
public void onJoystickMoved(JoystickEvent e) {
|
||||
switch (e.getJoystick().getPos()) {
|
||||
case LEFT:
|
||||
sh.previous();
|
||||
sh.play(true);
|
||||
break;
|
||||
case RIGHT:
|
||||
sh.next();
|
||||
sh.play(true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import model.GameModel;
|
||||
import model.SongHandler;
|
||||
import model.drawObjects.Bullet;
|
||||
import model.drawObjects.Enemy;
|
||||
import model.drawObjects.Player;
|
||||
@@ -34,8 +35,8 @@ public class PlayState extends GameState{
|
||||
public static int currentScore = 0;
|
||||
public static int lifePoints = 100;
|
||||
|
||||
public PlayState(GameStateManager gsm) {
|
||||
super(gsm);
|
||||
public PlayState(GameStateManager gsm, SongHandler sh) {
|
||||
super(gsm, sh);
|
||||
area = new PlayArea((int) borderRect.getX(),1024,1024,100);
|
||||
infoPanel = new InfoPanel(0, 0);
|
||||
enemys = new ArrayList<Enemy>();
|
||||
|
||||
@@ -8,9 +8,10 @@ import java.awt.Font;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import control.joystick.JoystickEvent;
|
||||
import model.SongHandler;
|
||||
import control.GameStateManager;
|
||||
import control.button.ButtonEvent;
|
||||
import control.joystick.JoystickEvent;
|
||||
|
||||
public class TitleState extends GameState {
|
||||
|
||||
@@ -23,8 +24,8 @@ public class TitleState extends GameState {
|
||||
int frame = 0;
|
||||
int maxFrames = 2560;
|
||||
|
||||
public TitleState(GameStateManager gsm) {
|
||||
super(gsm);
|
||||
public TitleState(GameStateManager gsm, SongHandler sh){
|
||||
super(gsm, sh);
|
||||
}
|
||||
@Override
|
||||
public void init() {
|
||||
@@ -63,7 +64,7 @@ public class TitleState extends GameState {
|
||||
Font textFont = new Font("OCR A Extended", Font.BOLD, 15);
|
||||
g2.setFont(textFont);
|
||||
g2.setColor(Color.WHITE);
|
||||
g2.drawString("©2015 Team Hamtaro", - 18*5, 500);
|
||||
g2.drawString("�2015 Team Hamtaro", - 18*5, 500);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -122,7 +122,10 @@ public class MenuButton {
|
||||
public void setSelected(boolean selected) {
|
||||
this.selected = selected;
|
||||
}
|
||||
|
||||
|
||||
public boolean isSelected(){
|
||||
return selected;
|
||||
}
|
||||
public void setX(int x){
|
||||
this.x = x;
|
||||
calculateButton();
|
||||
|
||||
|
After Width: | Height: | Size: 221 KiB |
|
After Width: | Height: | Size: 39 KiB |
|
After Width: | Height: | Size: 191 KiB |
|
After Width: | Height: | Size: 31 KiB |
|
After Width: | Height: | Size: 58 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 296 KiB |
|
After Width: | Height: | Size: 48 KiB |
|
After Width: | Height: | Size: 132 KiB |
|
After Width: | Height: | Size: 41 KiB |
|
After Width: | Height: | Size: 310 KiB |
|
After Width: | Height: | Size: 46 KiB |
|
After Width: | Height: | Size: 253 KiB |
|
After Width: | Height: | Size: 43 KiB |
|
After Width: | Height: | Size: 128 KiB |
|
After Width: | Height: | Size: 36 KiB |
@@ -0,0 +1,72 @@
|
||||
{
|
||||
"meta": {
|
||||
"title": "title of song",
|
||||
"subtitle": "subtitle of song",
|
||||
"author": "author of song",
|
||||
"sample_start": 12.00,
|
||||
"BPM": 0
|
||||
},
|
||||
"file": {
|
||||
"audio": "NAME_OF_SONG.mp3",
|
||||
"background": "background.png",
|
||||
"banner": "banner.png"
|
||||
},
|
||||
"data": [
|
||||
{
|
||||
"difficulty": "easy",
|
||||
"objects": [
|
||||
{
|
||||
"time": 1,
|
||||
"direction": 1,
|
||||
"button": 0,
|
||||
"hold": true,
|
||||
"length": 1000
|
||||
},
|
||||
{
|
||||
"time": 16,
|
||||
"direction": 6,
|
||||
"button": 1
|
||||
}
|
||||
],
|
||||
"button": [
|
||||
{
|
||||
"time": 0,
|
||||
"button": 0,
|
||||
"color": 0
|
||||
},
|
||||
{
|
||||
"time": 20,
|
||||
"button": 6,
|
||||
"color": 1
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"difficulty": "medium",
|
||||
"objects": [
|
||||
{
|
||||
"time": 4,
|
||||
"direction": 3,
|
||||
"button": 3
|
||||
},
|
||||
{
|
||||
"time": 12,
|
||||
"direction": 5,
|
||||
"button": 2
|
||||
}
|
||||
],
|
||||
"button": [
|
||||
{
|
||||
"time": 0,
|
||||
"button": 0,
|
||||
"color": 0
|
||||
},
|
||||
{
|
||||
"time": 20,
|
||||
"button": 6,
|
||||
"color": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
After Width: | Height: | Size: 46 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 247 KiB |
|
After Width: | Height: | Size: 30 KiB |
|
After Width: | Height: | Size: 228 KiB |
|
After Width: | Height: | Size: 45 KiB |
@@ -0,0 +1,72 @@
|
||||
{
|
||||
"meta": {
|
||||
"title": "Song #2",
|
||||
"subtitle": "Some song",
|
||||
"author": "Kenneth",
|
||||
"sample_start": 136.000,
|
||||
"BPM": 44.260
|
||||
},
|
||||
"file": {
|
||||
"audio": "NAME_OF_SONG.mp3",
|
||||
"background": "background.png",
|
||||
"banner": "banner.png"
|
||||
},
|
||||
"data": [
|
||||
{
|
||||
"difficulty": "easy",
|
||||
"objects": [
|
||||
{
|
||||
"time": 1,
|
||||
"direction": 1,
|
||||
"button": 0,
|
||||
"hold": true,
|
||||
"length": 1000
|
||||
},
|
||||
{
|
||||
"time": 16,
|
||||
"direction": 6,
|
||||
"button": 1
|
||||
}
|
||||
],
|
||||
"button": [
|
||||
{
|
||||
"time": 0,
|
||||
"button": 0,
|
||||
"color": 0
|
||||
},
|
||||
{
|
||||
"time": 20,
|
||||
"button": 6,
|
||||
"color": 1
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"difficulty": "medium",
|
||||
"objects": [
|
||||
{
|
||||
"time": 4,
|
||||
"direction": 3,
|
||||
"button": 3
|
||||
},
|
||||
{
|
||||
"time": 12,
|
||||
"direction": 5,
|
||||
"button": 2
|
||||
}
|
||||
],
|
||||
"button": [
|
||||
{
|
||||
"time": 0,
|
||||
"button": 0,
|
||||
"color": 0
|
||||
},
|
||||
{
|
||||
"time": 20,
|
||||
"button": 6,
|
||||
"color": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
After Width: | Height: | Size: 46 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 201 KiB |
|
After Width: | Height: | Size: 42 KiB |
|
After Width: | Height: | Size: 43 KiB |
|
After Width: | Height: | Size: 327 KiB |
|
After Width: | Height: | Size: 177 KiB |
|
After Width: | Height: | Size: 25 KiB |