game logic updated
This commit is contained in:
+2
-2
@@ -58,7 +58,7 @@ public class Window extends JFrame {
|
||||
JoystickHandler jsh = new JoystickHandler();
|
||||
|
||||
//Create Instances
|
||||
SongHandler sh = new SongHandler();
|
||||
SongHandler sh = null; //new SongHandler();
|
||||
GameStateManager gsm = new GameStateManager(sh);
|
||||
GameView view = new GameView(led,gsm);
|
||||
GameModel model = new GameModel(sh, gsm);
|
||||
@@ -69,7 +69,7 @@ public class Window extends JFrame {
|
||||
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
||||
addWindowListener(new WindowAdapter(){
|
||||
public void windowClosing(WindowEvent e) {
|
||||
sh.close();
|
||||
// sh.close();
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -10,7 +10,7 @@ import model.drawObjects.DrawObject;
|
||||
public class Enemy extends DrawObject {
|
||||
|
||||
|
||||
private int length,timeToClick = 5,currentTimeToClick;
|
||||
private int length,timeToClick = 10,currentTimeToClick;
|
||||
private double speedX,speedY,lengthOf1Side;//lengthOf1Side wordt alleen gebruikt als de lijn een schuine lijn is.
|
||||
public Line2D enemy;
|
||||
private Color c;
|
||||
|
||||
@@ -6,19 +6,15 @@ import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Stroke;
|
||||
import java.awt.geom.Area;
|
||||
import java.awt.geom.Line2D;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import model.GameModel;
|
||||
import model.SongHandler;
|
||||
import model.drawObjects.Player;
|
||||
import model.drawObjects.enemy.Enemy;
|
||||
import model.objects.InfoPanel;
|
||||
import model.objects.Path;
|
||||
import model.objects.PlayArea;
|
||||
import control.GameStateManager;
|
||||
import control.button.ButtonEvent;
|
||||
@@ -29,10 +25,8 @@ public class PlayState extends GameState{
|
||||
public static final Rectangle2D borderRect = new Rectangle2D.Double(256, 0, 1024, 1024);
|
||||
private PlayArea area;
|
||||
private InfoPanel infoPanel;
|
||||
private Player player;
|
||||
private List<Enemy> enemys;
|
||||
private Stroke stroke;
|
||||
private Iterator<Enemy> enemyIterator;
|
||||
private Player player;
|
||||
private Stroke stroke;
|
||||
|
||||
public static int sizeOfEnemy = 40;
|
||||
public static int currentScore = 0;
|
||||
@@ -40,12 +34,10 @@ public class PlayState extends GameState{
|
||||
|
||||
public PlayState(GameStateManager gsm, SongHandler sh) {
|
||||
super(gsm,sh);
|
||||
infoPanel = new InfoPanel(0, 0);
|
||||
enemys = new ArrayList<Enemy>();
|
||||
infoPanel = new InfoPanel(0, 0);
|
||||
area = new PlayArea(256, 1024, 1024, 100);
|
||||
for(int index = 0; index < 2; index++){
|
||||
Line2D path = area.paths.get(index);
|
||||
addEnemy(index, GameModel.colors[index % 6], path.getP1(),path.getP2());
|
||||
for(int index = 0; index < 8; index++){
|
||||
addEnemy(index, GameModel.colors[index % 6]);
|
||||
}
|
||||
|
||||
player = new Player(1280-1024+1024/2, 1024/2);
|
||||
@@ -61,6 +53,7 @@ public class PlayState extends GameState{
|
||||
@Override
|
||||
public void update() {
|
||||
player.update();
|
||||
for(Path path : area.paths){
|
||||
enemyIterator = enemys.iterator();
|
||||
while(enemyIterator.hasNext()){
|
||||
Enemy e = enemyIterator.next();
|
||||
@@ -71,13 +64,10 @@ public class PlayState extends GameState{
|
||||
if(hitArea.intersectsLine(e.enemy) && !e.isClickable()){
|
||||
e.clickable();
|
||||
}
|
||||
if(e.isClickable()){
|
||||
|
||||
e.update();
|
||||
}
|
||||
// System.out.println(e.enemy.getP1().distance(hitArea.getCenterX(), hitArea.getCenterY()));
|
||||
e.update();
|
||||
}
|
||||
infoPanel.updateIPanel();
|
||||
}
|
||||
infoPanel.updateIPanel();
|
||||
}
|
||||
|
||||
|
||||
@@ -89,11 +79,13 @@ public class PlayState extends GameState{
|
||||
area.draw(g2);
|
||||
|
||||
g2.setStroke(stroke);
|
||||
if(enemys != null){
|
||||
for(Enemy enemy : enemys){
|
||||
enemy.draw(g2);
|
||||
}
|
||||
}
|
||||
for(Path p : area.paths){
|
||||
if(p.getEnemysInPath() != null){
|
||||
for(Enemy enemy : p.getEnemysInPath()){
|
||||
enemy.draw(g2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(player != null)
|
||||
player.draw(g2);
|
||||
@@ -105,18 +97,15 @@ public class PlayState extends GameState{
|
||||
|
||||
@Override
|
||||
public void buttonPressed(ButtonEvent e) {
|
||||
enemyIterator = enemys.iterator();
|
||||
while(enemyIterator.hasNext()){
|
||||
Enemy enemy = enemyIterator.next();
|
||||
if(enemy.isClickable()){
|
||||
if(enemy.getIndex() == player.getIndex()){
|
||||
if(enemy.getColor().equals(e.getButton().getColor())){
|
||||
enemyIterator.remove();
|
||||
currentScore += enemy.getTimeLeftToClick();
|
||||
}
|
||||
}
|
||||
// int index = player.getIndex();
|
||||
Path currentPath = area.paths.get(player.getIndex());
|
||||
Enemy ce = currentPath.getEnemysInPath().getFirst();
|
||||
if(ce.isClickable()){
|
||||
if(ce.getColor().equals(e.getButton().getColor())){
|
||||
currentScore += ce.getTimeLeftToClick();
|
||||
currentPath.getEnemysInPath().remove(ce);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -157,7 +146,9 @@ public class PlayState extends GameState{
|
||||
}
|
||||
}
|
||||
|
||||
public void addEnemy(int pathID,Color color,Point2D beginPoint,Point2D endPoint){
|
||||
enemys.add(new Enemy(pathID,1,color,100,beginPoint, endPoint));
|
||||
public void addEnemy(int pathID,Color color){
|
||||
Path path = area.paths.get(pathID);
|
||||
Enemy e = new Enemy(pathID,1,color,100,path.getP1(),path.getP2());
|
||||
path.getEnemysInPath().addLast(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package model.objects;
|
||||
|
||||
import java.awt.geom.Line2D;
|
||||
import java.util.ArrayDeque;
|
||||
|
||||
import model.drawObjects.enemy.Enemy;
|
||||
|
||||
public class Path extends Line2D.Double {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -4209367336660836698L;
|
||||
private ArrayDeque<Enemy> enemysInPath;
|
||||
|
||||
public Path(double x1, double y1, double x2, double y2) {
|
||||
super(x1,y1,x2,y2);
|
||||
enemysInPath = new ArrayDeque<Enemy>();
|
||||
}
|
||||
|
||||
public ArrayDeque<Enemy> getEnemysInPath() {
|
||||
return enemysInPath;
|
||||
}
|
||||
|
||||
public void setEnemysInPath(ArrayDeque<Enemy> enemysInPath) {
|
||||
this.enemysInPath = enemysInPath;
|
||||
}
|
||||
}
|
||||
+11
-11
@@ -12,13 +12,13 @@ import model.gameState.PlayState;
|
||||
|
||||
public class PlayArea {
|
||||
|
||||
public List<Line2D> paths;
|
||||
public List<Path> paths;
|
||||
private Polygon octagon,hitArea;
|
||||
public Rectangle2D[] hitAreas; //de area voor elk path die de enemy moet raken
|
||||
|
||||
public PlayArea(double xToRight,double heightOfGameScreen,double widthOfGameScreen, int sizeOctagon) {
|
||||
super();
|
||||
paths = new ArrayList<Line2D>();
|
||||
paths = new ArrayList<Path>();
|
||||
|
||||
int amountOfAngles = 8;
|
||||
double middlePointX = widthOfGameScreen/2+xToRight;
|
||||
@@ -51,7 +51,7 @@ public class PlayArea {
|
||||
|
||||
|
||||
Rectangle2D cr = null;//cr --> current rectangle
|
||||
double size = hitAreas[1].getWidth();//dit is de grootte van een zijde als die van de oorspronklijke 0 was.
|
||||
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());
|
||||
@@ -67,14 +67,14 @@ public class PlayArea {
|
||||
|
||||
widthOfGameScreen += xToRight;
|
||||
|
||||
paths.add(new Line2D.Double(middlePointX,0 ,hitArea.xpoints[6],hitArea.ypoints[6]));//top
|
||||
paths.add(new Line2D.Double(widthOfGameScreen,0 ,hitArea.xpoints[7],hitArea.ypoints[7]));//right -top
|
||||
paths.add(new Line2D.Double(widthOfGameScreen,middlePointY ,hitArea.xpoints[0],hitArea.ypoints[0]));//right
|
||||
paths.add(new Line2D.Double(widthOfGameScreen,heightOfGameScreen,hitArea.xpoints[1],hitArea.ypoints[1]));//right -down
|
||||
paths.add(new Line2D.Double(middlePointX,heightOfGameScreen ,hitArea.xpoints[2],hitArea.ypoints[2]));//down
|
||||
paths.add(new Line2D.Double(xToRight,heightOfGameScreen ,hitArea.xpoints[3],hitArea.ypoints[3]));//left -down
|
||||
paths.add(new Line2D.Double(xToRight,middlePointY ,hitArea.xpoints[4],hitArea.ypoints[4]));//left
|
||||
paths.add(new Line2D.Double(xToRight,0 ,hitArea.xpoints[5],hitArea.ypoints[5]));//left -top
|
||||
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
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user