From 1e09c3e02456afd541aaa0763536be1584b7ff70 Mon Sep 17 00:00:00 2001 From: Bilel Bghiel Date: Thu, 11 Jun 2015 14:33:33 +0200 Subject: [PATCH 1/4] Coin on hit --- model/drawObjects/CoinAnimation.java | 66 ++++++++++++++++++++++++++++ model/gameState/PlayState.java | 1 + model/objects/InfoPanel.java | 13 +++++- 3 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 model/drawObjects/CoinAnimation.java diff --git a/model/drawObjects/CoinAnimation.java b/model/drawObjects/CoinAnimation.java new file mode 100644 index 0000000..3ab2318 --- /dev/null +++ b/model/drawObjects/CoinAnimation.java @@ -0,0 +1,66 @@ +package model.drawObjects; +import javax.imageio.ImageIO; +import java.awt.*; +import java.awt.geom.Ellipse2D; +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; + +/** + * Created by Bilel on 4-6-2015. + */ +public class CoinAnimation extends DrawObject { + + private Ellipse2D coinShape; + private Point2D.Double coinSetPoint; + + // Hoevaak de timer gelopen heeft + private static int timerLoops = 0; + + public CoinAnimation(int startX, int startY) { + coinSetPoint = new Point2D.Double(startX, startY); + coinShape = new Ellipse2D.Double(startX, startY, 20, 20); + } + + public void start() { + timerLoops = 1; + } + + public void draw(Graphics2D g2) { + + g2.setColor(new Color(255, 255, 0, (255 - timerLoops * 5))); // GEEL + g2.draw(coinShape); // MUNTJE TEKENEN + g2.fill(coinShape); + update(timerLoops); // UPDATE + + } + + // Wordt na elke paint aangeroepen + public void update(float factor) { + + if (areWeDoneYet()) { + System.out.println("Call initCoin(int startX, startY) first!"); + return; + } + + // Frame steeds aanpassen aan locatie van coin (Zodat hele coin wel te zien blijft) + coinShape.setFrame(coinSetPoint.getX(), coinSetPoint.getY() + 10 * timerLoops, + coinShape.getWidth(), coinShape.getHeight()); + + timerLoops++; + + } + + public boolean areWeDoneYet() { + System.out.println(timerLoops); + if (timerLoops > 50 || timerLoops == 0) { + timerLoops = 0; + return true; + } + + return false; + } + +} \ No newline at end of file diff --git a/model/gameState/PlayState.java b/model/gameState/PlayState.java index db5f309..a30c7a8 100644 --- a/model/gameState/PlayState.java +++ b/model/gameState/PlayState.java @@ -162,6 +162,7 @@ public class PlayState extends GameState { lifePoints = Math.min(lifePoints+10, 100); enemysInPath.remove(); notHit = false; + infoPanel.throwACoin(); break; } } diff --git a/model/objects/InfoPanel.java b/model/objects/InfoPanel.java index 624d040..43220d6 100644 --- a/model/objects/InfoPanel.java +++ b/model/objects/InfoPanel.java @@ -10,6 +10,7 @@ import java.awt.Transparency; import java.awt.image.VolatileImage; import model.SongHandler; +import model.drawObjects.CoinAnimation; import model.gameState.PlayState; public class InfoPanel { @@ -19,11 +20,14 @@ public class InfoPanel { private VolatileImage infoPanel; private SongHandler sh; private String time; + + private CoinAnimation coinAnimation = new CoinAnimation(150, 200); public InfoPanel(int x, int y, SongHandler sh){ this.x = x; this.y = y; this.sh = sh; + updateIPanel(); generateInfoPanel(); } @@ -77,12 +81,19 @@ public class InfoPanel { g2.drawString(sh.getCurrentSong().getAuthor(), 25, 230); g2.drawString(time, 25, 260); } - + + if (!coinAnimation.areWeDoneYet()) + coinAnimation.draw(g2); + g2.setColor(Color.YELLOW); g2.fillRect(25, 1000 - 7 * PlayState.comboScore, 200, 0 + 7 * PlayState.comboScore); g2.dispose(); infoPanel.createGraphics(); } + + public void throwACoin() { + coinAnimation.start(); + } public void draw(Graphics2D g2){ g2.drawImage(infoPanel, 0, 0, 256,1024,null); From 01169b0ab73bb9dbe2371af97a496ea296384634 Mon Sep 17 00:00:00 2001 From: Bilel Bghiel Date: Thu, 11 Jun 2015 15:36:07 +0200 Subject: [PATCH 2/4] Coin on hit --- .idea/libraries/Arcade.xml | 13 ++++ .idea/uiDesigner.xml | 124 +++++++++++++++++++++++++++++++++++ Arcade.iml | 12 ++++ model/objects/InfoPanel.java | 2 +- 4 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 .idea/libraries/Arcade.xml create mode 100644 .idea/uiDesigner.xml create mode 100644 Arcade.iml diff --git a/.idea/libraries/Arcade.xml b/.idea/libraries/Arcade.xml new file mode 100644 index 0000000..0daaa5c --- /dev/null +++ b/.idea/libraries/Arcade.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Arcade.iml b/Arcade.iml new file mode 100644 index 0000000..12329c9 --- /dev/null +++ b/Arcade.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/model/objects/InfoPanel.java b/model/objects/InfoPanel.java index 43220d6..7712426 100644 --- a/model/objects/InfoPanel.java +++ b/model/objects/InfoPanel.java @@ -21,7 +21,7 @@ public class InfoPanel { private SongHandler sh; private String time; - private CoinAnimation coinAnimation = new CoinAnimation(150, 200); + private CoinAnimation coinAnimation = new CoinAnimation(125, 200); public InfoPanel(int x, int y, SongHandler sh){ this.x = x; From 68f5f2392c9d1e6e7d5682fbf702e03835974d27 Mon Sep 17 00:00:00 2001 From: Bilel Bghiel Date: Thu, 11 Jun 2015 21:23:02 +0200 Subject: [PATCH 3/4] - mooiere afdaling. - scorebar vult pas nadat muntje 'erin valt' --- model/drawObjects/CoinAnimation.java | 19 ++++++++++--------- model/gameState/GameOverState.java | 3 +-- model/objects/InfoPanel.java | 21 +++++++++++++-------- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/model/drawObjects/CoinAnimation.java b/model/drawObjects/CoinAnimation.java index 3ab2318..13c667e 100644 --- a/model/drawObjects/CoinAnimation.java +++ b/model/drawObjects/CoinAnimation.java @@ -1,12 +1,8 @@ package model.drawObjects; -import javax.imageio.ImageIO; + import java.awt.*; import java.awt.geom.Ellipse2D; import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.IOException; /** * Created by Bilel on 4-6-2015. @@ -24,6 +20,7 @@ public class CoinAnimation extends DrawObject { coinShape = new Ellipse2D.Double(startX, startY, 20, 20); } + // Start public void start() { timerLoops = 1; } @@ -34,7 +31,6 @@ public class CoinAnimation extends DrawObject { g2.draw(coinShape); // MUNTJE TEKENEN g2.fill(coinShape); update(timerLoops); // UPDATE - } // Wordt na elke paint aangeroepen @@ -45,20 +41,25 @@ public class CoinAnimation extends DrawObject { return; } - // Frame steeds aanpassen aan locatie van coin (Zodat hele coin wel te zien blijft) + // Coin omlaag verschuiven doordat Y * loops omlaag gaat coinShape.setFrame(coinSetPoint.getX(), coinSetPoint.getY() + 10 * timerLoops, coinShape.getWidth(), coinShape.getHeight()); timerLoops++; - } + // Zijn we al begonnen/klaar? public boolean areWeDoneYet() { - System.out.println(timerLoops); if (timerLoops > 50 || timerLoops == 0) { timerLoops = 0; return true; } + return false; + } + + public boolean isLastLoop() { + if (timerLoops == 49) + return true; return false; } diff --git a/model/gameState/GameOverState.java b/model/gameState/GameOverState.java index 7dbb805..3af5047 100644 --- a/model/gameState/GameOverState.java +++ b/model/gameState/GameOverState.java @@ -23,8 +23,7 @@ public class GameOverState extends GameState { BufferedImage gameOver = Images.getImage(ImageType.gameover); VolatileImage background; Font textFont = new Font("OCR A Extended", Font.BOLD, 70); - - + private String endScore = ""; int frame; diff --git a/model/objects/InfoPanel.java b/model/objects/InfoPanel.java index 7712426..1604bcf 100644 --- a/model/objects/InfoPanel.java +++ b/model/objects/InfoPanel.java @@ -21,7 +21,9 @@ public class InfoPanel { private SongHandler sh; private String time; - private CoinAnimation coinAnimation = new CoinAnimation(125, 200); + private int tempComboScore; + + private CoinAnimation coinAnimation = new CoinAnimation(125, 250); public InfoPanel(int x, int y, SongHandler sh){ this.x = x; @@ -68,25 +70,28 @@ public class InfoPanel { 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); - if(sh.getCurrentSong().getSubtitle() != "") - { + + if(sh.getCurrentSong().getSubtitle() != "") { g2.drawString(sh.getCurrentSong().getSubtitle(), 25, 230); g2.drawString(sh.getCurrentSong().getAuthor(), 25, 260); g2.drawString(time, 25, 290); } - else - { + else { g2.drawString(sh.getCurrentSong().getAuthor(), 25, 230); g2.drawString(time, 25, 260); } - if (!coinAnimation.areWeDoneYet()) + if (!coinAnimation.areWeDoneYet()) { coinAnimation.draw(g2); + if (coinAnimation.isLastLoop()) + tempComboScore = PlayState.comboScore; + } + + g2.fillRect(25, 1000 - 7 * tempComboScore, 200, 7 * tempComboScore); g2.setColor(Color.YELLOW); - g2.fillRect(25, 1000 - 7 * PlayState.comboScore, 200, 0 + 7 * PlayState.comboScore); + g2.dispose(); infoPanel.createGraphics(); } From d0a91023b39acad3c7e62b68c0882d1104e16b01 Mon Sep 17 00:00:00 2001 From: Bilel Bghiel Date: Fri, 12 Jun 2015 19:17:21 +0200 Subject: [PATCH 4/4] - Scorebalk kleur krijgt geen Alpha meer mee - Scorebalk renderde niet opnieuw wanneer speler score verliest. - Boot Animatie toegevoegd. - Nog wat kleine verbeteringen. --- model/drawObjects/CoinAnimation.java | 22 +++--- model/gameState/PlayState.java | 3 +- model/gameState/TitleState.java | 114 +++++++++++++++++---------- model/objects/InfoPanel.java | 7 +- 4 files changed, 90 insertions(+), 56 deletions(-) diff --git a/model/drawObjects/CoinAnimation.java b/model/drawObjects/CoinAnimation.java index 13c667e..21183c8 100644 --- a/model/drawObjects/CoinAnimation.java +++ b/model/drawObjects/CoinAnimation.java @@ -6,6 +6,10 @@ import java.awt.geom.Point2D; /** * Created by Bilel on 4-6-2015. + * + * CoinAnimation klasse: Weergeeft een balletje (resembleerd een muntje) dat omlaag valt. + * Je hoeft alleen achter elkaar de paint(Graphics2D) methode aan te roepen, deze roep automatisch een 'reposition' aan, + * waardoor je het balletje alleen snel achter elkaar hoeft te repainten. */ public class CoinAnimation extends DrawObject { @@ -27,41 +31,39 @@ public class CoinAnimation extends DrawObject { public void draw(Graphics2D g2) { + update(timerLoops); // UPDATE g2.setColor(new Color(255, 255, 0, (255 - timerLoops * 5))); // GEEL g2.draw(coinShape); // MUNTJE TEKENEN g2.fill(coinShape); - update(timerLoops); // UPDATE + } // Wordt na elke paint aangeroepen public void update(float factor) { + // Alleen tekenen wanner de animatie ingesteld is om te tekenen (zie: areWeDoneYet()), anders doei. if (areWeDoneYet()) { System.out.println("Call initCoin(int startX, startY) first!"); return; } - // Coin omlaag verschuiven doordat Y * loops omlaag gaat + // Coin omlaag verschuiven doordat Y * loops omlaag gaat. + // Per frame verschuift het balletje delta 10 op Y-as. coinShape.setFrame(coinSetPoint.getX(), coinSetPoint.getY() + 10 * timerLoops, coinShape.getWidth(), coinShape.getHeight()); - timerLoops++; } // Zijn we al begonnen/klaar? public boolean areWeDoneYet() { - if (timerLoops > 50 || timerLoops == 0) { + if (timerLoops > 49 || timerLoops == 0) { timerLoops = 0; return true; } return false; } - public boolean isLastLoop() { - if (timerLoops == 49) - return true; - - return false; - } + // Zitten we in de laatste loop? + public boolean isLastLoop() { return (timerLoops == 49) ? true : false; } } \ No newline at end of file diff --git a/model/gameState/PlayState.java b/model/gameState/PlayState.java index 1658625..4131826 100644 --- a/model/gameState/PlayState.java +++ b/model/gameState/PlayState.java @@ -181,12 +181,11 @@ public class PlayState extends GameState { area.hit(); enemysInPath.remove(); notHit = false; - infoPanel.throwACoin(); + infoPanel.throwACoin(); // Coin Animatie starten bij hit break; } } } - player.setBeat(); diff --git a/model/gameState/TitleState.java b/model/gameState/TitleState.java index da64bfc..c0a3927 100644 --- a/model/gameState/TitleState.java +++ b/model/gameState/TitleState.java @@ -9,6 +9,8 @@ import java.awt.GradientPaint; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.Transparency; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.awt.image.BufferedImage; import java.awt.image.VolatileImage; @@ -18,7 +20,9 @@ import control.GameStateManager.State; import control.button.ButtonEvent; import control.joystick.JoystickEvent; -public class TitleState extends GameState { +import javax.swing.*; + +public class TitleState extends GameState implements ActionListener { BufferedImage pressStart = Images.getImage(ImageType.pressstart); BufferedImage colorStrike = Images.getImage(ImageType.colorstrike); @@ -28,18 +32,21 @@ public class TitleState extends GameState { Font textFont2 = new Font("OCR A Extended", Font.BOLD, 130); GradientPaint gp = new GradientPaint(300, 0, new Color(0, 0, 1, 0.6f), 980, 1024, new Color(0, 0, 1, 0.2f)); - int index = 0; int varx = 0; int frame; + private Timer timer; + + int showInLoops = 1; int indexKast = 0; int xKast=0; public TitleState(GameStateManager gsm, SongHandler sh){ super(gsm, sh); - createBackground(); + // Logica zit in ActionListener (dus actionPerformed()) + (timer = new Timer(1000/3, this)).start(); } @Override @@ -49,23 +56,26 @@ public class TitleState extends GameState { @Override public void update(float factor) { - frame++; indexKast++; } @Override public void draw(Graphics2D g2) { - g2.drawImage(background, 0, 0, 1280, 1024, null); - int image_x = ((frame / 6) % 6) * 49; - g2.drawImage(pressStart.getSubimage(image_x, 0, 49, 26), 640-122, 512, 245, 130, null); - - - - xKast = indexKast/10; - xKast%=4; - //g2.drawImage(kast.getSubimage(xKast*300,0,300,400), 640-122,650,300,400,null); - g2.drawImage(kast.getSubimage(xKast*300,0,300,400), 100,300,300,400,null); + // Scherm beelt wat kleurrijke rectangles op het scherm. + if (showInLoops > 0) { + g2.drawImage(background, 0, 0, 1280, 1024, null); + createBackground(); + } + if (showInLoops > 18) { + // Code die de arcadekast en 'Press Start' toont. + int image_x = ((frame / 6) % 6) * 49; + g2.drawImage(pressStart.getSubimage(image_x, 0, 49, 26), 640 - 122, 512, 245, 130, null); + + xKast = indexKast / 10; + xKast %= 4; + g2.drawImage(kast.getSubimage(xKast * 300, 0, 300, 400), 100, 300, 300, 400, null); + } } @Override @@ -91,36 +101,58 @@ public class TitleState extends GameState { public void createBackground() { background = Images.initVolatileImage(1280, 1024, Transparency.OPAQUE); Graphics2D g2 = background.createGraphics(); - RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - g2.setRenderingHints(rh); - g2.setColor(new Color(1, 1, 1, 0.3f)); - g2.fillRect(0, 0, 1280, 1024); - g2.setColor(new Color(0, 1, 0, 0.7f)); - g2.fillRect(0, 0, 100, 1024); - g2.fillRect(1180, 0, 100, 1024); + if (showInLoops > 0) { + RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g2.setRenderingHints(rh); + } + if (showInLoops > 2) { + g2.setColor(new Color(1, 1, 1, 0.3f)); + g2.fillRect(0, 0, 1280, 1024); + } + if (showInLoops > 4) { + g2.setColor(new Color(0, 1, 0, 0.7f)); + g2.fillRect(0, 0, 100, 1024); + g2.fillRect(1180, 0, 100, 1024); + } + if (showInLoops > 6) { + g2.setColor(new Color(1, 1, 0, 0.7f)); + g2.fillRect(100, 0, 100, 1024); + g2.fillRect(1080, 0, 100, 1024); + } + if (showInLoops > 8) { + g2.setColor(new Color(1, 0, 0, 0.7f)); + g2.fillRect(200, 0, 100, 1024); + g2.fillRect(980, 0, 100, 1024); + } + if (showInLoops > 12) { + g2.setPaint(gp); + g2.fillRect(300, 0, 680, 1024); + } + if (showInLoops > 14) { + g2.setFont(textFont); + g2.setColor(Color.WHITE); + g2.drawString("©2015 Team Hamtaro", 550, 1012); + } + if (showInLoops > 16) { + g2.setColor(Color.RED); + g2.setFont(textFont2); + g2.drawString("Color", 385, 212); + g2.drawString("Strike", 390, 342); + g2.dispose(); + } + if (showInLoops > 18) { + timer.stop(); + } - g2.setColor(new Color(1, 1, 0, 0.7f)); - g2.fillRect(100, 0, 100, 1024); - g2.fillRect(1080, 0, 100, 1024); - - g2.setColor(new Color(1, 0, 0, 0.7f)); - g2.fillRect(200, 0, 100, 1024); - g2.fillRect(980, 0, 100, 1024); - - g2.setPaint(gp); - g2.fillRect(300, 0, 680, 1024); - - g2.setFont(textFont); - g2.setColor(Color.WHITE); - g2.drawString("©2015 Team Hamtaro", 550, 1012); - - g2.setColor(Color.RED); - g2.setFont(textFont2); - g2.drawString("Color", 385, 212); - g2.drawString("Strike", 390, 342); - g2.dispose(); background.createGraphics(); } + @Override + public void actionPerformed(ActionEvent e) { + + createBackground(); + showInLoops++; + } + } diff --git a/model/objects/InfoPanel.java b/model/objects/InfoPanel.java index c430f8e..43ba976 100644 --- a/model/objects/InfoPanel.java +++ b/model/objects/InfoPanel.java @@ -84,13 +84,14 @@ public class InfoPanel { if (!coinAnimation.areWeDoneYet()) { coinAnimation.draw(g2); - + // Score pas updaten wanneer coin klaar is met afspelen if (coinAnimation.isLastLoop()) tempComboScore = PlayState.comboScore; - } + } else + tempComboScore = PlayState.comboScore; + g2.setColor(Color.YELLOW); g2.fillRect(25, 1000 - 7 * tempComboScore, 200, 7 * tempComboScore); - g2.setColor(Color.YELLOW); g2.dispose(); infoPanel.createGraphics();