Author SHA1 Message Date
Bilel Bghiel 811f778553 - Quick Fixes 2015-07-06 15:25:09 +02:00
Bilel Bghiel 03dae66c71 - Title Stage boot animation
- Coin Animation readded
- Point Animation added
2015-07-01 13:08:39 +02:00
6 changed files with 237 additions and 78 deletions
+74
View File
@@ -0,0 +1,74 @@
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() * timerLoops * 10, coinSetPoint.getY() * timerLoops,
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(); }
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; }
}
+48
View File
@@ -0,0 +1,48 @@
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<Point2D.Double> puntenPos = new LinkedList<>();
LinkedList<Integer> puntenGain = new LinkedList<>();
LinkedList<Integer> iterations = new LinkedList<>();
public static double LastPointIncrement = 0;
public PointAnimation() { }
public void enemyDied(Point2D.Double p) {
puntenPos.add(new Point2D.Double(p.getX(), p.getY()));
puntenGain.add((int)LastPointIncrement);
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);
}
}
}
}
+6 -2
View File
@@ -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;
@@ -12,6 +13,7 @@ import main.Window;
import model.SongHandler;
import model.drawObjects.Enemy;
import model.drawObjects.Player;
import model.drawObjects.PointAnimation;
import model.objects.InfoPanel;
import model.objects.Path;
import model.objects.PlayArea;
@@ -215,19 +217,21 @@ public class PlayState extends GameState {
Enemy enemy = enemysInPath.next();
if (enemy.getDistanceFromStart() > Enemy.distanceToOctagon || enemy.getDistanceFromStart() > Enemy.distanceToOctagon + sizeOfEnemy) {
if (e.getButton().getColor().equals(enemy.getColor())) {
currentScore += enemy.getDistanceFromStart() - Enemy.distanceToOctagon;
PointAnimation.LastPointIncrement = (int)(enemy.getDistanceFromStart() - Enemy.distanceToOctagon);
currentScore += PointAnimation.LastPointIncrement;
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;
}
}
}
player.setBeat();
+74 -63
View File
@@ -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();
}
+22 -4
View File
@@ -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);
}
+13 -9
View File
@@ -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); }
}