Verbetercode.

This commit is contained in:
Bilel Bghiel
2015-06-16 17:30:34 +02:00
parent 7507d0fd63
commit 1f44b5b487
4 changed files with 148 additions and 49 deletions
+69
View File
@@ -0,0 +1,69 @@
package model.drawObjects;
import java.awt.*;
import java.awt.geom.Ellipse2D;
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 {
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) {
update(timerLoops); // UPDATE
g2.setColor(new Color(255, 255, 0, (255 - timerLoops * 5))); // GEEL
g2.draw(coinShape); // MUNTJE TEKENEN
g2.fill(coinShape);
}
// 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.
// 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 > 49 || timerLoops == 0) {
timerLoops = 0;
return true;
}
return false;
}
// Zitten we in de laatste loop?
public boolean isLastLoop() { return (timerLoops == 49) ? true : false; }
}
+1
View File
@@ -218,6 +218,7 @@ public class PlayState extends GameState {
enemies_hit++;
enemysInPath.remove();
notHit = false;
infoPanel.throwACoin(); // Coin Animatie starten bij hit
break;
}
}
+58 -45
View File
@@ -30,13 +30,11 @@ public class TitleState extends GameState {
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;
int indexKast = 0;
int xKast=0;
private int index = 0,
varx = 0,
frame,
indexKast = 0,
xKast = 0;
public TitleState(GameStateManager gsm, SongHandler sh, SQLConnector sql){
super(gsm, sh, sql);
@@ -55,18 +53,21 @@ public class TitleState extends GameState {
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
@@ -92,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();
}
+20 -4
View File
@@ -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,6 +20,9 @@ public class InfoPanel {
private VolatileImage infoPanel;
private SongHandler sh;
private String time;
private CoinAnimation coinAnimation = new CoinAnimation(125, 300);
private int tempComboScore;
public InfoPanel(int x, int y, SongHandler sh){
this.x = x;
@@ -66,15 +70,27 @@ public class InfoPanel {
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);
g2.drawString(sh.getCurrentSongInstance().getDifficulty(), 25, 230);
g2.drawString(sh.getCurrentSong().getAuthor(), 25, 260);
g2.drawString(time, 25, 290);
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 * PlayState.comboScore, 200, 0 + 7 * PlayState.comboScore);
g2.fillRect(25, 1000 - 7 * tempComboScore, 200, 7 * tempComboScore);
g2.dispose();
infoPanel.createGraphics();
}
public void throwACoin() {
coinAnimation.start(); // Teller weer op 0 zetten
}
public void draw(Graphics2D g2){
g2.drawImage(infoPanel, 0, 0, 256,1024,null);