This commit is contained in:
Bilel Bghiel
2015-07-09 11:27:05 +02:00
parent 34f6d10532
commit 79cc140d2f
6 changed files with 86 additions and 54 deletions
+12 -11
View File
@@ -23,22 +23,26 @@ public class CoinAnimation extends DrawObject {
private Point2D.Double coinSetPoint; private Point2D.Double coinSetPoint;
// Hoevaak de timer gelopen heeft // Hoevaak de timer gelopen heeft
private static int timerLoops = 0; private static int timerLoops = 0;
private double reach = 0;
private Color color;
public CoinAnimation(int startX, int startY) { public CoinAnimation(int startX, int startY) {
coinSetPoint = new Point2D.Double(startX, startY); coinSetPoint = new Point2D.Double(startX + 180, startY - 10);
coinShape = new Ellipse2D.Double(startX, startY, 20, 20); coinShape = new Ellipse2D.Double(startX + 180, startY - 10, 20, 20);
} }
// Start // Start
public void start() { public void start(Color c) {
timerLoops = 1; timerLoops = 1;
reach = (180 - PlayState.comboScore * 2) / 14; // 'Eindbestemming' van het muntje
color = c;
} }
public void draw(Graphics2D g2) { public void draw(Graphics2D g2) {
Color oldColor = g2.getColor(); Color oldColor = g2.getColor();
update(timerLoops); // UPDATE update(timerLoops); // UPDATE
g2.setColor(new Color(255, 255, 0)); // GEEL g2.setColor(color); // GEEL
g2.draw(coinShape); // MUNTJE TEKENEN g2.draw(coinShape); // MUNTJE TEKENEN
g2.fill(coinShape); g2.fill(coinShape);
g2.setColor(oldColor); g2.setColor(oldColor);
@@ -46,14 +50,11 @@ public class CoinAnimation extends DrawObject {
// Wordt na elke paint aangeroepen // Wordt na elke paint aangeroepen
public void update(float factor) { public void update(float factor) {
// 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. // Per frame verschuift het balletje delta 10 op Y-as.
try { try {
coinShape.setFrame(coinSetPoint.getX() * timerLoops * 10, coinSetPoint.getY() * timerLoops, coinShape.setFrame(coinSetPoint.getX() - reach * timerLoops, coinSetPoint.getY(),
coinShape.getWidth(), coinShape.getHeight()); coinShape.getWidth(), coinShape.getHeight());
/* coinShape.setFrame(coinSetPoint.getX(), coinSetPoint.getY() + (1000 - 35 * PlayState.comboScore) / 25 * timerLoops,
coinShape.getWidth(), coinShape.getHeight());*/
} catch (ArithmeticException a) { a.printStackTrace(); } } catch (ArithmeticException a) { a.printStackTrace(); }
timerLoops++; timerLoops++;
@@ -61,7 +62,7 @@ public class CoinAnimation extends DrawObject {
// Zijn we al begonnen/klaar? // Zijn we al begonnen/klaar?
public boolean areWeDoneYet() { public boolean areWeDoneYet() {
if (timerLoops > 24 || timerLoops == 0) { if ((timerLoops > 14 || timerLoops == 0) || (reach * timerLoops > 180)) {
timerLoops = 0; timerLoops = 0;
return true; return true;
} }
@@ -69,6 +70,6 @@ public class CoinAnimation extends DrawObject {
} }
// Zitten we in de laatste loop? // Zitten we in de laatste loop?
public boolean isLastLoop() { return (timerLoops == 24) ? true : false; } public boolean isLastLoop() { return (timerLoops == 13) ? true : false; }
} }
+11 -5
View File
@@ -4,29 +4,34 @@ import model.gameState.PlayState;
import java.awt.*; import java.awt.*;
import java.awt.geom.Point2D; import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.LinkedList; import java.util.LinkedList;
public class PointAnimation extends DrawObject { public class PointAnimation extends DrawObject {
LinkedList<Point2D.Double> puntenPos = new LinkedList<>(); ArrayList<Point2D.Double> puntenPos = new ArrayList<>();
LinkedList<Integer> puntenGain = new LinkedList<>(); ArrayList<Integer> puntenGain = new ArrayList<>();
LinkedList<Integer> iterations = new LinkedList<>(); ArrayList<Integer> iterations = new ArrayList<>();
ArrayList<Color> colors = new ArrayList<>();
public static double LastPointIncrement = 0; public static double LastPointIncrement = 0;
public PointAnimation() { } public PointAnimation() { }
public void enemyDied(Point2D.Double p) { public void enemyDied(Point2D.Double p, Color c) {
puntenPos.add(new Point2D.Double(p.getX(), p.getY())); puntenPos.add(new Point2D.Double(p.getX(), p.getY()));
puntenGain.add((int)LastPointIncrement); puntenGain.add((int)LastPointIncrement);
iterations.add(0); iterations.add(0);
colors.add(c);
} }
@Override @Override
public void draw(Graphics2D g2) { public void draw(Graphics2D g2) {
for (int x = 0; x < puntenPos.size(); x++) { for (int x = 0; x < puntenPos.size(); x++) {
Color oldColor = g2.getColor();
g2.setColor(colors.get(x));
g2.drawString("" + puntenGain.get(x), (int) puntenPos.get(x).getX(), (int) puntenPos.get(x).getY()); g2.drawString("" + puntenGain.get(x), (int) puntenPos.get(x).getX(), (int) puntenPos.get(x).getY());
g2.setColor(oldColor);
update(0); update(0);
} }
} }
@@ -42,6 +47,7 @@ public class PointAnimation extends DrawObject {
puntenPos.remove(x); puntenPos.remove(x);
iterations.remove(x); iterations.remove(x);
puntenGain.remove(x); puntenGain.remove(x);
colors.remove(x);
} }
} }
} }
+1 -1
View File
@@ -222,7 +222,7 @@ public class PlayState extends GameState {
area.enemyDied((Point2D.Double) enemy.getEnemy().getP1()); area.enemyDied((Point2D.Double) enemy.getEnemy().getP1());
area.hit(); area.hit();
enemies_hit++; enemies_hit++;
infoPanel.throwACoin(); // Coin Animatie starten bij hit infoPanel.throwACoin(enemy.getColor()); // Coin Animatie starten bij hit
enemysInPath.remove(); enemysInPath.remove();
notHit = false; notHit = false;
break; break;
+2 -4
View File
@@ -50,12 +50,10 @@ public class PreGameState extends GameState {
@Override @Override
public void draw(Graphics2D g2) { public void draw(Graphics2D g2) {
g2.drawImage(screenshot,0,0,1280,1024,null); g2.drawImage(screenshot,0,0,1280,1024,null);
Font textFont = new Font("OCR A Extended", Font.BOLD,grootte); g2.setFont(new Font("OCR A Extended", Font.BOLD,grootte));
g2.setFont(textFont);
g2.setStroke(s); g2.setStroke(s);
g2.setColor(Color.RED); g2.setColor(Color.RED);
String text = "" + index; String text = "" + index;
int width = g2.getFontMetrics().stringWidth(text);
g2.drawString(text, 325, 400); g2.drawString(text, 325, 400);
if(index < 1){ if(index < 1){
text = "GO!!!"; text = "GO!!!";
@@ -66,7 +64,7 @@ public class PreGameState extends GameState {
else{ else{
text = "READY"; text = "READY";
} }
width = g2.getFontMetrics().stringWidth(text); int width = g2.getFontMetrics().stringWidth(text);
g2.drawString(text, (256+1024/2)-width/2, 600); g2.drawString(text, (256+1024/2)-width/2, 600);
} }
+59 -32
View File
@@ -9,11 +9,13 @@ import java.awt.Graphics2D;
import java.awt.RenderingHints; import java.awt.RenderingHints;
import java.awt.Transparency; import java.awt.Transparency;
import java.awt.geom.Ellipse2D; import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.VolatileImage; import java.awt.image.VolatileImage;
import control.button.ButtonHandler; import control.button.ButtonHandler;
import main.Window; import main.Window;
import model.SongHandler; import model.SongHandler;
import model.drawObjects.CoinAnimation;
import model.gameState.PlayState; import model.gameState.PlayState;
public class InfoPanel { public class InfoPanel {
@@ -23,7 +25,10 @@ public class InfoPanel {
private VolatileImage infoPanel; private VolatileImage infoPanel;
private SongHandler sh; private SongHandler sh;
private String time; private String time;
private int highscore = 0; private int highscore = 0,
tempComboScore = 0;
private CoinAnimation coinAnimation = new CoinAnimation(27, 820);
public InfoPanel(int x, int y, SongHandler sh){ public InfoPanel(int x, int y, SongHandler sh){
this.x = x; this.x = x;
@@ -60,10 +65,10 @@ public class InfoPanel {
g2.setPaint(gp); g2.setPaint(gp);
g2.setColor(Color.GREEN); g2.setColor(Color.GREEN);
g2.fillRect(25, 900, (int)(2 * PlayState.lifePoints), 30); g2.fillRect(25, 900, (int) (2 * PlayState.lifePoints), 30);
g2.setColor(Color.YELLOW); g2.setColor(Color.YELLOW);
g2.fillRect(25, 950, (int)(2 * PlayState.comboScore), 30); g2.fillRect(25, 950, (2 * PlayState.comboScore), 30);
g2.setColor(Color.BLACK); g2.setColor(Color.BLACK);
@@ -76,67 +81,89 @@ public class InfoPanel {
Font scoreFont2 = new Font("OCR A Extended", Font.BOLD, 25); Font scoreFont2 = new Font("OCR A Extended", Font.BOLD, 25);
g2.setFont(scoreFont2); g2.setFont(scoreFont2);
g2.drawString("Title: ", 25, 185); int charsPerLine = 10;
int linesNeeded = sh.getCurrentSong().getTitle().length() / charsPerLine + 1; // 9 chars per regel
g2.drawString("Title: ", 25, 225 - (linesNeeded) * 30);
g2.drawString("Time: ", 25, 265); g2.drawString("Time: ", 25, 265);
g2.drawString("Best: ", 25, 345); g2.drawString("Best: ", 25, 345);
Font scoreFont3 = new Font("OCR A Extended", Font.BOLD, 35); Font scoreFont3 = new Font("OCR A Extended", Font.BOLD, 35);
g2.setFont(scoreFont3); g2.setFont(scoreFont3);
g2.drawString("" + totalHighscore, 25, 105); g2.drawString("" + totalHighscore, 25, 105);
g2.drawString(sh.getCurrentSong().getTitle(), 25, 215);
// Aanpassen zodat hele titel zichtbaar is in infoP
for (int count = 0; count < linesNeeded; count++)
if (sh.getCurrentSong().getTitle().length() == count * charsPerLine + charsPerLine - 1)
g2.drawString( sh.getCurrentSong().getTitle().substring(count * charsPerLine,
count * charsPerLine + charsPerLine - 1),
25,
235 - (linesNeeded - count) * 30);
else
g2.drawString( sh.getCurrentSong().getTitle().substring(count * charsPerLine,
sh.getCurrentSong().getTitle().length()),
25,
235 - (linesNeeded - 1 - count) * 30);
/* g2.drawString(sh.getCurrentSong().getTitle(), 25, 215);*/
g2.drawString(time, 25, 295); g2.drawString(time, 25, 295);
g2.drawString("" + highscore, 25, 375); g2.drawString("" + highscore, 25, 375);
if(!Window.ON_RASP){ if(!Window.ON_RASP){
int width,height; Ellipse2D oval1 = new Ellipse2D.Double(25, 650, 50, 50);
width = g2.getFontMetrics().stringWidth("");
height = g2.getFontMetrics().getHeight();
Ellipse2D oval1 = new Ellipse2D.Double(25, 700, 50, 50);
g2.setColor(ButtonHandler.getButton(1).getColor()); g2.setColor(ButtonHandler.getButton(1).getColor());
g2.fill(oval1); g2.fill(oval1);
Ellipse2D oval2 = new Ellipse2D.Double(85, 700, 50, 50); Ellipse2D oval2 = new Ellipse2D.Double(85, 650, 50, 50);
g2.setColor(ButtonHandler.getButton(2).getColor()); g2.setColor(ButtonHandler.getButton(2).getColor());
g2.fill(oval2); g2.fill(oval2);
Ellipse2D oval3 = new Ellipse2D.Double(145, 700, 50, 50); Ellipse2D oval3 = new Ellipse2D.Double(145, 650, 50, 50);
g2.setColor(ButtonHandler.getButton(3).getColor()); g2.setColor(ButtonHandler.getButton(3).getColor());
g2.fill(oval3); g2.fill(oval3);
Ellipse2D oval4 = new Ellipse2D.Double(50, 760, 50, 50); Ellipse2D oval4 = new Ellipse2D.Double(50, 710, 50, 50);
g2.setColor(ButtonHandler.getButton(4).getColor()); g2.setColor(ButtonHandler.getButton(4).getColor());
g2.fill(oval4); g2.fill(oval4);
Ellipse2D oval5 = new Ellipse2D.Double(110, 760, 50, 50); Ellipse2D oval5 = new Ellipse2D.Double(110, 710, 50, 50);
g2.setColor(ButtonHandler.getButton(5).getColor()); g2.setColor(ButtonHandler.getButton(5).getColor());
g2.fill(oval5); g2.fill(oval5);
Ellipse2D oval6 = new Ellipse2D.Double(170, 760, 50, 50); Ellipse2D oval6 = new Ellipse2D.Double(170, 710, 50, 50);
g2.setColor(ButtonHandler.getButton(6).getColor()); g2.setColor(ButtonHandler.getButton(6).getColor());
g2.fill(oval6); g2.fill(oval6);
} }
// g2.setColor(Color.BLACK); if (!coinAnimation.areWeDoneYet()) {
// width = g2.getFontMetrics().stringWidth(""+i); coinAnimation.draw(g2);
// g2.drawString(""+i, (int)oval.getCenterX()-width/2,(int)oval.getMaxY()+height); // Score pas updaten wanneer coin in zijn laatste draw loop zit
if (coinAnimation.isLastLoop())
tempComboScore = PlayState.comboScore;
} else
tempComboScore = PlayState.comboScore;
//* Score/Coin animation bar
g2.setColor(Color.BLACK);
g2.fillRect(25, 800, 2 * tempComboScore, 40);
g2.drawRect(25, 800, 200, 40);
g2.dispose(); g2.dispose();
infoPanel.createGraphics(); infoPanel.createGraphics();
} }
public void draw(Graphics2D g2){ public void draw(Graphics2D g2){
g2.drawImage(infoPanel, 0, 0, 256,1024,null); g2.drawImage(infoPanel, 0, 0, 256, 1024,null);
} }
public static String getTotalHighscore() public static String getTotalHighscore()
{ {
return totalHighscore; return totalHighscore;
} }
public void throwACoin(Color c) {
coinAnimation.start(c); // Teller weer op 1 zetten
}
} }
+1 -1
View File
@@ -161,5 +161,5 @@ public class PlayArea {
this.pathColor = pathColor; this.pathColor = pathColor;
} }
public void enemyDied(Point2D.Double p) { pointAnimation.enemyDied(p); } public void enemyDied(Point2D.Double p) { pointAnimation.enemyDied(p, hitAreaColor); }
} }