Merged banaan and develop

This commit is contained in:
Yorick
2015-03-24 09:58:21 +01:00
6 changed files with 185 additions and 36 deletions
+75 -4
View File
@@ -31,6 +31,7 @@ public abstract class DrawObject
static final int UPPERRIGHT = 1;
static final int BOTTOMLEFT = 2;
static final int BOTTOMRIGHT = 3;
private Color rectangleColor;
public DrawObject(String filename, Point2D position)
{
@@ -39,6 +40,7 @@ public abstract class DrawObject
scale = 1;
rotation = 0;
this.position = position;
rectangleColor = Color.BLACK;
}
public abstract String getName();
@@ -54,7 +56,7 @@ public abstract class DrawObject
AffineTransform rotate = AffineTransform.getRotateInstance(Math.toRadians(rotation), position.getX() + image.getWidth(null) / 2, position.getY() + image.getHeight(null) / 2);
g.transform(rotate);
g.setColor(Color.BLACK);
g.setColor(rectangleColor);
g.setStroke(new BasicStroke(7));
rektAngle = new Rectangle2D.Double((int) position.getX(), (int) position.getY(), image.getWidth(null), image.getHeight(null));
tx = getTransformRectangle();
@@ -115,10 +117,10 @@ public abstract class DrawObject
shape = new Rectangle2D.Double(0, 0, image.getWidth(null), image.getHeight(null));
return getTransform().createTransformedShape(shape).contains(clickPoint);
} else
}
else
{
shape = new Rectangle2D.Double(-9, -9, image.getWidth(null) + 13, image.getHeight(null) + 13);
return getTransformSelection().createTransformedShape(shape).contains(clickPoint);
}
@@ -130,13 +132,72 @@ public abstract class DrawObject
{
return getTransform().inverseTransform(point, null);
} catch (NoninvertibleTransformException e)
}
catch (NoninvertibleTransformException e)
{
e.printStackTrace();
}
return null;
}
/**
* Method that gets all the corner coordinates index: 0 -> top left 1 -> top
* right 3 -> bottom left 4 -> bottom right
*
* @return corner coordinates
*/
public Point2D[] getCorners()
{
Rectangle2D tempRekt = new Rectangle2D.Double(0, 0, image.getWidth(null), image.getHeight(null));
tempRekt.setFrame(getTransform().createTransformedShape(tempRekt).getBounds());
Point2D[] points = new Point2D[4];
Point2D point = new Point2D.Double(tempRekt.getX(), tempRekt.getY());
points[0] = point;
point = new Point2D.Double(tempRekt.getX() + tempRekt.getHeight(), tempRekt.getY());
points[1] = point;
point = new Point2D.Double(tempRekt.getX(), tempRekt.getY() + tempRekt.getHeight());
points[2] = point;
point = new Point2D.Double(tempRekt.getX() + tempRekt.getHeight(), tempRekt.getY() + tempRekt.getHeight());
points[3] = point;
return points;
}
/**
*
* @param corners
* @return if there is a collision
*/
public boolean collision(DrawObject object)
{
// Point2D[] ownCorners = getCorners();
Point2D[] objectCorners = object.getCorners();
Shape ownShape = new Rectangle2D.Double(-9, -9, image.getWidth(null) + 13, image.getHeight(null) + 13);
ownShape = getTransformSelection().createTransformedShape(ownShape);
// Shape otherShape = new Rectangle2D.Double(-9,
// -9,object.getImage().getWidth(null) +
// 13,object.getImage().getHeight(null) + 13);
// otherShape =
// getTransformSelection().createTransformedShape(otherShape);
if (ownShape.contains(objectCorners[0]))
return true;
else if (ownShape.contains(objectCorners[1]))
return true;
else if (ownShape.contains(objectCorners[2]))
return true;
else if (ownShape.contains(objectCorners[3]))
return true;
// if(otherShape.contains(ownCorners[0]))
// return true;
// else if(otherShape.contains(ownCorners[1]))
// return true;
// else if(otherShape.contains(ownCorners[2]))
// return true;
// else if(otherShape.contains(ownCorners[3]))
// return true;
else
return false;
}
/**
* This method checks if the place thats clicked is inside one of the
* corners.
@@ -235,4 +296,14 @@ public abstract class DrawObject
rektAngle = rectangle;
}
public Color getRectangleColor()
{
return rectangleColor;
}
public void setRectangleColor(Color rectangleColor)
{
this.rectangleColor = rectangleColor;
}
}