From 03dae66c71028223a933094d8823781981be7a41 Mon Sep 17 00:00:00 2001 From: Bilel Bghiel Date: Wed, 1 Jul 2015 13:08:39 +0200 Subject: [PATCH] - Title Stage boot animation - Coin Animation readded - Point Animation added --- model/drawObjects/CoinAnimation.java | 72 ++++++++++++++ model/drawObjects/PointAnimation.java | 46 +++++++++ model/gameState/PlayState.java | 3 + model/gameState/TitleState.java | 137 ++++++++++++++------------ model/objects/InfoPanel.java | 26 ++++- model/objects/PlayArea.java | 22 +++-- 6 files changed, 230 insertions(+), 76 deletions(-) create mode 100644 model/drawObjects/CoinAnimation.java create mode 100644 model/drawObjects/PointAnimation.java diff --git a/model/drawObjects/CoinAnimation.java b/model/drawObjects/CoinAnimation.java new file mode 100644 index 0000000..911edc3 --- /dev/null +++ b/model/drawObjects/CoinAnimation.java @@ -0,0 +1,72 @@ +package model.drawObjects; + +import model.gameState.PlayState; + +import java.awt.*; +import java.awt.geom.Ellipse2D; +import java.awt.geom.Point2D; + +/** + * 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. + * + * * Init (startX, startY): Punt waar de animatie begint met vallen + * + * start(): aanroepen om te starten + * * + * * + **/ +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); + } + + // Start + public void start() { + timerLoops = 1; + } + + public void draw(Graphics2D g2) { + Color oldColor = g2.getColor(); + update(timerLoops); // UPDATE + g2.setColor(new Color(255, 255, 0)); // GEEL + g2.draw(coinShape); // MUNTJE TEKENEN + g2.fill(coinShape); + g2.setColor(oldColor); + } + + // Wordt na elke paint aangeroepen + public void update(float factor) { + + // 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.comboScore) / 25 * timerLoops, + coinShape.getWidth(), coinShape.getHeight()); + } catch (ArithmeticException a) { a.printStackTrace(); } + + timerLoops++; + } + + // Zijn we al begonnen/klaar? + public boolean areWeDoneYet() { + if (timerLoops > 24 || timerLoops == 0) { + timerLoops = 0; + return true; + } + return false; + } + + // Zitten we in de laatste loop? + public boolean isLastLoop() { return (timerLoops == 24) ? true : false; } + +} \ No newline at end of file diff --git a/model/drawObjects/PointAnimation.java b/model/drawObjects/PointAnimation.java new file mode 100644 index 0000000..302bb59 --- /dev/null +++ b/model/drawObjects/PointAnimation.java @@ -0,0 +1,46 @@ +package model.drawObjects; + +import model.gameState.PlayState; + +import java.awt.*; +import java.awt.geom.Point2D; +import java.util.LinkedList; + +public class PointAnimation extends DrawObject { + + LinkedList puntenPos = new LinkedList<>(); + LinkedList puntenGain = new LinkedList<>(); + LinkedList iterations = new LinkedList<>(); + + public PointAnimation() { } + + public void enemyDied(Point2D.Double p) { + puntenPos.add(new Point2D.Double(p.getX(), p.getY())); + puntenGain.add(PlayState.comboScore); + iterations.add(0); + } + + @Override + public void draw(Graphics2D g2) { + for (int x = 0; x < puntenPos.size(); x++) { + g2.drawString("" + puntenGain.get(x), (int) puntenPos.get(x).getX(), (int) puntenPos.get(x).getY()); + + update(0); + } + } + + @Override + public void update(float factor) { + + for (int x = 0; x < puntenPos.size(); x++) { + puntenPos.get(x).setLocation(puntenPos.get(x).getX(), puntenPos.get(x).getY() - 3); + iterations.set(x, iterations.get(x) + 1); + + if (iterations.get(x) > 100) { + puntenPos.remove(x); + iterations.remove(x); + puntenGain.remove(x); + } + } + } +} diff --git a/model/gameState/PlayState.java b/model/gameState/PlayState.java index bba92d1..c68e2df 100644 --- a/model/gameState/PlayState.java +++ b/model/gameState/PlayState.java @@ -5,6 +5,7 @@ import java.awt.Color; import java.awt.Graphics2D; import java.awt.Stroke; import java.awt.geom.Ellipse2D; +import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.util.Iterator; @@ -219,8 +220,10 @@ public class PlayState extends GameState { 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; break; diff --git a/model/gameState/TitleState.java b/model/gameState/TitleState.java index 008292f..d1e11c9 100644 --- a/model/gameState/TitleState.java +++ b/model/gameState/TitleState.java @@ -21,65 +21,64 @@ import data.io.SQLConnector; public class TitleState extends GameState { - BufferedImage pressStart = Images.getImage(ImageType.pressstart); - BufferedImage colorStrike = Images.getImage(ImageType.colorstrike); - BufferedImage kast = Images.getImage(ImageType.kast); - VolatileImage background; - Font textFont = new Font("OCR A Extended", Font.BOLD, 15); - 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)); + private BufferedImage pressStart = Images.getImage(ImageType.pressstart), + colorStrike = Images.getImage(ImageType.colorstrike), + kast = Images.getImage(ImageType.kast); + private VolatileImage background; - - int index = 0; - int varx = 0; - int frame; + private Font textFont = new Font("OCR A Extended", Font.BOLD, 15), + 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; - - int indexKast = 0; - int xKast=0; - public TitleState(GameStateManager gsm, SongHandler sh, SQLConnector sql){ super(gsm, sh, sql); - if(!sh.isPlaying()) - sh.play(); createBackground(); } @Override public void init() { - if(!sh.isPlaying()) - sh.play(); + sh.play(); } @Override public void update(float factor) { - frame+=5; - indexKast++; + 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 (frame > 0) { + g2.drawImage(background, 0, 0, 1280, 1024, null); + createBackground(); + } + if (frame > 160) { + // 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 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; } - } @Override @@ -94,35 +93,47 @@ 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 (frame > 0) { + RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g2.setRenderingHints(rh); + } + if (frame > 20) { + g2.setColor(new Color(1, 1, 1, 0.3f)); + g2.fillRect(0, 0, 1280, 1024); + } + if (frame > 40) { + g2.setColor(new Color(0, 1, 0, 0.7f)); + g2.fillRect(0, 0, 100, 1024); + g2.fillRect(1180, 0, 100, 1024); + } + if (frame > 60) { + g2.setColor(new Color(1, 1, 0, 0.7f)); + g2.fillRect(100, 0, 100, 1024); + g2.fillRect(1080, 0, 100, 1024); + } + if (frame > 80) { + g2.setColor(new Color(1, 0, 0, 0.7f)); + g2.fillRect(200, 0, 100, 1024); + g2.fillRect(980, 0, 100, 1024); + } + if (frame > 100) { + g2.setPaint(gp); + g2.fillRect(300, 0, 680, 1024); + } + if (frame > 120) { + g2.setFont(textFont); + g2.setColor(Color.WHITE); + g2.drawString("©2015 Team Hamtaro", 550, 1012); + } + if (frame > 140) { + g2.setColor(Color.RED); + g2.setFont(textFont2); + g2.drawString("Color", 385, 212); + g2.drawString("Strike", 390, 342); + g2.dispose(); + } - 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(); } diff --git a/model/objects/InfoPanel.java b/model/objects/InfoPanel.java index 682b118..6def545 100644 --- a/model/objects/InfoPanel.java +++ b/model/objects/InfoPanel.java @@ -11,6 +11,7 @@ import java.awt.Transparency; import java.awt.image.VolatileImage; import model.SongHandler; +import model.drawObjects.CoinAnimation; import model.gameState.PlayState; public class InfoPanel { @@ -20,6 +21,10 @@ public class InfoPanel { private VolatileImage infoPanel; private SongHandler sh; private String time; + + private int tempComboMulitplier; + + private CoinAnimation coinAnimation = new CoinAnimation(125, 300); public InfoPanel(int x, int y, SongHandler sh){ this.x = x; @@ -80,14 +85,27 @@ public class InfoPanel { // 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); + + 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.comboScore; + } else + tempComboMulitplier = PlayState.comboScore; + + g2.fillRect(25, 1000 - 7 * PlayState.comboScore, 200, 0 + 7 * PlayState.comboScore); g2.dispose(); infoPanel.createGraphics(); } - + + public void throwACoin() { + coinAnimation.start(); // Teller weer op 1 zetten + } + public void draw(Graphics2D g2){ g2.drawImage(infoPanel, 0, 0, 256,1024,null); } diff --git a/model/objects/PlayArea.java b/model/objects/PlayArea.java index feec629..76aae0b 100644 --- a/model/objects/PlayArea.java +++ b/model/objects/PlayArea.java @@ -2,22 +2,17 @@ package model.objects; import image.Images; -import java.awt.AlphaComposite; -import java.awt.BasicStroke; -import java.awt.Color; -import java.awt.Graphics2D; -import java.awt.Polygon; -import java.awt.RenderingHints; -import java.awt.Stroke; -import java.awt.Transparency; +import java.awt.*; import java.awt.geom.GeneralPath; import java.awt.geom.Line2D; +import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.awt.image.VolatileImage; import java.util.ArrayList; import java.util.List; import model.drawObjects.Enemy; +import model.drawObjects.PointAnimation; import model.gameState.PlayState; public class PlayArea { @@ -30,6 +25,7 @@ public class PlayArea { private boolean hit = false; 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); @@ -122,8 +118,14 @@ public class PlayArea { 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; @@ -158,4 +160,6 @@ public class PlayArea { this.pathID = pathID; this.pathColor = pathColor; } + + public void enemyDied(Point2D.Double p) { pointAnimation.enemyDied(p); } }