Compare commits
8
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
811f778553 | ||
|
|
03dae66c71 | ||
|
|
be274685b5 | ||
|
|
f229153346 | ||
|
|
4a3208c85f | ||
|
|
b4e7a7c213 | ||
|
|
951ff4367e | ||
|
|
c25ae6757d |
@@ -35,15 +35,17 @@ public class AudioPlayer{
|
||||
} catch (JavaLayerException | FileNotFoundException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
Thread thread = new Thread(() -> {
|
||||
while (clip != null){
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if(clip != null){
|
||||
try {
|
||||
clip.play();
|
||||
} catch (JavaLayerException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}});
|
||||
thread.start();
|
||||
}
|
||||
|
||||
@@ -52,13 +54,14 @@ public class AudioPlayer{
|
||||
{
|
||||
clip.close();
|
||||
clip = null;
|
||||
|
||||
try {
|
||||
if(fis != null)
|
||||
fis.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(thread != null && thread.isAlive())
|
||||
thread.stop();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,18 +15,19 @@ import control.joystick.JoystickListener;
|
||||
public class GameControl implements JoystickListener, ButtonListener, ActionListener {
|
||||
|
||||
private long lastTime = System.currentTimeMillis();
|
||||
private GameModel model;
|
||||
private GameView view;
|
||||
private GameStateManager gsm;
|
||||
private Timer update;
|
||||
GameModel model;
|
||||
GameView view;
|
||||
GameStateManager gsm;
|
||||
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.view = view;
|
||||
this.gsm = gsm;
|
||||
|
||||
view.setIgnoreRepaint(true);
|
||||
(update = new Timer(1000/60,this)).start();
|
||||
update = new Timer(1000/60,this);
|
||||
update.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,7 +5,13 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import model.SongHandler;
|
||||
import model.gameState.*;
|
||||
import model.gameState.GameOverState;
|
||||
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.ButtonEvent;
|
||||
import control.button.ButtonHandler;
|
||||
@@ -16,15 +22,11 @@ import data.io.SQLConnector;
|
||||
public class GameStateManager {
|
||||
|
||||
private List<GameState> gamestates;
|
||||
|
||||
public GameState currentState;
|
||||
private SongHandler sh;
|
||||
|
||||
private int index = 0;
|
||||
public int fps;
|
||||
private float timeOfNoAction = 0,
|
||||
maxTimeToHaveNoAction = 45000;
|
||||
|
||||
public GameState currentState;
|
||||
private int index = 0;
|
||||
public int fps;
|
||||
private float timeOfNoAction = 0,maxTimeToHaveNoAction = 45000;
|
||||
|
||||
public enum State {
|
||||
TITLE_STATE,
|
||||
MENU_STATE,
|
||||
@@ -35,25 +37,30 @@ public class GameStateManager {
|
||||
}
|
||||
|
||||
public GameStateManager(SongHandler sh, SQLConnector sql){
|
||||
this.sh = sh;
|
||||
gamestates = new ArrayList<>();
|
||||
gamestates = new ArrayList<GameState>();
|
||||
gamestates.add(new TitleState(this, sh, sql));
|
||||
gamestates.add(new MenuState(this, sh, sql));
|
||||
gamestates.add(new HelpState(this, sh, sql));
|
||||
gamestates.add(new PlayState(this, sh, sql));
|
||||
gamestates.add(new GameOverState(this, sh, sql));
|
||||
gamestates.add(new PreGameState(this, sh, sql));
|
||||
gamestates.add(new PreGameState(this,sh, sql));
|
||||
setState(State.TITLE_STATE);
|
||||
}
|
||||
|
||||
public void setState(State st)
|
||||
{
|
||||
if (currentState != null)
|
||||
|
||||
public void setState(State st) {
|
||||
if (st.ordinal() > 0 && !(currentState instanceof TitleState))
|
||||
currentState.stopAudio();
|
||||
|
||||
currentState = gamestates.get(st.ordinal());
|
||||
init();
|
||||
}
|
||||
|
||||
public void next() {
|
||||
index++;
|
||||
index %= gamestates.size();
|
||||
currentState = gamestates.get(index);
|
||||
init();
|
||||
}
|
||||
|
||||
public void update(float factor){
|
||||
timeOfNoAction += factor;
|
||||
@@ -78,11 +85,13 @@ public class GameStateManager {
|
||||
public void buttonPressed(ButtonEvent e) {
|
||||
timeOfNoAction = 0;
|
||||
currentState.buttonPressed(e);
|
||||
|
||||
}
|
||||
|
||||
public void buttonReleased(ButtonEvent e) {
|
||||
timeOfNoAction = 0;
|
||||
currentState.buttonReleased(e);
|
||||
|
||||
}
|
||||
|
||||
public void onJoystickMoved(JoystickEvent e) {
|
||||
|
||||
@@ -62,7 +62,17 @@ public class NetworkHandler implements Runnable{
|
||||
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()
|
||||
{
|
||||
|
||||
+13
-10
@@ -7,14 +7,14 @@ import control.NetworkHandler;
|
||||
|
||||
public class Button {
|
||||
|
||||
private Color color;
|
||||
private int ledID,
|
||||
buttonID;
|
||||
public int pressed;
|
||||
|
||||
private NetworkHandler ntw;
|
||||
Color color;
|
||||
int ledID;
|
||||
int buttonID;
|
||||
NetworkHandler ntw;
|
||||
public int pressed;
|
||||
|
||||
public Button(int buttonID, int ledID, NetworkHandler ntw) {
|
||||
public Button(int buttonID, int ledID, NetworkHandler ntw)
|
||||
{
|
||||
color = new Color(255,255,255);
|
||||
this.ledID = ledID;
|
||||
this.buttonID = buttonID;
|
||||
@@ -23,14 +23,17 @@ public class Button {
|
||||
setLed();
|
||||
}
|
||||
|
||||
private void setLed() {
|
||||
if(Window.ON_RASP) {
|
||||
private void setLed()
|
||||
{
|
||||
if(Window.ON_RASP)
|
||||
{
|
||||
ntw.setLed(ledID, color.getGreen(), color.getRed(), color.getBlue());
|
||||
ntw.show();
|
||||
}
|
||||
}
|
||||
|
||||
public void setColor(Color newColor) {
|
||||
public void setColor(Color newColor)
|
||||
{
|
||||
color = newColor;
|
||||
setLed();
|
||||
}
|
||||
|
||||
@@ -20,15 +20,19 @@ import control.NetworkHandler;
|
||||
|
||||
public class ButtonHandler implements KeyListener{
|
||||
|
||||
private List<ButtonListener> listeners;
|
||||
public static List<Button> buttons;
|
||||
private NetworkHandler ntw;
|
||||
List<ButtonListener> listeners;
|
||||
static List<Button> buttons;
|
||||
NetworkHandler ntw;
|
||||
|
||||
public ButtonHandler()
|
||||
{
|
||||
this.ntw = null;
|
||||
|
||||
listeners = new ArrayList<ButtonListener>();
|
||||
buttons = new ArrayList<Button>();
|
||||
|
||||
// if (Window.ON_RASP)
|
||||
// addGpioListeners();
|
||||
|
||||
}
|
||||
|
||||
@@ -44,6 +48,7 @@ public class ButtonHandler implements KeyListener{
|
||||
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
|
||||
@@ -77,12 +82,12 @@ public class ButtonHandler implements KeyListener{
|
||||
}
|
||||
|
||||
public void buttonRelease(Button b) {
|
||||
if(Window.ON_RASP) {
|
||||
if(Window.ON_RASP)
|
||||
{
|
||||
ntw.setLed(b.getLedID(), b.getColor().getGreen(), b.getColor().getRed(), b.getColor().getBlue());
|
||||
ntw.show();
|
||||
}
|
||||
ButtonEvent e = new ButtonEvent(b, System.currentTimeMillis());
|
||||
|
||||
for (ButtonListener bt : listeners)
|
||||
bt.buttonReleased(e);
|
||||
}
|
||||
@@ -156,9 +161,12 @@ public class ButtonHandler implements KeyListener{
|
||||
public static Button getButton(int id)
|
||||
{
|
||||
for(Button b : buttons)
|
||||
{
|
||||
if(b.getButtonID() == id)
|
||||
{
|
||||
return b;
|
||||
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package control.button;
|
||||
|
||||
public interface ButtonListener {
|
||||
void buttonPressed(ButtonEvent e);
|
||||
void buttonReleased(ButtonEvent e);
|
||||
public void buttonPressed(ButtonEvent e);
|
||||
public void buttonReleased(ButtonEvent e);
|
||||
}
|
||||
|
||||
+40
-17
@@ -16,8 +16,10 @@ import audio.SongInstance;
|
||||
|
||||
public class SQLConnector
|
||||
{
|
||||
|
||||
private Connection myConn = null;
|
||||
public SQLConnector()
|
||||
|
||||
public SQLConnector()
|
||||
{
|
||||
this("178.62.254.153", "3306","colorstrike","csadmin","aardbei123");
|
||||
}
|
||||
@@ -25,7 +27,8 @@ public class SQLConnector
|
||||
//Start connection with Database
|
||||
public SQLConnector(String host, String port, String dbName, String userName, String password)
|
||||
{
|
||||
try {
|
||||
try
|
||||
{
|
||||
String url = "jdbc:mysql://" + host + ":" + port + "/"+ dbName + "?user="
|
||||
+ userName
|
||||
+ "&password="
|
||||
@@ -33,7 +36,8 @@ public class SQLConnector
|
||||
Class.forName("com.mysql.jdbc.Driver").newInstance ();
|
||||
myConn = DriverManager.getConnection(url);
|
||||
}
|
||||
catch( SQLException ex) {
|
||||
catch( SQLException ex)
|
||||
{
|
||||
System.out.println("SQLException: " + ex.getMessage());
|
||||
System.out.println("SQLState: " + ex.getSQLState());
|
||||
System.out.println("VendorError: " + ex.getErrorCode());
|
||||
@@ -50,8 +54,7 @@ public class SQLConnector
|
||||
//System.out.println(query);
|
||||
Statement st = executeResultQuery(query);
|
||||
ResultSet result = null;
|
||||
List<Highscore> hsc = new ArrayList<>();
|
||||
|
||||
List<Highscore> hsc = new ArrayList<Highscore>();
|
||||
try {
|
||||
result = st.getResultSet();
|
||||
} catch (SQLException e1) {
|
||||
@@ -59,7 +62,9 @@ public class SQLConnector
|
||||
}
|
||||
try {
|
||||
while(result.next())
|
||||
{
|
||||
hsc.add(new Highscore(si, result.getString("username"), result.getInt("score"), result.getDate("date").getTime()));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -71,7 +76,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");
|
||||
ResultSet result = null;
|
||||
List<Highscore> hsc = new ArrayList<>();
|
||||
List<Highscore> hsc = new ArrayList<Highscore>();
|
||||
try {
|
||||
result = st.getResultSet();
|
||||
} catch (SQLException e1) {
|
||||
@@ -90,7 +95,8 @@ public class SQLConnector
|
||||
}
|
||||
|
||||
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() + "')))";
|
||||
//System.out.println(query);
|
||||
return executeInsertQuery(query);
|
||||
@@ -103,6 +109,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() + "')))";
|
||||
//System.out.println(query);
|
||||
executeInsertQuery(query);
|
||||
|
||||
}
|
||||
|
||||
public void update(List<Song> songs)
|
||||
@@ -124,18 +131,25 @@ public class SQLConnector
|
||||
rs.close();
|
||||
st.close();
|
||||
} catch (SQLException e) {
|
||||
System.out.println("Empty return set");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if(id != -1) {
|
||||
for(SongInstance si : s.getSongs()) {
|
||||
if(id != -1)
|
||||
{
|
||||
for(SongInstance si : s.getSongs())
|
||||
{
|
||||
Statement st2 = executeResultQuery("SELECT id FROM songinstance WHERE song=" + id + " AND difficulty='" + si.getDifficulty() + "'");
|
||||
|
||||
ResultSet rs2 = null;
|
||||
|
||||
try {
|
||||
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() + "');");
|
||||
//System.out.println("Songinstance Added");
|
||||
}
|
||||
@@ -157,6 +171,10 @@ public class SQLConnector
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//System.err.println("Insert Failed");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -167,11 +185,11 @@ public class SQLConnector
|
||||
Statement s = myConn.createStatement();
|
||||
s.executeUpdate(query, Statement.RETURN_GENERATED_KEYS);
|
||||
ResultSet rs = s.getGeneratedKeys();
|
||||
|
||||
int id = 0;
|
||||
if(rs.next())
|
||||
{
|
||||
id = rs.getInt(1);
|
||||
|
||||
}
|
||||
s.close();
|
||||
return id;
|
||||
}
|
||||
@@ -192,9 +210,11 @@ public class SQLConnector
|
||||
private Statement executeResultQuery(String query)
|
||||
{
|
||||
Statement s = null;
|
||||
try {
|
||||
|
||||
try{
|
||||
s = myConn.createStatement();
|
||||
s.executeQuery(query);
|
||||
|
||||
}
|
||||
catch( SQLException ex)
|
||||
{
|
||||
@@ -202,7 +222,8 @@ public class SQLConnector
|
||||
System.out.println("SQLState: " + ex.getSQLState());
|
||||
System.out.println("VendorError: " + ex.getErrorCode());
|
||||
}
|
||||
catch( Exception ex) {
|
||||
catch( Exception ex)
|
||||
{
|
||||
System.out.println("getMeasurement: " + ex.getMessage());
|
||||
}
|
||||
|
||||
@@ -214,8 +235,10 @@ public class SQLConnector
|
||||
public void finalize() throws Throwable
|
||||
{
|
||||
// Close database connection
|
||||
if( myConn != null ) {
|
||||
try {
|
||||
if( myConn != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
myConn.close();
|
||||
System.out.println("Database connection terminated");
|
||||
}
|
||||
|
||||
@@ -23,9 +23,7 @@ import com.google.zxing.qrcode.QRCodeWriter;
|
||||
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
||||
|
||||
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");
|
||||
|
||||
HttpURLConnection httpUrlConnection = (HttpURLConnection)new URL("http://178.62.254.153/colorstrike/images/photoupload.php?filename="+id+".jpeg").openConnection();
|
||||
|
||||
+4
-6
@@ -17,9 +17,10 @@ import main.Main;
|
||||
|
||||
public class Images {
|
||||
|
||||
public static ArrayList<BufferedImage> images = new ArrayList<>();
|
||||
public static ArrayList<BufferedImage> images = new ArrayList<BufferedImage>();
|
||||
|
||||
public Images() {
|
||||
|
||||
}
|
||||
|
||||
static {
|
||||
@@ -32,8 +33,8 @@ public class Images {
|
||||
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/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/screenshot.png")))); // HELP, MAAR NOG GEEN JUIST PLAATJE
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -44,10 +45,7 @@ public class Images {
|
||||
}
|
||||
|
||||
public enum ImageType {
|
||||
pulse, cursor, pressstart,
|
||||
colorstrike, background, aanwijzers,
|
||||
kast, gameover, help,
|
||||
screenshot
|
||||
pulse,cursor,pressstart,colorstrike,background,aanwijzers,kast,gameover, screenshot, help
|
||||
}
|
||||
|
||||
public static BufferedImage readImage(File f) {
|
||||
|
||||
+15
-15
@@ -36,21 +36,21 @@ public class Window extends JFrame {
|
||||
setSize(WIDTH, HEIGHT);
|
||||
|
||||
//Create Events
|
||||
Window.ON_RASP = ON_RASP;
|
||||
if(ON_RASP){ //Only on the raspberry pi
|
||||
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
|
||||
BufferedImage cursorImg = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
|
||||
Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImg, new Point(0, 0), "blank cursor");
|
||||
this.setCursor(blankCursor);
|
||||
}
|
||||
// Window.ON_RASP = ON_RASP;
|
||||
// if(ON_RASP){ //Only on the raspberry pi
|
||||
// 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
|
||||
// BufferedImage cursorImg = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
|
||||
// Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImg, new Point(0, 0), "blank cursor");
|
||||
// this.setCursor(blankCursor);
|
||||
// }
|
||||
|
||||
ButtonHandler bth = new ButtonHandler();
|
||||
JoystickHandler jsh = new JoystickHandler();
|
||||
|
||||
@@ -20,6 +20,7 @@ public class GameModel {
|
||||
|
||||
for (int i = 1; i < ButtonHandler.getButtons().size(); i++) {
|
||||
ButtonHandler.getButtons().get(i).setColor(colors[i - 1]);
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +31,8 @@ public class GameModel {
|
||||
|
||||
if (Window.ON_RASP) {
|
||||
count++;
|
||||
if(count>15) {
|
||||
if(count>15)
|
||||
{
|
||||
for (int i = 7; i < 54; i++) {
|
||||
ntw.setLed(i, c.getRed(), c.getGreen(), c.getBlue());
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import audio.AudioPlayer;
|
||||
import audio.Song;
|
||||
import audio.SongInstance;
|
||||
import audio.io.DirScanner;
|
||||
import audio.sorting.SortALPHA;
|
||||
import audio.sorting.SortPLAYED;
|
||||
import data.io.SQLConnector;
|
||||
|
||||
@@ -22,7 +21,7 @@ public class SongHandler {
|
||||
private Song currentSong;
|
||||
private SongInstance currentSongInstance;
|
||||
private int currentIndex;
|
||||
private SQLConnector sql;
|
||||
SQLConnector sql;
|
||||
|
||||
private File dir;
|
||||
|
||||
@@ -33,6 +32,7 @@ public class SongHandler {
|
||||
this.sql = sql;
|
||||
|
||||
songs = new ArrayList<Song>();
|
||||
|
||||
currentSong = null;
|
||||
currentSongInstance = null;
|
||||
currentIndex = 0;
|
||||
@@ -72,7 +72,9 @@ public class SongHandler {
|
||||
{
|
||||
currentSongInstance = si;
|
||||
}
|
||||
|
||||
public boolean isPlaying(){
|
||||
return getProgress() > 0 ? true : false;
|
||||
}
|
||||
|
||||
private void updatePlayer()
|
||||
{
|
||||
|
||||
@@ -5,7 +5,6 @@ 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.
|
||||
@@ -51,8 +50,10 @@ public class CoinAnimation extends DrawObject {
|
||||
// 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());
|
||||
coinShape.setFrame(coinSetPoint.getX() * timerLoops * 10, coinSetPoint.getY() * timerLoops,
|
||||
coinShape.getWidth(), coinShape.getHeight());
|
||||
/* coinShape.setFrame(coinSetPoint.getX(), coinSetPoint.getY() + (1000 - 35 * PlayState.comboScore) / 25 * timerLoops,
|
||||
coinShape.getWidth(), coinShape.getHeight());*/
|
||||
} catch (ArithmeticException a) { a.printStackTrace(); }
|
||||
|
||||
timerLoops++;
|
||||
|
||||
@@ -5,13 +5,10 @@ import java.awt.geom.AffineTransform;
|
||||
|
||||
public abstract class DrawObject {
|
||||
|
||||
|
||||
protected AffineTransform transform;
|
||||
|
||||
protected double width,
|
||||
height;
|
||||
|
||||
protected double width,height;
|
||||
protected int index = 0;
|
||||
|
||||
public DrawObject() {
|
||||
transform = new AffineTransform();
|
||||
}
|
||||
@@ -23,7 +20,8 @@ public abstract class DrawObject {
|
||||
public void setIndex(int index){
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public abstract void draw(Graphics2D g2);
|
||||
public abstract void update(float factor);
|
||||
}
|
||||
|
||||
@@ -8,14 +8,12 @@ import model.objects.Path;
|
||||
|
||||
public class Enemy extends DrawObject {
|
||||
|
||||
public static final double distanceToOctagon = 1000,
|
||||
secondsToEnd = 5.0;
|
||||
private int length;
|
||||
private double lengthOf1Side,
|
||||
distanceFromStart; //lengthOf1Side wordt alleen gebruikt als de lijn een schuine lijn is.
|
||||
public Line2D enemy;
|
||||
private Color c;
|
||||
private Path path;
|
||||
public static final double distanceToOctagon = 1000,secondsToEnd = 5.0;
|
||||
private int length;
|
||||
private double lengthOf1Side,distanceFromStart;//lengthOf1Side wordt alleen gebruikt als de lijn een schuine lijn is.
|
||||
public Line2D enemy;
|
||||
private Color c;
|
||||
private Path path;
|
||||
|
||||
public Enemy(int pathID,int lengthOfEnemy,Color c,Path path){
|
||||
super();
|
||||
@@ -91,7 +89,9 @@ public class Enemy extends DrawObject {
|
||||
double angleX,angleY;
|
||||
angleX = Math.cos(Math.toRadians(45))*distanceFromStart;
|
||||
angleY = Math.sin(Math.toRadians(45))*distanceFromStart;
|
||||
|
||||
|
||||
|
||||
|
||||
switch(index){
|
||||
case 0:
|
||||
y1 = path.getY1() + distanceFromStart;
|
||||
|
||||
@@ -29,26 +29,31 @@ public class Player extends DrawObject {
|
||||
}
|
||||
|
||||
public void draw(Graphics2D g2){//
|
||||
subImgX = (indexCursor % 8) * 100;
|
||||
subImgY = (indexCursor / 8) * 100;
|
||||
subImgXBeat = (indexBeat % 9 ) * 100;
|
||||
|
||||
subImgX = (indexCursor % 8)*100;
|
||||
subImgY = (indexCursor / 8)*100;
|
||||
|
||||
subImgXBeat = (indexBeat % 9)*100;
|
||||
|
||||
|
||||
BufferedImage subImg2 = pulse.getSubimage(subImgXBeat,0,100,100);
|
||||
g2.drawImage(subImg2, transform, null);
|
||||
|
||||
|
||||
|
||||
BufferedImage subImg = img.getSubimage(subImgX,subImgY,100,100);
|
||||
g2.drawImage(subImg, transform, null);
|
||||
g2.drawImage(subImg, transform, null);
|
||||
|
||||
}
|
||||
|
||||
public void update(float update){
|
||||
if(beat){
|
||||
indexBeat++;
|
||||
if(indexBeat >= 9) {
|
||||
if(indexBeat >= 9)
|
||||
{
|
||||
indexBeat = 0;
|
||||
beat = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
indexCursor++;
|
||||
indexCursor%=32;
|
||||
|
||||
@@ -63,6 +68,7 @@ public class Player extends DrawObject {
|
||||
public void setBeat() {
|
||||
beat = true;
|
||||
indexBeat = 0;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,21 +4,21 @@ 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<>();
|
||||
LinkedList<Point2D.Double> puntenPos = new LinkedList<>();
|
||||
LinkedList<Integer> puntenGain = new LinkedList<>();
|
||||
LinkedList<Integer> iterations = new LinkedList<>();
|
||||
|
||||
public static double LastPointIncrement = 0;
|
||||
|
||||
public PointAnimation() { }
|
||||
|
||||
public void enemyDied(Point2D.Double p) {
|
||||
puntenPos.add(new Point2D.Double(p.getX(), p.getY()));
|
||||
puntenGain.add(PlayState.lastScoreChange);
|
||||
puntenGain.add((int)LastPointIncrement);
|
||||
iterations.add(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,11 +29,11 @@ import data.io.WebcamUploader;
|
||||
|
||||
public class GameOverState extends GameState {
|
||||
|
||||
private BufferedImage gameOver = Images.getImage(Images.ImageType.gameover);
|
||||
private VolatileImage background;
|
||||
private Font textFont = new Font("OCR A Extended", Font.BOLD, 70);
|
||||
private HighscoreName hsn;
|
||||
private int image_x = 0;
|
||||
BufferedImage gameOver = Images.getImage(Images.ImageType.gameover);
|
||||
VolatileImage background;
|
||||
Font textFont = new Font("OCR A Extended", Font.BOLD, 70);
|
||||
HighscoreName hsn;
|
||||
int image_x = 0;
|
||||
private boolean uploaded;
|
||||
private BufferedImage QRimage;
|
||||
|
||||
@@ -49,13 +49,6 @@ public class GameOverState extends GameState {
|
||||
createBackground();
|
||||
ButtonHandler.getButton(1).setColor(GameModel.colors[0]);
|
||||
ButtonHandler.getButton(2).setColor(GameModel.colors[2]);
|
||||
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
JoystickHandler.REPEAT = true;
|
||||
uploaded = false;
|
||||
}
|
||||
@@ -112,9 +105,6 @@ public class GameOverState extends GameState {
|
||||
case 2:
|
||||
gsm.setState(State.MENU_STATE);
|
||||
break;
|
||||
case 3:
|
||||
gsm.setState(State.HELP_STATE);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -26,6 +26,5 @@ public abstract class GameState {
|
||||
public abstract void buttonPressed(ButtonEvent e);
|
||||
public abstract void buttonReleased(ButtonEvent e);
|
||||
public abstract void onJoystickMoved(JoystickEvent e);
|
||||
|
||||
public void stopAudio() { sh.close(); }
|
||||
}
|
||||
|
||||
@@ -20,12 +20,13 @@ import data.io.SQLConnector;
|
||||
|
||||
public class HelpState extends GameState {
|
||||
|
||||
private BufferedImage help = Images.getImage(ImageType.help);
|
||||
private VolatileImage background;
|
||||
private Font textFontSmall = new Font("OCR A Extended", Font.BOLD, 15);
|
||||
BufferedImage help = Images.getImage(ImageType.help);
|
||||
VolatileImage background;
|
||||
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){
|
||||
@@ -40,18 +41,23 @@ public class HelpState extends GameState {
|
||||
|
||||
@Override
|
||||
public void update(float factor) {
|
||||
|
||||
frame++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Graphics2D g2) {
|
||||
g2.drawImage(background, 0, 0, 1280, 1024, null);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buttonPressed(ButtonEvent e) {
|
||||
if(e.getButton().getButtonID() == 2)
|
||||
|
||||
if(e.getButton().getButtonID() == 2) {
|
||||
gsm.setState(State.MENU_STATE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+115
-65
@@ -40,31 +40,35 @@ public class MenuState extends GameState {
|
||||
private ArrayList<DifficultyButton> buttons2;
|
||||
private int selected, oldselected;
|
||||
private List<Song> songs;
|
||||
private SQLConnector sql;
|
||||
SQLConnector sql;
|
||||
|
||||
private int animationcounter;
|
||||
private boolean subscreen, startanimation;
|
||||
private VolatileImage mainScreenBackground, subScreenBackground, subScreenForeground;
|
||||
|
||||
|
||||
int yPosDiffButton = 900;
|
||||
private int difSelect=0, oldDifSelect = -1;
|
||||
Font textFont = new Font("OCR A Extended", Font.BOLD, 50);
|
||||
Font textFont2 = new Font("OCR A Extended", Font.BOLD, 35);
|
||||
Font textFont3 = new Font("OCR A Extended", Font.BOLD, 20);
|
||||
Font textFontSmall = new Font("OCR A Extended", Font.BOLD, 15);
|
||||
BufferedImage aanwijzers = Images.getImage(ImageType.aanwijzers);
|
||||
|
||||
private int index = 0,
|
||||
yPosDiffButton = 900,
|
||||
kleurButton1 = 0,
|
||||
kleurButton2 = 1,
|
||||
kleurButton3 = 2,
|
||||
kleurButton4 = 3,
|
||||
kleurButton5 = 4;
|
||||
|
||||
int index = 0;
|
||||
|
||||
|
||||
|
||||
int kleurButton1 = 0;
|
||||
int kleurButton2 = 1;
|
||||
int kleurButton3 = 2;
|
||||
int kleurButton4 = 3;
|
||||
int kleurButton5 = 4;
|
||||
|
||||
|
||||
|
||||
public MenuState(GameStateManager gsm, SongHandler sh, SQLConnector sql) {
|
||||
super(gsm, sh, sql);
|
||||
buttons = new ArrayList<>();
|
||||
buttons2 = new ArrayList<>();
|
||||
buttons = new ArrayList<MenuButton>();
|
||||
buttons2 = new ArrayList<DifficultyButton>();
|
||||
this.songs = sh.getSongs();
|
||||
startanimation = true;
|
||||
subscreen = false;
|
||||
@@ -89,19 +93,23 @@ public class MenuState extends GameState {
|
||||
}
|
||||
@Override
|
||||
public void init() {
|
||||
if(subscreen) {
|
||||
if(subscreen)
|
||||
{
|
||||
ButtonHandler.getButton(1).setColor(GameModel.colors[0]);
|
||||
ButtonHandler.getButton(2).setColor(GameModel.colors[2]);
|
||||
generateSubScreenForeground();
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
ButtonHandler.getButton(1).setColor(GameModel.colors[0]);
|
||||
|
||||
ButtonHandler.getButton(5).setColor(GameModel.colors[1]);
|
||||
ButtonHandler.getButton(6).setColor(GameModel.colors[4]);
|
||||
JoystickHandler.REPEAT = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -111,18 +119,20 @@ public class MenuState extends GameState {
|
||||
if(animationcounter == 5){
|
||||
startanimation = false;
|
||||
}
|
||||
}/*else if(subscreen){
|
||||
}else if(subscreen){
|
||||
//nextScreen();
|
||||
}else{
|
||||
//previousScreen();
|
||||
}*/
|
||||
}
|
||||
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)));
|
||||
|
||||
|
||||
}
|
||||
oldselected = selected;
|
||||
}
|
||||
if(difSelect != oldDifSelect) {
|
||||
if(difSelect != oldDifSelect)
|
||||
{
|
||||
oldDifSelect = difSelect;
|
||||
generateSubScreenForeground();
|
||||
}
|
||||
@@ -134,11 +144,11 @@ public class MenuState extends GameState {
|
||||
public void draw(Graphics2D g2) {
|
||||
|
||||
buttons.clear();
|
||||
buttons.add(new MenuButton(400,250,GameModel.colors[kleurButton1],selectedToSong(selected-2)));
|
||||
buttons.add(new MenuButton(400,390,GameModel.colors[kleurButton2],selectedToSong(selected-1)));
|
||||
buttons.add(new MenuButton(360,525,920,80,GameModel.colors[kleurButton3],selectedToSong(selected)));
|
||||
buttons.add(new MenuButton(400,670,GameModel.colors[kleurButton4],selectedToSong(selected+1)));
|
||||
buttons.add(new MenuButton(400,810,GameModel.colors[kleurButton5],selectedToSong(selected+2)));
|
||||
buttons.add(new MenuButton(300,260,GameModel.colors[kleurButton1],selectedToSong(selected-2)));
|
||||
buttons.add(new MenuButton(300,380,GameModel.colors[kleurButton2],selectedToSong(selected-1)));
|
||||
buttons.add(new MenuButton(260,520,1020,80,GameModel.colors[kleurButton3],selectedToSong(selected)));
|
||||
buttons.add(new MenuButton(300,680,GameModel.colors[kleurButton4],selectedToSong(selected+1)));
|
||||
buttons.add(new MenuButton(300,800,GameModel.colors[kleurButton5],selectedToSong(selected+2)));
|
||||
buttons.get(2).setSelected(true);
|
||||
|
||||
|
||||
@@ -170,7 +180,7 @@ public class MenuState extends GameState {
|
||||
}
|
||||
if(e.getButton().getButtonID() == 1){
|
||||
sh.close();
|
||||
gsm.setState(control.GameStateManager.State.PLAY_STATE);
|
||||
gsm.setState(control.GameStateManager.State.PRE_GAME_STATE);
|
||||
}
|
||||
}else{ //Screen for selecting song
|
||||
if(e.getButton().getButtonID() == 1){
|
||||
@@ -207,20 +217,25 @@ public class MenuState extends GameState {
|
||||
if(subscreen){
|
||||
if(e.getJoystick().getPos() == Joystick.Position.DOWN){
|
||||
difSelect--;
|
||||
if(difSelect < 0)
|
||||
if(difSelect < 0){
|
||||
difSelect += buttons2.size();
|
||||
else if(e.getJoystick().getPos() == Joystick.Position.UP)
|
||||
difSelect++;
|
||||
if(difSelect > buttons2.size()-1)
|
||||
}
|
||||
}else if(e.getJoystick().getPos() == Joystick.Position.UP){
|
||||
difSelect++;
|
||||
if(difSelect > buttons2.size()-1){
|
||||
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));
|
||||
}
|
||||
//generateSubScreenForeground();
|
||||
}else{ //Screen for selecting song
|
||||
if(e.getJoystick().getPos() == Joystick.Position.DOWN){
|
||||
selected++;
|
||||
|
||||
|
||||
kleurButton1++;
|
||||
kleurButton1 %= 6;
|
||||
|
||||
@@ -235,27 +250,41 @@ public class MenuState extends GameState {
|
||||
|
||||
kleurButton5++;
|
||||
kleurButton5 %= 6;
|
||||
|
||||
|
||||
|
||||
}else if(e.getJoystick().getPos() == Joystick.Position.UP){
|
||||
selected--;
|
||||
|
||||
if(--kleurButton1 < 0)
|
||||
kleurButton1--;
|
||||
if(kleurButton1 < 0){
|
||||
kleurButton1 = 5;
|
||||
|
||||
if(--kleurButton2 < 0)
|
||||
}
|
||||
|
||||
kleurButton2--;
|
||||
if(kleurButton2 < 0){
|
||||
kleurButton2 = 5;
|
||||
|
||||
if(--kleurButton3 < 0)
|
||||
}
|
||||
|
||||
kleurButton3--;
|
||||
if(kleurButton3 < 0){
|
||||
kleurButton3 = 5;
|
||||
|
||||
if(--kleurButton4 < 0)
|
||||
}
|
||||
|
||||
kleurButton4--;
|
||||
if(kleurButton4 < 0){
|
||||
kleurButton4 = 5;
|
||||
|
||||
if(--kleurButton5 < 0)
|
||||
}
|
||||
|
||||
kleurButton5--;
|
||||
if(kleurButton5 < 0){
|
||||
kleurButton5 = 5;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
else if(e.getJoystick().getPos() == Joystick.Position.CENTER)
|
||||
else if(e.getJoystick().getPos() == Position.CENTER)
|
||||
{
|
||||
buttons2.clear();
|
||||
int instanceNr = 0;
|
||||
@@ -283,9 +312,9 @@ public class MenuState extends GameState {
|
||||
g2.setPaint(new GradientPaint(0, 0, new Color(0,0,1, 0.6f),1280,1024 ,new Color(0,0,1, 0.2f)));
|
||||
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)));
|
||||
|
||||
Polygon triangle2 = new Polygon();
|
||||
|
||||
|
||||
|
||||
Polygon triangle2 = new Polygon();
|
||||
triangle2.addPoint(0, 0);
|
||||
triangle2.addPoint(0, 1024/4+50);
|
||||
triangle2.addPoint(1280/2+50, 0);
|
||||
@@ -302,7 +331,7 @@ public class MenuState extends GameState {
|
||||
g2.drawString("Main Menu", 32, 60);
|
||||
|
||||
g2.setFont(textFontSmall);
|
||||
|
||||
|
||||
//select
|
||||
g2.setColor(GameModel.colors[0]);
|
||||
g2.fillOval(20, 860, 30, 30);
|
||||
@@ -372,16 +401,17 @@ public class MenuState extends GameState {
|
||||
if(highscores.isEmpty())
|
||||
{
|
||||
highscores = sql.getHighscores(selectedToSong(selected), sh.getCurrentSong().getSongs().get(difSelect));
|
||||
|
||||
if(highscores.isEmpty())
|
||||
{
|
||||
highscoresFound = false;
|
||||
}
|
||||
else
|
||||
g2.drawString("All Time Highscores", 30, 300);
|
||||
}
|
||||
else
|
||||
g2.drawString("Daily Highscore", 30, 300);
|
||||
|
||||
g2.setFont(textFont2);
|
||||
g2.setFont(textFont2);
|
||||
|
||||
if(highscoresFound)
|
||||
{
|
||||
HIGHSCORES_TO_DISPLAY = HIGHSCORES_TO_DISPLAY > highscores.size() ? highscores.size() : HIGHSCORES_TO_DISPLAY;
|
||||
@@ -394,16 +424,14 @@ public class MenuState extends GameState {
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
g2.drawString("No Highscores found", 30, 400);
|
||||
}
|
||||
|
||||
/*
|
||||
List<Highscore> highscores = sql.getHighscores(selectedToSong(selected), sh.getCurrentSong().getSongs().get(difSelect));
|
||||
List<Highscore> dailyHighs = new ArrayList<Highscore>();
|
||||
int highest = 0;
|
||||
int oldHighest = 0;
|
||||
*/
|
||||
for(DifficultyButton b : buttons2)
|
||||
|
||||
for(DifficultyButton b : buttons2){
|
||||
b.draw(g2);
|
||||
}
|
||||
|
||||
g2.setFont(textFontSmall);
|
||||
|
||||
@@ -434,28 +462,50 @@ public class MenuState extends GameState {
|
||||
g2.fillPolygon(p2);
|
||||
|
||||
g2.drawString("Down", 55, 1000);
|
||||
|
||||
|
||||
|
||||
|
||||
g2.dispose();
|
||||
subScreenForeground.createGraphics();
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if(buttons.get(button).getX() >= 320)
|
||||
if(buttons.get(button).getX() >= 320){
|
||||
animationcounter++;
|
||||
if(buttons.get(button).getX() >= -200)
|
||||
}
|
||||
if(buttons.get(button).getX() >= -200){
|
||||
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){
|
||||
s %= songs.size();
|
||||
if(s < 0)
|
||||
if(s < 0){
|
||||
return songs.get(songs.size()+s);
|
||||
else
|
||||
}else{
|
||||
return songs.get(s);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import main.Window;
|
||||
import model.SongHandler;
|
||||
import model.drawObjects.Enemy;
|
||||
import model.drawObjects.Player;
|
||||
import model.drawObjects.PointAnimation;
|
||||
import model.objects.InfoPanel;
|
||||
import model.objects.Path;
|
||||
import model.objects.PlayArea;
|
||||
@@ -37,9 +38,7 @@ public class PlayState extends GameState {
|
||||
|
||||
public static int sizeOfEnemy = 40;
|
||||
public static int currentScore = 0;
|
||||
public static int comboMulitplier = 0;
|
||||
public static int lastScoreChange = 0;
|
||||
public static int sinceScoreChanged = 75;
|
||||
public static int comboScore = 0;
|
||||
public static double lifePoints = 100;
|
||||
|
||||
private int enemies_hit = 0;
|
||||
@@ -49,8 +48,6 @@ public class PlayState extends GameState {
|
||||
|
||||
private boolean init = false;
|
||||
|
||||
private boolean prestateShown = false;
|
||||
|
||||
private long oldProgress = 0;
|
||||
|
||||
public PlayState(GameStateManager gsm, SongHandler sh, SQLConnector sql) {
|
||||
@@ -65,7 +62,9 @@ public class PlayState extends GameState {
|
||||
@Override
|
||||
public void init() {
|
||||
init = true;
|
||||
lifePoints = 100;
|
||||
currentScore = 0;
|
||||
comboScore = 0;
|
||||
oldProgress = 0;
|
||||
|
||||
enemies_hit = 0;
|
||||
@@ -74,7 +73,9 @@ public class PlayState extends GameState {
|
||||
joystick_moved = 0;
|
||||
|
||||
for(Path p : area.paths)
|
||||
{
|
||||
p.getEnemysInPath().clear();
|
||||
}
|
||||
|
||||
for (int i = 1; i < ButtonHandler.getButtons().size(); i++) {
|
||||
Button b = ButtonHandler.getButton(i);
|
||||
@@ -91,12 +92,7 @@ public class PlayState extends GameState {
|
||||
public void update(float factor) {
|
||||
if(init)
|
||||
return;
|
||||
|
||||
if (!prestateShown) {
|
||||
gsm.setState(control.GameStateManager.State.PRE_GAME_STATE);
|
||||
prestateShown = true;
|
||||
}
|
||||
|
||||
|
||||
long progress = (long) ((sh.getProgress() / 1000) + (Enemy.secondsToEnd * 1000));
|
||||
|
||||
for (ButtonInstance bu : sh.getCurrentSongInstance().getButtonsBetween(oldProgress, progress)) {
|
||||
@@ -114,60 +110,61 @@ public class PlayState extends GameState {
|
||||
endGame();
|
||||
|
||||
oldProgress = progress;
|
||||
|
||||
Enemy closedEnemy = null;
|
||||
player.update(factor);
|
||||
|
||||
for (Path path : area.paths) {
|
||||
|
||||
Iterator<Enemy> enemyIterator = path.getEnemysInPath().iterator();
|
||||
|
||||
while (enemyIterator.hasNext()) {
|
||||
|
||||
Enemy e = enemyIterator.next();
|
||||
if (e.getDistanceFromStart() > Enemy.distanceToOctagon + (sizeOfEnemy * 1.5)) {
|
||||
enemyIterator.remove();
|
||||
lastScoreChange = -5;
|
||||
lifePoints -= lastScoreChange;
|
||||
sinceScoreChanged = 1;
|
||||
comboMulitplier = 0;
|
||||
lifePoints -= 5;
|
||||
comboScore /= 2;
|
||||
enemies_missed++;
|
||||
}
|
||||
if(closedEnemy == null)
|
||||
if(closedEnemy == null){
|
||||
closedEnemy = e;
|
||||
if((Enemy.distanceToOctagon-closedEnemy.getDistanceFromStart()) > (Enemy.distanceToOctagon-e.getDistanceFromStart()))
|
||||
}
|
||||
if((Enemy.distanceToOctagon-closedEnemy.getDistanceFromStart()) > (Enemy.distanceToOctagon-e.getDistanceFromStart())){
|
||||
closedEnemy = e;
|
||||
|
||||
}
|
||||
e.update(factor);
|
||||
}
|
||||
}
|
||||
|
||||
lifePoints -= 0.002 * factor;
|
||||
|
||||
infoPanel.updateIPanel();
|
||||
|
||||
if(lifePoints <= 0) // STERF!
|
||||
|
||||
if(lifePoints <= 0)
|
||||
{
|
||||
endGame();
|
||||
|
||||
if(comboMulitplier >= 20) { // '20' hit streak voor bonuspunten
|
||||
comboMulitplier = 0;
|
||||
sinceScoreChanged = 1;
|
||||
lastScoreChange = 500;
|
||||
currentScore += lastScoreChange;
|
||||
}
|
||||
if(comboScore >= 100)
|
||||
{
|
||||
comboScore = 0;
|
||||
currentScore += 500;
|
||||
}
|
||||
|
||||
|
||||
area.count();
|
||||
if(closedEnemy == null)
|
||||
if(closedEnemy == null){
|
||||
area.pathPainted(-1, null);
|
||||
else
|
||||
}else{
|
||||
area.pathPainted(closedEnemy.getIndex(), closedEnemy.getColor());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
sh.getCurrentSongInstance().played();
|
||||
}
|
||||
|
||||
comboMulitplier = 0;
|
||||
prestateShown = false;
|
||||
|
||||
if(currentScore == 0)
|
||||
gsm.setState(State.MENU_STATE);
|
||||
@@ -181,7 +178,6 @@ public class PlayState extends GameState {
|
||||
infoPanel.draw(g2);
|
||||
g2.setClip(borderRect);
|
||||
area.draw(g2);
|
||||
sinceScoreChanged++;
|
||||
|
||||
for (Path p : area.paths) {
|
||||
if (p.getEnemysInPath() != null) {
|
||||
@@ -193,13 +189,14 @@ public class PlayState extends GameState {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (player != null)
|
||||
player.draw(g2);
|
||||
|
||||
} catch (Exception e) {
|
||||
}
|
||||
if(!Window.ON_RASP){
|
||||
int width,height;
|
||||
width = g2.getFontMetrics().stringWidth("");
|
||||
height = g2.getFontMetrics().getHeight();
|
||||
for (int i = 1; i < ButtonHandler.getButtons().size(); i++) {
|
||||
Ellipse2D oval = new Ellipse2D.Double(880+(50*i), 0, 50, 50);
|
||||
@@ -220,18 +217,17 @@ public class PlayState extends GameState {
|
||||
Enemy enemy = enemysInPath.next();
|
||||
if (enemy.getDistanceFromStart() > Enemy.distanceToOctagon || enemy.getDistanceFromStart() > Enemy.distanceToOctagon + sizeOfEnemy) {
|
||||
if (e.getButton().getColor().equals(enemy.getColor())) {
|
||||
comboMulitplier++;
|
||||
lastScoreChange = 5 * comboMulitplier;
|
||||
currentScore += lastScoreChange;
|
||||
sinceScoreChanged = 1;
|
||||
area.enemyDied((Point2D.Double) enemy.getEnemy().getP1());
|
||||
PointAnimation.LastPointIncrement = (int)(enemy.getDistanceFromStart() - Enemy.distanceToOctagon);
|
||||
currentScore += PointAnimation.LastPointIncrement;
|
||||
comboScore += 5;
|
||||
lifePoints = Math.min(lifePoints+10, 100);
|
||||
area.setHitAreaColor(enemy.getColor());
|
||||
area.enemyDied((Point2D.Double) enemy.getEnemy().getP1());
|
||||
area.hit();
|
||||
enemies_hit++;
|
||||
infoPanel.throwACoin(); // Coin Animatie starten bij hit
|
||||
enemysInPath.remove();
|
||||
notHit = false;
|
||||
infoPanel.throwACoin(); // Coin Animatie starten bij hit
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -239,13 +235,18 @@ public class PlayState extends GameState {
|
||||
|
||||
player.setBeat();
|
||||
|
||||
if(notHit) {
|
||||
if(notHit)
|
||||
{
|
||||
if(area.paths.get(player.getIndex()).getEnemysInPath().size() > 0)
|
||||
{
|
||||
lifePoints -= 1.5;
|
||||
}
|
||||
}
|
||||
|
||||
if(e.getButton().getButtonID() == 0)
|
||||
{
|
||||
endGame();
|
||||
}
|
||||
else
|
||||
buttons_pressed++;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package model.gameState;
|
||||
|
||||
import data.io.SQLConnector;
|
||||
import image.Images;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
@@ -13,24 +12,21 @@ import model.SongHandler;
|
||||
import control.GameStateManager;
|
||||
import control.button.ButtonEvent;
|
||||
import control.joystick.JoystickEvent;
|
||||
import data.io.SQLConnector;
|
||||
|
||||
public class PreGameState extends GameState {
|
||||
|
||||
private double index2 = 3,
|
||||
index = 3;
|
||||
|
||||
private int grootte = 150;
|
||||
|
||||
private SQLConnector sql;
|
||||
|
||||
private BasicStroke s = new BasicStroke(20);
|
||||
double index2 = 3;
|
||||
double index = 3;
|
||||
double timer;
|
||||
int grootte = 150;
|
||||
BasicStroke s = new BasicStroke(20);
|
||||
|
||||
private BufferedImage screenshot;
|
||||
BufferedImage screenshot;
|
||||
|
||||
public PreGameState(GameStateManager gsm, SongHandler sh, SQLConnector sql) {
|
||||
super(gsm, sh, sql);
|
||||
this.sql = sql;
|
||||
screenshot = Images.getImage(Images.ImageType.screenshot);
|
||||
screenshot = Images.getImage(Images.ImageType.screenshot);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -40,13 +36,9 @@ public class PreGameState extends GameState {
|
||||
|
||||
@Override
|
||||
public void update(float factor) {
|
||||
|
||||
index2 -= factor/1000;
|
||||
index = (double) Math.round(index2*1000)/1000;
|
||||
if(index <= 0){
|
||||
grootte = 150;
|
||||
index = 3;
|
||||
index2 = 3;
|
||||
gsm.setState(control.GameStateManager.State.PLAY_STATE);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,22 +22,22 @@ import data.io.SQLConnector;
|
||||
public class TitleState extends GameState {
|
||||
|
||||
private BufferedImage pressStart = Images.getImage(ImageType.pressstart),
|
||||
colorStrike = Images.getImage(ImageType.colorstrike),
|
||||
kast = Images.getImage(ImageType.kast);
|
||||
colorStrike = Images.getImage(ImageType.colorstrike),
|
||||
kast = Images.getImage(ImageType.kast);
|
||||
private VolatileImage background;
|
||||
|
||||
private Font textFont = new Font("OCR A Extended", Font.BOLD, 15),
|
||||
textFont2 = new Font("OCR A Extended", Font.BOLD, 130);
|
||||
textFont2 = new Font("OCR A Extended", Font.BOLD, 130);
|
||||
|
||||
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,
|
||||
varx = 0,
|
||||
indexKast = 0,
|
||||
xKast = 0,
|
||||
frame;
|
||||
|
||||
|
||||
private int index = 0,
|
||||
varx = 0,
|
||||
indexKast = 0,
|
||||
xKast = 0,
|
||||
frame;
|
||||
|
||||
public TitleState(GameStateManager gsm, SongHandler sh, SQLConnector sql){
|
||||
super(gsm, sh, sql);
|
||||
createBackground();
|
||||
@@ -50,8 +50,8 @@ public class TitleState extends GameState {
|
||||
|
||||
@Override
|
||||
public void update(float factor) {
|
||||
frame++;
|
||||
indexKast++;
|
||||
frame++;
|
||||
indexKast++;
|
||||
}
|
||||
|
||||
public void draw(Graphics2D g2) {
|
||||
@@ -75,9 +75,9 @@ public class TitleState extends GameState {
|
||||
public void buttonPressed(ButtonEvent e) {
|
||||
|
||||
switch (e.getButton().getButtonID()) {
|
||||
case 0:
|
||||
gsm.setState(State.MENU_STATE);
|
||||
break;
|
||||
case 0:
|
||||
gsm.setState(State.MENU_STATE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ public class TitleState extends GameState {
|
||||
if (frame > 120) {
|
||||
g2.setFont(textFont);
|
||||
g2.setColor(Color.WHITE);
|
||||
g2.drawString("©2015 Team Hamtaro", 550, 1012);
|
||||
g2.drawString("©2015 Team Hamtaro", 550, 1012);
|
||||
}
|
||||
if (frame > 140) {
|
||||
g2.setColor(Color.RED);
|
||||
|
||||
@@ -2,13 +2,16 @@ package model.objects;
|
||||
|
||||
import image.Images;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.GradientPaint;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.Transparency;
|
||||
import java.awt.image.VolatileImage;
|
||||
|
||||
import model.SongHandler;
|
||||
import model.drawObjects.CoinAnimation;
|
||||
import model.drawObjects.PointAnimation;
|
||||
import model.gameState.PlayState;
|
||||
|
||||
public class InfoPanel {
|
||||
@@ -22,8 +25,7 @@ public class InfoPanel {
|
||||
private int tempComboMulitplier;
|
||||
|
||||
private CoinAnimation coinAnimation = new CoinAnimation(125, 300);
|
||||
|
||||
|
||||
|
||||
public InfoPanel(int x, int y, SongHandler sh){
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
@@ -34,9 +36,16 @@ public class InfoPanel {
|
||||
|
||||
public void updateIPanel() {
|
||||
totalHighscore = "" + PlayState.currentScore;
|
||||
// time = "";
|
||||
// long progress = (sh.getProgress() / 1000);
|
||||
// time = progress%1000 + time;
|
||||
// progress /= 1000;
|
||||
// time = progress%1000 + ":" + time;
|
||||
// progress /= 1000;
|
||||
// time = progress + ":" + time;
|
||||
|
||||
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 minute = ((progress / (1000 * 60)) % 60 + "").length() <= 1 ? "0" +((progress / (1000 * 60)) % 60) : "" + ((progress / (1000 * 60)) % 60);
|
||||
time = minute + ":" + second + ":" + millis;
|
||||
@@ -48,58 +57,47 @@ public class InfoPanel {
|
||||
Graphics2D g2 = infoPanel.createGraphics();
|
||||
RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
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);
|
||||
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.fillRect(25, 100, (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.drawString("Score: " + totalHighscore, 25, 75);
|
||||
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);
|
||||
|
||||
// GradientPaint gp = new GradientPaint(300, 0, new Color(200,200,255), 256, 1024, Color.WHITE);
|
||||
// g2.setPaint(gp);
|
||||
// g2.fillRect(x, y, 256, 1024);
|
||||
|
||||
g2.setColor(Color.YELLOW);
|
||||
// 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;
|
||||
tempComboMulitplier = PlayState.comboScore;
|
||||
} else
|
||||
tempComboMulitplier = PlayState.comboMulitplier;
|
||||
tempComboMulitplier = PlayState.comboScore;
|
||||
|
||||
g2.drawString(sh.getCurrentSongInstance().getDifficulty(), 25, 230);
|
||||
g2.drawString(sh.getCurrentSong().getAuthor(), 25, 260);
|
||||
g2.drawString(time, 25, 290);
|
||||
|
||||
g2.setColor(Color.YELLOW);
|
||||
g2.fillRect(25, 1000 - tempComboMulitplier * 35, 200, 35 * tempComboMulitplier);
|
||||
|
||||
g2.fillRect(25, 1000 - 7 * PlayState.comboScore, 200, 0 + 7 * PlayState.comboScore);
|
||||
g2.dispose();
|
||||
infoPanel.createGraphics();
|
||||
}
|
||||
|
||||
+58
-70
@@ -17,25 +17,22 @@ import model.gameState.PlayState;
|
||||
|
||||
public class PlayArea {
|
||||
|
||||
public List<Path> paths;
|
||||
public List<Path> paths;
|
||||
private Polygon innerHitAreaBorder,outsideHitAreaBorder;
|
||||
private GeneralPath hitArea;
|
||||
private Color hitAreaColor,pathColor = null;
|
||||
private VolatileImage background;
|
||||
private boolean hit = false;
|
||||
private int count = 0,
|
||||
maxCount = 100,
|
||||
pathID = -1,
|
||||
oldPathId = pathID;
|
||||
|
||||
private PointAnimation pointAnimation = new PointAnimation();
|
||||
private int count = 0,maxCount = 100,pathID = -1;
|
||||
private Stroke stroke = new BasicStroke(5);
|
||||
private PointAnimation pointAnimation = new PointAnimation();
|
||||
|
||||
private Rectangle2D backgroundPlay = new Rectangle2D.Double(256, 0, 1024, 1024);
|
||||
|
||||
|
||||
|
||||
public PlayArea(double xToRight,double heightOfGameScreen,double widthOfGameScreen, int sizeOctagon) {
|
||||
super();
|
||||
paths = new ArrayList<>();
|
||||
paths = new ArrayList<Path>();
|
||||
setHitAreaColor(Color.WHITE);
|
||||
//make the polygons
|
||||
int amountOfAngles = 8;
|
||||
@@ -61,36 +58,48 @@ public class PlayArea {
|
||||
hitArea = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
|
||||
|
||||
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.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]);
|
||||
}
|
||||
|
||||
//make the paths
|
||||
double angleX,angleY;
|
||||
angleX = (Math.cos(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,
|
||||
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[0]+Enemy.distanceToOctagon,outsideHitAreaBorder.ypoints[0],
|
||||
outsideHitAreaBorder.xpoints[0],outsideHitAreaBorder.ypoints[0]));//right
|
||||
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[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();
|
||||
paths.add(new Path(outsideHitAreaBorder.xpoints[6],outsideHitAreaBorder.ypoints[6]-Enemy.distanceToOctagon ,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[0]+Enemy.distanceToOctagon,outsideHitAreaBorder.ypoints[0] ,outsideHitAreaBorder.xpoints[0],outsideHitAreaBorder.ypoints[0]));//right
|
||||
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[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
|
||||
|
||||
|
||||
//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){
|
||||
@@ -98,28 +107,35 @@ public class PlayArea {
|
||||
if(hit){
|
||||
g2.setColor(hitAreaColor);
|
||||
g2.fill(hitArea);
|
||||
|
||||
if(count == maxCount)
|
||||
if(count == maxCount){
|
||||
hit = false;
|
||||
}
|
||||
}
|
||||
if (oldPathId != pathID){
|
||||
generateBackground();
|
||||
oldPathId = pathID;
|
||||
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));
|
||||
}
|
||||
|
||||
Font scoreFont = new Font("OCR A Extended", Font.BOLD, 40);
|
||||
Font tempFont = g2.getFont();
|
||||
g2.setFont(scoreFont);
|
||||
pointAnimation.draw(g2);
|
||||
g2.setFont(tempFont);
|
||||
}
|
||||
|
||||
public Line2D getLine(int index){
|
||||
if(index < 0)
|
||||
index = 0;
|
||||
else if(index >= 8)
|
||||
index = 7;
|
||||
|
||||
public Line2D getLine(int index){
|
||||
if(index < 0){
|
||||
index = 0;
|
||||
}
|
||||
if(index >= 8 ){
|
||||
index = 7;
|
||||
}
|
||||
return paths.get(index);
|
||||
}
|
||||
|
||||
|
||||
public void setHitAreaColor(Color color) {
|
||||
hitAreaColor = color;
|
||||
@@ -133,8 +149,9 @@ public class PlayArea {
|
||||
public void count(){
|
||||
if(hit){
|
||||
count += 3;
|
||||
if(count > maxCount)
|
||||
if(count > maxCount){
|
||||
count = maxCount;
|
||||
}
|
||||
hitAreaColor = new Color(hitAreaColor.getRed(),hitAreaColor.getGreen(),hitAreaColor.getBlue(),255-(255*count)/maxCount);
|
||||
}
|
||||
}
|
||||
@@ -143,35 +160,6 @@ public class PlayArea {
|
||||
this.pathID = pathID;
|
||||
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); }
|
||||
}
|
||||
|
||||
+4
-1
@@ -12,9 +12,12 @@ import control.GameStateManager;
|
||||
|
||||
public class GameView extends JPanel {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1939480784205689618L;
|
||||
|
||||
private GameStateManager gsm;
|
||||
GameStateManager gsm;
|
||||
|
||||
// Font fpsfont = new Font("OCR A Extended", Font.BOLD, 60);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user