Merge branch 'develop' of https://github.com/ProjectGroepA2/Arcade into coin
This commit is contained in:
@@ -45,7 +45,7 @@ public class InfoPanel {
|
||||
// time = progress + ":" + time;
|
||||
|
||||
long progress = (sh.getProgress() / 1000);
|
||||
String millis = ((progress) % 1000) + "".length() >= 3 ? ("" +((progress) % 1000)).substring(0, 2) : "" + ((progress) % 1000);
|
||||
String millis = ((progress) % 1000) + "".length() > 3 ? ("" +((progress) % 1000)).substring(0, 2) : "" + ((progress) % 1000);
|
||||
String second = ((progress / 1000) % 60 + "").length() <= 1 ? "0" +((progress / 1000) % 60) : "" + ((progress / 1000) % 60);
|
||||
String minute = ((progress / (1000 * 60)) % 60 + "").length() <= 1 ? "0" +((progress / (1000 * 60)) % 60) : "" + ((progress / (1000 * 60)) % 60);
|
||||
time = minute + ":" + second + ":" + millis;
|
||||
|
||||
@@ -1,122 +1,74 @@
|
||||
package model.objects;
|
||||
|
||||
import image.Images;
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Composite;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.LinearGradientPaint;
|
||||
import java.awt.Paint;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.Transparency;
|
||||
import java.awt.geom.GeneralPath;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.image.VolatileImage;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import audio.Song;
|
||||
|
||||
public class MenuButton {
|
||||
|
||||
private int x, y, rounding;
|
||||
private double scalefactor;
|
||||
private Color buttoncolor;
|
||||
|
||||
private ArrayList<Color> colors;
|
||||
private int x, y;
|
||||
private int xx,yy;
|
||||
private boolean selected;
|
||||
private VolatileImage background;
|
||||
|
||||
private Song song;
|
||||
Color color;
|
||||
|
||||
public MenuButton(int x, int y, double scale, int rounding, Color c0, Song song){
|
||||
public MenuButton(int x, int y, Color color, Song song){
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.scalefactor = scale;
|
||||
this.rounding = rounding;
|
||||
this.buttoncolor = c0;
|
||||
this.color = color;
|
||||
setSong(song);
|
||||
|
||||
}
|
||||
|
||||
public void calculateButton(){
|
||||
Color c1 = buttoncolor.darker();
|
||||
Color c2 = buttoncolor.darker().darker();
|
||||
Color c3 = buttoncolor.darker().darker().darker();
|
||||
|
||||
c1 = new Color((int)(c1.getRed()*0.8), (int)(c1.getGreen()*0.8),(int)(c1.getBlue()*0.8));
|
||||
c2 = new Color((int)(c2.getRed()*0.8), (int)(c2.getGreen()*0.8),(int)(c2.getBlue()*0.8));
|
||||
c3 = new Color((int)(c3.getRed()*0.8), (int)(c3.getGreen()*0.8),(int)(c3.getBlue()*0.8));
|
||||
|
||||
|
||||
GeneralPath border = arrayToGeneralpath(new int[][]{{449,15}, {114,48},{78,25+rounding},{10,43+(int)(rounding*0.5)},{15,88+(int)(rounding*0.5)},{82,73+rounding},{118,88},{449,54}});
|
||||
GeneralPath line = arrayToGeneralpath(new int[][]{{-11,55},{-40,60},{-38,78},{-358,170-rounding*3},{-358,174-rounding*3},{-37,87},{-35,102},{-5,95}});
|
||||
Paint gradient = new LinearGradientPaint( new Point2D.Double((-100)*scalefactor,(512)*scalefactor),
|
||||
new Point2D.Double((600)*scalefactor,(512)*scalefactor),
|
||||
new float[]{0.0f, 1.0f},
|
||||
new Color[]{new Color(c1.getRed(), c1.getGreen(), c1.getBlue(), 10), buttoncolor});
|
||||
//Draw the generated button to the buffered image
|
||||
background = Images.initVolatileImage(1280, 500, Transparency.TRANSLUCENT);
|
||||
Graphics2D g2d = background.createGraphics();
|
||||
RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g2d.setRenderingHints(rh);
|
||||
g2d.setComposite(AlphaComposite.DstOut);
|
||||
g2d.fillRect(0, 0, background.getWidth(), background.getHeight());
|
||||
g2d.setComposite(AlphaComposite.SrcOver);
|
||||
|
||||
g2d.setColor(c2);
|
||||
g2d.fill(arrayToGeneralpath(new int[][]{{449, 1}, {449, 68},{113, 103}, {106, 35}}));
|
||||
g2d.setColor(c3);
|
||||
g2d.fill(arrayToGeneralpath(new int[][]{{113, 103}, {106, 35},{70, 12+rounding}, {77, 88+rounding}}));
|
||||
g2d.setColor(c2);
|
||||
g2d.fill(arrayToGeneralpath(new int[][]{{70, 12+rounding}, {77, 88+rounding},{4, 104+(int)(rounding*0.5)}, {-4, 32+(int)(rounding*0.5)}}));
|
||||
g2d.setColor(buttoncolor);
|
||||
g2d.fill(arrayToGeneralpath(new int[][]{{449, 15}, {449, 54},{118, 88}, {114, 48}}));
|
||||
g2d.setColor(c1);
|
||||
g2d.fill(arrayToGeneralpath(new int[][]{{118, 88}, {114, 48},{78, 25+rounding}, {82, 73+rounding}}));
|
||||
g2d.setColor(buttoncolor);
|
||||
g2d.fill(arrayToGeneralpath(new int[][]{{78, 25+rounding}, {82, 73+rounding},{15, 88+(int)(rounding*0.5)}, {10, 43+(int)(rounding*0.5)}}));
|
||||
|
||||
if(selected){
|
||||
g2d.setStroke(new BasicStroke(4));
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.draw(border);
|
||||
}
|
||||
g2d.setPaint(gradient);
|
||||
g2d.fill(line);
|
||||
|
||||
//draw text
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.setFont(new Font("OCR A Extended", Font.BOLD, (int)(30*scalefactor)));
|
||||
g2d.translate((160+358)*scalefactor, (74)*scalefactor);
|
||||
g2d.rotate(-0.1);
|
||||
g2d.drawString(song.getTitle(), 0, 0);
|
||||
g2d.dispose();
|
||||
background.createGraphics();
|
||||
}
|
||||
|
||||
public GeneralPath arrayToGeneralpath(int block[][]){
|
||||
GeneralPath polyline = new GeneralPath(GeneralPath.WIND_EVEN_ODD, block.length);
|
||||
polyline.moveTo ((block[0][0]+358)*scalefactor, (block[0][1])*scalefactor);
|
||||
for (int index = 1; index < block.length; index++) {
|
||||
polyline.lineTo((block[index][0]+358)*scalefactor, (block[index][1])*scalefactor);
|
||||
};
|
||||
polyline.closePath();
|
||||
return polyline;
|
||||
public MenuButton(int x, int y, int xx, int yy, Color color, Song song){
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.color = color;
|
||||
this.yy = yy;
|
||||
this.xx = xx;
|
||||
setSong(song);
|
||||
}
|
||||
|
||||
public void draw(Graphics2D g2d){
|
||||
g2d.drawImage(background, (int)((x-320)*scalefactor), (int) ((y)*scalefactor), 1280, 500, null);
|
||||
|
||||
|
||||
if(selected){
|
||||
g2d.setColor(color.darker().darker().darker().darker());
|
||||
g2d.fillRect(x-10, y-10,xx+20,yy+20);
|
||||
g2d.setColor(color.darker().darker());
|
||||
g2d.fillRect(x-5, y-5,xx+10,yy+10);
|
||||
g2d.setColor(color);
|
||||
g2d.fillRect(x,y,xx,yy);
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.drawRect(x-10, y-10, xx+20, yy+20);
|
||||
g2d.drawRect(x-5, y-5, xx+10, yy+10);
|
||||
g2d.drawRect(x, y, xx, yy);
|
||||
}
|
||||
else{
|
||||
g2d.setColor(color.darker().darker());
|
||||
g2d.fillRect(x-5, y-5,890,80);
|
||||
g2d.setColor(color);
|
||||
g2d.fillRect(x,y,880,70);
|
||||
}
|
||||
|
||||
//draw text
|
||||
g2d.setColor(Color.BLACK);
|
||||
Font textFont = new Font("OCR A Extended", Font.BOLD,60);
|
||||
g2d.setFont(textFont);
|
||||
if(selected)
|
||||
g2d.drawString(song.getTitle(), x+50, y+63);
|
||||
else
|
||||
g2d.drawString(song.getTitle(), x+50, y+57);
|
||||
}
|
||||
|
||||
public void update(){
|
||||
}
|
||||
|
||||
public void setSelected(boolean selected) {
|
||||
this.selected = selected;
|
||||
x += 100;
|
||||
y -= 40;
|
||||
scalefactor += 0.2;
|
||||
calculateButton();
|
||||
}
|
||||
|
||||
public boolean isSelected(){
|
||||
@@ -136,6 +88,5 @@ public class MenuButton {
|
||||
|
||||
public void setSong(Song song) {
|
||||
this.song = song;
|
||||
calculateButton();
|
||||
}
|
||||
}
|
||||
|
||||
+75
-62
@@ -7,10 +7,8 @@ import java.awt.Graphics2D;
|
||||
import java.awt.Polygon;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.Transparency;
|
||||
import java.awt.geom.GeneralPath;
|
||||
import java.awt.geom.Line2D;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.VolatileImage;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -21,82 +19,63 @@ import model.gameState.PlayState;
|
||||
public class PlayArea {
|
||||
|
||||
public List<Path> paths;
|
||||
private Polygon octagon,hitArea;
|
||||
public Rectangle2D[] hitAreas; //de area voor elk path die de enemy moet raken
|
||||
private Polygon innerHitAreaBorder,outsideHitAreaBorder;
|
||||
private GeneralPath hitArea;
|
||||
private Color hitAreaColor,pathColor = null;
|
||||
private VolatileImage background;
|
||||
private boolean hit = false;
|
||||
private int count = 0,maxCount = 100,pathID = -1;
|
||||
|
||||
public PlayArea(double xToRight,double heightOfGameScreen,double widthOfGameScreen, int sizeOctagon) {
|
||||
super();
|
||||
paths = new ArrayList<Path>();
|
||||
|
||||
setHitAreaColor(Color.RED);
|
||||
//make the polygons
|
||||
int amountOfAngles = 8;
|
||||
double middlePointX = widthOfGameScreen/2+xToRight;
|
||||
double middlePointY = heightOfGameScreen/2;
|
||||
|
||||
octagon = new Polygon();
|
||||
//the inner octagon
|
||||
innerHitAreaBorder = new Polygon();
|
||||
for(int i = 0; i < amountOfAngles; i++){
|
||||
octagon.addPoint((int)(middlePointX+sizeOctagon*Math.cos(i*Math.PI/(amountOfAngles/2))),
|
||||
innerHitAreaBorder.addPoint((int)(middlePointX+sizeOctagon*Math.cos(i*Math.PI/(amountOfAngles/2))),
|
||||
(int)(middlePointY+sizeOctagon*Math.sin(i*Math.PI/(amountOfAngles/2))));
|
||||
}
|
||||
|
||||
hitArea = new Polygon();
|
||||
//the outside octagon
|
||||
outsideHitAreaBorder = new Polygon();
|
||||
sizeOctagon += PlayState.sizeOfEnemy;
|
||||
for(int i = 0; i < amountOfAngles; i++){
|
||||
hitArea.addPoint((int)(middlePointX+sizeOctagon*Math.cos(i*Math.PI/(amountOfAngles/2))),
|
||||
outsideHitAreaBorder.addPoint((int)(middlePointX+sizeOctagon*Math.cos(i*Math.PI/(amountOfAngles/2))),
|
||||
(int)(middlePointY+sizeOctagon*Math.sin(i*Math.PI/(amountOfAngles/2))));
|
||||
}
|
||||
|
||||
hitAreas = new Rectangle2D[amountOfAngles];
|
||||
int newIndex;
|
||||
Point2D beginPoint,endPoint;
|
||||
for(int index = 0; index < hitAreas.length; index++){
|
||||
//in het polygon staat de cooridinaten van de top niet als eerste in de array, maar op index 6.n
|
||||
newIndex = (index+6+8)%8;
|
||||
hitAreas[index] = new Rectangle2D.Double();
|
||||
beginPoint = new Point2D.Double(octagon.xpoints[newIndex], octagon.ypoints[newIndex]);
|
||||
endPoint = new Point2D.Double(hitArea.xpoints[newIndex], hitArea.ypoints[newIndex]);
|
||||
hitAreas[index].setFrameFromDiagonal(beginPoint,endPoint);
|
||||
//hitArea the area where you must click the enemy
|
||||
hitArea = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
|
||||
|
||||
hitArea.moveTo(innerHitAreaBorder.xpoints[0], innerHitAreaBorder.ypoints[0]);
|
||||
for(int i = 1; i < innerHitAreaBorder.npoints;i++){
|
||||
hitArea.lineTo(innerHitAreaBorder.xpoints[i], innerHitAreaBorder.ypoints[i]);
|
||||
}
|
||||
|
||||
hitArea.moveTo(outsideHitAreaBorder.xpoints[0], outsideHitAreaBorder.ypoints[0]);
|
||||
for(int i = 1; i < innerHitAreaBorder.npoints;i++){
|
||||
hitArea.lineTo(outsideHitAreaBorder.xpoints[i], outsideHitAreaBorder.ypoints[i]);
|
||||
}
|
||||
|
||||
Rectangle2D cr = null;//cr --> current rectangle
|
||||
double size = (hitAreas[1].getWidth() - 10)/2;//dit is de grootte van een zijde als die van de oorspronklijke 0 was.
|
||||
|
||||
cr = hitAreas[0];
|
||||
hitAreas[0].setFrame(cr.getX()-size/2, cr.getY()+1, size, cr.getHeight());
|
||||
|
||||
cr = hitAreas[2];
|
||||
hitAreas[2].setFrame(cr.getX()-1, cr.getY()-size/2, cr.getWidth(), size);
|
||||
|
||||
cr = hitAreas[4];
|
||||
hitAreas[4].setFrame(cr.getX()-size/2, cr.getY()-1, size, cr.getHeight());
|
||||
|
||||
cr = hitAreas[6];
|
||||
hitAreas[6].setFrame(cr.getX()+1, cr.getY()-size/2, cr.getWidth(), size);
|
||||
|
||||
widthOfGameScreen += xToRight;
|
||||
|
||||
// paths.add(new Path(middlePointX,0 ,hitArea.xpoints[6],hitArea.ypoints[6]));//top
|
||||
// paths.add(new Path(widthOfGameScreen,0 ,hitArea.xpoints[7],hitArea.ypoints[7]));//right -top
|
||||
// paths.add(new Path(widthOfGameScreen,middlePointY ,hitArea.xpoints[0],hitArea.ypoints[0]));//right
|
||||
// paths.add(new Path(widthOfGameScreen,heightOfGameScreen,hitArea.xpoints[1],hitArea.ypoints[1]));//right -down
|
||||
// paths.add(new Path(middlePointX,heightOfGameScreen ,hitArea.xpoints[2],hitArea.ypoints[2]));//down
|
||||
// paths.add(new Path(xToRight,heightOfGameScreen ,hitArea.xpoints[3],hitArea.ypoints[3]));//left -down
|
||||
// paths.add(new Path(xToRight,middlePointY ,hitArea.xpoints[4],hitArea.ypoints[4]));//left
|
||||
// paths.add(new Path(xToRight,0 ,hitArea.xpoints[5],hitArea.ypoints[5]));//left -top
|
||||
|
||||
//make the paths
|
||||
double angleX,angleY;
|
||||
angleX = (Math.cos(Math.toRadians(45)))*Enemy.distanceToOctagon;
|
||||
angleY = (Math.sin(Math.toRadians(45)))*Enemy.distanceToOctagon;
|
||||
|
||||
paths.add(new Path(hitArea.xpoints[6],hitArea.ypoints[6]-Enemy.distanceToOctagon ,hitArea.xpoints[6],hitArea.ypoints[6]));//top
|
||||
paths.add(new Path(hitArea.xpoints[7] + angleX,hitArea.ypoints[7] - angleY ,hitArea.xpoints[7],hitArea.ypoints[7]));//right -top
|
||||
paths.add(new Path(hitArea.xpoints[0]+Enemy.distanceToOctagon,hitArea.ypoints[0] ,hitArea.xpoints[0],hitArea.ypoints[0]));//right
|
||||
paths.add(new Path(hitArea.xpoints[1]+angleX,hitArea.ypoints[1]+angleY ,hitArea.xpoints[1],hitArea.ypoints[1]));//right -down
|
||||
paths.add(new Path(hitArea.xpoints[2],hitArea.ypoints[2]+Enemy.distanceToOctagon ,hitArea.xpoints[2],hitArea.ypoints[2]));//down
|
||||
paths.add(new Path(hitArea.xpoints[3] - angleX,hitArea.ypoints[3] + angleY ,hitArea.xpoints[3],hitArea.ypoints[3]));//left -down
|
||||
paths.add(new Path(hitArea.xpoints[4] - Enemy.distanceToOctagon,hitArea.ypoints[4] ,hitArea.xpoints[4],hitArea.ypoints[4]));//left
|
||||
paths.add(new Path(hitArea.xpoints[5] - angleX,hitArea.ypoints[5] - angleY ,hitArea.xpoints[5],hitArea.ypoints[5]));//left -top
|
||||
paths.add(new Path(outsideHitAreaBorder.xpoints[6],outsideHitAreaBorder.ypoints[6]-Enemy.distanceToOctagon ,outsideHitAreaBorder.xpoints[6],outsideHitAreaBorder.ypoints[6]));//top
|
||||
paths.add(new Path(outsideHitAreaBorder.xpoints[7] + angleX,outsideHitAreaBorder.ypoints[7] - angleY ,outsideHitAreaBorder.xpoints[7],outsideHitAreaBorder.ypoints[7]));//right -top
|
||||
paths.add(new Path(outsideHitAreaBorder.xpoints[0]+Enemy.distanceToOctagon,outsideHitAreaBorder.ypoints[0] ,outsideHitAreaBorder.xpoints[0],outsideHitAreaBorder.ypoints[0]));//right
|
||||
paths.add(new Path(outsideHitAreaBorder.xpoints[1]+angleX,outsideHitAreaBorder.ypoints[1]+angleY ,outsideHitAreaBorder.xpoints[1],outsideHitAreaBorder.ypoints[1]));//right -down
|
||||
paths.add(new Path(outsideHitAreaBorder.xpoints[2],outsideHitAreaBorder.ypoints[2]+Enemy.distanceToOctagon ,outsideHitAreaBorder.xpoints[2],outsideHitAreaBorder.ypoints[2]));//down
|
||||
paths.add(new Path(outsideHitAreaBorder.xpoints[3] - angleX,outsideHitAreaBorder.ypoints[3] + angleY ,outsideHitAreaBorder.xpoints[3],outsideHitAreaBorder.ypoints[3]));//left -down
|
||||
paths.add(new Path(outsideHitAreaBorder.xpoints[4] - Enemy.distanceToOctagon,outsideHitAreaBorder.ypoints[4] ,outsideHitAreaBorder.xpoints[4],outsideHitAreaBorder.ypoints[4]));//left
|
||||
paths.add(new Path(outsideHitAreaBorder.xpoints[5] - angleX,outsideHitAreaBorder.ypoints[5] - angleY ,outsideHitAreaBorder.xpoints[5],outsideHitAreaBorder.ypoints[5]));//left -top
|
||||
|
||||
|
||||
//drawing into buffer
|
||||
@@ -104,22 +83,31 @@ public class PlayArea {
|
||||
Graphics2D g2 = background.createGraphics();
|
||||
RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g2.setRenderingHints(rh);
|
||||
Line2D current;
|
||||
int index;
|
||||
Line2D current;
|
||||
g2.setColor(Color.BLACK);
|
||||
for(int i = 0; i < paths.size(); i++){
|
||||
current = paths.get(i);
|
||||
index = (i+14)%8;
|
||||
g2.drawLine((int)current.getX1(), (int)current.getY1(), octagon.xpoints[index],octagon.ypoints[index]);
|
||||
current = paths.get(i);
|
||||
g2.draw(current);
|
||||
}
|
||||
g2.draw(octagon);
|
||||
g2.draw(hitArea);
|
||||
g2.draw(innerHitAreaBorder);
|
||||
g2.draw(outsideHitAreaBorder);
|
||||
g2.dispose();
|
||||
background.createGraphics();
|
||||
}
|
||||
|
||||
public void draw(Graphics2D g2){
|
||||
public void draw(Graphics2D g2){
|
||||
g2.drawImage(background, 0, 0, 1280, 1024, null);
|
||||
if(hit){
|
||||
g2.setColor(hitAreaColor);
|
||||
g2.fill(hitArea);
|
||||
if(count == maxCount){
|
||||
hit = false;
|
||||
}
|
||||
}
|
||||
if(pathID >= 0 && pathColor != null){
|
||||
g2.setColor(pathColor);
|
||||
g2.draw(paths.get(pathID));
|
||||
}
|
||||
}
|
||||
|
||||
public Line2D getLine(int index){
|
||||
@@ -131,4 +119,29 @@ public class PlayArea {
|
||||
}
|
||||
return paths.get(index);
|
||||
}
|
||||
|
||||
|
||||
public void setHitAreaColor(Color color) {
|
||||
hitAreaColor = color;
|
||||
count = 0;
|
||||
}
|
||||
|
||||
public void hit(){
|
||||
hit = true;
|
||||
}
|
||||
|
||||
public void count(){
|
||||
if(hit){
|
||||
count += 3;
|
||||
if(count > maxCount){
|
||||
count = maxCount;
|
||||
}
|
||||
hitAreaColor = new Color(hitAreaColor.getRed(),hitAreaColor.getGreen(),hitAreaColor.getBlue(),255-(255*count)/maxCount);
|
||||
}
|
||||
}
|
||||
|
||||
public void pathPainted(int pathID,Color pathColor){
|
||||
this.pathID = pathID;
|
||||
this.pathColor = pathColor;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user