Merge branch 'develop' of https://github.com/ProjectGroepA2/Arcade into coin
This commit is contained in:
@@ -2,6 +2,10 @@ package control;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.InetAddress;
|
||||
import java.net.SocketException;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import javax.swing.Timer;
|
||||
|
||||
@@ -28,18 +32,6 @@ public class GameControl implements JoystickListener, ButtonListener, ActionList
|
||||
view.setIgnoreRepaint(true);
|
||||
update = new Timer(1000/60,this);
|
||||
update.start();
|
||||
// Timer update = new Timer();
|
||||
// update.schedule(new TimerTask() {
|
||||
//
|
||||
// @Override
|
||||
// public void run() {
|
||||
// long currentTime = System.currentTimeMillis();
|
||||
// model.update(currentTime - lastTime);
|
||||
// lastTime = currentTime;
|
||||
// view.repaint();
|
||||
// System.out.println("Test");
|
||||
// }
|
||||
// }, 0,1000/120);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -62,7 +54,10 @@ public class GameControl implements JoystickListener, ButtonListener, ActionList
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
model.update(currentTime - lastTime);
|
||||
long time = currentTime - lastTime;
|
||||
if(time > 1000/60)
|
||||
time = 1000/60;
|
||||
model.update(time);
|
||||
lastTime = currentTime;
|
||||
view.repaint();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,175 @@
|
||||
package control;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.InetAddress;
|
||||
import java.net.SocketException;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import control.button.ButtonHandler;
|
||||
import control.joystick.Joystick.Position;
|
||||
import control.joystick.JoystickHandler;
|
||||
|
||||
public class NetworkHandler implements Runnable{
|
||||
|
||||
DatagramSocket udp;
|
||||
|
||||
String host;
|
||||
int port;
|
||||
|
||||
boolean running;
|
||||
Thread t;
|
||||
|
||||
byte[] send;
|
||||
byte[] receive;
|
||||
|
||||
ButtonHandler bth;
|
||||
JoystickHandler jth;
|
||||
|
||||
public NetworkHandler(String host, int port, ButtonHandler bth, JoystickHandler jth)
|
||||
{
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
|
||||
this.bth = bth;
|
||||
this.jth = jth;
|
||||
|
||||
udp = null;
|
||||
|
||||
send = new byte[1024];
|
||||
receive = new byte[1024];
|
||||
|
||||
try {
|
||||
udp = new DatagramSocket(1112);
|
||||
} catch (SocketException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
running = true;
|
||||
t = new Thread(this);
|
||||
t.start();
|
||||
}
|
||||
|
||||
public void setLed(int led, int r, int g , int b)
|
||||
{
|
||||
String cmd = "1|" + led + "|" + r + "|" + g + "|" + b + "\n";
|
||||
send(cmd);
|
||||
}
|
||||
|
||||
public void show(){
|
||||
String cmd = "0\n";
|
||||
send(cmd);
|
||||
}
|
||||
|
||||
private void send(String str)
|
||||
{
|
||||
send = str.getBytes();
|
||||
try {
|
||||
udp.send(new DatagramPacket(send, send.length));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void close()
|
||||
{
|
||||
running = false;
|
||||
udp.disconnect();
|
||||
udp.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
while(running)
|
||||
{
|
||||
DatagramPacket receivePacket = new DatagramPacket(receive, receive.length);
|
||||
try {
|
||||
udp.receive(receivePacket);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String sentence = new String( receivePacket.getData());
|
||||
|
||||
if(sentence.length() != 21)
|
||||
return;
|
||||
|
||||
System.out.println("RECEIVED: " + sentence);
|
||||
|
||||
String[] controls = sentence.split("\\|");
|
||||
int[] control = new int[controls.length];
|
||||
for(int i=0; i<controls.length; i++)
|
||||
control[i] = Integer.parseInt(controls[i]);
|
||||
|
||||
for(int i = 0; i < 7; i++){
|
||||
if(control[i] != ButtonHandler.getButton(i).pressed)
|
||||
{
|
||||
System.out.println("PRESS BITCH " + controls[i]);
|
||||
ButtonHandler.getButton(i).pressed = control[i];
|
||||
if(control[i] == 0)
|
||||
bth.buttonPress(ButtonHandler.getButton(i));
|
||||
}
|
||||
}
|
||||
|
||||
if(control[7] == 0 && control[8] == 0){
|
||||
if(JoystickHandler.j.getPos() != Position.UP_LEFT)
|
||||
{
|
||||
JoystickHandler.j.setPosition(Position.UP_LEFT);
|
||||
jth.onJoystickMoved(JoystickHandler.j);
|
||||
}
|
||||
}
|
||||
else if(control[7] == 0 && control[9] == 0){
|
||||
if(JoystickHandler.j.getPos() != Position.UP_RIGHT)
|
||||
{
|
||||
JoystickHandler.j.setPosition(Position.UP_RIGHT);
|
||||
jth.onJoystickMoved(JoystickHandler.j);
|
||||
}
|
||||
}
|
||||
else if(control[10] == 0 && control[8] == 0){
|
||||
if(JoystickHandler.j.getPos() != Position.DOWN_LEFT)
|
||||
{
|
||||
JoystickHandler.j.setPosition(Position.DOWN_LEFT);
|
||||
jth.onJoystickMoved(JoystickHandler.j);
|
||||
}
|
||||
}
|
||||
else if(control[10] == 0 && control[9] == 0){
|
||||
if(JoystickHandler.j.getPos() != Position.DOWN_RIGHT)
|
||||
{
|
||||
JoystickHandler.j.setPosition(Position.DOWN_RIGHT);
|
||||
jth.onJoystickMoved(JoystickHandler.j);
|
||||
}
|
||||
}
|
||||
|
||||
else if(control[7] == 0){
|
||||
if(JoystickHandler.j.getPos() != Position.UP)
|
||||
{
|
||||
JoystickHandler.j.setPosition(Position.UP);
|
||||
jth.onJoystickMoved(JoystickHandler.j);
|
||||
}
|
||||
}
|
||||
else if(control[8] == 0){
|
||||
if(JoystickHandler.j.getPos() != Position.LEFT)
|
||||
{
|
||||
JoystickHandler.j.setPosition(Position.LEFT);
|
||||
jth.onJoystickMoved(JoystickHandler.j);
|
||||
}
|
||||
}
|
||||
else if(control[9] == 0){
|
||||
if(JoystickHandler.j.getPos() != Position.RIGHT)
|
||||
{
|
||||
JoystickHandler.j.setPosition(Position.RIGHT);
|
||||
jth.onJoystickMoved(JoystickHandler.j);
|
||||
}
|
||||
}
|
||||
else if(control[10] == 0){
|
||||
if(JoystickHandler.j.getPos() != Position.DOWN)
|
||||
{
|
||||
JoystickHandler.j.setPosition(Position.DOWN);
|
||||
jth.onJoystickMoved(JoystickHandler.j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -3,21 +3,23 @@ package control.button;
|
||||
import java.awt.Color;
|
||||
|
||||
import main.Window;
|
||||
import control.LedHandler;
|
||||
import control.NetworkHandler;
|
||||
|
||||
public class Button {
|
||||
|
||||
Color color;
|
||||
int ledID;
|
||||
int buttonID;
|
||||
LedHandler led;
|
||||
NetworkHandler ntw;
|
||||
public int pressed;
|
||||
|
||||
public Button(int buttonID, int ledID, LedHandler led)
|
||||
public Button(int buttonID, int ledID, NetworkHandler ntw)
|
||||
{
|
||||
color = new Color(255,255,255);
|
||||
this.ledID = ledID;
|
||||
this.buttonID = buttonID;
|
||||
this.led = led;
|
||||
this.ntw = ntw;
|
||||
pressed = 1;
|
||||
setLed();
|
||||
}
|
||||
|
||||
@@ -25,8 +27,8 @@ public class Button {
|
||||
{
|
||||
if(Window.ON_RASP)
|
||||
{
|
||||
led.setLed(ledID, color.getGreen(), color.getRed(), color.getBlue());
|
||||
led.show();
|
||||
ntw.setLed(ledID, color.getGreen(), color.getRed(), color.getBlue());
|
||||
ntw.show();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,28 +16,20 @@ import com.pi4j.io.gpio.RaspiPin;
|
||||
import com.pi4j.io.gpio.event.GpioPinDigitalStateChangeEvent;
|
||||
import com.pi4j.io.gpio.event.GpioPinListenerDigital;
|
||||
|
||||
import control.LedHandler;
|
||||
import control.NetworkHandler;
|
||||
|
||||
public class ButtonHandler implements KeyListener{
|
||||
|
||||
List<ButtonListener> listeners;
|
||||
static List<Button> buttons;
|
||||
LedHandler led;
|
||||
NetworkHandler ntw;
|
||||
|
||||
public ButtonHandler(LedHandler led)
|
||||
public ButtonHandler()
|
||||
{
|
||||
this.led = led;
|
||||
this.ntw = null;
|
||||
|
||||
listeners = new ArrayList<ButtonListener>();
|
||||
buttons = new ArrayList<Button>();
|
||||
|
||||
buttons.add(new Button(0, -1, led));
|
||||
buttons.add(new Button(1, 2, led));
|
||||
buttons.add(new Button(2, 1, led));
|
||||
buttons.add(new Button(3, 0, led));
|
||||
buttons.add(new Button(4, 3, led));
|
||||
buttons.add(new Button(5, 4, led));
|
||||
buttons.add(new Button(6, 5, led));
|
||||
|
||||
// if (Window.ON_RASP)
|
||||
// addGpioListeners();
|
||||
@@ -81,8 +73,8 @@ public class ButtonHandler implements KeyListener{
|
||||
if(Window.ON_RASP)
|
||||
{
|
||||
Color c = b.getColor().brighter().brighter();
|
||||
led.setLed(b.getLedID(), c.getGreen(), c.getRed(), c.getBlue());
|
||||
led.show();
|
||||
ntw.setLed(b.getLedID(), c.getGreen(), c.getRed(), c.getBlue());
|
||||
ntw.show();
|
||||
}
|
||||
ButtonEvent e = new ButtonEvent(b, System.currentTimeMillis());
|
||||
for (ButtonListener bt : listeners)
|
||||
@@ -92,8 +84,8 @@ public class ButtonHandler implements KeyListener{
|
||||
public void buttonRelease(Button b) {
|
||||
if(Window.ON_RASP)
|
||||
{
|
||||
led.setLed(b.getLedID(), b.getColor().getGreen(), b.getColor().getRed(), b.getColor().getBlue());
|
||||
led.show();
|
||||
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)
|
||||
@@ -177,4 +169,16 @@ public class ButtonHandler implements KeyListener{
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setNetwork(NetworkHandler ntw) {
|
||||
this.ntw = ntw;
|
||||
|
||||
buttons.add(new Button(0, -1, ntw));
|
||||
buttons.add(new Button(1, 2, ntw));
|
||||
buttons.add(new Button(2, 1, ntw));
|
||||
buttons.add(new Button(3, 0, ntw));
|
||||
buttons.add(new Button(4, 3, ntw));
|
||||
buttons.add(new Button(5, 4, ntw));
|
||||
buttons.add(new Button(6, 5, ntw));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,13 +23,12 @@ public class JoystickHandler implements KeyListener{
|
||||
|
||||
List<JoystickListener> listeners;
|
||||
Set<Integer> keys;
|
||||
Joystick j;
|
||||
public static Joystick j = new Joystick();;
|
||||
|
||||
public JoystickHandler()
|
||||
{
|
||||
listeners = new ArrayList<JoystickListener>();
|
||||
keys = new HashSet<Integer>();
|
||||
j = new Joystick();
|
||||
// if(Window.ON_RASP)
|
||||
// addGpioListeners();
|
||||
}
|
||||
|
||||
+7
-3
@@ -18,6 +18,7 @@ import view.GameView;
|
||||
import control.GameControl;
|
||||
import control.GameStateManager;
|
||||
import control.LedHandler;
|
||||
import control.NetworkHandler;
|
||||
import control.button.ButtonHandler;
|
||||
import control.joystick.JoystickHandler;
|
||||
|
||||
@@ -35,9 +36,8 @@ public class Window extends JFrame {
|
||||
setSize(WIDTH, HEIGHT);
|
||||
|
||||
//Create Events
|
||||
LedHandler led = null;
|
||||
Window.ON_RASP = ON_RASP;
|
||||
|
||||
LedHandler led = null;
|
||||
if(ON_RASP){ //Only on the raspberry pi
|
||||
led = new LedHandler();
|
||||
GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
@@ -54,9 +54,13 @@ public class Window extends JFrame {
|
||||
this.setCursor(blankCursor);
|
||||
}
|
||||
|
||||
ButtonHandler bth = new ButtonHandler(led);
|
||||
ButtonHandler bth = new ButtonHandler();
|
||||
JoystickHandler jsh = new JoystickHandler();
|
||||
|
||||
NetworkHandler ntw = new NetworkHandler("192.168.1.6", 1113, bth, jsh);
|
||||
|
||||
bth.setNetwork(ntw);
|
||||
|
||||
//Create Instances
|
||||
final SongHandler sh = new SongHandler();
|
||||
GameStateManager gsm = new GameStateManager(sh);
|
||||
|
||||
@@ -18,8 +18,6 @@ public class Enemy extends DrawObject {
|
||||
public Enemy(int pathID,int lengthOfEnemy,Color c,Path path){
|
||||
super();
|
||||
this.length = lengthOfEnemy;
|
||||
// System.out.println(this.length*this.length/2);
|
||||
// System.out.println(Math.sqrt(Math.pow(this.length,2)/2));
|
||||
lengthOf1Side = Math.sqrt(Math.pow(lengthOfEnemy,2)/2);
|
||||
this.c = c;
|
||||
this.index = pathID;
|
||||
@@ -65,7 +63,6 @@ public class Enemy extends DrawObject {
|
||||
endY += beginY;
|
||||
|
||||
enemy = new Line2D.Double(beginX, beginY, endX, endY);
|
||||
// System.out.println("Enemy added on path: "+pathID);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -73,6 +70,10 @@ public class Enemy extends DrawObject {
|
||||
g2.setPaint(c);
|
||||
g2.draw(enemy);
|
||||
}
|
||||
public void draw(Graphics2D g2, boolean b) {
|
||||
g2.setPaint(c.darker().darker());
|
||||
g2.draw(enemy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(float factor) {
|
||||
@@ -89,8 +90,7 @@ public class Enemy extends DrawObject {
|
||||
angleX = Math.cos(Math.toRadians(45))*distanceFromStart;
|
||||
angleY = Math.sin(Math.toRadians(45))*distanceFromStart;
|
||||
|
||||
// System.out.println(Math.toRadians(45)*distanceFromStart);
|
||||
// System.out.println(angleX+" - "+angleY);
|
||||
|
||||
|
||||
switch(index){
|
||||
case 0:
|
||||
@@ -98,7 +98,6 @@ public class Enemy extends DrawObject {
|
||||
y2 = y1 - length;
|
||||
break;
|
||||
case 1:
|
||||
// x1 -= speedX;
|
||||
x1 = path.getX1() - angleX;
|
||||
x2 = x1 + lengthOf1Side;
|
||||
|
||||
|
||||
+149
-22
@@ -43,10 +43,21 @@ public class MenuState extends GameState {
|
||||
|
||||
int yPosDiffButton = 900;
|
||||
private int difSelect=0;
|
||||
Font textFont2 = new Font("OCR A Extended", Font.BOLD, 50);
|
||||
Font textFont = new Font("OCR A Extended", Font.BOLD, 50);
|
||||
Font textFontSmall = new Font("OCR A Extended", Font.BOLD, 15);
|
||||
BufferedImage aanwijzers = Images.getImage(ImageType.aanwijzers);
|
||||
int index = 0;
|
||||
|
||||
|
||||
|
||||
int kleurButton1 = 0;
|
||||
int kleurButton2 = 1;
|
||||
int kleurButton3 = 2;
|
||||
int kleurButton4 = 3;
|
||||
int kleurButton5 = 4;
|
||||
|
||||
|
||||
|
||||
public MenuState(GameStateManager gsm, SongHandler sh) {
|
||||
super(gsm, sh);
|
||||
buttons = new ArrayList<MenuButton>();
|
||||
@@ -54,23 +65,25 @@ public class MenuState extends GameState {
|
||||
this.songs = sh.getSongs();
|
||||
startanimation = true;
|
||||
subscreen = false;
|
||||
|
||||
buttons.add(new MenuButton(-600, 50,1.7, 0, Color.green, selectedToSong(selected-2) ));
|
||||
buttons.add(new MenuButton(-600, 150, 1.7, 10, Color.BLUE, selectedToSong(selected-1)));
|
||||
buttons.add(new MenuButton(-600, 250, 1.7, 20, Color.red, selectedToSong(selected)));
|
||||
buttons.add(new MenuButton(-600, 350, 1.7, 30, Color.yellow,selectedToSong(selected+1)));
|
||||
buttons.add(new MenuButton(-600, 450, 1.7, 30, Color.WHITE,selectedToSong(selected+2)));
|
||||
buttons.get(2).setSelected(true);
|
||||
|
||||
generateMainScreenBackground();
|
||||
generateSubScreenBackground();
|
||||
}
|
||||
@Override
|
||||
public void init() {
|
||||
ButtonHandler.getButton(1).setColor(GameModel.colors[0]);
|
||||
ButtonHandler.getButton(2).setColor(GameModel.colors[2]);
|
||||
if(subscreen)
|
||||
{
|
||||
ButtonHandler.getButton(1).setColor(GameModel.colors[0]);
|
||||
ButtonHandler.getButton(2).setColor(GameModel.colors[2]);
|
||||
}
|
||||
else
|
||||
{
|
||||
ButtonHandler.getButton(1).setColor(GameModel.colors[0]);
|
||||
|
||||
ButtonHandler.getButton(5).setColor(GameModel.colors[1]);
|
||||
ButtonHandler.getButton(6).setColor(GameModel.colors[4]);
|
||||
}
|
||||
|
||||
ButtonHandler.getButton(5).setColor(GameModel.colors[1]);
|
||||
ButtonHandler.getButton(6).setColor(GameModel.colors[4]);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -85,15 +98,14 @@ public class MenuState extends GameState {
|
||||
}else{
|
||||
previousScreen();
|
||||
}
|
||||
for(MenuButton b:buttons){
|
||||
b.update();
|
||||
}
|
||||
if(selected != oldselected){
|
||||
for(int i = 0; i < buttons.size(); i++){
|
||||
buttons.get(i).setSong(selectedToSong(selected+(i-2)));
|
||||
|
||||
}
|
||||
oldselected = selected;
|
||||
|
||||
|
||||
buttons2.clear();
|
||||
int instanceNr = 0;
|
||||
for(int i = sh.getCurrentSong().getSongs().size(); i>0; i--){
|
||||
@@ -105,10 +117,24 @@ public class MenuState extends GameState {
|
||||
}
|
||||
}
|
||||
index++;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
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.get(2).setSelected(true);
|
||||
|
||||
|
||||
g2.setColor(Color.BLACK);
|
||||
Font textFont2 = new Font("OCR A Extended", Font.BOLD, 50);
|
||||
g2.setFont(textFont2);
|
||||
if(!subscreen) {
|
||||
g2.drawImage(mainScreenBackground, 0, 0, 1280,1024,null);
|
||||
for(MenuButton b:buttons){
|
||||
@@ -130,6 +156,7 @@ public class MenuState extends GameState {
|
||||
if(subscreen){ //Screen for Song details
|
||||
if(e.getButton().getButtonID() == 2){
|
||||
subscreen = false;
|
||||
gsm.init();
|
||||
}
|
||||
if(e.getButton().getButtonID() == 1){
|
||||
sh.close();
|
||||
@@ -138,9 +165,8 @@ public class MenuState extends GameState {
|
||||
}else{ //Screen for selecting song
|
||||
if(e.getButton().getButtonID() == 1){
|
||||
subscreen = true;
|
||||
gsm.init();
|
||||
generateSubScreenForeground();
|
||||
}else if(e.getButton().getButtonID() == 2){
|
||||
subscreen = false;
|
||||
}else if(e.getButton().getButtonID() == 5){
|
||||
sh.sort(new SortALPHA());
|
||||
oldselected = 1;
|
||||
@@ -175,14 +201,61 @@ public class MenuState extends GameState {
|
||||
if(difSelect > buttons2.size()-1){
|
||||
difSelect = 0;
|
||||
}
|
||||
|
||||
// System.out.println(difSelect);
|
||||
}
|
||||
sh.set(sh.getCurrentSong().getSongs().get(difSelect));
|
||||
generateSubScreenForeground();
|
||||
}else{ //Screen for selecting song
|
||||
if(e.getJoystick().getPos() == Joystick.Position.DOWN){
|
||||
selected++;
|
||||
|
||||
kleurButton1++;
|
||||
kleurButton1 %= 6;
|
||||
|
||||
kleurButton2++;
|
||||
kleurButton2 %= 6;
|
||||
|
||||
kleurButton3++;
|
||||
kleurButton3 %= 6;
|
||||
|
||||
kleurButton4++;
|
||||
kleurButton4 %= 6;
|
||||
|
||||
kleurButton5++;
|
||||
kleurButton5 %= 6;
|
||||
|
||||
|
||||
|
||||
}else if(e.getJoystick().getPos() == Joystick.Position.UP){
|
||||
selected--;
|
||||
kleurButton1--;
|
||||
if(kleurButton1 < 0){
|
||||
kleurButton1 = 5;
|
||||
}
|
||||
|
||||
kleurButton2--;
|
||||
if(kleurButton2 < 0){
|
||||
kleurButton2 = 5;
|
||||
}
|
||||
|
||||
kleurButton3--;
|
||||
if(kleurButton3 < 0){
|
||||
kleurButton3 = 5;
|
||||
}
|
||||
|
||||
kleurButton4--;
|
||||
if(kleurButton4 < 0){
|
||||
kleurButton4 = 5;
|
||||
}
|
||||
|
||||
kleurButton5--;
|
||||
if(kleurButton5 < 0){
|
||||
kleurButton5 = 5;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
sh.set(songs.indexOf(selectedToSong(selected)));
|
||||
sh.play();
|
||||
@@ -194,7 +267,7 @@ public class MenuState extends GameState {
|
||||
Graphics2D g2 = mainScreenBackground.createGraphics();
|
||||
RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g2.setRenderingHints(rh);
|
||||
g2.setFont(textFont2);
|
||||
g2.setFont(textFont);
|
||||
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)));
|
||||
@@ -215,8 +288,28 @@ public class MenuState extends GameState {
|
||||
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawString("Main Menu", 32, 60);
|
||||
|
||||
g2.setFont(textFontSmall);
|
||||
|
||||
//select
|
||||
g2.setColor(GameModel.colors[0]);
|
||||
g2.fillOval(20, 900, 30, 30);
|
||||
g2.drawString("Play", 55, 920);
|
||||
|
||||
//letters
|
||||
g2.setColor(GameModel.colors[1]);
|
||||
g2.fillOval(20, 940, 30, 30);
|
||||
g2.drawString("A-Z", 55, 960);
|
||||
|
||||
//most played
|
||||
g2.setColor(GameModel.colors[4]);
|
||||
g2.fillOval(20, 980, 30, 30);
|
||||
g2.drawString("Most Played", 55, 1000);
|
||||
g2.dispose();
|
||||
|
||||
mainScreenBackground.createGraphics();
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void generateSubScreenBackground(){
|
||||
@@ -247,18 +340,52 @@ public class MenuState extends GameState {
|
||||
g2.setComposite(AlphaComposite.SrcOver);
|
||||
g2.setRenderingHints(rh);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.setFont(textFont2);
|
||||
g2.setFont(textFont);
|
||||
g2.drawString(selectedToSong(selected).getTitle(), 30, 60);
|
||||
|
||||
|
||||
g2.setColor(Color.WHITE);
|
||||
g2.drawString("Overall Highscore: " + "", 30, 200);
|
||||
g2.drawString("Daily Highscore: " + "", 30, 300);
|
||||
g2.drawString("Beats per Minute: " + selectedToSong(selected).getBPM(), 30, 400);
|
||||
g2.drawString("Author: " + selectedToSong(selected).getAuthor(), 30, 200);
|
||||
g2.drawString("Overall Highscore: " + "", 30, 300);
|
||||
g2.drawString("Daily Highscore: " + "", 30, 400);
|
||||
g2.drawString("Personal Highscore: " + "", 30, 500);
|
||||
|
||||
for(DifficultyButton b : buttons2){
|
||||
b.draw(g2);
|
||||
}
|
||||
|
||||
g2.setFont(textFontSmall);
|
||||
|
||||
//play song
|
||||
g2.setColor(GameModel.colors[0]);
|
||||
g2.fillOval(20, 860, 30, 30);
|
||||
g2.drawString("Play", 55, 880);
|
||||
|
||||
//back
|
||||
g2.setColor(GameModel.colors[2]);
|
||||
g2.fillOval(20, 900, 30, 30);
|
||||
g2.drawString("Back", 55, 920);
|
||||
|
||||
//up
|
||||
g2.setColor(Color.BLACK);
|
||||
Polygon p = new Polygon();
|
||||
p.addPoint(35, 940);
|
||||
p.addPoint(20, 960);
|
||||
p.addPoint(50, 960);
|
||||
g2.fillPolygon(p);
|
||||
g2.drawString("Up", 55, 960);
|
||||
|
||||
//down
|
||||
Polygon p2 = new Polygon();
|
||||
p2.addPoint(35, 1000);
|
||||
p2.addPoint(20, 980);
|
||||
p2.addPoint(50, 980);
|
||||
g2.fillPolygon(p2);
|
||||
|
||||
g2.drawString("Down", 55, 1000);
|
||||
|
||||
|
||||
|
||||
g2.dispose();
|
||||
subScreenForeground.createGraphics();
|
||||
}
|
||||
|
||||
@@ -29,11 +29,14 @@ public class PlayState extends GameState {
|
||||
private InfoPanel infoPanel;
|
||||
private Player player;
|
||||
private Stroke stroke;
|
||||
private Stroke borderStroke;
|
||||
|
||||
public static int sizeOfEnemy = 40;
|
||||
public static int currentScore = 0;
|
||||
public static int comboScore = 0;
|
||||
public static double lifePoints = 100;
|
||||
|
||||
private boolean init = false;
|
||||
|
||||
private long oldProgress = 0;
|
||||
|
||||
@@ -43,11 +46,12 @@ public class PlayState extends GameState {
|
||||
area = new PlayArea(256, 1024, 1024, 125);
|
||||
player = new Player(1280 - 1024 + 1024 / 2, 1024 / 2);
|
||||
stroke = new BasicStroke(sizeOfEnemy, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
|
||||
borderStroke = new BasicStroke(sizeOfEnemy+2, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
|
||||
init = true;
|
||||
lifePoints = 100;
|
||||
currentScore = 0;
|
||||
comboScore = 0;
|
||||
@@ -57,14 +61,6 @@ public class PlayState extends GameState {
|
||||
{
|
||||
p.getEnemysInPath().clear();
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
sh.play();
|
||||
|
||||
for (int i = 1; i < ButtonHandler.getButtons().size(); i++) {
|
||||
Button b = ButtonHandler.getButton(i);
|
||||
@@ -72,12 +68,16 @@ public class PlayState extends GameState {
|
||||
}
|
||||
|
||||
ButtonHandler.getButton(1).setColor(sh.getCurrentSongInstance().getButtons().get(0).getColor());
|
||||
|
||||
|
||||
sh.play();
|
||||
init = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(float factor) {
|
||||
|
||||
if(init)
|
||||
return;
|
||||
|
||||
long progress = (long) ((sh.getProgress() / 1000) + (Enemy.secondsToEnd * 1000));
|
||||
|
||||
for (ButtonInstance bu : sh.getCurrentSongInstance().getButtonsBetween(oldProgress, progress)) {
|
||||
@@ -90,11 +90,15 @@ public class PlayState extends GameState {
|
||||
p.addEnemy(ob.getColor(), ob.getDirection(), (int) ob.getLength());
|
||||
}
|
||||
|
||||
|
||||
if(progress > sh.getCurrentSongInstance().getEndTime() + Enemy.secondsToEnd*1000*2)
|
||||
gsm.setState(State.GAMEOVER_STATE);
|
||||
|
||||
// System.out.println(progress - oldProgress + " / " + area.paths.get(player.getIndex()).getEnemysInPath().size());
|
||||
|
||||
oldProgress = progress;
|
||||
|
||||
Enemy closedEnemy = null;
|
||||
player.update(factor);
|
||||
for (Path path : area.paths) {
|
||||
|
||||
@@ -103,13 +107,18 @@ public class PlayState extends GameState {
|
||||
while (enemyIterator.hasNext()) {
|
||||
|
||||
Enemy e = enemyIterator.next();
|
||||
|
||||
// System.out.println("Path: "+e.getIndex()+"\tDistance: "+(Enemy.distanceToOctagon-e.getDistanceFromStart()));
|
||||
if (e.getDistanceFromStart() > Enemy.distanceToOctagon + (sizeOfEnemy * 1.5)) {
|
||||
enemyIterator.remove();
|
||||
lifePoints -= 5;
|
||||
comboScore /= 2;
|
||||
}
|
||||
|
||||
if(closedEnemy == null){
|
||||
closedEnemy = e;
|
||||
}
|
||||
if((Enemy.distanceToOctagon-closedEnemy.getDistanceFromStart()) > (Enemy.distanceToOctagon-e.getDistanceFromStart())){
|
||||
closedEnemy = e;
|
||||
}
|
||||
e.update(factor);
|
||||
}
|
||||
}
|
||||
@@ -125,6 +134,12 @@ public class PlayState extends GameState {
|
||||
}
|
||||
|
||||
infoPanel.updateIPanel();
|
||||
area.count();
|
||||
if(closedEnemy == null){
|
||||
area.pathPainted(-1, null);
|
||||
}else{
|
||||
area.pathPainted(closedEnemy.getIndex(), closedEnemy.getColor());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -134,10 +149,12 @@ public class PlayState extends GameState {
|
||||
g2.setClip(borderRect);
|
||||
area.draw(g2);
|
||||
|
||||
g2.setStroke(stroke);
|
||||
for (Path p : area.paths) {
|
||||
if (p.getEnemysInPath() != null) {
|
||||
for (Enemy enemy : p.getEnemysInPath()) {
|
||||
g2.setStroke(borderStroke);
|
||||
enemy.draw(g2, true);
|
||||
g2.setStroke(stroke);
|
||||
enemy.draw(g2);
|
||||
}
|
||||
}
|
||||
@@ -160,6 +177,8 @@ public class PlayState extends GameState {
|
||||
currentScore += enemy.getDistanceFromStart() - Enemy.distanceToOctagon;
|
||||
comboScore += 5;
|
||||
lifePoints = Math.min(lifePoints+10, 100);
|
||||
area.setHitAreaColor(enemy.getColor());
|
||||
area.hit();
|
||||
enemysInPath.remove();
|
||||
notHit = false;
|
||||
infoPanel.throwACoin();
|
||||
|
||||
@@ -45,7 +45,7 @@ public class InfoPanel {
|
||||
// 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;
|
||||
|
||||
@@ -1,122 +1,74 @@
|
||||
package model.objects;
|
||||
|
||||
import image.Images;
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Composite;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.LinearGradientPaint;
|
||||
import java.awt.Paint;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.Transparency;
|
||||
import java.awt.geom.GeneralPath;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.image.VolatileImage;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import audio.Song;
|
||||
|
||||
public class MenuButton {
|
||||
|
||||
private int x, y, rounding;
|
||||
private double scalefactor;
|
||||
private Color buttoncolor;
|
||||
|
||||
private ArrayList<Color> colors;
|
||||
private int x, y;
|
||||
private int xx,yy;
|
||||
private boolean selected;
|
||||
private VolatileImage background;
|
||||
|
||||
private Song song;
|
||||
Color color;
|
||||
|
||||
public MenuButton(int x, int y, double scale, int rounding, Color c0, Song song){
|
||||
public MenuButton(int x, int y, Color color, Song song){
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.scalefactor = scale;
|
||||
this.rounding = rounding;
|
||||
this.buttoncolor = c0;
|
||||
this.color = color;
|
||||
setSong(song);
|
||||
|
||||
}
|
||||
|
||||
public void calculateButton(){
|
||||
Color c1 = buttoncolor.darker();
|
||||
Color c2 = buttoncolor.darker().darker();
|
||||
Color c3 = buttoncolor.darker().darker().darker();
|
||||
|
||||
c1 = new Color((int)(c1.getRed()*0.8), (int)(c1.getGreen()*0.8),(int)(c1.getBlue()*0.8));
|
||||
c2 = new Color((int)(c2.getRed()*0.8), (int)(c2.getGreen()*0.8),(int)(c2.getBlue()*0.8));
|
||||
c3 = new Color((int)(c3.getRed()*0.8), (int)(c3.getGreen()*0.8),(int)(c3.getBlue()*0.8));
|
||||
|
||||
|
||||
GeneralPath border = arrayToGeneralpath(new int[][]{{449,15}, {114,48},{78,25+rounding},{10,43+(int)(rounding*0.5)},{15,88+(int)(rounding*0.5)},{82,73+rounding},{118,88},{449,54}});
|
||||
GeneralPath line = arrayToGeneralpath(new int[][]{{-11,55},{-40,60},{-38,78},{-358,170-rounding*3},{-358,174-rounding*3},{-37,87},{-35,102},{-5,95}});
|
||||
Paint gradient = new LinearGradientPaint( new Point2D.Double((-100)*scalefactor,(512)*scalefactor),
|
||||
new Point2D.Double((600)*scalefactor,(512)*scalefactor),
|
||||
new float[]{0.0f, 1.0f},
|
||||
new Color[]{new Color(c1.getRed(), c1.getGreen(), c1.getBlue(), 10), buttoncolor});
|
||||
//Draw the generated button to the buffered image
|
||||
background = Images.initVolatileImage(1280, 500, Transparency.TRANSLUCENT);
|
||||
Graphics2D g2d = background.createGraphics();
|
||||
RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g2d.setRenderingHints(rh);
|
||||
g2d.setComposite(AlphaComposite.DstOut);
|
||||
g2d.fillRect(0, 0, background.getWidth(), background.getHeight());
|
||||
g2d.setComposite(AlphaComposite.SrcOver);
|
||||
|
||||
g2d.setColor(c2);
|
||||
g2d.fill(arrayToGeneralpath(new int[][]{{449, 1}, {449, 68},{113, 103}, {106, 35}}));
|
||||
g2d.setColor(c3);
|
||||
g2d.fill(arrayToGeneralpath(new int[][]{{113, 103}, {106, 35},{70, 12+rounding}, {77, 88+rounding}}));
|
||||
g2d.setColor(c2);
|
||||
g2d.fill(arrayToGeneralpath(new int[][]{{70, 12+rounding}, {77, 88+rounding},{4, 104+(int)(rounding*0.5)}, {-4, 32+(int)(rounding*0.5)}}));
|
||||
g2d.setColor(buttoncolor);
|
||||
g2d.fill(arrayToGeneralpath(new int[][]{{449, 15}, {449, 54},{118, 88}, {114, 48}}));
|
||||
g2d.setColor(c1);
|
||||
g2d.fill(arrayToGeneralpath(new int[][]{{118, 88}, {114, 48},{78, 25+rounding}, {82, 73+rounding}}));
|
||||
g2d.setColor(buttoncolor);
|
||||
g2d.fill(arrayToGeneralpath(new int[][]{{78, 25+rounding}, {82, 73+rounding},{15, 88+(int)(rounding*0.5)}, {10, 43+(int)(rounding*0.5)}}));
|
||||
|
||||
if(selected){
|
||||
g2d.setStroke(new BasicStroke(4));
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.draw(border);
|
||||
}
|
||||
g2d.setPaint(gradient);
|
||||
g2d.fill(line);
|
||||
|
||||
//draw text
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.setFont(new Font("OCR A Extended", Font.BOLD, (int)(30*scalefactor)));
|
||||
g2d.translate((160+358)*scalefactor, (74)*scalefactor);
|
||||
g2d.rotate(-0.1);
|
||||
g2d.drawString(song.getTitle(), 0, 0);
|
||||
g2d.dispose();
|
||||
background.createGraphics();
|
||||
}
|
||||
|
||||
public GeneralPath arrayToGeneralpath(int block[][]){
|
||||
GeneralPath polyline = new GeneralPath(GeneralPath.WIND_EVEN_ODD, block.length);
|
||||
polyline.moveTo ((block[0][0]+358)*scalefactor, (block[0][1])*scalefactor);
|
||||
for (int index = 1; index < block.length; index++) {
|
||||
polyline.lineTo((block[index][0]+358)*scalefactor, (block[index][1])*scalefactor);
|
||||
};
|
||||
polyline.closePath();
|
||||
return polyline;
|
||||
public MenuButton(int x, int y, int xx, int yy, Color color, Song song){
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.color = color;
|
||||
this.yy = yy;
|
||||
this.xx = xx;
|
||||
setSong(song);
|
||||
}
|
||||
|
||||
public void draw(Graphics2D g2d){
|
||||
g2d.drawImage(background, (int)((x-320)*scalefactor), (int) ((y)*scalefactor), 1280, 500, null);
|
||||
|
||||
|
||||
if(selected){
|
||||
g2d.setColor(color.darker().darker().darker().darker());
|
||||
g2d.fillRect(x-10, y-10,xx+20,yy+20);
|
||||
g2d.setColor(color.darker().darker());
|
||||
g2d.fillRect(x-5, y-5,xx+10,yy+10);
|
||||
g2d.setColor(color);
|
||||
g2d.fillRect(x,y,xx,yy);
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.drawRect(x-10, y-10, xx+20, yy+20);
|
||||
g2d.drawRect(x-5, y-5, xx+10, yy+10);
|
||||
g2d.drawRect(x, y, xx, yy);
|
||||
}
|
||||
else{
|
||||
g2d.setColor(color.darker().darker());
|
||||
g2d.fillRect(x-5, y-5,890,80);
|
||||
g2d.setColor(color);
|
||||
g2d.fillRect(x,y,880,70);
|
||||
}
|
||||
|
||||
//draw text
|
||||
g2d.setColor(Color.BLACK);
|
||||
Font textFont = new Font("OCR A Extended", Font.BOLD,60);
|
||||
g2d.setFont(textFont);
|
||||
if(selected)
|
||||
g2d.drawString(song.getTitle(), x+50, y+63);
|
||||
else
|
||||
g2d.drawString(song.getTitle(), x+50, y+57);
|
||||
}
|
||||
|
||||
public void update(){
|
||||
}
|
||||
|
||||
public void setSelected(boolean selected) {
|
||||
this.selected = selected;
|
||||
x += 100;
|
||||
y -= 40;
|
||||
scalefactor += 0.2;
|
||||
calculateButton();
|
||||
}
|
||||
|
||||
public boolean isSelected(){
|
||||
@@ -136,6 +88,5 @@ public class MenuButton {
|
||||
|
||||
public void setSong(Song song) {
|
||||
this.song = song;
|
||||
calculateButton();
|
||||
}
|
||||
}
|
||||
|
||||
+75
-62
@@ -7,10 +7,8 @@ import java.awt.Graphics2D;
|
||||
import java.awt.Polygon;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.Transparency;
|
||||
import java.awt.geom.GeneralPath;
|
||||
import java.awt.geom.Line2D;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.VolatileImage;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -21,82 +19,63 @@ import model.gameState.PlayState;
|
||||
public class PlayArea {
|
||||
|
||||
public List<Path> paths;
|
||||
private Polygon octagon,hitArea;
|
||||
public Rectangle2D[] hitAreas; //de area voor elk path die de enemy moet raken
|
||||
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;
|
||||
|
||||
public PlayArea(double xToRight,double heightOfGameScreen,double widthOfGameScreen, int sizeOctagon) {
|
||||
super();
|
||||
paths = new ArrayList<Path>();
|
||||
|
||||
setHitAreaColor(Color.RED);
|
||||
//make the polygons
|
||||
int amountOfAngles = 8;
|
||||
double middlePointX = widthOfGameScreen/2+xToRight;
|
||||
double middlePointY = heightOfGameScreen/2;
|
||||
|
||||
octagon = new Polygon();
|
||||
//the inner octagon
|
||||
innerHitAreaBorder = new Polygon();
|
||||
for(int i = 0; i < amountOfAngles; i++){
|
||||
octagon.addPoint((int)(middlePointX+sizeOctagon*Math.cos(i*Math.PI/(amountOfAngles/2))),
|
||||
innerHitAreaBorder.addPoint((int)(middlePointX+sizeOctagon*Math.cos(i*Math.PI/(amountOfAngles/2))),
|
||||
(int)(middlePointY+sizeOctagon*Math.sin(i*Math.PI/(amountOfAngles/2))));
|
||||
}
|
||||
|
||||
hitArea = new Polygon();
|
||||
//the outside octagon
|
||||
outsideHitAreaBorder = new Polygon();
|
||||
sizeOctagon += PlayState.sizeOfEnemy;
|
||||
for(int i = 0; i < amountOfAngles; i++){
|
||||
hitArea.addPoint((int)(middlePointX+sizeOctagon*Math.cos(i*Math.PI/(amountOfAngles/2))),
|
||||
outsideHitAreaBorder.addPoint((int)(middlePointX+sizeOctagon*Math.cos(i*Math.PI/(amountOfAngles/2))),
|
||||
(int)(middlePointY+sizeOctagon*Math.sin(i*Math.PI/(amountOfAngles/2))));
|
||||
}
|
||||
|
||||
hitAreas = new Rectangle2D[amountOfAngles];
|
||||
int newIndex;
|
||||
Point2D beginPoint,endPoint;
|
||||
for(int index = 0; index < hitAreas.length; index++){
|
||||
//in het polygon staat de cooridinaten van de top niet als eerste in de array, maar op index 6.n
|
||||
newIndex = (index+6+8)%8;
|
||||
hitAreas[index] = new Rectangle2D.Double();
|
||||
beginPoint = new Point2D.Double(octagon.xpoints[newIndex], octagon.ypoints[newIndex]);
|
||||
endPoint = new Point2D.Double(hitArea.xpoints[newIndex], hitArea.ypoints[newIndex]);
|
||||
hitAreas[index].setFrameFromDiagonal(beginPoint,endPoint);
|
||||
//hitArea the area where you must click the enemy
|
||||
hitArea = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
|
||||
|
||||
hitArea.moveTo(innerHitAreaBorder.xpoints[0], innerHitAreaBorder.ypoints[0]);
|
||||
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++){
|
||||
hitArea.lineTo(outsideHitAreaBorder.xpoints[i], outsideHitAreaBorder.ypoints[i]);
|
||||
}
|
||||
|
||||
Rectangle2D cr = null;//cr --> current rectangle
|
||||
double size = (hitAreas[1].getWidth() - 10)/2;//dit is de grootte van een zijde als die van de oorspronklijke 0 was.
|
||||
|
||||
cr = hitAreas[0];
|
||||
hitAreas[0].setFrame(cr.getX()-size/2, cr.getY()+1, size, cr.getHeight());
|
||||
|
||||
cr = hitAreas[2];
|
||||
hitAreas[2].setFrame(cr.getX()-1, cr.getY()-size/2, cr.getWidth(), size);
|
||||
|
||||
cr = hitAreas[4];
|
||||
hitAreas[4].setFrame(cr.getX()-size/2, cr.getY()-1, size, cr.getHeight());
|
||||
|
||||
cr = hitAreas[6];
|
||||
hitAreas[6].setFrame(cr.getX()+1, cr.getY()-size/2, cr.getWidth(), size);
|
||||
|
||||
widthOfGameScreen += xToRight;
|
||||
|
||||
// paths.add(new Path(middlePointX,0 ,hitArea.xpoints[6],hitArea.ypoints[6]));//top
|
||||
// paths.add(new Path(widthOfGameScreen,0 ,hitArea.xpoints[7],hitArea.ypoints[7]));//right -top
|
||||
// paths.add(new Path(widthOfGameScreen,middlePointY ,hitArea.xpoints[0],hitArea.ypoints[0]));//right
|
||||
// paths.add(new Path(widthOfGameScreen,heightOfGameScreen,hitArea.xpoints[1],hitArea.ypoints[1]));//right -down
|
||||
// paths.add(new Path(middlePointX,heightOfGameScreen ,hitArea.xpoints[2],hitArea.ypoints[2]));//down
|
||||
// paths.add(new Path(xToRight,heightOfGameScreen ,hitArea.xpoints[3],hitArea.ypoints[3]));//left -down
|
||||
// paths.add(new Path(xToRight,middlePointY ,hitArea.xpoints[4],hitArea.ypoints[4]));//left
|
||||
// paths.add(new Path(xToRight,0 ,hitArea.xpoints[5],hitArea.ypoints[5]));//left -top
|
||||
|
||||
//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(hitArea.xpoints[6],hitArea.ypoints[6]-Enemy.distanceToOctagon ,hitArea.xpoints[6],hitArea.ypoints[6]));//top
|
||||
paths.add(new Path(hitArea.xpoints[7] + angleX,hitArea.ypoints[7] - angleY ,hitArea.xpoints[7],hitArea.ypoints[7]));//right -top
|
||||
paths.add(new Path(hitArea.xpoints[0]+Enemy.distanceToOctagon,hitArea.ypoints[0] ,hitArea.xpoints[0],hitArea.ypoints[0]));//right
|
||||
paths.add(new Path(hitArea.xpoints[1]+angleX,hitArea.ypoints[1]+angleY ,hitArea.xpoints[1],hitArea.ypoints[1]));//right -down
|
||||
paths.add(new Path(hitArea.xpoints[2],hitArea.ypoints[2]+Enemy.distanceToOctagon ,hitArea.xpoints[2],hitArea.ypoints[2]));//down
|
||||
paths.add(new Path(hitArea.xpoints[3] - angleX,hitArea.ypoints[3] + angleY ,hitArea.xpoints[3],hitArea.ypoints[3]));//left -down
|
||||
paths.add(new Path(hitArea.xpoints[4] - Enemy.distanceToOctagon,hitArea.ypoints[4] ,hitArea.xpoints[4],hitArea.ypoints[4]));//left
|
||||
paths.add(new Path(hitArea.xpoints[5] - angleX,hitArea.ypoints[5] - angleY ,hitArea.xpoints[5],hitArea.ypoints[5]));//left -top
|
||||
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
|
||||
@@ -104,22 +83,31 @@ public class PlayArea {
|
||||
Graphics2D g2 = background.createGraphics();
|
||||
RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g2.setRenderingHints(rh);
|
||||
Line2D current;
|
||||
int index;
|
||||
Line2D current;
|
||||
g2.setColor(Color.BLACK);
|
||||
for(int i = 0; i < paths.size(); i++){
|
||||
current = paths.get(i);
|
||||
index = (i+14)%8;
|
||||
g2.drawLine((int)current.getX1(), (int)current.getY1(), octagon.xpoints[index],octagon.ypoints[index]);
|
||||
current = paths.get(i);
|
||||
g2.draw(current);
|
||||
}
|
||||
g2.draw(octagon);
|
||||
g2.draw(hitArea);
|
||||
g2.draw(innerHitAreaBorder);
|
||||
g2.draw(outsideHitAreaBorder);
|
||||
g2.dispose();
|
||||
background.createGraphics();
|
||||
}
|
||||
|
||||
public void draw(Graphics2D g2){
|
||||
public void draw(Graphics2D g2){
|
||||
g2.drawImage(background, 0, 0, 1280, 1024, null);
|
||||
if(hit){
|
||||
g2.setColor(hitAreaColor);
|
||||
g2.fill(hitArea);
|
||||
if(count == maxCount){
|
||||
hit = false;
|
||||
}
|
||||
}
|
||||
if(pathID >= 0 && pathColor != null){
|
||||
g2.setColor(pathColor);
|
||||
g2.draw(paths.get(pathID));
|
||||
}
|
||||
}
|
||||
|
||||
public Line2D getLine(int index){
|
||||
@@ -131,4 +119,29 @@ public class PlayArea {
|
||||
}
|
||||
return paths.get(index);
|
||||
}
|
||||
|
||||
|
||||
public void setHitAreaColor(Color color) {
|
||||
hitAreaColor = color;
|
||||
count = 0;
|
||||
}
|
||||
|
||||
public void hit(){
|
||||
hit = true;
|
||||
}
|
||||
|
||||
public void count(){
|
||||
if(hit){
|
||||
count += 3;
|
||||
if(count > maxCount){
|
||||
count = maxCount;
|
||||
}
|
||||
hitAreaColor = new Color(hitAreaColor.getRed(),hitAreaColor.getGreen(),hitAreaColor.getBlue(),255-(255*count)/maxCount);
|
||||
}
|
||||
}
|
||||
|
||||
public void pathPainted(int pathID,Color pathColor){
|
||||
this.pathID = pathID;
|
||||
this.pathColor = pathColor;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user