Saven werkt van guus

This commit is contained in:
Yorick
2015-04-07 13:12:02 +02:00
parent 5a9c3f259a
commit ea7ecfcd56
17 changed files with 1163 additions and 98 deletions
+29 -39
View File
@@ -10,18 +10,22 @@ import java.awt.geom.Ellipse2D;
import java.awt.geom.NoninvertibleTransformException;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.io.Serializable;
import javax.swing.ImageIcon;
public abstract class DrawObject
import Applicatie.Images;
public abstract class DrawObject implements Serializable
{
Point2D position;
double rotation;
double scale;
int width;
int height;
private Image image;
// private Image image;
protected boolean selected;
private String filename;
protected int areaTop;
protected int areaBottom;
@@ -43,11 +47,12 @@ public abstract class DrawObject
public DrawObject(String filename, Point2D position)
{
image = new ImageIcon(filename).getImage();
// image = new ImageIcon(filename).getImage();
Image image = Images.getImage(filename);
width = image.getWidth(null);
height = image.getHeight(null);
this.filename = filename;
scale = 1;
rotation = 0;
this.position = position;
@@ -64,6 +69,7 @@ public abstract class DrawObject
public void draw(Graphics2D g)
{
AffineTransform tx = getTransform();
Image image = Images.getImage(filename);
g.drawImage(image, tx, null);
if (selected)
{
@@ -156,31 +162,7 @@ public abstract class DrawObject
}
/**
* 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;
}
/**
* Checking
* collision.
* Checking collision.
*
* @param object
* . the drawObject to check collision with.
@@ -269,16 +251,6 @@ public abstract class DrawObject
this.scale = scale;
}
public Image getImage()
{
return image;
}
public void setImage(Image image)
{
this.image = image;
}
public boolean isSelected()
{
return selected;
@@ -306,6 +278,7 @@ public abstract class DrawObject
public Rectangle2D getImageRectangle()
{
Image image = Images.getImage(filename);
return new Rectangle2D.Double(0, 0, image.getWidth(null), image.getHeight(null));
}
@@ -349,4 +322,21 @@ public abstract class DrawObject
this.areaRight = areaRight;
}
public int getEndX()
{
Image image = Images.getImage(filename);
return (int) (position.getX() + image.getWidth(null));
}
public int getEndY()
{
Image image = Images.getImage(filename);
return (int) (position.getY() + image.getHeight(null));
}
public String getFileName()
{
return filename;
}
}
+1 -1
View File
@@ -7,7 +7,7 @@ public class Entrance extends DrawObject
public Entrance(Point2D position)
{
super("images/entrance.png", position);
super("entrance", position);
}
@Override
+1 -1
View File
@@ -5,7 +5,7 @@ import java.awt.geom.Point2D;
public class Food extends DrawObject {
public Food(Point2D position) {
super("images/food.png", position);
super("food", position);
}
public String getName() {
+1 -1
View File
@@ -7,7 +7,7 @@ public class OldPath extends DrawObject
public OldPath(Point2D position)
{
super("images/path.jpg", position);
super("path", position);
}
@Override
+1 -1
View File
@@ -6,7 +6,7 @@ public class Stage extends DrawObject
{
public Stage(Point2D position)
{
super("images/stage4.png", position);
super("stage", position);
}
@Override
+1 -1
View File
@@ -7,7 +7,7 @@ public class Toilet extends DrawObject
public Toilet(Point2D position)
{
super("images/wc.png", position);
super("wc", position);
}
@Override
+1 -1
View File
@@ -7,7 +7,7 @@ public class Wall extends DrawObject
public Wall(Point2D position)
{
super("images/wall.png", position);
super("wall", position);
}
@Override