diff --git a/model/gameState/MenuState.java b/model/gameState/MenuState.java index 06568d4..3877dc1 100644 --- a/model/gameState/MenuState.java +++ b/model/gameState/MenuState.java @@ -117,14 +117,12 @@ public class MenuState extends GameState { //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(); } diff --git a/model/gameState/PlayState.java b/model/gameState/PlayState.java index 10b1b50..103aa80 100644 --- a/model/gameState/PlayState.java +++ b/model/gameState/PlayState.java @@ -37,6 +37,8 @@ public class PlayState extends GameState { public static int sizeOfEnemy = 40; public static int currentScore = 0; public static int comboScore = 0; + public static int lastScoreChange = 0; + public static int sinceScoreChanged = 75; public static double lifePoints = 100; private int enemies_hit = 0; @@ -71,9 +73,7 @@ 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); @@ -108,28 +108,27 @@ public class PlayState extends GameState { endGame(); oldProgress = progress; - Enemy closedEnemy = null; player.update(factor); - for (Path path : area.paths) { + for (Path path : area.paths) { Iterator enemyIterator = path.getEnemysInPath().iterator(); while (enemyIterator.hasNext()) { - Enemy e = enemyIterator.next(); if (e.getDistanceFromStart() > Enemy.distanceToOctagon + (sizeOfEnemy * 1.5)) { enemyIterator.remove(); lifePoints -= 5; + lastScoreChange = -5; + sinceScoreChanged = 1; 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); } } @@ -139,27 +138,25 @@ public class PlayState extends GameState { infoPanel.updateIPanel(); if(lifePoints <= 0) - { endGame(); - } - if(comboScore >= 100) - { - comboScore = 0; - currentScore += 500; + + if(comboScore >= 100) { + comboScore = 0; + currentScore += 500; + sinceScoreChanged = 1; + lastScoreChange = 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(); } @@ -176,6 +173,7 @@ public class PlayState extends GameState { infoPanel.draw(g2); g2.setClip(borderRect); area.draw(g2); + sinceScoreChanged++; for (Path p : area.paths) { if (p.getEnemysInPath() != null) { @@ -187,14 +185,13 @@ 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); @@ -217,6 +214,8 @@ public class PlayState extends GameState { if (e.getButton().getColor().equals(enemy.getColor())) { currentScore += enemy.getDistanceFromStart() - Enemy.distanceToOctagon; comboScore += 5; + lastScoreChange = 5; + sinceScoreChanged = 1; lifePoints = Math.min(lifePoints+10, 100); area.setHitAreaColor(enemy.getColor()); area.hit(); @@ -235,15 +234,11 @@ public class PlayState extends GameState { if(notHit) { if(area.paths.get(player.getIndex()).getEnemysInPath().size() > 0) - { lifePoints -= 1.5; - } } if(e.getButton().getButtonID() == 0) - { endGame(); - } else buttons_pressed++; } diff --git a/model/objects/InfoPanel.java b/model/objects/InfoPanel.java index 8ee5db0..b5f183a 100644 --- a/model/objects/InfoPanel.java +++ b/model/objects/InfoPanel.java @@ -2,12 +2,7 @@ package model.objects; import image.Images; -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.*; import java.awt.image.VolatileImage; import model.SongHandler; @@ -22,8 +17,10 @@ public class InfoPanel { private SongHandler sh; private String time; - private CoinAnimation coinAnimation = new CoinAnimation(125, 300); private int tempComboScore; + + private CoinAnimation coinAnimation = new CoinAnimation(125, 300); + public InfoPanel(int x, int y, SongHandler sh){ this.x = x; @@ -58,33 +55,44 @@ public class InfoPanel { 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 < 75 && PlayState.sinceScoreChanged != 0) { + g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float)(1 - (PlayState.sinceScoreChanged * 0.01)))); + g2.setColor(Color.RED); + g2.drawString("+" + PlayState.lastScoreChange, 205, 40); + g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f)); + } + g2.setColor(Color.ORANGE); g2.drawString("Score: " + totalHighscore, 25, 75); + + // BALK g2.drawRect(25, 100, 200, 30); g2.drawRect(25, 300, 200, 700); - + g2.drawString(sh.getCurrentSong().getTitle(), 25, 200); g2.drawString(sh.getCurrentSongInstance().getDifficulty(), 25, 230); g2.drawString(sh.getCurrentSong().getAuthor(), 25, 260); g2.drawString(time, 25, 290); + // Controlen of coin animatie nodig is if (!coinAnimation.areWeDoneYet()) { coinAnimation.draw(g2); - // Score pas updaten wanneer coin klaar is met afspelen + // Score pas updaten wanneer coin in zijn laatste draw loop zit if (coinAnimation.isLastLoop()) tempComboScore = PlayState.comboScore; } else @@ -101,7 +109,7 @@ public class InfoPanel { } public void throwACoin() { - coinAnimation.start(); // Teller weer op 0 zetten + coinAnimation.start(); // Teller weer op 1 zetten } public void draw(Graphics2D g2){ diff --git a/model/objects/PlayArea.java b/model/objects/PlayArea.java index 6fb418d..31f4552 100644 --- a/model/objects/PlayArea.java +++ b/model/objects/PlayArea.java @@ -22,21 +22,23 @@ import model.gameState.PlayState; public class PlayArea { - public List paths; + public List 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 int count = 0, + maxCount = 100, + pathID = -1, + oldPathId = pathID; private Stroke stroke = new BasicStroke(5); 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<>(); setHitAreaColor(Color.WHITE); //make the polygons int amountOfAngles = 8; @@ -62,30 +64,35 @@ 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 - - + 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(); } @@ -94,23 +101,22 @@ public class PlayArea { if(hit){ g2.setColor(hitAreaColor); g2.fill(hitArea); - if(count == maxCount){ + + if(count == maxCount) hit = false; - } } - if( oldPathId != pathID){ + if (oldPathId != pathID){ generateBackground(); oldPathId = pathID; } } public Line2D getLine(int index){ - if(index < 0){ + if(index < 0) index = 0; - } - if(index >= 8 ){ + else if(index >= 8) index = 7; - } + return paths.get(index); } @@ -127,9 +133,8 @@ 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); } } @@ -149,10 +154,10 @@ public class PlayArea { Line2D current; g2.setColor(Color.BLACK); g2.setStroke(stroke); - for(int i = 0; i < paths.size(); i++){ - current = paths.get(i); - g2.draw(current); - } + + paths.forEach(path -> { + g2.draw(path); + }); g2.draw(innerHitAreaBorder); g2.draw(outsideHitAreaBorder);