@@ -34,6 +34,7 @@ public class InfoPanel {
|
||||
}
|
||||
|
||||
public void draw(Graphics2D g2){
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.fillRect(x, y, 256, 1024);
|
||||
Font scoreFont = new Font("OCR A Extended", Font.BOLD, 30);
|
||||
g2.setFont(scoreFont);
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
package model.objects;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.LinearGradientPaint;
|
||||
import java.awt.Paint;
|
||||
import java.awt.geom.GeneralPath;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class MenuButton {
|
||||
|
||||
private ArrayList<GeneralPath> buttonparts;
|
||||
private GeneralPath border, line;
|
||||
private ArrayList<Color> colors;
|
||||
private Paint gradient;
|
||||
private int x, y, rounding;
|
||||
private double scalefactor;
|
||||
private String text;
|
||||
|
||||
private boolean selected;
|
||||
private int fadecounter;
|
||||
|
||||
public MenuButton(int x, int y, double scale, String text, int rounding, Color c0){
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.scalefactor = scale;
|
||||
this.text = text;
|
||||
this.rounding = rounding;
|
||||
calculateButton();
|
||||
|
||||
colors = new ArrayList<Color>();
|
||||
|
||||
Color c1 = c0.darker();
|
||||
Color c2 = c0.darker().darker();
|
||||
Color c3 = c0.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));
|
||||
|
||||
colors.add(c2);
|
||||
colors.add(c3);
|
||||
colors.add(c2);
|
||||
colors.add(c0);
|
||||
colors.add(c1);
|
||||
colors.add(c0);
|
||||
|
||||
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), c0});
|
||||
}
|
||||
|
||||
public void calculateButton(){
|
||||
buttonparts = new ArrayList<GeneralPath>();
|
||||
buttonparts.add(arrayToGeneralpath(new int[][]{{449, 1}, {449, 68},{113, 103}, {106, 35}})); //background right
|
||||
buttonparts.add(arrayToGeneralpath(new int[][]{{113, 103}, {106, 35},{70, 12+rounding}, {77, 88+rounding}})); //background middle
|
||||
buttonparts.add(arrayToGeneralpath(new int[][]{{70, 12+rounding}, {77, 88+rounding},{4, 104+(int)(rounding*0.5)}, {-4, 32+(int)(rounding*0.5)}})); //background left
|
||||
buttonparts.add(arrayToGeneralpath(new int[][]{{449, 15}, {449, 54},{118, 88}, {114, 48}})); //foreground right
|
||||
buttonparts.add(arrayToGeneralpath(new int[][]{{118, 88}, {114, 48},{78, 25+rounding}, {82, 73+rounding}})); //foreground middle
|
||||
buttonparts.add(arrayToGeneralpath(new int[][]{{78, 25+rounding}, {82, 73+rounding},{15, 88+(int)(rounding*0.5)}, {10, 43+(int)(rounding*0.5)}})); //foreground left
|
||||
|
||||
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}});
|
||||
line = arrayToGeneralpath(new int[][]{{-11,55},{-40,60},{-38,78},{-358,170-rounding*3},{-358,174-rounding*3},{-37,87},{-35,102},{-5,95}});
|
||||
}
|
||||
|
||||
public GeneralPath arrayToGeneralpath(int block[][]){
|
||||
GeneralPath polyline = new GeneralPath(GeneralPath.WIND_EVEN_ODD, block.length);
|
||||
polyline.moveTo ((block[0][0]+x)*scalefactor, (block[0][1]+y)*scalefactor);
|
||||
for (int index = 1; index < block.length; index++) {
|
||||
polyline.lineTo((block[index][0]+x)*scalefactor, (block[index][1]+y)*scalefactor);
|
||||
};
|
||||
polyline.closePath();
|
||||
return polyline;
|
||||
}
|
||||
|
||||
public void draw(Graphics2D g2d){
|
||||
for(int i = 0; i < buttonparts.size(); i++){ //fill every part of the button with a specific color
|
||||
g2d.setColor(colors.get(i));
|
||||
g2d.fill((buttonparts.get(i)));
|
||||
}
|
||||
|
||||
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);
|
||||
Font textFont = new Font("OCR A Extended", Font.BOLD, (int)(30*scalefactor));
|
||||
g2d.setFont(textFont);
|
||||
g2d.translate((x+160)*scalefactor, (y+74)*scalefactor);
|
||||
g2d.rotate(-0.1);
|
||||
g2d.drawString(text, 0, 0);
|
||||
g2d.rotate(0.1);
|
||||
g2d.translate(-(x+160)*scalefactor, -(y+74)*scalefactor);
|
||||
}
|
||||
|
||||
public void update(){
|
||||
if(selected && fadecounter < 5){
|
||||
x -= 8;
|
||||
y -=8;
|
||||
scalefactor += 0.04;
|
||||
fadecounter++;
|
||||
calculateButton();
|
||||
}else if(!selected && fadecounter >0){
|
||||
x += 8;
|
||||
y += 8;
|
||||
fadecounter--;
|
||||
scalefactor -= 0.04;
|
||||
calculateButton();
|
||||
}
|
||||
}
|
||||
|
||||
public void setSelected(boolean selected) {
|
||||
this.selected = selected;
|
||||
}
|
||||
|
||||
public void setX(int x){
|
||||
this.x = x;
|
||||
calculateButton();
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+18
-66
@@ -2,96 +2,48 @@ package model.objects;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Polygon;
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.Line2D;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import model.gameState.PlayState;
|
||||
|
||||
public class PlayArea {
|
||||
|
||||
public List<Line2D> paths;
|
||||
private Polygon octagon,hitArea;
|
||||
public Rectangle2D[] hitAreas; //de area voor elk path die de enemy moet raken
|
||||
public Polygon octagon;
|
||||
|
||||
public PlayArea(double xToRight,double heightOfGameScreen,double widthOfGameScreen, int sizeOctagon) {
|
||||
|
||||
public PlayArea(int xToRight,int heightOfGameScreen,int widthOfGameScreen, int sizeOctagon) {
|
||||
super();
|
||||
paths = new ArrayList<Line2D>();
|
||||
|
||||
paths = new ArrayList<Line2D>();
|
||||
int middlePointX = widthOfGameScreen/2+xToRight;
|
||||
int middlePointY = heightOfGameScreen/2;
|
||||
int amountOfAngles = 8;
|
||||
double middlePointX = widthOfGameScreen/2+xToRight;
|
||||
double middlePointY = heightOfGameScreen/2;
|
||||
|
||||
octagon = new Polygon();
|
||||
for(int i = 0; i < amountOfAngles; i++){
|
||||
octagon.addPoint((int)(middlePointX+sizeOctagon*Math.cos(i*Math.PI/(amountOfAngles/2))),
|
||||
(int)(middlePointY+sizeOctagon*Math.sin(i*Math.PI/(amountOfAngles/2))));
|
||||
}
|
||||
|
||||
hitArea = new Polygon();
|
||||
sizeOctagon += PlayState.sizeOfEnemy;
|
||||
for(int i = 0; i < amountOfAngles; i++){
|
||||
hitArea.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);
|
||||
}
|
||||
|
||||
|
||||
Rectangle2D cr = null;//cr --> current rectangle
|
||||
double size = hitAreas[1].getWidth();//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 Line2D.Double(middlePointX,0 ,hitArea.xpoints[6],hitArea.ypoints[6]));//top
|
||||
paths.add(new Line2D.Double(widthOfGameScreen,0 ,hitArea.xpoints[7],hitArea.ypoints[7]));//right -top
|
||||
paths.add(new Line2D.Double(widthOfGameScreen,middlePointY ,hitArea.xpoints[0],hitArea.ypoints[0]));//right
|
||||
paths.add(new Line2D.Double(widthOfGameScreen,heightOfGameScreen,hitArea.xpoints[1],hitArea.ypoints[1]));//right -down
|
||||
paths.add(new Line2D.Double(middlePointX,heightOfGameScreen ,hitArea.xpoints[2],hitArea.ypoints[2]));//down
|
||||
paths.add(new Line2D.Double(xToRight,heightOfGameScreen ,hitArea.xpoints[3],hitArea.ypoints[3]));//left -down
|
||||
paths.add(new Line2D.Double(xToRight,middlePointY ,hitArea.xpoints[4],hitArea.ypoints[4]));//left
|
||||
paths.add(new Line2D.Double(xToRight,0 ,hitArea.xpoints[5],hitArea.ypoints[5]));//left -top
|
||||
widthOfGameScreen += xToRight;
|
||||
|
||||
|
||||
paths.add(new Line2D.Double(middlePointX,0 ,octagon.xpoints[6],octagon.ypoints[6]));//top
|
||||
paths.add(new Line2D.Double(widthOfGameScreen,0 ,octagon.xpoints[7],octagon.ypoints[7]));//right -top
|
||||
paths.add(new Line2D.Double(widthOfGameScreen,middlePointY ,octagon.xpoints[0],octagon.ypoints[0]));//right
|
||||
paths.add(new Line2D.Double(widthOfGameScreen,heightOfGameScreen,octagon.xpoints[1],octagon.ypoints[1]));//right -down
|
||||
paths.add(new Line2D.Double(middlePointX,heightOfGameScreen ,octagon.xpoints[2],octagon.ypoints[2]));//down
|
||||
paths.add(new Line2D.Double(xToRight,heightOfGameScreen ,octagon.xpoints[3],octagon.ypoints[3]));//left -down
|
||||
paths.add(new Line2D.Double(xToRight,middlePointY ,octagon.xpoints[4],octagon.ypoints[4]));//left
|
||||
paths.add(new Line2D.Double(xToRight,0 ,octagon.xpoints[5],octagon.ypoints[5]));//left -top
|
||||
}
|
||||
|
||||
public void draw(Graphics2D g2){
|
||||
Line2D current;
|
||||
int index;
|
||||
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]);
|
||||
for(Shape s : paths){
|
||||
g2.draw(s);
|
||||
}
|
||||
g2.draw(octagon);
|
||||
g2.draw(hitArea);
|
||||
// for(Rectangle2D hit : hitAreas){
|
||||
// g2.fill(hit);
|
||||
// }
|
||||
}
|
||||
|
||||
public Line2D getLine(int index){
|
||||
|
||||
Reference in New Issue
Block a user