Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b4d0706443 | ||
|
|
5c239b17f7 | ||
|
|
78acc6aa5f | ||
|
|
55f9c1a623 | ||
|
|
d322e0ca3f | ||
|
|
04ad4edc2b | ||
|
|
675daadd13 | ||
|
|
137eb5384f | ||
|
|
9d50e6d9f9 | ||
|
|
06a3d74445 | ||
|
|
7ebf6a18e8 | ||
|
|
4250e99682 | ||
|
|
c0123378aa | ||
|
|
cb57ce7fe6 | ||
|
|
b39e62d69b | ||
|
|
86cec99367 | ||
|
|
fc21037006 | ||
|
|
da934f7111 | ||
|
|
f771fb4e2d | ||
|
|
e32165f654 | ||
|
|
67455ccd72 | ||
|
|
6dda54928c | ||
|
|
56710c1b46 | ||
|
|
b81c5c73f9 | ||
|
|
3f08675d9e | ||
|
|
f3f1a11a75 | ||
|
|
1edab2daac | ||
|
|
e739255d23 | ||
|
|
201fa6d0b1 | ||
|
|
cc69ad63c3 | ||
|
|
749c80c748 | ||
|
|
bac38b5aa5 | ||
|
|
effbcc3670 | ||
|
|
8c858e93e1 | ||
|
|
a6f7177084 | ||
|
|
2c3cdd4d15 | ||
|
|
764fc33836 | ||
|
|
713cfaf836 | ||
|
|
9380506d06 | ||
|
|
61fdeb27c5 | ||
|
|
458ccb99d0 | ||
|
|
7a6d2e9d5d | ||
|
|
74b6cafc40 | ||
|
|
5679b20616 | ||
|
|
172454e13f | ||
|
|
5480476837 | ||
|
|
e349ec9fa6 | ||
|
|
4cc41ea2c8 | ||
|
|
06cc34a8fe | ||
|
|
b4cd80807f | ||
|
|
18d6a9dcbd | ||
|
|
c111a52f52 | ||
|
|
e64fc291fe | ||
|
|
803c0e1707 | ||
|
|
fc86051f04 | ||
|
|
2fa9c3afe8 | ||
|
|
54d9a91f6a | ||
|
|
bedd6899db | ||
|
|
0516027069 | ||
|
|
be274685b5 | ||
|
|
f229153346 | ||
|
|
4a3208c85f | ||
|
|
b4e7a7c213 | ||
|
|
951ff4367e | ||
|
|
c25ae6757d |
@@ -35,15 +35,17 @@ public class AudioPlayer{
|
|||||||
} catch (JavaLayerException | FileNotFoundException e1) {
|
} catch (JavaLayerException | FileNotFoundException e1) {
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
Thread thread = new Thread(() -> {
|
Thread thread = new Thread(new Runnable() {
|
||||||
while (clip != null){
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if(clip != null){
|
||||||
try {
|
try {
|
||||||
clip.play();
|
clip.play();
|
||||||
} catch (JavaLayerException e) {
|
} catch (JavaLayerException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}});
|
||||||
thread.start();
|
thread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,13 +54,14 @@ public class AudioPlayer{
|
|||||||
{
|
{
|
||||||
clip.close();
|
clip.close();
|
||||||
clip = null;
|
clip = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if(fis != null)
|
if(fis != null)
|
||||||
fis.close();
|
fis.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
if(thread != null && thread.isAlive())
|
||||||
|
thread.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -165,4 +165,15 @@ public class Song implements Comparable<Song>{
|
|||||||
}
|
}
|
||||||
return timesPlayed;
|
return timesPlayed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getHighestScore()
|
||||||
|
{
|
||||||
|
int highest = 0;
|
||||||
|
for(SongInstance s : songs)
|
||||||
|
{
|
||||||
|
if(s.getHighestScore() > highest)
|
||||||
|
highest = s.getHighestScore();
|
||||||
|
}
|
||||||
|
return highest;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ public class SongInstance {
|
|||||||
|
|
||||||
private String difficulty;
|
private String difficulty;
|
||||||
private int timesPlayed;
|
private int timesPlayed;
|
||||||
|
private int highestScore;
|
||||||
|
|
||||||
private List<ObjectInstance> objects;
|
private List<ObjectInstance> objects;
|
||||||
private List<ButtonInstance> buttons;
|
private List<ButtonInstance> buttons;
|
||||||
@@ -15,6 +16,7 @@ public class SongInstance {
|
|||||||
{
|
{
|
||||||
this.difficulty = difficulty;
|
this.difficulty = difficulty;
|
||||||
this.timesPlayed = 0;
|
this.timesPlayed = 0;
|
||||||
|
this.highestScore = 0;
|
||||||
|
|
||||||
objects = new ArrayList<ObjectInstance>();
|
objects = new ArrayList<ObjectInstance>();
|
||||||
buttons = new ArrayList<ButtonInstance>();
|
buttons = new ArrayList<ButtonInstance>();
|
||||||
@@ -65,6 +67,8 @@ public class SongInstance {
|
|||||||
|
|
||||||
public long getEndTime()
|
public long getEndTime()
|
||||||
{
|
{
|
||||||
|
if(objects.size() == 0)
|
||||||
|
return 0;
|
||||||
return objects.get(objects.size()-1).getTime();
|
return objects.get(objects.size()-1).getTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,6 +98,14 @@ public class SongInstance {
|
|||||||
this.timesPlayed = timesPlayed;
|
this.timesPlayed = timesPlayed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getHighestScore() {
|
||||||
|
return highestScore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHighestScore(int highestScore) {
|
||||||
|
this.highestScore = highestScore;
|
||||||
|
}
|
||||||
|
|
||||||
public void played()
|
public void played()
|
||||||
{
|
{
|
||||||
timesPlayed++;
|
timesPlayed++;
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package audio.sorting;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
|
import audio.Song;
|
||||||
|
|
||||||
|
public class SortAUTHOR implements Comparator<Song> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compare(Song s1, Song s2) {
|
||||||
|
return s1.getAuthor().compareTo(s2.getAuthor());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package audio.sorting;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
|
import audio.Song;
|
||||||
|
|
||||||
|
public class SortSCORE implements Comparator<Song> {
|
||||||
|
|
||||||
|
public int compare(Song s1, Song s2) {
|
||||||
|
if(s1.getHighestScore() < s2.getHighestScore())
|
||||||
|
return 1;
|
||||||
|
else if(s1.getHighestScore() > s2.getHighestScore())
|
||||||
|
return -1;
|
||||||
|
else
|
||||||
|
return s1.getTitle().compareTo(s2.getTitle());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -15,18 +15,19 @@ import control.joystick.JoystickListener;
|
|||||||
public class GameControl implements JoystickListener, ButtonListener, ActionListener {
|
public class GameControl implements JoystickListener, ButtonListener, ActionListener {
|
||||||
|
|
||||||
private long lastTime = System.currentTimeMillis();
|
private long lastTime = System.currentTimeMillis();
|
||||||
private GameModel model;
|
GameModel model;
|
||||||
private GameView view;
|
GameView view;
|
||||||
private GameStateManager gsm;
|
GameStateManager gsm;
|
||||||
private Timer update;
|
Timer update;
|
||||||
|
|
||||||
public GameControl(final GameModel model, final GameView view,GameStateManager gsm) {
|
public GameControl(final GameModel model, final GameView view,GameStateManager gsm)
|
||||||
|
{
|
||||||
this.model = model;
|
this.model = model;
|
||||||
this.view = view;
|
this.view = view;
|
||||||
this.gsm = gsm;
|
this.gsm = gsm;
|
||||||
|
|
||||||
view.setIgnoreRepaint(true);
|
view.setIgnoreRepaint(true);
|
||||||
(update = new Timer(1000/60,this)).start();
|
update = new Timer(1000/60,this);
|
||||||
|
update.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -4,8 +4,13 @@ import java.awt.Color;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import model.SongHandler;
|
import model.gameState.EndState;
|
||||||
import model.gameState.*;
|
import model.gameState.GameState;
|
||||||
|
import model.gameState.HelpState;
|
||||||
|
import model.gameState.MenuState;
|
||||||
|
import model.gameState.PlayState;
|
||||||
|
import model.gameState.PreGameState;
|
||||||
|
import model.gameState.TitleState;
|
||||||
import control.button.Button;
|
import control.button.Button;
|
||||||
import control.button.ButtonEvent;
|
import control.button.ButtonEvent;
|
||||||
import control.button.ButtonHandler;
|
import control.button.ButtonHandler;
|
||||||
@@ -16,45 +21,46 @@ import data.io.SQLConnector;
|
|||||||
public class GameStateManager {
|
public class GameStateManager {
|
||||||
|
|
||||||
private List<GameState> gamestates;
|
private List<GameState> gamestates;
|
||||||
|
|
||||||
public GameState currentState;
|
public GameState currentState;
|
||||||
private SongHandler sh;
|
|
||||||
|
|
||||||
private int index = 0;
|
private int index = 0;
|
||||||
public int fps;
|
public int fps;
|
||||||
private float timeOfNoAction = 0,
|
private float timeOfNoAction = 0,maxTimeToHaveNoAction = 45000;
|
||||||
maxTimeToHaveNoAction = 45000;
|
|
||||||
|
|
||||||
public enum State {
|
public enum State {
|
||||||
TITLE_STATE,
|
TITLE_STATE,
|
||||||
MENU_STATE,
|
MENU_STATE,
|
||||||
HELP_STATE,
|
HELP_STATE,
|
||||||
PLAY_STATE,
|
PLAY_STATE,
|
||||||
GAMEOVER_STATE,
|
END_STATE,
|
||||||
PRE_GAME_STATE
|
PRE_GAME_STATE
|
||||||
}
|
}
|
||||||
|
|
||||||
public GameStateManager(SongHandler sh, SQLConnector sql){
|
public GameStateManager(SongHandler sh, SQLConnector sql){
|
||||||
this.sh = sh;
|
gamestates = new ArrayList<GameState>();
|
||||||
gamestates = new ArrayList<>();
|
|
||||||
gamestates.add(new TitleState(this, sh, sql));
|
gamestates.add(new TitleState(this, sh, sql));
|
||||||
gamestates.add(new MenuState(this, sh, sql));
|
gamestates.add(new MenuState(this, sh, sql));
|
||||||
gamestates.add(new HelpState(this, sh, sql));
|
gamestates.add(new HelpState(this, sh, sql));
|
||||||
gamestates.add(new PlayState(this, sh, sql));
|
gamestates.add(new PlayState(this, sh, sql));
|
||||||
gamestates.add(new GameOverState(this, sh, sql));
|
gamestates.add(new EndState(this, sh, sql));
|
||||||
gamestates.add(new PreGameState(this,sh, sql));
|
gamestates.add(new PreGameState(this,sh, sql));
|
||||||
setState(State.TITLE_STATE);
|
setState(State.TITLE_STATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setState(State st)
|
public void setState(State st) {
|
||||||
{
|
if (st.ordinal() > 0 && ( !(currentState instanceof TitleState) || !(currentState instanceof EndState) ))
|
||||||
if (currentState != null)
|
|
||||||
currentState.stopAudio();
|
currentState.stopAudio();
|
||||||
|
|
||||||
currentState = gamestates.get(st.ordinal());
|
currentState = gamestates.get(st.ordinal());
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void next() {
|
||||||
|
index++;
|
||||||
|
index %= gamestates.size();
|
||||||
|
currentState = gamestates.get(index);
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
public void update(float factor){
|
public void update(float factor){
|
||||||
timeOfNoAction += factor;
|
timeOfNoAction += factor;
|
||||||
if(timeOfNoAction > maxTimeToHaveNoAction){
|
if(timeOfNoAction > maxTimeToHaveNoAction){
|
||||||
@@ -78,11 +84,13 @@ public class GameStateManager {
|
|||||||
public void buttonPressed(ButtonEvent e) {
|
public void buttonPressed(ButtonEvent e) {
|
||||||
timeOfNoAction = 0;
|
timeOfNoAction = 0;
|
||||||
currentState.buttonPressed(e);
|
currentState.buttonPressed(e);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void buttonReleased(ButtonEvent e) {
|
public void buttonReleased(ButtonEvent e) {
|
||||||
timeOfNoAction = 0;
|
timeOfNoAction = 0;
|
||||||
currentState.buttonReleased(e);
|
currentState.buttonReleased(e);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onJoystickMoved(JoystickEvent e) {
|
public void onJoystickMoved(JoystickEvent e) {
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ public class NetworkHandler implements Runnable{
|
|||||||
|
|
||||||
private String host;
|
private String host;
|
||||||
private int port;
|
private int port;
|
||||||
|
private long fistpressed;
|
||||||
|
|
||||||
private boolean running;
|
private boolean running;
|
||||||
private Thread t;
|
private Thread t;
|
||||||
@@ -62,7 +63,17 @@ public class NetworkHandler implements Runnable{
|
|||||||
send(cmd);
|
send(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void send(String str) { }
|
private void send(String str)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
DatagramPacket sendPacket = new DatagramPacket(str.getBytes(), str.length(), InetAddress.getByName(host), 1113);
|
||||||
|
udp.send(sendPacket);
|
||||||
|
} catch (UnknownHostException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void close()
|
public void close()
|
||||||
{
|
{
|
||||||
@@ -130,11 +141,19 @@ public class NetworkHandler implements Runnable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
else if(control[7] == 0){
|
else if(control[7] == 0){
|
||||||
|
if(JoystickHandler.j.getPos() != Position.UP || JoystickHandler.REPEAT)
|
||||||
|
{
|
||||||
if(JoystickHandler.j.getPos() != Position.UP)
|
if(JoystickHandler.j.getPos() != Position.UP)
|
||||||
{
|
{
|
||||||
|
fistpressed = System.currentTimeMillis();
|
||||||
JoystickHandler.j.setPosition(Position.UP);
|
JoystickHandler.j.setPosition(Position.UP);
|
||||||
jth.onJoystickMoved(JoystickHandler.j);
|
jth.onJoystickMoved(JoystickHandler.j);
|
||||||
}
|
}
|
||||||
|
if((fistpressed + 500) < System.currentTimeMillis()){
|
||||||
|
JoystickHandler.j.setPosition(Position.UP);
|
||||||
|
jth.onJoystickMoved(JoystickHandler.j);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if(control[8] == 0){
|
else if(control[8] == 0){
|
||||||
if(JoystickHandler.j.getPos() != Position.LEFT)
|
if(JoystickHandler.j.getPos() != Position.LEFT)
|
||||||
@@ -151,13 +170,21 @@ public class NetworkHandler implements Runnable{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(control[10] == 0){
|
else if(control[10] == 0){
|
||||||
if(JoystickHandler.j.getPos() != Position.DOWN)
|
if(JoystickHandler.j.getPos() != Position.DOWN || JoystickHandler.REPEAT)
|
||||||
{
|
{
|
||||||
|
if(JoystickHandler.j.getPos() != Position.DOWN){
|
||||||
|
fistpressed = System.currentTimeMillis();
|
||||||
JoystickHandler.j.setPosition(Position.DOWN);
|
JoystickHandler.j.setPosition(Position.DOWN);
|
||||||
jth.onJoystickMoved(JoystickHandler.j);
|
jth.onJoystickMoved(JoystickHandler.j);
|
||||||
}
|
}
|
||||||
|
if((fistpressed + 500) < System.currentTimeMillis()){
|
||||||
|
JoystickHandler.j.setPosition(Position.DOWN);
|
||||||
|
jth.onJoystickMoved(JoystickHandler.j);
|
||||||
|
}
|
||||||
|
}
|
||||||
}else {
|
}else {
|
||||||
if(JoystickHandler.j.getPos() != Position.CENTER){
|
if(JoystickHandler.j.getPos() != Position.CENTER){
|
||||||
|
fistpressed = 0;
|
||||||
JoystickHandler.j.setPosition(Position.CENTER);
|
JoystickHandler.j.setPosition(Position.CENTER);
|
||||||
jth.onJoystickMoved(JoystickHandler.j);
|
jth.onJoystickMoved(JoystickHandler.j);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package model;
|
package control;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -11,7 +11,6 @@ import audio.AudioPlayer;
|
|||||||
import audio.Song;
|
import audio.Song;
|
||||||
import audio.SongInstance;
|
import audio.SongInstance;
|
||||||
import audio.io.DirScanner;
|
import audio.io.DirScanner;
|
||||||
import audio.sorting.SortALPHA;
|
|
||||||
import audio.sorting.SortPLAYED;
|
import audio.sorting.SortPLAYED;
|
||||||
import data.io.SQLConnector;
|
import data.io.SQLConnector;
|
||||||
|
|
||||||
@@ -22,7 +21,7 @@ public class SongHandler {
|
|||||||
private Song currentSong;
|
private Song currentSong;
|
||||||
private SongInstance currentSongInstance;
|
private SongInstance currentSongInstance;
|
||||||
private int currentIndex;
|
private int currentIndex;
|
||||||
private SQLConnector sql;
|
SQLConnector sql;
|
||||||
|
|
||||||
private File dir;
|
private File dir;
|
||||||
|
|
||||||
@@ -33,13 +32,14 @@ public class SongHandler {
|
|||||||
this.sql = sql;
|
this.sql = sql;
|
||||||
|
|
||||||
songs = new ArrayList<Song>();
|
songs = new ArrayList<Song>();
|
||||||
|
|
||||||
currentSong = null;
|
currentSong = null;
|
||||||
currentSongInstance = null;
|
currentSongInstance = null;
|
||||||
currentIndex = 0;
|
currentIndex = 0;
|
||||||
|
|
||||||
p = new AudioPlayer();
|
p = new AudioPlayer();
|
||||||
|
|
||||||
if(Window.ON_RASP)
|
if(Window.ON_ARCADE)
|
||||||
dir = new File(System.getProperty( "user.home" ) + "/ColorStrike/Songs/");
|
dir = new File(System.getProperty( "user.home" ) + "/ColorStrike/Songs/");
|
||||||
else
|
else
|
||||||
dir = new File(System.getProperty( "user.home" ) + "/Documents/songs/");
|
dir = new File(System.getProperty( "user.home" ) + "/Documents/songs/");
|
||||||
@@ -72,7 +72,9 @@ public class SongHandler {
|
|||||||
{
|
{
|
||||||
currentSongInstance = si;
|
currentSongInstance = si;
|
||||||
}
|
}
|
||||||
|
public boolean isPlaying(){
|
||||||
|
return getProgress() > 0 ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
private void updatePlayer()
|
private void updatePlayer()
|
||||||
{
|
{
|
||||||
@@ -7,14 +7,14 @@ import control.NetworkHandler;
|
|||||||
|
|
||||||
public class Button {
|
public class Button {
|
||||||
|
|
||||||
private Color color;
|
Color color;
|
||||||
private int ledID,
|
int ledID;
|
||||||
buttonID;
|
int buttonID;
|
||||||
|
NetworkHandler ntw;
|
||||||
public int pressed;
|
public int pressed;
|
||||||
|
|
||||||
private NetworkHandler ntw;
|
public Button(int buttonID, int ledID, NetworkHandler ntw)
|
||||||
|
{
|
||||||
public Button(int buttonID, int ledID, NetworkHandler ntw) {
|
|
||||||
color = new Color(255,255,255);
|
color = new Color(255,255,255);
|
||||||
this.ledID = ledID;
|
this.ledID = ledID;
|
||||||
this.buttonID = buttonID;
|
this.buttonID = buttonID;
|
||||||
@@ -23,14 +23,17 @@ public class Button {
|
|||||||
setLed();
|
setLed();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setLed() {
|
private void setLed()
|
||||||
if(Window.ON_RASP) {
|
{
|
||||||
|
if(Window.ON_ARCADE)
|
||||||
|
{
|
||||||
ntw.setLed(ledID, color.getGreen(), color.getRed(), color.getBlue());
|
ntw.setLed(ledID, color.getGreen(), color.getRed(), color.getBlue());
|
||||||
ntw.show();
|
ntw.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setColor(Color newColor) {
|
public void setColor(Color newColor)
|
||||||
|
{
|
||||||
color = newColor;
|
color = newColor;
|
||||||
setLed();
|
setLed();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,65 +7,30 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import main.Window;
|
import main.Window;
|
||||||
|
import model.GameModel;
|
||||||
import com.pi4j.io.gpio.GpioController;
|
|
||||||
import com.pi4j.io.gpio.GpioFactory;
|
|
||||||
import com.pi4j.io.gpio.GpioPinDigitalInput;
|
|
||||||
import com.pi4j.io.gpio.PinState;
|
|
||||||
import com.pi4j.io.gpio.RaspiPin;
|
|
||||||
import com.pi4j.io.gpio.event.GpioPinDigitalStateChangeEvent;
|
|
||||||
import com.pi4j.io.gpio.event.GpioPinListenerDigital;
|
|
||||||
|
|
||||||
import control.NetworkHandler;
|
import control.NetworkHandler;
|
||||||
|
|
||||||
public class ButtonHandler implements KeyListener{
|
public class ButtonHandler implements KeyListener{
|
||||||
|
|
||||||
private List<ButtonListener> listeners;
|
List<ButtonListener> listeners;
|
||||||
public static List<Button> buttons;
|
static List<Button> buttons;
|
||||||
private NetworkHandler ntw;
|
NetworkHandler ntw;
|
||||||
|
|
||||||
public ButtonHandler()
|
public ButtonHandler()
|
||||||
{
|
{
|
||||||
this.ntw = null;
|
this.ntw = null;
|
||||||
|
|
||||||
listeners = new ArrayList<ButtonListener>();
|
listeners = new ArrayList<ButtonListener>();
|
||||||
buttons = new ArrayList<Button>();
|
buttons = new ArrayList<Button>();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addGpioListeners(){
|
|
||||||
ArrayList<GpioPinDigitalInput> inputpins = new ArrayList<GpioPinDigitalInput>();
|
|
||||||
final GpioController gpio = GpioFactory.getInstance();
|
|
||||||
|
|
||||||
inputpins.add(gpio.provisionDigitalInputPin(RaspiPin.GPIO_02, "1")); //button 1 to 6 + start button
|
|
||||||
inputpins.add(gpio.provisionDigitalInputPin(RaspiPin.GPIO_03, "2"));
|
|
||||||
inputpins.add(gpio.provisionDigitalInputPin(RaspiPin.GPIO_13, "3"));
|
|
||||||
inputpins.add(gpio.provisionDigitalInputPin(RaspiPin.GPIO_14, "4"));
|
|
||||||
inputpins.add(gpio.provisionDigitalInputPin(RaspiPin.GPIO_00, "5"));
|
|
||||||
inputpins.add(gpio.provisionDigitalInputPin(RaspiPin.GPIO_12, "6"));
|
|
||||||
inputpins.add(gpio.provisionDigitalInputPin(RaspiPin.GPIO_06, "0"));
|
|
||||||
|
|
||||||
for(GpioPinDigitalInput p:inputpins){
|
|
||||||
p.addListener(new GpioPinListenerDigital() {
|
|
||||||
@Override
|
|
||||||
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent e) {
|
|
||||||
if(e.getState() == PinState.HIGH){
|
|
||||||
buttonRelease(buttons.get(Integer.parseInt(e.getPin().getName())));
|
|
||||||
System.out.println(e.getPin().getName() + " Released");
|
|
||||||
}else{
|
|
||||||
buttonPress(buttons.get(Integer.parseInt(e.getPin().getName())));
|
|
||||||
System.out.println(e.getPin().getName() + " Pressed");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addButtonListener(ButtonListener toAdd) {
|
public void addButtonListener(ButtonListener toAdd) {
|
||||||
listeners.add(toAdd);
|
listeners.add(toAdd);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void buttonPress(Button b) {
|
public void buttonPress(Button b) {
|
||||||
if(Window.ON_RASP)
|
if(Window.ON_ARCADE)
|
||||||
{
|
{
|
||||||
Color c = b.getColor().brighter().brighter();
|
Color c = b.getColor().brighter().brighter();
|
||||||
ntw.setLed(b.getLedID(), c.getGreen(), c.getRed(), c.getBlue());
|
ntw.setLed(b.getLedID(), c.getGreen(), c.getRed(), c.getBlue());
|
||||||
@@ -77,12 +42,12 @@ public class ButtonHandler implements KeyListener{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void buttonRelease(Button b) {
|
public void buttonRelease(Button b) {
|
||||||
if(Window.ON_RASP) {
|
if(Window.ON_ARCADE)
|
||||||
|
{
|
||||||
ntw.setLed(b.getLedID(), b.getColor().getGreen(), b.getColor().getRed(), b.getColor().getBlue());
|
ntw.setLed(b.getLedID(), b.getColor().getGreen(), b.getColor().getRed(), b.getColor().getBlue());
|
||||||
ntw.show();
|
ntw.show();
|
||||||
}
|
}
|
||||||
ButtonEvent e = new ButtonEvent(b, System.currentTimeMillis());
|
ButtonEvent e = new ButtonEvent(b, System.currentTimeMillis());
|
||||||
|
|
||||||
for (ButtonListener bt : listeners)
|
for (ButtonListener bt : listeners)
|
||||||
bt.buttonReleased(e);
|
bt.buttonReleased(e);
|
||||||
}
|
}
|
||||||
@@ -114,7 +79,7 @@ public class ButtonHandler implements KeyListener{
|
|||||||
buttonPress(buttons.get(6));
|
buttonPress(buttons.get(6));
|
||||||
break;
|
break;
|
||||||
case KeyEvent.VK_ESCAPE:
|
case KeyEvent.VK_ESCAPE:
|
||||||
if(!Window.ON_RASP)
|
if(!Window.ON_ARCADE)
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -156,9 +121,12 @@ public class ButtonHandler implements KeyListener{
|
|||||||
public static Button getButton(int id)
|
public static Button getButton(int id)
|
||||||
{
|
{
|
||||||
for(Button b : buttons)
|
for(Button b : buttons)
|
||||||
|
{
|
||||||
if(b.getButtonID() == id)
|
if(b.getButtonID() == id)
|
||||||
|
{
|
||||||
return b;
|
return b;
|
||||||
|
}
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,8 +137,12 @@ public class ButtonHandler implements KeyListener{
|
|||||||
buttons.add(new Button(1, 2, ntw));
|
buttons.add(new Button(1, 2, ntw));
|
||||||
buttons.add(new Button(2, 1, ntw));
|
buttons.add(new Button(2, 1, ntw));
|
||||||
buttons.add(new Button(3, 0, ntw));
|
buttons.add(new Button(3, 0, ntw));
|
||||||
buttons.add(new Button(4, 3, ntw));
|
buttons.add(new Button(4, -1, ntw));
|
||||||
buttons.add(new Button(5, 4, ntw));
|
buttons.add(new Button(5, 3, ntw));
|
||||||
buttons.add(new Button(6, 5, ntw));
|
buttons.add(new Button(6, 4, ntw));
|
||||||
|
|
||||||
|
for (int i = 1; i < buttons.size(); i++) {
|
||||||
|
buttons.get(i).setColor(GameModel.colors[i - 1]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package control.button;
|
package control.button;
|
||||||
|
|
||||||
public interface ButtonListener {
|
public interface ButtonListener {
|
||||||
void buttonPressed(ButtonEvent e);
|
public void buttonPressed(ButtonEvent e);
|
||||||
void buttonReleased(ButtonEvent e);
|
public void buttonReleased(ButtonEvent e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,15 +8,15 @@ import java.sql.Statement;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.sun.crypto.provider.RSACipher;
|
|
||||||
|
|
||||||
import model.objects.highscore.Highscore;
|
import model.objects.highscore.Highscore;
|
||||||
import audio.Song;
|
import audio.Song;
|
||||||
import audio.SongInstance;
|
import audio.SongInstance;
|
||||||
|
|
||||||
public class SQLConnector
|
public class SQLConnector
|
||||||
{
|
{
|
||||||
|
|
||||||
private Connection myConn = null;
|
private Connection myConn = null;
|
||||||
|
|
||||||
public SQLConnector()
|
public SQLConnector()
|
||||||
{
|
{
|
||||||
this("178.62.254.153", "3306","colorstrike","csadmin","aardbei123");
|
this("178.62.254.153", "3306","colorstrike","csadmin","aardbei123");
|
||||||
@@ -25,7 +25,8 @@ public class SQLConnector
|
|||||||
//Start connection with Database
|
//Start connection with Database
|
||||||
public SQLConnector(String host, String port, String dbName, String userName, String password)
|
public SQLConnector(String host, String port, String dbName, String userName, String password)
|
||||||
{
|
{
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
String url = "jdbc:mysql://" + host + ":" + port + "/"+ dbName + "?user="
|
String url = "jdbc:mysql://" + host + ":" + port + "/"+ dbName + "?user="
|
||||||
+ userName
|
+ userName
|
||||||
+ "&password="
|
+ "&password="
|
||||||
@@ -33,7 +34,8 @@ public class SQLConnector
|
|||||||
Class.forName("com.mysql.jdbc.Driver").newInstance ();
|
Class.forName("com.mysql.jdbc.Driver").newInstance ();
|
||||||
myConn = DriverManager.getConnection(url);
|
myConn = DriverManager.getConnection(url);
|
||||||
}
|
}
|
||||||
catch( SQLException ex) {
|
catch( SQLException ex)
|
||||||
|
{
|
||||||
System.out.println("SQLException: " + ex.getMessage());
|
System.out.println("SQLException: " + ex.getMessage());
|
||||||
System.out.println("SQLState: " + ex.getSQLState());
|
System.out.println("SQLState: " + ex.getSQLState());
|
||||||
System.out.println("VendorError: " + ex.getErrorCode());
|
System.out.println("VendorError: " + ex.getErrorCode());
|
||||||
@@ -44,14 +46,38 @@ public class SQLConnector
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Highscore getHighscore(Song s, SongInstance si)
|
||||||
|
{
|
||||||
|
String query = "SELECT * FROM highscore WHERE songinstance = (SELECT id FROM songinstance WHERE difficulty='" + si.getDifficulty() + "' AND song=(SELECT id FROM song WHERE folder='" + s.getFolder() + "')) ORDER BY score DESC LIMIT 1";
|
||||||
|
//System.out.println(query);
|
||||||
|
Statement st = executeResultQuery(query);
|
||||||
|
ResultSet result = null;
|
||||||
|
try {
|
||||||
|
result = st.getResultSet();
|
||||||
|
} catch (SQLException e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
Highscore hsc = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
if(result.next() && result != null)
|
||||||
|
hsc = new Highscore(si, result.getString("username"), result.getInt("score"), result.getDate("date").getTime());
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return hsc;
|
||||||
|
}
|
||||||
|
|
||||||
public List<Highscore> getHighscores(Song s, SongInstance si)
|
public List<Highscore> getHighscores(Song s, SongInstance si)
|
||||||
{
|
{
|
||||||
String query = "SELECT * FROM highscore WHERE songinstance = (SELECT id FROM songinstance WHERE difficulty='" + si.getDifficulty() + "' AND song=(SELECT id FROM song WHERE folder='" + s.getFolder() + "')) ORDER BY score DESC";
|
String query = "SELECT * FROM highscore WHERE songinstance = (SELECT id FROM songinstance WHERE difficulty='" + si.getDifficulty() + "' AND song=(SELECT id FROM song WHERE folder='" + s.getFolder() + "')) ORDER BY score DESC";
|
||||||
//System.out.println(query);
|
//System.out.println(query);
|
||||||
Statement st = executeResultQuery(query);
|
Statement st = executeResultQuery(query);
|
||||||
ResultSet result = null;
|
ResultSet result = null;
|
||||||
List<Highscore> hsc = new ArrayList<>();
|
List<Highscore> hsc = new ArrayList<Highscore>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = st.getResultSet();
|
result = st.getResultSet();
|
||||||
} catch (SQLException e1) {
|
} catch (SQLException e1) {
|
||||||
@@ -59,7 +85,9 @@ public class SQLConnector
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
while(result.next())
|
while(result.next())
|
||||||
|
{
|
||||||
hsc.add(new Highscore(si, result.getString("username"), result.getInt("score"), result.getDate("date").getTime()));
|
hsc.add(new Highscore(si, result.getString("username"), result.getInt("score"), result.getDate("date").getTime()));
|
||||||
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -71,7 +99,7 @@ public class SQLConnector
|
|||||||
{
|
{
|
||||||
Statement st = executeResultQuery("SELECT * FROM highscore WHERE date=CURDATE() AND songinstance = (SELECT id FROM songinstance WHERE difficulty='" + si.getDifficulty() + "' AND song=(SELECT id FROM song WHERE folder='" + s.getFolder() + "')) ORDER BY score DESC");
|
Statement st = executeResultQuery("SELECT * FROM highscore WHERE date=CURDATE() AND songinstance = (SELECT id FROM songinstance WHERE difficulty='" + si.getDifficulty() + "' AND song=(SELECT id FROM song WHERE folder='" + s.getFolder() + "')) ORDER BY score DESC");
|
||||||
ResultSet result = null;
|
ResultSet result = null;
|
||||||
List<Highscore> hsc = new ArrayList<>();
|
List<Highscore> hsc = new ArrayList<Highscore>();
|
||||||
try {
|
try {
|
||||||
result = st.getResultSet();
|
result = st.getResultSet();
|
||||||
} catch (SQLException e1) {
|
} catch (SQLException e1) {
|
||||||
@@ -90,7 +118,8 @@ public class SQLConnector
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int addHighscore(Song s, SongInstance si, String name, int currentScore) {
|
public int addHighscore(Song s, SongInstance si, String name, int currentScore) {
|
||||||
if(name.length() <= 5 && currentScore <= Integer.MAX_VALUE) {
|
if(name.length() <= 5 && currentScore <= Integer.MAX_VALUE)
|
||||||
|
{
|
||||||
String query = "INSERT INTO highscore (username, score, date, songinstance) VALUES ('" + name.trim() + "', " + currentScore + ", CURDATE(), (SELECT id FROM songinstance WHERE difficulty='" + si.getDifficulty() + "' AND song=(SELECT id FROM song WHERE folder='" + s.getFolder() + "')))";
|
String query = "INSERT INTO highscore (username, score, date, songinstance) VALUES ('" + name.trim() + "', " + currentScore + ", CURDATE(), (SELECT id FROM songinstance WHERE difficulty='" + si.getDifficulty() + "' AND song=(SELECT id FROM song WHERE folder='" + s.getFolder() + "')))";
|
||||||
//System.out.println(query);
|
//System.out.println(query);
|
||||||
return executeInsertQuery(query);
|
return executeInsertQuery(query);
|
||||||
@@ -103,6 +132,7 @@ public class SQLConnector
|
|||||||
String query = "INSERT INTO playdata (enemies_missed, enemies_hit, buttons_pressed, joystick_moved, start_time, play_time, songinstance) VALUES (" + enemies_missed + ", " + enemies_hit + ", " + buttons_pressed + ", " + joystick_moved + ", NOW(), " + time + ", (SELECT id FROM songinstance WHERE difficulty='" + si.getDifficulty() + "' AND song=(SELECT id FROM song WHERE folder='" + s.getFolder() + "')))";
|
String query = "INSERT INTO playdata (enemies_missed, enemies_hit, buttons_pressed, joystick_moved, start_time, play_time, songinstance) VALUES (" + enemies_missed + ", " + enemies_hit + ", " + buttons_pressed + ", " + joystick_moved + ", NOW(), " + time + ", (SELECT id FROM songinstance WHERE difficulty='" + si.getDifficulty() + "' AND song=(SELECT id FROM song WHERE folder='" + s.getFolder() + "')))";
|
||||||
//System.out.println(query);
|
//System.out.println(query);
|
||||||
executeInsertQuery(query);
|
executeInsertQuery(query);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(List<Song> songs)
|
public void update(List<Song> songs)
|
||||||
@@ -124,18 +154,25 @@ public class SQLConnector
|
|||||||
rs.close();
|
rs.close();
|
||||||
st.close();
|
st.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
System.out.println("Empty return set");
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(id != -1) {
|
if(id != -1)
|
||||||
for(SongInstance si : s.getSongs()) {
|
{
|
||||||
|
for(SongInstance si : s.getSongs())
|
||||||
|
{
|
||||||
Statement st2 = executeResultQuery("SELECT id FROM songinstance WHERE song=" + id + " AND difficulty='" + si.getDifficulty() + "'");
|
Statement st2 = executeResultQuery("SELECT id FROM songinstance WHERE song=" + id + " AND difficulty='" + si.getDifficulty() + "'");
|
||||||
|
|
||||||
ResultSet rs2 = null;
|
ResultSet rs2 = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
rs2 = st2.getResultSet();
|
rs2 = st2.getResultSet();
|
||||||
if(!rs2.first()) {
|
if(rs2.first())
|
||||||
|
{
|
||||||
|
//System.err.println("SongInstance Already Exists ");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
executeInsertQuery("INSERT INTO songinstance (song, enemies, difficulty) VALUES (" + id + ", " + si.getObjects().size() + ", '" + si.getDifficulty() + "');");
|
executeInsertQuery("INSERT INTO songinstance (song, enemies, difficulty) VALUES (" + id + ", " + si.getObjects().size() + ", '" + si.getDifficulty() + "');");
|
||||||
//System.out.println("Songinstance Added");
|
//System.out.println("Songinstance Added");
|
||||||
}
|
}
|
||||||
@@ -155,7 +192,23 @@ public class SQLConnector
|
|||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Statement st4 = executeResultQuery("SELECT MAX(`score`) as score FROM `highscore` WHERE `songinstance`=(SELECT id FROM songinstance WHERE song=" + id + " AND difficulty='" + si.getDifficulty() + "')");
|
||||||
|
try {
|
||||||
|
ResultSet rs4 = st4.getResultSet();
|
||||||
|
if(rs4.next())
|
||||||
|
{
|
||||||
|
int i = rs4.getInt(1);
|
||||||
|
si.setHighestScore(i);
|
||||||
}
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//System.err.println("Insert Failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -167,11 +220,11 @@ public class SQLConnector
|
|||||||
Statement s = myConn.createStatement();
|
Statement s = myConn.createStatement();
|
||||||
s.executeUpdate(query, Statement.RETURN_GENERATED_KEYS);
|
s.executeUpdate(query, Statement.RETURN_GENERATED_KEYS);
|
||||||
ResultSet rs = s.getGeneratedKeys();
|
ResultSet rs = s.getGeneratedKeys();
|
||||||
|
|
||||||
int id = 0;
|
int id = 0;
|
||||||
if(rs.next())
|
if(rs.next())
|
||||||
|
{
|
||||||
id = rs.getInt(1);
|
id = rs.getInt(1);
|
||||||
|
}
|
||||||
s.close();
|
s.close();
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@@ -192,9 +245,11 @@ public class SQLConnector
|
|||||||
private Statement executeResultQuery(String query)
|
private Statement executeResultQuery(String query)
|
||||||
{
|
{
|
||||||
Statement s = null;
|
Statement s = null;
|
||||||
|
|
||||||
try{
|
try{
|
||||||
s = myConn.createStatement();
|
s = myConn.createStatement();
|
||||||
s.executeQuery(query);
|
s.executeQuery(query);
|
||||||
|
|
||||||
}
|
}
|
||||||
catch( SQLException ex)
|
catch( SQLException ex)
|
||||||
{
|
{
|
||||||
@@ -202,7 +257,8 @@ public class SQLConnector
|
|||||||
System.out.println("SQLState: " + ex.getSQLState());
|
System.out.println("SQLState: " + ex.getSQLState());
|
||||||
System.out.println("VendorError: " + ex.getErrorCode());
|
System.out.println("VendorError: " + ex.getErrorCode());
|
||||||
}
|
}
|
||||||
catch( Exception ex) {
|
catch( Exception ex)
|
||||||
|
{
|
||||||
System.out.println("getMeasurement: " + ex.getMessage());
|
System.out.println("getMeasurement: " + ex.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,8 +270,10 @@ public class SQLConnector
|
|||||||
public void finalize() throws Throwable
|
public void finalize() throws Throwable
|
||||||
{
|
{
|
||||||
// Close database connection
|
// Close database connection
|
||||||
if( myConn != null ) {
|
if( myConn != null )
|
||||||
try {
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
myConn.close();
|
myConn.close();
|
||||||
System.out.println("Database connection terminated");
|
System.out.println("Database connection terminated");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,9 +23,7 @@ import com.google.zxing.qrcode.QRCodeWriter;
|
|||||||
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
||||||
|
|
||||||
public class WebcamUploader {
|
public class WebcamUploader {
|
||||||
|
|
||||||
public static void takePictureAndUpload(int id) throws IOException{
|
public static void takePictureAndUpload(int id) throws IOException{
|
||||||
|
|
||||||
Runtime.getRuntime().exec("streamer -c /dev/video0 -b 16 -o" + System.getProperty( "user.home" ) + "/ColorStrike/picture.jpeg");
|
Runtime.getRuntime().exec("streamer -c /dev/video0 -b 16 -o" + System.getProperty( "user.home" ) + "/ColorStrike/picture.jpeg");
|
||||||
|
|
||||||
HttpURLConnection httpUrlConnection = (HttpURLConnection)new URL("http://178.62.254.153/colorstrike/images/photoupload.php?filename="+id+".jpeg").openConnection();
|
HttpURLConnection httpUrlConnection = (HttpURLConnection)new URL("http://178.62.254.153/colorstrike/images/photoupload.php?filename="+id+".jpeg").openConnection();
|
||||||
|
|||||||
@@ -17,9 +17,10 @@ import main.Main;
|
|||||||
|
|
||||||
public class Images {
|
public class Images {
|
||||||
|
|
||||||
public static ArrayList<BufferedImage> images = new ArrayList<>();
|
public static ArrayList<BufferedImage> images = new ArrayList<BufferedImage>();
|
||||||
|
|
||||||
public Images() {
|
public Images() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
static {
|
||||||
@@ -32,8 +33,9 @@ public class Images {
|
|||||||
images.add(toCompatibleImage(ImageIO.read(Main.class.getResource("/image/aanwijzers4sho.png"))));
|
images.add(toCompatibleImage(ImageIO.read(Main.class.getResource("/image/aanwijzers4sho.png"))));
|
||||||
images.add(toCompatibleImage(ImageIO.read(Main.class.getResource("/image/kast.png"))));
|
images.add(toCompatibleImage(ImageIO.read(Main.class.getResource("/image/kast.png"))));
|
||||||
images.add(toCompatibleImage(ImageIO.read(Main.class.getResource("/image/gameover.png"))));
|
images.add(toCompatibleImage(ImageIO.read(Main.class.getResource("/image/gameover.png"))));
|
||||||
|
images.add(toCompatibleImage(ImageIO.read(Main.class.getResource("/image/screenshot.png"))));
|
||||||
images.add(toCompatibleImage(ImageIO.read(Main.class.getResource("/image/help.png"))));
|
images.add(toCompatibleImage(ImageIO.read(Main.class.getResource("/image/help.png"))));
|
||||||
images.add(toCompatibleImage(ImageIO.read(Main.class.getResource("/image/screenshot.png")))); // HELP, MAAR NOG GEEN JUIST PLAATJE
|
images.add(toCompatibleImage(ImageIO.read(Main.class.getResource("/image/youwon.png"))));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -44,10 +46,7 @@ public class Images {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public enum ImageType {
|
public enum ImageType {
|
||||||
pulse, cursor, pressstart,
|
pulse,cursor,pressstart,colorstrike,background,aanwijzers,kast,gameover, screenshot, help,youwon
|
||||||
colorstrike, background, aanwijzers,
|
|
||||||
kast, gameover, help,
|
|
||||||
screenshot
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BufferedImage readImage(File f) {
|
public static BufferedImage readImage(File f) {
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 112 KiB After Width: | Height: | Size: 108 KiB |
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 102 KiB |
|
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 36 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
@@ -2,8 +2,6 @@ package main;
|
|||||||
|
|
||||||
|
|
||||||
import java.awt.Cursor;
|
import java.awt.Cursor;
|
||||||
import java.awt.GraphicsDevice;
|
|
||||||
import java.awt.GraphicsEnvironment;
|
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
import java.awt.Toolkit;
|
import java.awt.Toolkit;
|
||||||
import java.awt.event.WindowAdapter;
|
import java.awt.event.WindowAdapter;
|
||||||
@@ -13,40 +11,33 @@ import java.awt.image.BufferedImage;
|
|||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
|
|
||||||
import model.GameModel;
|
import model.GameModel;
|
||||||
import model.SongHandler;
|
|
||||||
import view.GameView;
|
import view.GameView;
|
||||||
import control.GameControl;
|
import control.GameControl;
|
||||||
import control.GameStateManager;
|
import control.GameStateManager;
|
||||||
import control.NetworkHandler;
|
import control.NetworkHandler;
|
||||||
|
import control.SongHandler;
|
||||||
import control.button.ButtonHandler;
|
import control.button.ButtonHandler;
|
||||||
import control.joystick.JoystickHandler;
|
import control.joystick.JoystickHandler;
|
||||||
import data.io.SQLConnector;
|
import data.io.SQLConnector;
|
||||||
|
|
||||||
public class Window extends JFrame {
|
public class Window extends JFrame {
|
||||||
private static final long serialVersionUID = -9222956702898533696L;
|
private static final long serialVersionUID = -9222956702898533696L;
|
||||||
public static boolean ON_RASP;
|
public static boolean ON_ARCADE;
|
||||||
|
|
||||||
public final static int WIDTH = 1280;
|
public final static int WIDTH = 1280;
|
||||||
public final static int HEIGHT = 1024;
|
public final static int HEIGHT = 1024;
|
||||||
|
|
||||||
public Window(boolean ON_RASP)
|
public Window(boolean ON_ARCADE)
|
||||||
{
|
{
|
||||||
//Create window
|
//Create window
|
||||||
super("Arcade");
|
super("Arcade");
|
||||||
setSize(WIDTH, HEIGHT);
|
setSize(WIDTH, HEIGHT);
|
||||||
|
|
||||||
//Create Events
|
//Create Events
|
||||||
Window.ON_RASP = ON_RASP;
|
Window.ON_ARCADE = ON_ARCADE;
|
||||||
if(ON_RASP){ //Only on the raspberry pi
|
if(ON_ARCADE){ //Only on the arcade machine
|
||||||
GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
|
||||||
GraphicsDevice[] devices = graphicsEnvironment.getScreenDevices();
|
|
||||||
|
|
||||||
if (!devices[0].isFullScreenSupported ()){
|
|
||||||
throw new UnsupportedOperationException ("Fullscreen mode is unsupported.");
|
|
||||||
}else{
|
|
||||||
devices[0].setFullScreenWindow(this);
|
|
||||||
}
|
|
||||||
//Remove cursor
|
//Remove cursor
|
||||||
|
setUndecorated(true);
|
||||||
BufferedImage cursorImg = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
|
BufferedImage cursorImg = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
|
||||||
Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImg, new Point(0, 0), "blank cursor");
|
Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImg, new Point(0, 0), "blank cursor");
|
||||||
this.setCursor(blankCursor);
|
this.setCursor(blankCursor);
|
||||||
|
|||||||
@@ -5,11 +5,12 @@ import java.awt.Color;
|
|||||||
import main.Window;
|
import main.Window;
|
||||||
import control.GameStateManager;
|
import control.GameStateManager;
|
||||||
import control.NetworkHandler;
|
import control.NetworkHandler;
|
||||||
import control.button.ButtonHandler;
|
import control.SongHandler;
|
||||||
|
|
||||||
public class GameModel {
|
public class GameModel {
|
||||||
|
|
||||||
public static Color[] colors = { Color.GREEN, Color.YELLOW, Color.RED, Color.MAGENTA, Color.CYAN, Color.ORANGE };
|
public static Color[] colors = { Color.GREEN, Color.YELLOW, Color.RED, Color.MAGENTA, Color.CYAN, Color.BLUE };
|
||||||
|
private static String[] ledStripModes = {"full", "half", "quarter", "random"};
|
||||||
private GameStateManager gsm;
|
private GameStateManager gsm;
|
||||||
private NetworkHandler ntw;
|
private NetworkHandler ntw;
|
||||||
private int count = 0;
|
private int count = 0;
|
||||||
@@ -17,26 +18,101 @@ public class GameModel {
|
|||||||
public GameModel(SongHandler sh, GameStateManager gsm, NetworkHandler ntw) {
|
public GameModel(SongHandler sh, GameStateManager gsm, NetworkHandler ntw) {
|
||||||
this.gsm = gsm;
|
this.gsm = gsm;
|
||||||
this.ntw = ntw;
|
this.ntw = ntw;
|
||||||
|
|
||||||
for (int i = 1; i < ButtonHandler.getButtons().size(); i++) {
|
|
||||||
ButtonHandler.getButtons().get(i).setColor(colors[i - 1]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(float factor) {
|
public void update(float factor) {
|
||||||
gsm.update(factor);
|
gsm.update(factor);
|
||||||
|
if (Window.ON_ARCADE)
|
||||||
|
updateLedStrip(factor);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateLedStrip(float factor)
|
||||||
|
{
|
||||||
|
|
||||||
|
count += factor;
|
||||||
|
if(count > 400)
|
||||||
|
{
|
||||||
|
String mode = ledStripModes[(int) (Math.random() * (ledStripModes.length - 1) + 1)];
|
||||||
|
|
||||||
|
switch(mode)
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
case "full":
|
||||||
|
|
||||||
Color c = colors[(int) (Math.random() * (colors.length - 1) + 1)];
|
Color c = colors[(int) (Math.random() * (colors.length - 1) + 1)];
|
||||||
|
|
||||||
if (Window.ON_RASP) {
|
for (int i = 6; i < 46; i++) {
|
||||||
count++;
|
|
||||||
if(count>15) {
|
|
||||||
for (int i = 7; i < 54; i++) {
|
|
||||||
ntw.setLed(i, c.getRed(), c.getGreen(), c.getBlue());
|
ntw.setLed(i, c.getRed(), c.getGreen(), c.getBlue());
|
||||||
}
|
}
|
||||||
|
|
||||||
ntw.show();
|
ntw.show();
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "half":
|
||||||
|
|
||||||
|
Color c1 = colors[(int) (Math.random() * (colors.length - 1) + 1)];
|
||||||
|
Color c2 = colors[(int) (Math.random() * (colors.length - 1) + 1)];
|
||||||
|
while(c1==c2)
|
||||||
|
c2 = colors[(int) (Math.random() * (colors.length - 1) + 1)];
|
||||||
|
|
||||||
|
for (int i = 6; i < 26; i++) {
|
||||||
|
ntw.setLed(i, c1.getRed(), c1.getGreen(), c1.getBlue());
|
||||||
|
}
|
||||||
|
for (int i = 27; i < 46; i++) {
|
||||||
|
ntw.setLed(i, c2.getRed(), c2.getGreen(), c2.getBlue());
|
||||||
|
}
|
||||||
|
|
||||||
|
ntw.show();
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "quarter":
|
||||||
|
|
||||||
|
Color c3 = colors[(int) (Math.random() * (colors.length - 1) + 1)];
|
||||||
|
Color c4 = colors[(int) (Math.random() * (colors.length - 1) + 1)];
|
||||||
|
Color c5 = colors[(int) (Math.random() * (colors.length - 1) + 1)];
|
||||||
|
Color c6 = colors[(int) (Math.random() * (colors.length - 1) + 1)];
|
||||||
|
|
||||||
|
while(c3==c4)
|
||||||
|
c4 = colors[(int) (Math.random() * (colors.length - 1) + 1)];
|
||||||
|
while(c4==c5)
|
||||||
|
c5 = colors[(int) (Math.random() * (colors.length - 1) + 1)];
|
||||||
|
while(c5==c6)
|
||||||
|
c6 = colors[(int) (Math.random() * (colors.length - 1) + 1)];
|
||||||
|
|
||||||
|
for (int i = 6; i < 16; i++) {
|
||||||
|
ntw.setLed(i, c3.getRed(), c3.getGreen(), c3.getBlue());
|
||||||
|
}
|
||||||
|
for (int i = 17; i < 26; i++) {
|
||||||
|
ntw.setLed(i, c4.getRed(), c4.getGreen(), c4.getBlue());
|
||||||
|
}
|
||||||
|
for (int i = 27; i < 36; i++) {
|
||||||
|
ntw.setLed(i, c5.getRed(), c5.getGreen(), c5.getBlue());
|
||||||
|
}
|
||||||
|
for (int i = 37; i <46; i++) {
|
||||||
|
ntw.setLed(i, c6.getRed(), c6.getGreen(), c6.getBlue());
|
||||||
|
}
|
||||||
|
|
||||||
|
ntw.show();
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "random":
|
||||||
|
|
||||||
|
Color c7;
|
||||||
|
|
||||||
|
for (int i = 6; i < 46; i++) {
|
||||||
|
c7 = colors[(int) (Math.random() * (colors.length - 1) + 1)];
|
||||||
|
ntw.setLed(i, c7.getRed(), c7.getGreen(), c7.getBlue());
|
||||||
|
}
|
||||||
|
|
||||||
|
ntw.show();
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
count = 0;
|
count = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,73 +0,0 @@
|
|||||||
package model.drawObjects;
|
|
||||||
|
|
||||||
import model.gameState.PlayState;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.geom.Ellipse2D;
|
|
||||||
import java.awt.geom.Point2D;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* CoinAnimation klasse: Weergeeft een balletje (resembleerd een muntje) dat omlaag valt.
|
|
||||||
* Je hoeft alleen achter elkaar de paint(Graphics2D) methode aan te roepen, deze roep automatisch een 'reposition' aan,
|
|
||||||
* waardoor je het balletje alleen snel achter elkaar hoeft te repainten.
|
|
||||||
*
|
|
||||||
* * Init (startX, startY): Punt waar de animatie begint met vallen
|
|
||||||
*
|
|
||||||
* start(): aanroepen om te starten
|
|
||||||
* *
|
|
||||||
* *
|
|
||||||
**/
|
|
||||||
public class CoinAnimation extends DrawObject {
|
|
||||||
|
|
||||||
private Ellipse2D coinShape;
|
|
||||||
private Point2D.Double coinSetPoint;
|
|
||||||
|
|
||||||
// Hoevaak de timer gelopen heeft
|
|
||||||
private static int timerLoops = 0;
|
|
||||||
|
|
||||||
public CoinAnimation(int startX, int startY) {
|
|
||||||
coinSetPoint = new Point2D.Double(startX, startY);
|
|
||||||
coinShape = new Ellipse2D.Double(startX, startY, 20, 20);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start
|
|
||||||
public void start() {
|
|
||||||
timerLoops = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void draw(Graphics2D g2) {
|
|
||||||
Color oldColor = g2.getColor();
|
|
||||||
update(timerLoops); // UPDATE
|
|
||||||
g2.setColor(new Color(255, 255, 0)); // GEEL
|
|
||||||
g2.draw(coinShape); // MUNTJE TEKENEN
|
|
||||||
g2.fill(coinShape);
|
|
||||||
g2.setColor(oldColor);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wordt na elke paint aangeroepen
|
|
||||||
public void update(float factor) {
|
|
||||||
|
|
||||||
// Coin omlaag verschuiven doordat Y * loops omlaag gaat.
|
|
||||||
// Per frame verschuift het balletje delta 10 op Y-as.
|
|
||||||
try {
|
|
||||||
coinShape.setFrame(coinSetPoint.getX(), coinSetPoint.getY() + (1000 - 35 * PlayState.comboMulitplier) / 25 * timerLoops,
|
|
||||||
coinShape.getWidth(), coinShape.getHeight());
|
|
||||||
} catch (ArithmeticException a) { a.printStackTrace(); }
|
|
||||||
|
|
||||||
timerLoops++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Zijn we al begonnen/klaar?
|
|
||||||
public boolean areWeDoneYet() {
|
|
||||||
if (timerLoops > 24 || timerLoops == 0) {
|
|
||||||
timerLoops = 0;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Zitten we in de laatste loop?
|
|
||||||
public boolean isLastLoop() { return (timerLoops == 24) ? true : false; }
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -5,13 +5,10 @@ import java.awt.geom.AffineTransform;
|
|||||||
|
|
||||||
public abstract class DrawObject {
|
public abstract class DrawObject {
|
||||||
|
|
||||||
|
|
||||||
protected AffineTransform transform;
|
protected AffineTransform transform;
|
||||||
|
protected double width,height;
|
||||||
protected double width,
|
|
||||||
height;
|
|
||||||
|
|
||||||
protected int index = 0;
|
protected int index = 0;
|
||||||
|
|
||||||
public DrawObject() {
|
public DrawObject() {
|
||||||
transform = new AffineTransform();
|
transform = new AffineTransform();
|
||||||
}
|
}
|
||||||
@@ -24,6 +21,7 @@ public abstract class DrawObject {
|
|||||||
this.index = index;
|
this.index = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public abstract void draw(Graphics2D g2);
|
public abstract void draw(Graphics2D g2);
|
||||||
public abstract void update(float factor);
|
public abstract void update(float factor);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,11 +8,9 @@ import model.objects.Path;
|
|||||||
|
|
||||||
public class Enemy extends DrawObject {
|
public class Enemy extends DrawObject {
|
||||||
|
|
||||||
public static final double distanceToOctagon = 1000,
|
public static final double distanceToOctagon = 1000,secondsToEnd = 5.0;
|
||||||
secondsToEnd = 5.0;
|
|
||||||
private int length;
|
private int length;
|
||||||
private double lengthOf1Side,
|
private double lengthOf1Side,distanceFromStart;//lengthOf1Side wordt alleen gebruikt als de lijn een schuine lijn is.
|
||||||
distanceFromStart; //lengthOf1Side wordt alleen gebruikt als de lijn een schuine lijn is.
|
|
||||||
public Line2D enemy;
|
public Line2D enemy;
|
||||||
private Color c;
|
private Color c;
|
||||||
private Path path;
|
private Path path;
|
||||||
@@ -92,6 +90,8 @@ public class Enemy extends DrawObject {
|
|||||||
angleX = Math.cos(Math.toRadians(45))*distanceFromStart;
|
angleX = Math.cos(Math.toRadians(45))*distanceFromStart;
|
||||||
angleY = Math.sin(Math.toRadians(45))*distanceFromStart;
|
angleY = Math.sin(Math.toRadians(45))*distanceFromStart;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
switch(index){
|
switch(index){
|
||||||
case 0:
|
case 0:
|
||||||
y1 = path.getY1() + distanceFromStart;
|
y1 = path.getY1() + distanceFromStart;
|
||||||
|
|||||||
@@ -31,19 +31,24 @@ public class Player extends DrawObject {
|
|||||||
public void draw(Graphics2D g2){//
|
public void draw(Graphics2D g2){//
|
||||||
subImgX = (indexCursor % 8)*100;
|
subImgX = (indexCursor % 8)*100;
|
||||||
subImgY = (indexCursor / 8)*100;
|
subImgY = (indexCursor / 8)*100;
|
||||||
|
|
||||||
subImgXBeat = (indexBeat % 9)*100;
|
subImgXBeat = (indexBeat % 9)*100;
|
||||||
|
|
||||||
|
|
||||||
BufferedImage subImg2 = pulse.getSubimage(subImgXBeat,0,100,100);
|
BufferedImage subImg2 = pulse.getSubimage(subImgXBeat,0,100,100);
|
||||||
g2.drawImage(subImg2, transform, null);
|
g2.drawImage(subImg2, transform, null);
|
||||||
|
|
||||||
|
|
||||||
BufferedImage subImg = img.getSubimage(subImgX,subImgY,100,100);
|
BufferedImage subImg = img.getSubimage(subImgX,subImgY,100,100);
|
||||||
g2.drawImage(subImg, transform, null);
|
g2.drawImage(subImg, transform, null);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(float update){
|
public void update(float update){
|
||||||
if(beat){
|
if(beat){
|
||||||
indexBeat++;
|
indexBeat++;
|
||||||
if(indexBeat >= 9) {
|
if(indexBeat >= 9)
|
||||||
|
{
|
||||||
indexBeat = 0;
|
indexBeat = 0;
|
||||||
beat = false;
|
beat = false;
|
||||||
}
|
}
|
||||||
@@ -63,6 +68,7 @@ public class Player extends DrawObject {
|
|||||||
public void setBeat() {
|
public void setBeat() {
|
||||||
beat = true;
|
beat = true;
|
||||||
indexBeat = 0;
|
indexBeat = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
package model.drawObjects;
|
|
||||||
|
|
||||||
import model.gameState.PlayState;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.geom.Point2D;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
|
|
||||||
public class PointAnimation extends DrawObject {
|
|
||||||
|
|
||||||
LinkedList<Point2D.Double> puntenPos = new LinkedList<>();
|
|
||||||
LinkedList<Integer> puntenGain = new LinkedList<>();
|
|
||||||
LinkedList<Integer> iterations = new LinkedList<>();
|
|
||||||
|
|
||||||
public PointAnimation() { }
|
|
||||||
|
|
||||||
public void enemyDied(Point2D.Double p) {
|
|
||||||
puntenPos.add(new Point2D.Double(p.getX(), p.getY()));
|
|
||||||
puntenGain.add(PlayState.lastScoreChange);
|
|
||||||
iterations.add(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void draw(Graphics2D g2) {
|
|
||||||
for (int x = 0; x < puntenPos.size(); x++) {
|
|
||||||
g2.drawString("" + puntenGain.get(x), (int) puntenPos.get(x).getX(), (int) puntenPos.get(x).getY());
|
|
||||||
|
|
||||||
update(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void update(float factor) {
|
|
||||||
|
|
||||||
for (int x = 0; x < puntenPos.size(); x++) {
|
|
||||||
puntenPos.get(x).setLocation(puntenPos.get(x).getX(), puntenPos.get(x).getY() - 3);
|
|
||||||
iterations.set(x, iterations.get(x) + 1);
|
|
||||||
|
|
||||||
if (iterations.get(x) > 100) {
|
|
||||||
puntenPos.remove(x);
|
|
||||||
iterations.remove(x);
|
|
||||||
puntenGain.remove(x);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -12,13 +12,13 @@ import java.awt.image.VolatileImage;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import model.GameModel;
|
import model.GameModel;
|
||||||
import model.SongHandler;
|
|
||||||
import model.objects.InfoPanel;
|
import model.objects.InfoPanel;
|
||||||
import model.objects.highscore.HighscoreName;
|
import model.objects.highscore.HighscoreName;
|
||||||
|
|
||||||
import com.google.zxing.WriterException;
|
import com.google.zxing.WriterException;
|
||||||
|
|
||||||
import control.GameStateManager;
|
import control.GameStateManager;
|
||||||
|
import control.SongHandler;
|
||||||
import control.GameStateManager.State;
|
import control.GameStateManager.State;
|
||||||
import control.button.ButtonEvent;
|
import control.button.ButtonEvent;
|
||||||
import control.button.ButtonHandler;
|
import control.button.ButtonHandler;
|
||||||
@@ -27,19 +27,22 @@ import control.joystick.JoystickHandler;
|
|||||||
import data.io.SQLConnector;
|
import data.io.SQLConnector;
|
||||||
import data.io.WebcamUploader;
|
import data.io.WebcamUploader;
|
||||||
|
|
||||||
public class GameOverState extends GameState {
|
public class EndState extends GameState {
|
||||||
|
|
||||||
private BufferedImage gameOver = Images.getImage(Images.ImageType.gameover);
|
BufferedImage end = null;
|
||||||
private VolatileImage background;
|
VolatileImage background;
|
||||||
private Font textFont = new Font("OCR A Extended", Font.BOLD, 70);
|
Font textFont = new Font("OCR A Extended", Font.BOLD, 70);
|
||||||
private HighscoreName hsn;
|
HighscoreName hsn;
|
||||||
private int image_x = 0;
|
int image_x = 0;
|
||||||
private boolean uploaded;
|
private boolean uploaded;
|
||||||
private BufferedImage QRimage;
|
private BufferedImage QRimage;
|
||||||
|
|
||||||
|
boolean timeOut = false;
|
||||||
|
float timeOutCounter = 0;
|
||||||
|
|
||||||
int frame;
|
int frame;
|
||||||
|
|
||||||
public GameOverState(GameStateManager gsm, SongHandler sh, SQLConnector sql) {
|
public EndState(GameStateManager gsm, SongHandler sh, SQLConnector sql) {
|
||||||
super(gsm, sh, sql);
|
super(gsm, sh, sql);
|
||||||
hsn = new HighscoreName(640,717,5,textFont);
|
hsn = new HighscoreName(640,717,5,textFont);
|
||||||
}
|
}
|
||||||
@@ -47,21 +50,35 @@ public class GameOverState extends GameState {
|
|||||||
@Override
|
@Override
|
||||||
public void init() {
|
public void init() {
|
||||||
createBackground();
|
createBackground();
|
||||||
|
|
||||||
ButtonHandler.getButton(1).setColor(GameModel.colors[0]);
|
ButtonHandler.getButton(1).setColor(GameModel.colors[0]);
|
||||||
ButtonHandler.getButton(2).setColor(GameModel.colors[2]);
|
ButtonHandler.getButton(2).setColor(GameModel.colors[2]);
|
||||||
|
|
||||||
try {
|
|
||||||
Thread.sleep(1000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
JoystickHandler.REPEAT = true;
|
JoystickHandler.REPEAT = true;
|
||||||
uploaded = false;
|
uploaded = false;
|
||||||
|
timeOut = true;
|
||||||
|
timeOutCounter = 0;
|
||||||
|
|
||||||
|
if(PlayState.won()){
|
||||||
|
end = Images.getImage(Images.ImageType.youwon);
|
||||||
|
}else{
|
||||||
|
end = Images.getImage(Images.ImageType.gameover);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(float factor) {
|
public void update(float factor) {
|
||||||
|
if(timeOut)
|
||||||
|
{
|
||||||
|
timeOutCounter += factor;
|
||||||
|
|
||||||
|
if(timeOutCounter > 800)
|
||||||
|
{
|
||||||
|
timeOut = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
image_x = ((frame / 5) % 5) * 40;
|
image_x = ((frame / 5) % 5) * 40;
|
||||||
frame++;
|
frame++;
|
||||||
}
|
}
|
||||||
@@ -69,7 +86,11 @@ public class GameOverState extends GameState {
|
|||||||
@Override
|
@Override
|
||||||
public void draw(Graphics2D g2) {
|
public void draw(Graphics2D g2) {
|
||||||
g2.drawImage(background, 0, 0, 1280, 1024, null);
|
g2.drawImage(background, 0, 0, 1280, 1024, null);
|
||||||
g2.drawImage(gameOver.getSubimage(image_x, 0, 40, 26), 640-122, 400, 245, 130, null);
|
|
||||||
|
if(end != null){
|
||||||
|
g2.drawImage(end.getSubimage(image_x, 0, 40, 26), 640-122, 400, 245, 130, null);
|
||||||
|
}
|
||||||
|
|
||||||
if(!uploaded)
|
if(!uploaded)
|
||||||
hsn.drawName(g2);
|
hsn.drawName(g2);
|
||||||
else if(QRimage != null){
|
else if(QRimage != null){
|
||||||
@@ -81,7 +102,8 @@ public class GameOverState extends GameState {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void buttonPressed(ButtonEvent e) {
|
public void buttonPressed(ButtonEvent e) {
|
||||||
//System.out.println("Name: "+hsn.getName());
|
if(!timeOut)
|
||||||
|
{
|
||||||
switch(e.getButton().getButtonID()){
|
switch(e.getButton().getButtonID()){
|
||||||
case 0:
|
case 0:
|
||||||
gsm.setState(State.TITLE_STATE);
|
gsm.setState(State.TITLE_STATE);
|
||||||
@@ -112,19 +134,17 @@ public class GameOverState extends GameState {
|
|||||||
case 2:
|
case 2:
|
||||||
gsm.setState(State.MENU_STATE);
|
gsm.setState(State.MENU_STATE);
|
||||||
break;
|
break;
|
||||||
case 3:
|
}
|
||||||
gsm.setState(State.HELP_STATE);
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@Override
|
@Override
|
||||||
public void buttonReleased(ButtonEvent e) {
|
public void buttonReleased(ButtonEvent e) {}
|
||||||
|
|
||||||
}
|
|
||||||
@Override
|
@Override
|
||||||
public void onJoystickMoved(JoystickEvent e) {
|
public void onJoystickMoved(JoystickEvent e) {
|
||||||
|
if(!timeOut)
|
||||||
|
{
|
||||||
switch(e.getJoystick().getPos()){
|
switch(e.getJoystick().getPos()){
|
||||||
case DOWN:
|
case DOWN:
|
||||||
hsn.down();
|
hsn.down();
|
||||||
@@ -142,6 +162,7 @@ public class GameOverState extends GameState {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void createBackground(){
|
public void createBackground(){
|
||||||
background = Images.initVolatileImage(1280, 1024, Transparency.OPAQUE);
|
background = Images.initVolatileImage(1280, 1024, Transparency.OPAQUE);
|
||||||
@@ -2,8 +2,8 @@ package model.gameState;
|
|||||||
|
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
|
|
||||||
import model.SongHandler;
|
|
||||||
import control.GameStateManager;
|
import control.GameStateManager;
|
||||||
|
import control.SongHandler;
|
||||||
import control.button.ButtonEvent;
|
import control.button.ButtonEvent;
|
||||||
import control.joystick.JoystickEvent;
|
import control.joystick.JoystickEvent;
|
||||||
import data.io.SQLConnector;
|
import data.io.SQLConnector;
|
||||||
@@ -26,6 +26,5 @@ public abstract class GameState {
|
|||||||
public abstract void buttonPressed(ButtonEvent e);
|
public abstract void buttonPressed(ButtonEvent e);
|
||||||
public abstract void buttonReleased(ButtonEvent e);
|
public abstract void buttonReleased(ButtonEvent e);
|
||||||
public abstract void onJoystickMoved(JoystickEvent e);
|
public abstract void onJoystickMoved(JoystickEvent e);
|
||||||
|
|
||||||
public void stopAudio() { sh.close(); }
|
public void stopAudio() { sh.close(); }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,21 +11,23 @@ import java.awt.image.BufferedImage;
|
|||||||
import java.awt.image.VolatileImage;
|
import java.awt.image.VolatileImage;
|
||||||
|
|
||||||
import model.GameModel;
|
import model.GameModel;
|
||||||
import model.SongHandler;
|
|
||||||
import control.GameStateManager;
|
import control.GameStateManager;
|
||||||
|
import control.SongHandler;
|
||||||
import control.GameStateManager.State;
|
import control.GameStateManager.State;
|
||||||
import control.button.ButtonEvent;
|
import control.button.ButtonEvent;
|
||||||
|
import control.button.ButtonHandler;
|
||||||
import control.joystick.JoystickEvent;
|
import control.joystick.JoystickEvent;
|
||||||
import data.io.SQLConnector;
|
import data.io.SQLConnector;
|
||||||
|
|
||||||
public class HelpState extends GameState {
|
public class HelpState extends GameState {
|
||||||
|
|
||||||
private BufferedImage help = Images.getImage(ImageType.help);
|
BufferedImage help = Images.getImage(ImageType.help);
|
||||||
private VolatileImage background;
|
VolatileImage background;
|
||||||
private Font textFontSmall = new Font("OCR A Extended", Font.BOLD, 15);
|
Font textFontSmall = new Font("OCR A Extended", Font.BOLD, 15);
|
||||||
|
|
||||||
int index = 0,
|
|
||||||
frame;
|
int index = 0;
|
||||||
|
int frame;
|
||||||
|
|
||||||
|
|
||||||
public HelpState(GameStateManager gsm, SongHandler sh, SQLConnector sql){
|
public HelpState(GameStateManager gsm, SongHandler sh, SQLConnector sql){
|
||||||
@@ -35,25 +37,31 @@ public class HelpState extends GameState {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() {
|
public void init() {
|
||||||
|
ButtonHandler.getButton(2).setColor(GameModel.colors[2]);
|
||||||
sh.play();
|
sh.play();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(float factor) {
|
public void update(float factor) {
|
||||||
|
|
||||||
frame++;
|
frame++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Graphics2D g2) {
|
public void draw(Graphics2D g2) {
|
||||||
g2.drawImage(background, 0, 0, 1280, 1024, null);
|
g2.drawImage(background, 0, 0, 1280, 1024, null);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void buttonPressed(ButtonEvent e) {
|
public void buttonPressed(ButtonEvent e) {
|
||||||
if(e.getButton().getButtonID() == 2)
|
|
||||||
|
if(e.getButton().getButtonID() == 2) {
|
||||||
gsm.setState(State.MENU_STATE);
|
gsm.setState(State.MENU_STATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void buttonReleased(ButtonEvent e) {
|
public void buttonReleased(ButtonEvent e) {
|
||||||
|
|
||||||
|
|||||||
@@ -17,15 +17,17 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import model.GameModel;
|
import model.GameModel;
|
||||||
import model.SongHandler;
|
|
||||||
import model.objects.DifficultyButton;
|
import model.objects.DifficultyButton;
|
||||||
import model.objects.MenuButton;
|
import model.objects.MenuButton;
|
||||||
import model.objects.highscore.Highscore;
|
import model.objects.highscore.Highscore;
|
||||||
import audio.Song;
|
import audio.Song;
|
||||||
import audio.SongInstance;
|
import audio.SongInstance;
|
||||||
import audio.sorting.SortALPHA;
|
import audio.sorting.SortALPHA;
|
||||||
|
import audio.sorting.SortAUTHOR;
|
||||||
import audio.sorting.SortPLAYED;
|
import audio.sorting.SortPLAYED;
|
||||||
|
import audio.sorting.SortSCORE;
|
||||||
import control.GameStateManager;
|
import control.GameStateManager;
|
||||||
|
import control.SongHandler;
|
||||||
import control.GameStateManager.State;
|
import control.GameStateManager.State;
|
||||||
import control.button.ButtonEvent;
|
import control.button.ButtonEvent;
|
||||||
import control.button.ButtonHandler;
|
import control.button.ButtonHandler;
|
||||||
@@ -40,31 +42,35 @@ public class MenuState extends GameState {
|
|||||||
private ArrayList<DifficultyButton> buttons2;
|
private ArrayList<DifficultyButton> buttons2;
|
||||||
private int selected, oldselected;
|
private int selected, oldselected;
|
||||||
private List<Song> songs;
|
private List<Song> songs;
|
||||||
private SQLConnector sql;
|
SQLConnector sql;
|
||||||
|
|
||||||
private int animationcounter;
|
private int animationcounter;
|
||||||
private boolean subscreen, startanimation;
|
private boolean subscreen, startanimation;
|
||||||
private VolatileImage mainScreenBackground, subScreenBackground, subScreenForeground;
|
private VolatileImage mainScreenBackground, subScreenBackground, subScreenForeground;
|
||||||
|
|
||||||
|
int yPosDiffButton = 900;
|
||||||
private int difSelect=0, oldDifSelect = -1;
|
private int difSelect=0, oldDifSelect = -1;
|
||||||
Font textFont = new Font("OCR A Extended", Font.BOLD, 50);
|
Font textFont = new Font("OCR A Extended", Font.BOLD, 50);
|
||||||
Font textFont2 = new Font("OCR A Extended", Font.BOLD, 35);
|
Font textFont2 = new Font("OCR A Extended", Font.BOLD, 35);
|
||||||
Font textFont3 = new Font("OCR A Extended", Font.BOLD, 20);
|
Font textFont3 = new Font("OCR A Extended", Font.BOLD, 20);
|
||||||
Font textFontSmall = new Font("OCR A Extended", Font.BOLD, 15);
|
Font textFontSmall = new Font("OCR A Extended", Font.BOLD, 15);
|
||||||
BufferedImage aanwijzers = Images.getImage(ImageType.aanwijzers);
|
BufferedImage aanwijzers = Images.getImage(ImageType.aanwijzers);
|
||||||
|
int index = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int kleurButton1 = 0;
|
||||||
|
int kleurButton2 = 1;
|
||||||
|
int kleurButton3 = 2;
|
||||||
|
int kleurButton4 = 3;
|
||||||
|
int kleurButton5 = 4;
|
||||||
|
|
||||||
|
|
||||||
private int index = 0,
|
|
||||||
yPosDiffButton = 900,
|
|
||||||
kleurButton1 = 0,
|
|
||||||
kleurButton2 = 1,
|
|
||||||
kleurButton3 = 2,
|
|
||||||
kleurButton4 = 3,
|
|
||||||
kleurButton5 = 4;
|
|
||||||
|
|
||||||
public MenuState(GameStateManager gsm, SongHandler sh, SQLConnector sql) {
|
public MenuState(GameStateManager gsm, SongHandler sh, SQLConnector sql) {
|
||||||
super(gsm, sh, sql);
|
super(gsm, sh, sql);
|
||||||
buttons = new ArrayList<>();
|
buttons = new ArrayList<MenuButton>();
|
||||||
buttons2 = new ArrayList<>();
|
buttons2 = new ArrayList<DifficultyButton>();
|
||||||
this.songs = sh.getSongs();
|
this.songs = sh.getSongs();
|
||||||
startanimation = true;
|
startanimation = true;
|
||||||
subscreen = false;
|
subscreen = false;
|
||||||
@@ -89,19 +95,26 @@ public class MenuState extends GameState {
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void init() {
|
public void init() {
|
||||||
if(subscreen) {
|
if(subscreen)
|
||||||
|
{
|
||||||
ButtonHandler.getButton(1).setColor(GameModel.colors[0]);
|
ButtonHandler.getButton(1).setColor(GameModel.colors[0]);
|
||||||
ButtonHandler.getButton(2).setColor(GameModel.colors[2]);
|
ButtonHandler.getButton(2).setColor(GameModel.colors[2]);
|
||||||
generateSubScreenForeground();
|
generateSubScreenForeground();
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
ButtonHandler.getButton(1).setColor(GameModel.colors[0]);
|
ButtonHandler.getButton(1).setColor(GameModel.colors[0]);
|
||||||
|
ButtonHandler.getButton(2).setColor(GameModel.colors[3]);
|
||||||
|
|
||||||
ButtonHandler.getButton(5).setColor(GameModel.colors[1]);
|
ButtonHandler.getButton(3).setColor(GameModel.colors[1]);
|
||||||
ButtonHandler.getButton(6).setColor(GameModel.colors[4]);
|
ButtonHandler.getButton(4).setColor(GameModel.colors[2]);
|
||||||
|
ButtonHandler.getButton(5).setColor(GameModel.colors[4]);
|
||||||
|
ButtonHandler.getButton(6).setColor(GameModel.colors[5]);
|
||||||
JoystickHandler.REPEAT = true;
|
JoystickHandler.REPEAT = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -111,18 +124,20 @@ public class MenuState extends GameState {
|
|||||||
if(animationcounter == 5){
|
if(animationcounter == 5){
|
||||||
startanimation = false;
|
startanimation = false;
|
||||||
}
|
}
|
||||||
}/*else if(subscreen){
|
}else if(subscreen){
|
||||||
//nextScreen();
|
//nextScreen();
|
||||||
}else{
|
}else{
|
||||||
//previousScreen();
|
//previousScreen();
|
||||||
}*/
|
}
|
||||||
if(selected != oldselected){
|
if(selected != oldselected){
|
||||||
for(int i = 0; i < buttons.size(); i++)
|
for(int i = 0; i < buttons.size(); i++){
|
||||||
buttons.get(i).setSong(selectedToSong(selected+(i-2)));
|
buttons.get(i).setSong(selectedToSong(selected+(i-2)));
|
||||||
|
|
||||||
|
}
|
||||||
oldselected = selected;
|
oldselected = selected;
|
||||||
}
|
}
|
||||||
if(difSelect != oldDifSelect) {
|
if(difSelect != oldDifSelect)
|
||||||
|
{
|
||||||
oldDifSelect = difSelect;
|
oldDifSelect = difSelect;
|
||||||
generateSubScreenForeground();
|
generateSubScreenForeground();
|
||||||
}
|
}
|
||||||
@@ -134,11 +149,11 @@ public class MenuState extends GameState {
|
|||||||
public void draw(Graphics2D g2) {
|
public void draw(Graphics2D g2) {
|
||||||
|
|
||||||
buttons.clear();
|
buttons.clear();
|
||||||
buttons.add(new MenuButton(400,250,GameModel.colors[kleurButton1],selectedToSong(selected-2)));
|
buttons.add(new MenuButton(300,260,GameModel.colors[kleurButton1],selectedToSong(selected-2)));
|
||||||
buttons.add(new MenuButton(400,390,GameModel.colors[kleurButton2],selectedToSong(selected-1)));
|
buttons.add(new MenuButton(300,380,GameModel.colors[kleurButton2],selectedToSong(selected-1)));
|
||||||
buttons.add(new MenuButton(360,525,920,80,GameModel.colors[kleurButton3],selectedToSong(selected)));
|
buttons.add(new MenuButton(260,520,1020,80,GameModel.colors[kleurButton3],selectedToSong(selected)));
|
||||||
buttons.add(new MenuButton(400,670,GameModel.colors[kleurButton4],selectedToSong(selected+1)));
|
buttons.add(new MenuButton(300,680,GameModel.colors[kleurButton4],selectedToSong(selected+1)));
|
||||||
buttons.add(new MenuButton(400,810,GameModel.colors[kleurButton5],selectedToSong(selected+2)));
|
buttons.add(new MenuButton(300,800,GameModel.colors[kleurButton5],selectedToSong(selected+2)));
|
||||||
buttons.get(2).setSelected(true);
|
buttons.get(2).setSelected(true);
|
||||||
|
|
||||||
|
|
||||||
@@ -170,26 +185,32 @@ public class MenuState extends GameState {
|
|||||||
}
|
}
|
||||||
if(e.getButton().getButtonID() == 1){
|
if(e.getButton().getButtonID() == 1){
|
||||||
sh.close();
|
sh.close();
|
||||||
gsm.setState(control.GameStateManager.State.PLAY_STATE);
|
gsm.setState(control.GameStateManager.State.PRE_GAME_STATE);
|
||||||
}
|
}
|
||||||
}else{ //Screen for selecting song
|
}else{ //Screen for selecting song
|
||||||
if(e.getButton().getButtonID() == 1){
|
if(e.getButton().getButtonID() == 1){
|
||||||
subscreen = true;
|
subscreen = true;
|
||||||
gsm.init();
|
gsm.init();
|
||||||
generateSubScreenForeground();
|
generateSubScreenForeground();
|
||||||
}else if(e.getButton().getButtonID() == 5){
|
}else if(e.getButton().getButtonID() == 2){
|
||||||
sh.sort(new SortALPHA());
|
|
||||||
selected = 0;
|
|
||||||
sh.set(songs.indexOf(selectedToSong(selected)));
|
|
||||||
sh.play();
|
|
||||||
}else if(e.getButton().getButtonID() == 6){
|
|
||||||
sh.sort(new SortPLAYED());
|
|
||||||
selected = 0;
|
|
||||||
sh.set(songs.indexOf(selectedToSong(selected)));
|
|
||||||
sh.play();
|
|
||||||
}else if(e.getButton().getButtonID() == 3){
|
|
||||||
gsm.setState(control.GameStateManager.State.HELP_STATE);
|
gsm.setState(control.GameStateManager.State.HELP_STATE);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(e.getButton().getButtonID() == 3){
|
||||||
|
sh.sort(new SortALPHA());
|
||||||
|
}else if(e.getButton().getButtonID() == 4){
|
||||||
|
sh.sort(new SortAUTHOR());
|
||||||
|
}else if(e.getButton().getButtonID() == 5){
|
||||||
|
sh.sort(new SortPLAYED());
|
||||||
|
}else if(e.getButton().getButtonID() == 6){
|
||||||
|
sh.sort(new SortSCORE());
|
||||||
|
}
|
||||||
|
|
||||||
|
selected = 0;
|
||||||
|
sh.set(songs.indexOf(selectedToSong(selected)));
|
||||||
|
sh.play();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(e.getButton().getButtonID() == 0)
|
if(e.getButton().getButtonID() == 0)
|
||||||
@@ -207,15 +228,20 @@ public class MenuState extends GameState {
|
|||||||
if(subscreen){
|
if(subscreen){
|
||||||
if(e.getJoystick().getPos() == Joystick.Position.DOWN){
|
if(e.getJoystick().getPos() == Joystick.Position.DOWN){
|
||||||
difSelect--;
|
difSelect--;
|
||||||
if(difSelect < 0)
|
if(difSelect < 0){
|
||||||
difSelect += buttons2.size();
|
difSelect += buttons2.size();
|
||||||
else if(e.getJoystick().getPos() == Joystick.Position.UP)
|
}
|
||||||
|
}else if(e.getJoystick().getPos() == Joystick.Position.UP){
|
||||||
difSelect++;
|
difSelect++;
|
||||||
if(difSelect > buttons2.size()-1)
|
if(difSelect > buttons2.size()-1){
|
||||||
difSelect = 0;
|
difSelect = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
else if(e.getJoystick().getPos() == Joystick.Position.CENTER)
|
else if(e.getJoystick().getPos() == Joystick.Position.CENTER)
|
||||||
sh.set(selectedToSong(selected).getSongs().get(difSelect));
|
{
|
||||||
|
sh.set(selectedToSong(selected).getSongs().get( (sh.getCurrentSong().getSongs().size()-1) - difSelect));
|
||||||
|
}
|
||||||
//generateSubScreenForeground();
|
//generateSubScreenForeground();
|
||||||
}else{ //Screen for selecting song
|
}else{ //Screen for selecting song
|
||||||
if(e.getJoystick().getPos() == Joystick.Position.DOWN){
|
if(e.getJoystick().getPos() == Joystick.Position.DOWN){
|
||||||
@@ -236,26 +262,40 @@ public class MenuState extends GameState {
|
|||||||
kleurButton5++;
|
kleurButton5++;
|
||||||
kleurButton5 %= 6;
|
kleurButton5 %= 6;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}else if(e.getJoystick().getPos() == Joystick.Position.UP){
|
}else if(e.getJoystick().getPos() == Joystick.Position.UP){
|
||||||
selected--;
|
selected--;
|
||||||
|
kleurButton1--;
|
||||||
if(--kleurButton1 < 0)
|
if(kleurButton1 < 0){
|
||||||
kleurButton1 = 5;
|
kleurButton1 = 5;
|
||||||
|
}
|
||||||
|
|
||||||
if(--kleurButton2 < 0)
|
kleurButton2--;
|
||||||
|
if(kleurButton2 < 0){
|
||||||
kleurButton2 = 5;
|
kleurButton2 = 5;
|
||||||
|
}
|
||||||
|
|
||||||
if(--kleurButton3 < 0)
|
kleurButton3--;
|
||||||
|
if(kleurButton3 < 0){
|
||||||
kleurButton3 = 5;
|
kleurButton3 = 5;
|
||||||
|
}
|
||||||
|
|
||||||
if(--kleurButton4 < 0)
|
kleurButton4--;
|
||||||
|
if(kleurButton4 < 0){
|
||||||
kleurButton4 = 5;
|
kleurButton4 = 5;
|
||||||
|
}
|
||||||
|
|
||||||
if(--kleurButton5 < 0)
|
kleurButton5--;
|
||||||
|
if(kleurButton5 < 0){
|
||||||
kleurButton5 = 5;
|
kleurButton5 = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(e.getJoystick().getPos() == Joystick.Position.CENTER)
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
else if(e.getJoystick().getPos() == Position.CENTER)
|
||||||
{
|
{
|
||||||
buttons2.clear();
|
buttons2.clear();
|
||||||
int instanceNr = 0;
|
int instanceNr = 0;
|
||||||
@@ -284,8 +324,8 @@ public class MenuState extends GameState {
|
|||||||
g2.fillRect(0, 0, 1280, 1024);
|
g2.fillRect(0, 0, 1280, 1024);
|
||||||
g2.setPaint(new GradientPaint(0, 0, new Color(1,1,0, 0.6f),1280,1024 ,new Color(0,0,1, 0.2f)));
|
g2.setPaint(new GradientPaint(0, 0, new Color(1,1,0, 0.6f),1280,1024 ,new Color(0,0,1, 0.2f)));
|
||||||
|
|
||||||
Polygon triangle2 = new Polygon();
|
|
||||||
|
|
||||||
|
Polygon triangle2 = new Polygon();
|
||||||
triangle2.addPoint(0, 0);
|
triangle2.addPoint(0, 0);
|
||||||
triangle2.addPoint(0, 1024/4+50);
|
triangle2.addPoint(0, 1024/4+50);
|
||||||
triangle2.addPoint(1280/2+50, 0);
|
triangle2.addPoint(1280/2+50, 0);
|
||||||
@@ -305,23 +345,34 @@ public class MenuState extends GameState {
|
|||||||
|
|
||||||
//select
|
//select
|
||||||
g2.setColor(GameModel.colors[0]);
|
g2.setColor(GameModel.colors[0]);
|
||||||
g2.fillOval(20, 860, 30, 30);
|
g2.fillOval(20, 780, 30, 30);
|
||||||
g2.drawString("Play", 55, 880);
|
g2.drawString("Play", 55, 800);
|
||||||
|
|
||||||
//help
|
//help
|
||||||
g2.setColor(GameModel.colors[3]);
|
g2.setColor(GameModel.colors[3]);
|
||||||
g2.fillOval(20, 900, 30, 30);
|
g2.fillOval(20, 820, 30, 30);
|
||||||
g2.drawString("Help", 55, 920);
|
g2.drawString("Help", 55, 840);
|
||||||
|
|
||||||
//letters
|
//letters
|
||||||
g2.setColor(GameModel.colors[1]);
|
g2.setColor(GameModel.colors[1]);
|
||||||
g2.fillOval(20, 940, 30, 30);
|
g2.fillOval(20, 860, 30, 30);
|
||||||
g2.drawString("A-Z", 55, 960);
|
g2.drawString("A-Z", 55, 880);
|
||||||
|
|
||||||
|
//most played
|
||||||
|
g2.setColor(GameModel.colors[2]);
|
||||||
|
g2.fillOval(20, 900, 30, 30);
|
||||||
|
g2.drawString("Author", 55, 920);
|
||||||
|
|
||||||
//most played
|
//most played
|
||||||
g2.setColor(GameModel.colors[4]);
|
g2.setColor(GameModel.colors[4]);
|
||||||
|
g2.fillOval(20, 940, 30, 30);
|
||||||
|
g2.drawString("Most Played", 55, 960);
|
||||||
|
|
||||||
|
//most played
|
||||||
|
g2.setColor(GameModel.colors[5]);
|
||||||
g2.fillOval(20, 980, 30, 30);
|
g2.fillOval(20, 980, 30, 30);
|
||||||
g2.drawString("Most Played", 55, 1000);
|
g2.drawString("Highest Score", 55, 1000);
|
||||||
|
|
||||||
g2.dispose();
|
g2.dispose();
|
||||||
|
|
||||||
mainScreenBackground.createGraphics();
|
mainScreenBackground.createGraphics();
|
||||||
@@ -366,22 +417,23 @@ public class MenuState extends GameState {
|
|||||||
g2.setFont(textFont);
|
g2.setFont(textFont);
|
||||||
|
|
||||||
boolean highscoresFound = true;
|
boolean highscoresFound = true;
|
||||||
int HIGHSCORES_TO_DISPLAY = 5;
|
int HIGHSCORES_TO_DISPLAY = 7;
|
||||||
|
|
||||||
List<Highscore> highscores = sql.getHighscoresToday(selectedToSong(selected), sh.getCurrentSong().getSongs().get(difSelect));
|
List<Highscore> highscores = sql.getHighscoresToday(selectedToSong(selected), sh.getCurrentSong().getSongs().get((sh.getCurrentSong().getSongs().size() - 1) - difSelect));
|
||||||
if(highscores.isEmpty())
|
if(highscores.isEmpty())
|
||||||
{
|
{
|
||||||
highscores = sql.getHighscores(selectedToSong(selected), sh.getCurrentSong().getSongs().get(difSelect));
|
highscores = sql.getHighscores(selectedToSong(selected), sh.getCurrentSong().getSongs().get((sh.getCurrentSong().getSongs().size() - 1) - difSelect));
|
||||||
|
|
||||||
if(highscores.isEmpty())
|
if(highscores.isEmpty())
|
||||||
|
{
|
||||||
highscoresFound = false;
|
highscoresFound = false;
|
||||||
else
|
|
||||||
g2.drawString("All Time Highscores", 30, 300);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
g2.drawString("Daily Highscore", 30, 300);
|
g2.drawString("All Time Highscores", 30, 235);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
g2.drawString("Daily Highscore", 30, 235);
|
||||||
g2.setFont(textFont2);
|
g2.setFont(textFont2);
|
||||||
|
|
||||||
if(highscoresFound)
|
if(highscoresFound)
|
||||||
{
|
{
|
||||||
HIGHSCORES_TO_DISPLAY = HIGHSCORES_TO_DISPLAY > highscores.size() ? highscores.size() : HIGHSCORES_TO_DISPLAY;
|
HIGHSCORES_TO_DISPLAY = HIGHSCORES_TO_DISPLAY > highscores.size() ? highscores.size() : HIGHSCORES_TO_DISPLAY;
|
||||||
@@ -390,20 +442,18 @@ public class MenuState extends GameState {
|
|||||||
{
|
{
|
||||||
Highscore hi = highscores.get(i);
|
Highscore hi = highscores.get(i);
|
||||||
|
|
||||||
g2.drawString(hi.getName() + " - " + hi.getScore(), 30, 350 + i*100);
|
g2.drawString(" " + (i+1) + "# " + hi.getName() + " - " + hi.getScore(), 30, 290 + i*80);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
g2.drawString("No Highscores found", 30, 400);
|
g2.drawString("No Highscores found", 30, 400);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
List<Highscore> highscores = sql.getHighscores(selectedToSong(selected), sh.getCurrentSong().getSongs().get(difSelect));
|
for(DifficultyButton b : buttons2){
|
||||||
List<Highscore> dailyHighs = new ArrayList<Highscore>();
|
|
||||||
int highest = 0;
|
|
||||||
int oldHighest = 0;
|
|
||||||
*/
|
|
||||||
for(DifficultyButton b : buttons2)
|
|
||||||
b.draw(g2);
|
b.draw(g2);
|
||||||
|
}
|
||||||
|
|
||||||
g2.setFont(textFontSmall);
|
g2.setFont(textFontSmall);
|
||||||
|
|
||||||
@@ -435,6 +485,8 @@ public class MenuState extends GameState {
|
|||||||
|
|
||||||
g2.drawString("Down", 55, 1000);
|
g2.drawString("Down", 55, 1000);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
g2.dispose();
|
g2.dispose();
|
||||||
subScreenForeground.createGraphics();
|
subScreenForeground.createGraphics();
|
||||||
}
|
}
|
||||||
@@ -442,20 +494,40 @@ public class MenuState extends GameState {
|
|||||||
public void buttonInAnimation(int button){
|
public void buttonInAnimation(int button){
|
||||||
if(button >= 0 && button < buttons.size() ){
|
if(button >= 0 && button < buttons.size() ){
|
||||||
buttons.get(button).setX(buttons.get(button).getX()+40);
|
buttons.get(button).setX(buttons.get(button).getX()+40);
|
||||||
|
if(buttons.get(button).getX() >= 320){
|
||||||
if(buttons.get(button).getX() >= 320)
|
|
||||||
animationcounter++;
|
animationcounter++;
|
||||||
if(buttons.get(button).getX() >= -200)
|
}
|
||||||
|
if(buttons.get(button).getX() >= -200){
|
||||||
buttonInAnimation(button+1);
|
buttonInAnimation(button+1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
public void nextScreen(){
|
||||||
|
if(buttons.get(0).getX() > -700){
|
||||||
|
for(MenuButton b:buttons){
|
||||||
|
b.setX(b.getX()-100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void previousScreen(){
|
||||||
|
if(buttons.get(0).getX() < 300){
|
||||||
|
for(MenuButton b:buttons){
|
||||||
|
b.setX(b.getX()+100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
public Song selectedToSong(int s){
|
public Song selectedToSong(int s){
|
||||||
s %= songs.size();
|
s %= songs.size();
|
||||||
if(s < 0)
|
if(s < 0){
|
||||||
return songs.get(songs.size()+s);
|
return songs.get(songs.size()+s);
|
||||||
else
|
}else{
|
||||||
return songs.get(s);
|
return songs.get(s);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -4,21 +4,19 @@ import java.awt.BasicStroke;
|
|||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Stroke;
|
import java.awt.Stroke;
|
||||||
import java.awt.geom.Ellipse2D;
|
|
||||||
import java.awt.geom.Point2D;
|
|
||||||
import java.awt.geom.Rectangle2D;
|
import java.awt.geom.Rectangle2D;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import main.Window;
|
|
||||||
import model.SongHandler;
|
|
||||||
import model.drawObjects.Enemy;
|
import model.drawObjects.Enemy;
|
||||||
import model.drawObjects.Player;
|
import model.drawObjects.Player;
|
||||||
import model.objects.InfoPanel;
|
import model.objects.InfoPanel;
|
||||||
import model.objects.Path;
|
import model.objects.Path;
|
||||||
import model.objects.PlayArea;
|
import model.objects.PlayArea;
|
||||||
|
import model.objects.highscore.Highscore;
|
||||||
import audio.ButtonInstance;
|
import audio.ButtonInstance;
|
||||||
import audio.ObjectInstance;
|
import audio.ObjectInstance;
|
||||||
import control.GameStateManager;
|
import control.GameStateManager;
|
||||||
|
import control.SongHandler;
|
||||||
import control.GameStateManager.State;
|
import control.GameStateManager.State;
|
||||||
import control.button.Button;
|
import control.button.Button;
|
||||||
import control.button.ButtonEvent;
|
import control.button.ButtonEvent;
|
||||||
@@ -37,9 +35,7 @@ public class PlayState extends GameState {
|
|||||||
|
|
||||||
public static int sizeOfEnemy = 40;
|
public static int sizeOfEnemy = 40;
|
||||||
public static int currentScore = 0;
|
public static int currentScore = 0;
|
||||||
public static int comboMulitplier = 0;
|
public static int comboScore = 0;
|
||||||
public static int lastScoreChange = 0;
|
|
||||||
public static int sinceScoreChanged = 75;
|
|
||||||
public static double lifePoints = 100;
|
public static double lifePoints = 100;
|
||||||
|
|
||||||
private int enemies_hit = 0;
|
private int enemies_hit = 0;
|
||||||
@@ -48,14 +44,13 @@ public class PlayState extends GameState {
|
|||||||
private int joystick_moved = 0;
|
private int joystick_moved = 0;
|
||||||
|
|
||||||
private boolean init = false;
|
private boolean init = false;
|
||||||
|
private static boolean won = false;
|
||||||
private boolean prestateShown = false;
|
|
||||||
|
|
||||||
private long oldProgress = 0;
|
private long oldProgress = 0;
|
||||||
|
|
||||||
public PlayState(GameStateManager gsm, SongHandler sh, SQLConnector sql) {
|
public PlayState(GameStateManager gsm, SongHandler sh, SQLConnector sql) {
|
||||||
super(gsm, sh, sql);
|
super(gsm, sh, sql);
|
||||||
infoPanel = new InfoPanel(0, 0, sh);
|
infoPanel = new InfoPanel(sh);
|
||||||
area = new PlayArea(256, 1024, 1024, 125);
|
area = new PlayArea(256, 1024, 1024, 125);
|
||||||
player = new Player(1280 - 1024 + 1024 / 2, 1024 / 2);
|
player = new Player(1280 - 1024 + 1024 / 2, 1024 / 2);
|
||||||
stroke = new BasicStroke(sizeOfEnemy, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
|
stroke = new BasicStroke(sizeOfEnemy, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
|
||||||
@@ -65,20 +60,23 @@ public class PlayState extends GameState {
|
|||||||
@Override
|
@Override
|
||||||
public void init() {
|
public void init() {
|
||||||
init = true;
|
init = true;
|
||||||
|
won = false;
|
||||||
|
lifePoints = 100;
|
||||||
currentScore = 0;
|
currentScore = 0;
|
||||||
|
comboScore = 0;
|
||||||
oldProgress = 0;
|
oldProgress = 0;
|
||||||
|
|
||||||
enemies_hit = 0;
|
enemies_hit = 0;
|
||||||
enemies_missed = 0;
|
enemies_missed = 0;
|
||||||
buttons_pressed = 0;
|
buttons_pressed = 0;
|
||||||
joystick_moved = 0;
|
joystick_moved = 0;
|
||||||
|
Highscore h = sql.getHighscore(sh.getCurrentSong(), sh.getCurrentSongInstance());
|
||||||
|
if(h != null)
|
||||||
|
infoPanel.init(h.getScore());
|
||||||
|
|
||||||
for(Path p : area.paths)
|
for(Path p : area.paths)
|
||||||
|
{
|
||||||
p.getEnemysInPath().clear();
|
p.getEnemysInPath().clear();
|
||||||
|
|
||||||
for (int i = 1; i < ButtonHandler.getButtons().size(); i++) {
|
|
||||||
Button b = ButtonHandler.getButton(i);
|
|
||||||
b.setColor(Color.BLACK);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ButtonHandler.getButton(1).setColor(sh.getCurrentSongInstance().getButtons().get(0).getColor());
|
ButtonHandler.getButton(1).setColor(sh.getCurrentSongInstance().getButtons().get(0).getColor());
|
||||||
@@ -92,11 +90,6 @@ public class PlayState extends GameState {
|
|||||||
if(init)
|
if(init)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!prestateShown) {
|
|
||||||
gsm.setState(control.GameStateManager.State.PRE_GAME_STATE);
|
|
||||||
prestateShown = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
long progress = (long) ((sh.getProgress() / 1000) + (Enemy.secondsToEnd * 1000));
|
long progress = (long) ((sh.getProgress() / 1000) + (Enemy.secondsToEnd * 1000));
|
||||||
|
|
||||||
for (ButtonInstance bu : sh.getCurrentSongInstance().getButtonsBetween(oldProgress, progress)) {
|
for (ButtonInstance bu : sh.getCurrentSongInstance().getButtonsBetween(oldProgress, progress)) {
|
||||||
@@ -110,69 +103,73 @@ public class PlayState extends GameState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(progress > sh.getCurrentSongInstance().getEndTime() + Enemy.secondsToEnd*1000*2)
|
if(progress > sh.getCurrentSongInstance().getEndTime() + Enemy.secondsToEnd*2500){
|
||||||
|
won = true;
|
||||||
endGame();
|
endGame();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
oldProgress = progress;
|
oldProgress = progress;
|
||||||
|
|
||||||
Enemy closedEnemy = null;
|
Enemy closedEnemy = null;
|
||||||
player.update(factor);
|
player.update(factor);
|
||||||
|
|
||||||
for (Path path : area.paths) {
|
for (Path path : area.paths) {
|
||||||
|
|
||||||
Iterator<Enemy> enemyIterator = path.getEnemysInPath().iterator();
|
Iterator<Enemy> enemyIterator = path.getEnemysInPath().iterator();
|
||||||
|
|
||||||
while (enemyIterator.hasNext()) {
|
while (enemyIterator.hasNext()) {
|
||||||
|
|
||||||
Enemy e = enemyIterator.next();
|
Enemy e = enemyIterator.next();
|
||||||
if (e.getDistanceFromStart() > Enemy.distanceToOctagon + (sizeOfEnemy * 1.5)) {
|
if (e.getDistanceFromStart() > Enemy.distanceToOctagon + (sizeOfEnemy * 1.5)) {
|
||||||
enemyIterator.remove();
|
enemyIterator.remove();
|
||||||
lastScoreChange = -5;
|
lifePoints -= 6;
|
||||||
lifePoints -= lastScoreChange;
|
comboScore /= 2;
|
||||||
sinceScoreChanged = 1;
|
|
||||||
comboMulitplier = 0;
|
|
||||||
enemies_missed++;
|
enemies_missed++;
|
||||||
}
|
}
|
||||||
if(closedEnemy == null)
|
if(closedEnemy == null){
|
||||||
closedEnemy = e;
|
closedEnemy = e;
|
||||||
if((Enemy.distanceToOctagon-closedEnemy.getDistanceFromStart()) > (Enemy.distanceToOctagon-e.getDistanceFromStart()))
|
}
|
||||||
|
if((Enemy.distanceToOctagon-closedEnemy.getDistanceFromStart()) > (Enemy.distanceToOctagon-e.getDistanceFromStart())){
|
||||||
closedEnemy = e;
|
closedEnemy = e;
|
||||||
|
}
|
||||||
e.update(factor);
|
e.update(factor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lifePoints -= 0.002 * factor;
|
lifePoints -= 0.003 * factor;
|
||||||
|
|
||||||
infoPanel.updateIPanel();
|
infoPanel.updateIPanel();
|
||||||
|
|
||||||
if(lifePoints <= 0) // STERF!
|
if(lifePoints <= 0)
|
||||||
|
{
|
||||||
endGame();
|
endGame();
|
||||||
|
}
|
||||||
if(comboMulitplier >= 20) { // '20' hit streak voor bonuspunten
|
if(comboScore >= 100)
|
||||||
comboMulitplier = 0;
|
{
|
||||||
sinceScoreChanged = 1;
|
comboScore = 0;
|
||||||
lastScoreChange = 500;
|
currentScore += 500;
|
||||||
currentScore += lastScoreChange;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
area.count();
|
|
||||||
if(closedEnemy == null)
|
|
||||||
area.pathPainted(-1, null);
|
|
||||||
else
|
|
||||||
area.pathPainted(closedEnemy.getIndex(), closedEnemy.getColor());
|
|
||||||
|
|
||||||
|
area.count();
|
||||||
|
if(closedEnemy == null){
|
||||||
|
area.pathPainted(-1, null);
|
||||||
|
}else{
|
||||||
|
area.pathPainted(closedEnemy.getIndex(), closedEnemy.getColor());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void endGame() {
|
private void endGame() {
|
||||||
if(sh.getProgress()/1000 > 5000) {
|
if(sh.getProgress()/1000 > 5000)
|
||||||
|
{
|
||||||
sql.addPlaydata(sh.getCurrentSong(), sh.getCurrentSongInstance(), sh.getProgress()/1000, enemies_missed, enemies_hit, buttons_pressed, joystick_moved);
|
sql.addPlaydata(sh.getCurrentSong(), sh.getCurrentSongInstance(), sh.getProgress()/1000, enemies_missed, enemies_hit, buttons_pressed, joystick_moved);
|
||||||
sh.getCurrentSongInstance().played();
|
sh.getCurrentSongInstance().played();
|
||||||
}
|
}
|
||||||
|
|
||||||
comboMulitplier = 0;
|
|
||||||
prestateShown = false;
|
|
||||||
|
|
||||||
if(currentScore == 0)
|
if(currentScore == 0)
|
||||||
gsm.setState(State.MENU_STATE);
|
gsm.setState(State.MENU_STATE);
|
||||||
else
|
else
|
||||||
gsm.setState(State.GAMEOVER_STATE);
|
gsm.setState(State.END_STATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -181,7 +178,6 @@ public class PlayState extends GameState {
|
|||||||
infoPanel.draw(g2);
|
infoPanel.draw(g2);
|
||||||
g2.setClip(borderRect);
|
g2.setClip(borderRect);
|
||||||
area.draw(g2);
|
area.draw(g2);
|
||||||
sinceScoreChanged++;
|
|
||||||
|
|
||||||
for (Path p : area.paths) {
|
for (Path p : area.paths) {
|
||||||
if (p.getEnemysInPath() != null) {
|
if (p.getEnemysInPath() != null) {
|
||||||
@@ -193,23 +189,11 @@ public class PlayState extends GameState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player != null)
|
if (player != null)
|
||||||
player.draw(g2);
|
player.draw(g2);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
if(!Window.ON_RASP){
|
|
||||||
int width,height;
|
|
||||||
height = g2.getFontMetrics().getHeight();
|
|
||||||
for (int i = 1; i < ButtonHandler.getButtons().size(); i++) {
|
|
||||||
Ellipse2D oval = new Ellipse2D.Double(880+(50*i), 0, 50, 50);
|
|
||||||
g2.setColor(ButtonHandler.getButton(i).getColor());
|
|
||||||
g2.fill(oval);
|
|
||||||
g2.setColor(Color.BLACK);
|
|
||||||
width = g2.getFontMetrics().stringWidth(""+i);
|
|
||||||
g2.drawString(""+i, (int)oval.getCenterX()-width/2,(int)oval.getMaxY()+height);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -220,32 +204,34 @@ public class PlayState extends GameState {
|
|||||||
Enemy enemy = enemysInPath.next();
|
Enemy enemy = enemysInPath.next();
|
||||||
if (enemy.getDistanceFromStart() > Enemy.distanceToOctagon || enemy.getDistanceFromStart() > Enemy.distanceToOctagon + sizeOfEnemy) {
|
if (enemy.getDistanceFromStart() > Enemy.distanceToOctagon || enemy.getDistanceFromStart() > Enemy.distanceToOctagon + sizeOfEnemy) {
|
||||||
if (e.getButton().getColor().equals(enemy.getColor())) {
|
if (e.getButton().getColor().equals(enemy.getColor())) {
|
||||||
comboMulitplier++;
|
currentScore += enemy.getDistanceFromStart() - Enemy.distanceToOctagon;
|
||||||
lastScoreChange = 5 * comboMulitplier;
|
comboScore += 5;
|
||||||
currentScore += lastScoreChange;
|
lifePoints = Math.min(lifePoints+8, 100);
|
||||||
sinceScoreChanged = 1;
|
|
||||||
area.enemyDied((Point2D.Double) enemy.getEnemy().getP1());
|
|
||||||
lifePoints = Math.min(lifePoints+10, 100);
|
|
||||||
area.setHitAreaColor(enemy.getColor());
|
area.setHitAreaColor(enemy.getColor());
|
||||||
area.hit();
|
area.hit();
|
||||||
enemies_hit++;
|
enemies_hit++;
|
||||||
enemysInPath.remove();
|
enemysInPath.remove();
|
||||||
notHit = false;
|
notHit = false;
|
||||||
infoPanel.throwACoin(); // Coin Animatie starten bij hit
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
player.setBeat();
|
player.setBeat();
|
||||||
|
|
||||||
if(notHit) {
|
if(notHit)
|
||||||
|
{
|
||||||
if(area.paths.get(player.getIndex()).getEnemysInPath().size() > 0)
|
if(area.paths.get(player.getIndex()).getEnemysInPath().size() > 0)
|
||||||
|
{
|
||||||
lifePoints -= 1.5;
|
lifePoints -= 1.5;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(e.getButton().getButtonID() == 0)
|
if(e.getButton().getButtonID() == 0)
|
||||||
|
{
|
||||||
endGame();
|
endGame();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
buttons_pressed++;
|
buttons_pressed++;
|
||||||
}
|
}
|
||||||
@@ -294,4 +280,8 @@ public class PlayState extends GameState {
|
|||||||
Enemy e = new Enemy(pathID, 1, color, path);
|
Enemy e = new Enemy(pathID, 1, color, path);
|
||||||
path.getEnemysInPath().addLast(e);
|
path.getEnemysInPath().addLast(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean won(){
|
||||||
|
return won;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package model.gameState;
|
package model.gameState;
|
||||||
|
|
||||||
import data.io.SQLConnector;
|
|
||||||
import image.Images;
|
import image.Images;
|
||||||
|
|
||||||
import java.awt.BasicStroke;
|
import java.awt.BasicStroke;
|
||||||
@@ -9,44 +8,38 @@ import java.awt.Font;
|
|||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
|
||||||
import model.SongHandler;
|
|
||||||
import control.GameStateManager;
|
import control.GameStateManager;
|
||||||
|
import control.SongHandler;
|
||||||
import control.button.ButtonEvent;
|
import control.button.ButtonEvent;
|
||||||
import control.joystick.JoystickEvent;
|
import control.joystick.JoystickEvent;
|
||||||
|
import data.io.SQLConnector;
|
||||||
|
|
||||||
public class PreGameState extends GameState {
|
public class PreGameState extends GameState {
|
||||||
|
|
||||||
private double index2 = 3,
|
double index2 = 3;
|
||||||
index = 3;
|
double index = 3;
|
||||||
|
int grootte = 150;
|
||||||
|
BasicStroke s = new BasicStroke(20);
|
||||||
|
|
||||||
private int grootte = 150;
|
BufferedImage screenshot;
|
||||||
|
|
||||||
private SQLConnector sql;
|
|
||||||
|
|
||||||
private BasicStroke s = new BasicStroke(20);
|
|
||||||
|
|
||||||
private BufferedImage screenshot;
|
|
||||||
|
|
||||||
public PreGameState(GameStateManager gsm, SongHandler sh, SQLConnector sql) {
|
public PreGameState(GameStateManager gsm, SongHandler sh, SQLConnector sql) {
|
||||||
super(gsm, sh, sql);
|
super(gsm, sh, sql);
|
||||||
this.sql = sql;
|
|
||||||
screenshot = Images.getImage(Images.ImageType.screenshot);
|
screenshot = Images.getImage(Images.ImageType.screenshot);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() {
|
public void init() {
|
||||||
|
grootte = 150;
|
||||||
|
index = 3;
|
||||||
|
index2 = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(float factor) {
|
public void update(float factor) {
|
||||||
|
|
||||||
index2 -= factor/1000;
|
index2 -= factor/1000;
|
||||||
index = (double) Math.round(index2*1000)/1000;
|
index = (double) Math.round(index2*1000)/1000;
|
||||||
if(index <= 0){
|
if(index <= 0){
|
||||||
grootte = 150;
|
|
||||||
index = 3;
|
|
||||||
index2 = 3;
|
|
||||||
gsm.setState(control.GameStateManager.State.PLAY_STATE);
|
gsm.setState(control.GameStateManager.State.PLAY_STATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ import java.awt.Transparency;
|
|||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.awt.image.VolatileImage;
|
import java.awt.image.VolatileImage;
|
||||||
|
|
||||||
import model.SongHandler;
|
|
||||||
import control.GameStateManager;
|
import control.GameStateManager;
|
||||||
|
import control.SongHandler;
|
||||||
import control.GameStateManager.State;
|
import control.GameStateManager.State;
|
||||||
import control.button.ButtonEvent;
|
import control.button.ButtonEvent;
|
||||||
import control.joystick.JoystickEvent;
|
import control.joystick.JoystickEvent;
|
||||||
@@ -21,54 +21,65 @@ import data.io.SQLConnector;
|
|||||||
|
|
||||||
public class TitleState extends GameState {
|
public class TitleState extends GameState {
|
||||||
|
|
||||||
private BufferedImage pressStart = Images.getImage(ImageType.pressstart),
|
BufferedImage pressStart = Images.getImage(ImageType.pressstart);
|
||||||
colorStrike = Images.getImage(ImageType.colorstrike),
|
BufferedImage colorStrike = Images.getImage(ImageType.colorstrike);
|
||||||
kast = Images.getImage(ImageType.kast);
|
BufferedImage kast = Images.getImage(ImageType.kast);
|
||||||
private VolatileImage background;
|
VolatileImage background;
|
||||||
|
Font textFont = new Font("OCR A Extended", Font.BOLD, 15);
|
||||||
private Font textFont = new Font("OCR A Extended", Font.BOLD, 15),
|
Font textFont2 = new Font("OCR A Extended", Font.BOLD, 130);
|
||||||
textFont2 = new Font("OCR A Extended", Font.BOLD, 130);
|
GradientPaint gp = new GradientPaint(300, 0, new Color(0, 0, 1, 0.6f), 980, 1024, new Color(0, 0, 1, 0.2f));
|
||||||
|
|
||||||
private GradientPaint gp = new GradientPaint(300, 0, new Color(0, 0, 1, 0.6f), 980, 1024, new Color(0, 0, 1, 0.2f));
|
|
||||||
|
|
||||||
|
|
||||||
private int index = 0,
|
int index = 0;
|
||||||
varx = 0,
|
int varx = 0;
|
||||||
indexKast = 0,
|
|
||||||
xKast = 0,
|
int frame = 0;
|
||||||
frame;
|
int image_x = 0;
|
||||||
|
|
||||||
|
|
||||||
|
int indexKast = 0;
|
||||||
|
int xKast=0;
|
||||||
|
|
||||||
public TitleState(GameStateManager gsm, SongHandler sh, SQLConnector sql){
|
public TitleState(GameStateManager gsm, SongHandler sh, SQLConnector sql){
|
||||||
super(gsm, sh, sql);
|
super(gsm, sh, sql);
|
||||||
|
if(!sh.isPlaying())
|
||||||
|
sh.play();
|
||||||
createBackground();
|
createBackground();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() {
|
public void init() {
|
||||||
|
if(!sh.isPlaying())
|
||||||
sh.play();
|
sh.play();
|
||||||
|
|
||||||
|
frame = 0;
|
||||||
|
image_x = 0;
|
||||||
|
|
||||||
|
indexKast = 0;
|
||||||
|
xKast = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(float factor) {
|
public void update(float factor) {
|
||||||
|
image_x = ((frame / 6) % 6) * 49;
|
||||||
frame++;
|
frame++;
|
||||||
|
|
||||||
indexKast++;
|
indexKast++;
|
||||||
}
|
|
||||||
|
|
||||||
public void draw(Graphics2D g2) {
|
|
||||||
// Scherm beelt wat kleurrijke rectangles op het scherm.
|
|
||||||
if (frame > 0) {
|
|
||||||
g2.drawImage(background, 0, 0, 1280, 1024, null);
|
|
||||||
createBackground();
|
|
||||||
}
|
|
||||||
if (frame > 160) {
|
|
||||||
// Code die de arcadekast en 'Press Start' toont.
|
|
||||||
int image_x = ((frame / 6) % 6) * 49;
|
|
||||||
g2.drawImage(pressStart.getSubimage(image_x, 0, 49, 26), 640 - 122, 512, 245, 130, null);
|
|
||||||
|
|
||||||
xKast = indexKast/10;
|
xKast = indexKast/10;
|
||||||
xKast%=4;
|
xKast%=4;
|
||||||
g2.drawImage(kast.getSubimage(xKast * 300, 0, 300, 400), 100, 300, 300, 400, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw(Graphics2D g2) {
|
||||||
|
g2.drawImage(background, 0, 0, 1280, 1024, null);
|
||||||
|
|
||||||
|
g2.drawImage(pressStart.getSubimage(image_x, 0, 49, 26), 640-122, 512, 245, 130, null);
|
||||||
|
|
||||||
|
g2.drawImage(kast.getSubimage(xKast*600,0,600,800), 490,624,300,400,null);
|
||||||
|
|
||||||
|
g2.setFont(textFont);
|
||||||
|
g2.setColor(Color.WHITE);
|
||||||
|
g2.drawString("©2015 Team Hamtaro", 550, 1012);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -79,6 +90,7 @@ public class TitleState extends GameState {
|
|||||||
gsm.setState(State.MENU_STATE);
|
gsm.setState(State.MENU_STATE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -93,47 +105,31 @@ public class TitleState extends GameState {
|
|||||||
public void createBackground() {
|
public void createBackground() {
|
||||||
background = Images.initVolatileImage(1280, 1024, Transparency.OPAQUE);
|
background = Images.initVolatileImage(1280, 1024, Transparency.OPAQUE);
|
||||||
Graphics2D g2 = background.createGraphics();
|
Graphics2D g2 = background.createGraphics();
|
||||||
|
|
||||||
if (frame > 0) {
|
|
||||||
RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||||
g2.setRenderingHints(rh);
|
g2.setRenderingHints(rh);
|
||||||
}
|
|
||||||
if (frame > 20) {
|
|
||||||
g2.setColor(new Color(1, 1, 1, 0.3f));
|
g2.setColor(new Color(1, 1, 1, 0.3f));
|
||||||
g2.fillRect(0, 0, 1280, 1024);
|
g2.fillRect(0, 0, 1280, 1024);
|
||||||
}
|
|
||||||
if (frame > 40) {
|
|
||||||
g2.setColor(new Color(0, 1, 0, 0.7f));
|
g2.setColor(new Color(0, 1, 0, 0.7f));
|
||||||
g2.fillRect(0, 0, 100, 1024);
|
g2.fillRect(0, 0, 100, 1024);
|
||||||
g2.fillRect(1180, 0, 100, 1024);
|
g2.fillRect(1180, 0, 100, 1024);
|
||||||
}
|
|
||||||
if (frame > 60) {
|
|
||||||
g2.setColor(new Color(1, 1, 0, 0.7f));
|
g2.setColor(new Color(1, 1, 0, 0.7f));
|
||||||
g2.fillRect(100, 0, 100, 1024);
|
g2.fillRect(100, 0, 100, 1024);
|
||||||
g2.fillRect(1080, 0, 100, 1024);
|
g2.fillRect(1080, 0, 100, 1024);
|
||||||
}
|
|
||||||
if (frame > 80) {
|
|
||||||
g2.setColor(new Color(1, 0, 0, 0.7f));
|
g2.setColor(new Color(1, 0, 0, 0.7f));
|
||||||
g2.fillRect(200, 0, 100, 1024);
|
g2.fillRect(200, 0, 100, 1024);
|
||||||
g2.fillRect(980, 0, 100, 1024);
|
g2.fillRect(980, 0, 100, 1024);
|
||||||
}
|
|
||||||
if (frame > 100) {
|
|
||||||
g2.setPaint(gp);
|
g2.setPaint(gp);
|
||||||
g2.fillRect(300, 0, 680, 1024);
|
g2.fillRect(300, 0, 680, 1024);
|
||||||
}
|
|
||||||
if (frame > 120) {
|
|
||||||
g2.setFont(textFont);
|
|
||||||
g2.setColor(Color.WHITE);
|
|
||||||
g2.drawString("©2015 Team Hamtaro", 550, 1012);
|
|
||||||
}
|
|
||||||
if (frame > 140) {
|
|
||||||
g2.setColor(Color.RED);
|
g2.setColor(Color.RED);
|
||||||
g2.setFont(textFont2);
|
g2.setFont(textFont2);
|
||||||
g2.drawString("Color", 385, 212);
|
g2.drawString("Color", 385, 212);
|
||||||
g2.drawString("Strike", 390, 342);
|
g2.drawString("Strike", 390, 342);
|
||||||
g2.dispose();
|
g2.dispose();
|
||||||
}
|
|
||||||
|
|
||||||
background.createGraphics();
|
background.createGraphics();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,11 +27,14 @@ public class DifficultyButton {
|
|||||||
button = Images.initVolatileImage(305, 80, Transparency.OPAQUE);
|
button = Images.initVolatileImage(305, 80, Transparency.OPAQUE);
|
||||||
Graphics2D g2 = button.createGraphics();
|
Graphics2D g2 = button.createGraphics();
|
||||||
g2.setColor(Color.WHITE);
|
g2.setColor(Color.WHITE);
|
||||||
g2.fillRect(0, 0, 300, 75);
|
g2.fillRect(0, 0, 305, 80);
|
||||||
g2.setColor(Color.ORANGE);
|
g2.setColor(Color.ORANGE);
|
||||||
g2.drawRect(0, 0, 300, 75);
|
g2.drawRect(0, 0, 304, 79);
|
||||||
|
g2.drawRect(2, 2, 300, 75);
|
||||||
|
// g2.drawRect(0, 0, 300, 75);
|
||||||
// g2.drawRect(0-2, 0-2, 304, 79);
|
// g2.drawRect(0-2, 0-2, 304, 79);
|
||||||
|
g2.drawRect(0, 0, 304, 79);
|
||||||
|
g2.drawRect(2, 2, 300, 75);
|
||||||
g2.setColor(color);
|
g2.setColor(color);
|
||||||
Font textFont2 = new Font("OCR A Extended", Font.BOLD, 50);
|
Font textFont2 = new Font("OCR A Extended", Font.BOLD, 50);
|
||||||
g2.setFont(textFont2);
|
g2.setFont(textFont2);
|
||||||
|
|||||||
@@ -2,41 +2,44 @@ package model.objects;
|
|||||||
|
|
||||||
import image.Images;
|
import image.Images;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.Color;
|
||||||
import java.awt.geom.Point2D;
|
import java.awt.Font;
|
||||||
|
import java.awt.GradientPaint;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.RenderingHints;
|
||||||
|
import java.awt.Transparency;
|
||||||
|
import java.awt.geom.Ellipse2D;
|
||||||
import java.awt.image.VolatileImage;
|
import java.awt.image.VolatileImage;
|
||||||
|
|
||||||
import model.SongHandler;
|
|
||||||
import model.drawObjects.CoinAnimation;
|
|
||||||
import model.drawObjects.PointAnimation;
|
|
||||||
import model.gameState.PlayState;
|
import model.gameState.PlayState;
|
||||||
|
import control.SongHandler;
|
||||||
|
import control.button.ButtonHandler;
|
||||||
|
|
||||||
public class InfoPanel {
|
public class InfoPanel {
|
||||||
|
|
||||||
private static String totalHighscore = "000000";
|
private static String totalHighscore = "000000";
|
||||||
private int x, y;
|
|
||||||
private VolatileImage infoPanel;
|
private VolatileImage infoPanel;
|
||||||
private SongHandler sh;
|
private SongHandler sh;
|
||||||
private String time;
|
private String time;
|
||||||
|
private int highscore = 0;
|
||||||
|
|
||||||
private int tempComboMulitplier;
|
public InfoPanel(SongHandler sh){
|
||||||
|
|
||||||
private CoinAnimation coinAnimation = new CoinAnimation(125, 300);
|
|
||||||
|
|
||||||
|
|
||||||
public InfoPanel(int x, int y, SongHandler sh){
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
this.sh = sh;
|
this.sh = sh;
|
||||||
updateIPanel();
|
updateIPanel();
|
||||||
generateInfoPanel();
|
generateInfoPanel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void init(int highscore)
|
||||||
|
{
|
||||||
|
this.highscore = highscore;
|
||||||
|
updateIPanel();
|
||||||
|
generateInfoPanel();
|
||||||
|
}
|
||||||
public void updateIPanel() {
|
public void updateIPanel() {
|
||||||
totalHighscore = "" + PlayState.currentScore;
|
totalHighscore = "" + PlayState.currentScore;
|
||||||
|
|
||||||
long progress = (sh.getProgress() / 1000);
|
long progress = (sh.getProgress() / 1000);
|
||||||
String millis = ((progress) % 1000) + "".length() > 3 ? ("" +((progress) % 1000)).substring(0, 2) : "" + ((progress) % 1000);
|
String millis = (((progress) % 1000) + "").length() > 3 ? ("" +((progress) % 1000)).substring(0, 2) : "" + ((progress) % 1000);
|
||||||
String second = ((progress / 1000) % 60 + "").length() <= 1 ? "0" +((progress / 1000) % 60) : "" + ((progress / 1000) % 60);
|
String second = ((progress / 1000) % 60 + "").length() <= 1 ? "0" +((progress / 1000) % 60) : "" + ((progress / 1000) % 60);
|
||||||
String minute = ((progress / (1000 * 60)) % 60 + "").length() <= 1 ? "0" +((progress / (1000 * 60)) % 60) : "" + ((progress / (1000 * 60)) % 60);
|
String minute = ((progress / (1000 * 60)) % 60 + "").length() <= 1 ? "0" +((progress / (1000 * 60)) % 60) : "" + ((progress / (1000 * 60)) % 60);
|
||||||
time = minute + ":" + second + ":" + millis;
|
time = minute + ":" + second + ":" + millis;
|
||||||
@@ -48,66 +51,76 @@ public class InfoPanel {
|
|||||||
Graphics2D g2 = infoPanel.createGraphics();
|
Graphics2D g2 = infoPanel.createGraphics();
|
||||||
RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||||
g2.setRenderingHints(rh);
|
g2.setRenderingHints(rh);
|
||||||
g2.setColor(Color.BLACK);
|
|
||||||
|
|
||||||
// g2.setColor(Color.GRAY);
|
|
||||||
GradientPaint gp = new GradientPaint(0, 0, new Color(245,245,245), 256, 1024, Color.WHITE);
|
GradientPaint gp = new GradientPaint(0, 0, new Color(245,245,245), 256, 1024, Color.WHITE);
|
||||||
g2.setPaint(gp);
|
g2.setPaint(gp);
|
||||||
g2.fillRect(x, y, 256, 1024);
|
|
||||||
|
|
||||||
// Score balk
|
|
||||||
g2.setColor(Color.BLACK);
|
|
||||||
g2.drawRect(x, y, 255, 1023);
|
|
||||||
|
|
||||||
Font scoreFont = new Font("OCR A Extended", Font.BOLD, 30);
|
|
||||||
g2.setFont(scoreFont);
|
|
||||||
g2.setColor(Color.GREEN);
|
g2.setColor(Color.GREEN);
|
||||||
g2.fillRect(25, 100, (int)(2 * PlayState.lifePoints), 30);
|
g2.fillRect(25, 900, (int)(2 * PlayState.lifePoints), 30);
|
||||||
|
|
||||||
// Laatste punten in-/decrease tonen.
|
|
||||||
if (PlayState.sinceScoreChanged < 60 && PlayState.sinceScoreChanged != 0) {
|
|
||||||
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float)(1 - (PlayState.sinceScoreChanged * 0.015))));
|
|
||||||
g2.setColor(Color.RED);
|
|
||||||
g2.drawString("+" + PlayState.lastScoreChange, 185, 40);
|
|
||||||
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f));
|
|
||||||
}
|
|
||||||
|
|
||||||
g2.setColor(Color.ORANGE);
|
|
||||||
g2.drawString("Score: " + totalHighscore, 25, 75);
|
|
||||||
|
|
||||||
g2.setColor(Color.BLACK);
|
|
||||||
// BALK
|
|
||||||
g2.drawRect(25, 100, 200, 30);
|
|
||||||
g2.drawRect(25, 300, 200, 700);
|
|
||||||
|
|
||||||
g2.drawString(sh.getCurrentSong().getTitle(), 25, 200);
|
|
||||||
g2.drawString(sh.getCurrentSongInstance().getDifficulty(), 25, 230);
|
|
||||||
g2.drawString(sh.getCurrentSong().getAuthor(), 25, 260);
|
|
||||||
g2.drawString(time, 25, 290);
|
|
||||||
|
|
||||||
// Controlen of coin animatie nodig is
|
|
||||||
if (!coinAnimation.areWeDoneYet()) {
|
|
||||||
coinAnimation.draw(g2);
|
|
||||||
// Score pas updaten wanneer coin in zijn laatste draw loop zit
|
|
||||||
if (coinAnimation.isLastLoop())
|
|
||||||
tempComboMulitplier = PlayState.comboMulitplier;
|
|
||||||
} else
|
|
||||||
tempComboMulitplier = PlayState.comboMulitplier;
|
|
||||||
|
|
||||||
g2.drawString(sh.getCurrentSongInstance().getDifficulty(), 25, 230);
|
|
||||||
g2.drawString(sh.getCurrentSong().getAuthor(), 25, 260);
|
|
||||||
g2.drawString(time, 25, 290);
|
|
||||||
|
|
||||||
g2.setColor(Color.YELLOW);
|
g2.setColor(Color.YELLOW);
|
||||||
g2.fillRect(25, 1000 - tempComboMulitplier * 35, 200, 35 * tempComboMulitplier);
|
g2.fillRect(25, 950, (int)(2 * PlayState.comboScore), 30);
|
||||||
|
|
||||||
|
g2.setColor(Color.BLACK);
|
||||||
|
|
||||||
|
g2.drawRect(25, 900, 200, 30);
|
||||||
|
g2.drawRect(25, 950, 200, 30);
|
||||||
|
|
||||||
|
Font scoreFont = new Font("OCR A Extended", Font.BOLD, 35);
|
||||||
|
g2.setFont(scoreFont);
|
||||||
|
g2.drawString("Score: ", 25, 75);
|
||||||
|
|
||||||
|
g2.drawString(sh.getCurrentSong().getTitle(), 25, 215);
|
||||||
|
g2.drawString(sh.getCurrentSongInstance().getDifficulty(), 25, 295);
|
||||||
|
g2.drawString(time, 25, 375);
|
||||||
|
g2.drawString("" + highscore, 25, 455);
|
||||||
|
|
||||||
|
Font scoreFont2 = new Font("OCR A Extended", Font.BOLD, 25);
|
||||||
|
g2.setFont(scoreFont2);
|
||||||
|
g2.drawString("Title: ", 25, 185);
|
||||||
|
g2.drawString("Difficulty: ", 25, 265);
|
||||||
|
g2.drawString("Time: ", 25, 345);
|
||||||
|
g2.drawString("Best: ", 25, 425);
|
||||||
|
|
||||||
|
|
||||||
|
Font scoreFont3 = new Font("OCR A Extended", Font.BOLD, 45);
|
||||||
|
g2.setFont(scoreFont3);
|
||||||
|
g2.drawString("" + totalHighscore, 25, 115);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Ellipse2D oval1 = new Ellipse2D.Double(25, 700, 50, 50);
|
||||||
|
g2.setColor(ButtonHandler.getButton(1).getColor());
|
||||||
|
g2.fill(oval1);
|
||||||
|
|
||||||
|
Ellipse2D oval2 = new Ellipse2D.Double(85, 700, 50, 50);
|
||||||
|
g2.setColor(ButtonHandler.getButton(2).getColor());
|
||||||
|
g2.fill(oval2);
|
||||||
|
|
||||||
|
Ellipse2D oval3 = new Ellipse2D.Double(145, 700, 50, 50);
|
||||||
|
g2.setColor(ButtonHandler.getButton(3).getColor());
|
||||||
|
g2.fill(oval3);
|
||||||
|
|
||||||
|
Ellipse2D oval4 = new Ellipse2D.Double(50, 760, 50, 50);
|
||||||
|
g2.setColor(ButtonHandler.getButton(4).getColor());
|
||||||
|
g2.fill(oval4);
|
||||||
|
|
||||||
|
Ellipse2D oval5 = new Ellipse2D.Double(110, 760, 50, 50);
|
||||||
|
g2.setColor(ButtonHandler.getButton(5).getColor());
|
||||||
|
g2.fill(oval5);
|
||||||
|
|
||||||
|
Ellipse2D oval6 = new Ellipse2D.Double(170, 760, 50, 50);
|
||||||
|
g2.setColor(ButtonHandler.getButton(6).getColor());
|
||||||
|
g2.fill(oval6);
|
||||||
|
|
||||||
g2.dispose();
|
g2.dispose();
|
||||||
infoPanel.createGraphics();
|
infoPanel.createGraphics();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void throwACoin() {
|
|
||||||
coinAnimation.start(); // Teller weer op 1 zetten
|
|
||||||
}
|
|
||||||
|
|
||||||
public void draw(Graphics2D g2){
|
public void draw(Graphics2D g2){
|
||||||
g2.drawImage(infoPanel, 0, 0, 256,1024,null);
|
g2.drawImage(infoPanel, 0, 0, 256,1024,null);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,17 +2,21 @@ package model.objects;
|
|||||||
|
|
||||||
import image.Images;
|
import image.Images;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.BasicStroke;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Polygon;
|
||||||
|
import java.awt.RenderingHints;
|
||||||
|
import java.awt.Stroke;
|
||||||
|
import java.awt.Transparency;
|
||||||
import java.awt.geom.GeneralPath;
|
import java.awt.geom.GeneralPath;
|
||||||
import java.awt.geom.Line2D;
|
import java.awt.geom.Line2D;
|
||||||
import java.awt.geom.Point2D;
|
|
||||||
import java.awt.geom.Rectangle2D;
|
import java.awt.geom.Rectangle2D;
|
||||||
import java.awt.image.VolatileImage;
|
import java.awt.image.VolatileImage;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import model.drawObjects.Enemy;
|
import model.drawObjects.Enemy;
|
||||||
import model.drawObjects.PointAnimation;
|
|
||||||
import model.gameState.PlayState;
|
import model.gameState.PlayState;
|
||||||
|
|
||||||
public class PlayArea {
|
public class PlayArea {
|
||||||
@@ -23,19 +27,15 @@ public class PlayArea {
|
|||||||
private Color hitAreaColor,pathColor = null;
|
private Color hitAreaColor,pathColor = null;
|
||||||
private VolatileImage background;
|
private VolatileImage background;
|
||||||
private boolean hit = false;
|
private boolean hit = false;
|
||||||
private int count = 0,
|
private int count = 0,maxCount = 100,pathID = -1;
|
||||||
maxCount = 100,
|
private Stroke stroke = new BasicStroke(5,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND);
|
||||||
pathID = -1,
|
|
||||||
oldPathId = pathID;
|
|
||||||
|
|
||||||
private PointAnimation pointAnimation = new PointAnimation();
|
|
||||||
private Stroke stroke = new BasicStroke(5);
|
|
||||||
|
|
||||||
private Rectangle2D backgroundPlay = new Rectangle2D.Double(256, 0, 1024, 1024);
|
private Rectangle2D backgroundPlay = new Rectangle2D.Double(256, 0, 1024, 1024);
|
||||||
|
|
||||||
|
|
||||||
public PlayArea(double xToRight,double heightOfGameScreen,double widthOfGameScreen, int sizeOctagon) {
|
public PlayArea(double xToRight,double heightOfGameScreen,double widthOfGameScreen, int sizeOctagon) {
|
||||||
super();
|
super();
|
||||||
paths = new ArrayList<>();
|
paths = new ArrayList<Path>();
|
||||||
setHitAreaColor(Color.WHITE);
|
setHitAreaColor(Color.WHITE);
|
||||||
//make the polygons
|
//make the polygons
|
||||||
int amountOfAngles = 8;
|
int amountOfAngles = 8;
|
||||||
@@ -61,36 +61,48 @@ public class PlayArea {
|
|||||||
hitArea = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
|
hitArea = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
|
||||||
|
|
||||||
hitArea.moveTo(innerHitAreaBorder.xpoints[0], innerHitAreaBorder.ypoints[0]);
|
hitArea.moveTo(innerHitAreaBorder.xpoints[0], innerHitAreaBorder.ypoints[0]);
|
||||||
for(int i = 1; i < innerHitAreaBorder.npoints;i++)
|
for(int i = 1; i < innerHitAreaBorder.npoints;i++){
|
||||||
hitArea.lineTo(innerHitAreaBorder.xpoints[i], innerHitAreaBorder.ypoints[i]);
|
hitArea.lineTo(innerHitAreaBorder.xpoints[i], innerHitAreaBorder.ypoints[i]);
|
||||||
|
}
|
||||||
|
|
||||||
hitArea.moveTo(outsideHitAreaBorder.xpoints[0], outsideHitAreaBorder.ypoints[0]);
|
hitArea.moveTo(outsideHitAreaBorder.xpoints[0], outsideHitAreaBorder.ypoints[0]);
|
||||||
for(int i = 1; i < innerHitAreaBorder.npoints;i++)
|
for(int i = 1; i < innerHitAreaBorder.npoints;i++){
|
||||||
hitArea.lineTo(outsideHitAreaBorder.xpoints[i], outsideHitAreaBorder.ypoints[i]);
|
hitArea.lineTo(outsideHitAreaBorder.xpoints[i], outsideHitAreaBorder.ypoints[i]);
|
||||||
|
}
|
||||||
|
|
||||||
//make the paths
|
//make the paths
|
||||||
double angleX,angleY;
|
double angleX,angleY;
|
||||||
angleX = (Math.cos(Math.toRadians(45)))*Enemy.distanceToOctagon;
|
angleX = (Math.cos(Math.toRadians(45)))*Enemy.distanceToOctagon;
|
||||||
angleY = (Math.sin(Math.toRadians(45)))*Enemy.distanceToOctagon;
|
angleY = (Math.sin(Math.toRadians(45)))*Enemy.distanceToOctagon;
|
||||||
|
|
||||||
paths.add(new Path(outsideHitAreaBorder.xpoints[6],outsideHitAreaBorder.ypoints[6]-Enemy.distanceToOctagon,
|
paths.add(new Path(outsideHitAreaBorder.xpoints[6],outsideHitAreaBorder.ypoints[6]-Enemy.distanceToOctagon ,outsideHitAreaBorder.xpoints[6],outsideHitAreaBorder.ypoints[6]));//top
|
||||||
outsideHitAreaBorder.xpoints[6],outsideHitAreaBorder.ypoints[6]));//top
|
paths.add(new Path(outsideHitAreaBorder.xpoints[7] + angleX,outsideHitAreaBorder.ypoints[7] - angleY ,outsideHitAreaBorder.xpoints[7],outsideHitAreaBorder.ypoints[7]));//right -top
|
||||||
paths.add(new Path(outsideHitAreaBorder.xpoints[7] + angleX,outsideHitAreaBorder.ypoints[7] - angleY,
|
paths.add(new Path(outsideHitAreaBorder.xpoints[0]+Enemy.distanceToOctagon,outsideHitAreaBorder.ypoints[0] ,outsideHitAreaBorder.xpoints[0],outsideHitAreaBorder.ypoints[0]));//right
|
||||||
outsideHitAreaBorder.xpoints[7],outsideHitAreaBorder.ypoints[7]));//right -top
|
paths.add(new Path(outsideHitAreaBorder.xpoints[1]+angleX,outsideHitAreaBorder.ypoints[1]+angleY ,outsideHitAreaBorder.xpoints[1],outsideHitAreaBorder.ypoints[1]));//right -down
|
||||||
paths.add(new Path(outsideHitAreaBorder.xpoints[0]+Enemy.distanceToOctagon,outsideHitAreaBorder.ypoints[0],
|
paths.add(new Path(outsideHitAreaBorder.xpoints[2],outsideHitAreaBorder.ypoints[2]+Enemy.distanceToOctagon ,outsideHitAreaBorder.xpoints[2],outsideHitAreaBorder.ypoints[2]));//down
|
||||||
outsideHitAreaBorder.xpoints[0],outsideHitAreaBorder.ypoints[0]));//right
|
paths.add(new Path(outsideHitAreaBorder.xpoints[3] - angleX,outsideHitAreaBorder.ypoints[3] + angleY ,outsideHitAreaBorder.xpoints[3],outsideHitAreaBorder.ypoints[3]));//left -down
|
||||||
paths.add(new Path(outsideHitAreaBorder.xpoints[1]+angleX,outsideHitAreaBorder.ypoints[1]+angleY,
|
paths.add(new Path(outsideHitAreaBorder.xpoints[4] - Enemy.distanceToOctagon,outsideHitAreaBorder.ypoints[4] ,outsideHitAreaBorder.xpoints[4],outsideHitAreaBorder.ypoints[4]));//left
|
||||||
outsideHitAreaBorder.xpoints[1],outsideHitAreaBorder.ypoints[1]));//right -down
|
paths.add(new Path(outsideHitAreaBorder.xpoints[5] - angleX,outsideHitAreaBorder.ypoints[5] - angleY ,outsideHitAreaBorder.xpoints[5],outsideHitAreaBorder.ypoints[5]));//left -top
|
||||||
paths.add(new Path(outsideHitAreaBorder.xpoints[2],outsideHitAreaBorder.ypoints[2]+Enemy.distanceToOctagon,
|
|
||||||
outsideHitAreaBorder.xpoints[2],outsideHitAreaBorder.ypoints[2]));//down
|
|
||||||
paths.add(new Path(outsideHitAreaBorder.xpoints[3] - angleX,outsideHitAreaBorder.ypoints[3] + angleY,
|
|
||||||
outsideHitAreaBorder.xpoints[3],outsideHitAreaBorder.ypoints[3]));//left -down
|
|
||||||
paths.add(new Path(outsideHitAreaBorder.xpoints[4] - Enemy.distanceToOctagon,outsideHitAreaBorder.ypoints[4],
|
|
||||||
outsideHitAreaBorder.xpoints[4],outsideHitAreaBorder.ypoints[4]));//left
|
|
||||||
paths.add(new Path(outsideHitAreaBorder.xpoints[5] - angleX,outsideHitAreaBorder.ypoints[5] - angleY,
|
|
||||||
outsideHitAreaBorder.xpoints[5],outsideHitAreaBorder.ypoints[5]));//left -top
|
|
||||||
|
|
||||||
generateBackground();
|
|
||||||
|
//drawing into buffer
|
||||||
|
background = Images.initVolatileImage(1280,1024, Transparency.BITMASK);
|
||||||
|
Graphics2D g2 = background.createGraphics();
|
||||||
|
RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||||
|
g2.setRenderingHints(rh);
|
||||||
|
// g2.setColor(Color.WHITE);
|
||||||
|
// g2.fillRect(256, 0, 1024, 1024);
|
||||||
|
Line2D current;
|
||||||
|
g2.setColor(Color.BLACK);
|
||||||
|
g2.setStroke(stroke);
|
||||||
|
for(int i = 0; i < paths.size(); i++){
|
||||||
|
current = paths.get(i);
|
||||||
|
g2.draw(current);
|
||||||
|
}
|
||||||
|
g2.draw(innerHitAreaBorder);
|
||||||
|
g2.draw(outsideHitAreaBorder);
|
||||||
|
g2.dispose();
|
||||||
|
background.createGraphics();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void draw(Graphics2D g2){
|
public void draw(Graphics2D g2){
|
||||||
@@ -98,29 +110,30 @@ public class PlayArea {
|
|||||||
if(hit){
|
if(hit){
|
||||||
g2.setColor(hitAreaColor);
|
g2.setColor(hitAreaColor);
|
||||||
g2.fill(hitArea);
|
g2.fill(hitArea);
|
||||||
|
if(count == maxCount){
|
||||||
if(count == maxCount)
|
|
||||||
hit = false;
|
hit = false;
|
||||||
}
|
}
|
||||||
if (oldPathId != pathID){
|
|
||||||
generateBackground();
|
|
||||||
oldPathId = pathID;
|
|
||||||
}
|
}
|
||||||
|
if(pathID >= 0 && pathColor != null){
|
||||||
Font scoreFont = new Font("OCR A Extended", Font.BOLD, 40);
|
g2.setColor(new Color(pathColor.getRed(), pathColor.getGreen(), pathColor.getBlue(),50));
|
||||||
g2.setFont(scoreFont);
|
g2.fill(backgroundPlay);
|
||||||
pointAnimation.draw(g2);
|
g2.setStroke(stroke);
|
||||||
|
g2.setColor(pathColor);
|
||||||
|
g2.draw(paths.get(pathID));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Line2D getLine(int index){
|
public Line2D getLine(int index){
|
||||||
if(index < 0)
|
if(index < 0){
|
||||||
index = 0;
|
index = 0;
|
||||||
else if(index >= 8)
|
}
|
||||||
|
if(index >= 8 ){
|
||||||
index = 7;
|
index = 7;
|
||||||
|
}
|
||||||
return paths.get(index);
|
return paths.get(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setHitAreaColor(Color color) {
|
public void setHitAreaColor(Color color) {
|
||||||
hitAreaColor = color;
|
hitAreaColor = color;
|
||||||
count = 0;
|
count = 0;
|
||||||
@@ -133,8 +146,9 @@ public class PlayArea {
|
|||||||
public void count(){
|
public void count(){
|
||||||
if(hit){
|
if(hit){
|
||||||
count += 3;
|
count += 3;
|
||||||
if(count > maxCount)
|
if(count > maxCount){
|
||||||
count = maxCount;
|
count = maxCount;
|
||||||
|
}
|
||||||
hitAreaColor = new Color(hitAreaColor.getRed(),hitAreaColor.getGreen(),hitAreaColor.getBlue(),255-(255*count)/maxCount);
|
hitAreaColor = new Color(hitAreaColor.getRed(),hitAreaColor.getGreen(),hitAreaColor.getBlue(),255-(255*count)/maxCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -143,35 +157,4 @@ public class PlayArea {
|
|||||||
this.pathID = pathID;
|
this.pathID = pathID;
|
||||||
this.pathColor = pathColor;
|
this.pathColor = pathColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void generateBackground(){
|
|
||||||
//drawing into buffer
|
|
||||||
background = Images.initVolatileImage(1280,1024, Transparency.BITMASK);
|
|
||||||
Graphics2D g2 = background.createGraphics();
|
|
||||||
RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
||||||
g2.setRenderingHints(rh);
|
|
||||||
|
|
||||||
Line2D current;
|
|
||||||
g2.setColor(Color.BLACK);
|
|
||||||
g2.setStroke(stroke);
|
|
||||||
|
|
||||||
paths.forEach(path -> {
|
|
||||||
g2.draw(path);
|
|
||||||
});
|
|
||||||
g2.draw(innerHitAreaBorder);
|
|
||||||
g2.draw(outsideHitAreaBorder);
|
|
||||||
|
|
||||||
if(pathID >= 0 && pathColor != null ){
|
|
||||||
g2.setColor(new Color(pathColor.getRed(), pathColor.getGreen(), pathColor.getBlue(),50));
|
|
||||||
g2.fill(backgroundPlay);
|
|
||||||
g2.setStroke(stroke);
|
|
||||||
g2.setColor(pathColor);
|
|
||||||
g2.draw(paths.get(pathID));
|
|
||||||
}
|
|
||||||
|
|
||||||
g2.dispose();
|
|
||||||
background.createGraphics();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void enemyDied(Point2D.Double p) { pointAnimation.enemyDied(p); }
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,9 +12,12 @@ import control.GameStateManager;
|
|||||||
|
|
||||||
public class GameView extends JPanel {
|
public class GameView extends JPanel {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
private static final long serialVersionUID = 1939480784205689618L;
|
private static final long serialVersionUID = 1939480784205689618L;
|
||||||
|
|
||||||
private GameStateManager gsm;
|
GameStateManager gsm;
|
||||||
|
|
||||||
// Font fpsfont = new Font("OCR A Extended", Font.BOLD, 60);
|
// Font fpsfont = new Font("OCR A Extended", Font.BOLD, 60);
|
||||||
|
|
||||||
|
|||||||