Feature/json
# Conflicts: # control/GameStateManager.java # image/Images.java # main/Window.java # model/gameState/MenuState.java
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user