spawn
hoi
This commit is contained in:
@@ -234,6 +234,10 @@ public abstract class DrawObject implements Serializable
|
||||
{
|
||||
this.position = position;
|
||||
}
|
||||
public void setPosition(Point2D position, boolean b)
|
||||
{
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public double getRotation()
|
||||
{
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package Objects;
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
import Applicatie.Panel;
|
||||
|
||||
public class Entrance extends DrawObject
|
||||
{
|
||||
@@ -15,5 +18,35 @@ public class Entrance extends DrawObject
|
||||
{
|
||||
return "Entrance";
|
||||
}
|
||||
|
||||
public void setPosition(Point2D position, boolean b)
|
||||
{
|
||||
//this.position = position;
|
||||
Rectangle2D rect = getRectangle();
|
||||
double xl = (Panel.getFieldWidth()/2) + rect.getMinX();
|
||||
double xr = Panel.getFieldWidth() - (Panel.getFieldWidth()/2 + rect.getMaxX());
|
||||
double yt = (Panel.getFieldHeight()/2) + rect.getMinY();
|
||||
double yb = Panel.getFieldHeight() - (Panel.getFieldHeight()/2 + rect.getMaxY());
|
||||
if(xl < xr && xl < yt && xl < yb)
|
||||
{
|
||||
this.position = new Point2D.Double(-Panel.getFieldWidth()/2, position.getY());
|
||||
}
|
||||
else if(xr < xl && xr < yt && xr < yb)
|
||||
{
|
||||
this.position = new Point2D.Double(Panel.getFieldWidth()/2 - rect.getWidth(), position.getY());
|
||||
}
|
||||
else if(yt < xl && yt < xr && yt < yb)
|
||||
{
|
||||
this.position = new Point2D.Double(position.getX(), -Panel.getFieldHeight()/2);
|
||||
}
|
||||
else if(yb < xl && yb < yt && yb < xr)
|
||||
{
|
||||
this.position = new Point2D.Double(position.getX(), Panel.getFieldHeight()/2 - rect.getHeight());
|
||||
}
|
||||
else
|
||||
{
|
||||
this.position = new Point2D.Double(-Panel.getFieldWidth()/2, -Panel.getFieldHeight()/2);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+107
-39
@@ -14,105 +14,173 @@ import java.util.ArrayList;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import Applicatie.Waypoint;
|
||||
|
||||
/**
|
||||
* Create's a path.
|
||||
*
|
||||
* @author Wesley de Hek
|
||||
* @version 1.2
|
||||
*/
|
||||
public class Path {
|
||||
|
||||
public class Path
|
||||
{
|
||||
|
||||
private ArrayList<Point2D> points;
|
||||
private ArrayList<Shape> lines;
|
||||
private Point2D tempPoint;
|
||||
private BufferedImage pathBackground;
|
||||
|
||||
private ArrayList<Waypoint> waypoints;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public Path() {
|
||||
public Path()
|
||||
{
|
||||
points = new ArrayList<>();
|
||||
lines = new ArrayList<>();
|
||||
try {
|
||||
waypoints = new ArrayList<Waypoint>();
|
||||
try
|
||||
{
|
||||
pathBackground = ImageIO.read(new File("images/newPath.png"));
|
||||
} catch (IOException e) {
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draws the path.
|
||||
* @param g2 - the Graphics2D object.
|
||||
*
|
||||
* @param g2
|
||||
* - the Graphics2D object.
|
||||
*/
|
||||
public void draw(Graphics2D g2) {
|
||||
TexturePaint paint = new TexturePaint(pathBackground,new Rectangle2D.Double(0,0,128,128));
|
||||
public void draw(Graphics2D g2)
|
||||
{
|
||||
TexturePaint paint = new TexturePaint(pathBackground, new Rectangle2D.Double(0, 0, 128, 128));
|
||||
g2.setPaint(paint);
|
||||
g2.setStroke(new BasicStroke(30,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
|
||||
if(!points.isEmpty()) {
|
||||
for(int i = 1; i < points.size(); i++) {
|
||||
Point2D previousPoint = points.get(i-1);
|
||||
g2.setStroke(new BasicStroke(30, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
|
||||
if (!points.isEmpty())
|
||||
{
|
||||
for (int i = 1; i < points.size(); i++)
|
||||
{
|
||||
Point2D previousPoint = points.get(i - 1);
|
||||
Point2D point = points.get(i);
|
||||
g2.drawLine((int) previousPoint.getX(),(int) previousPoint.getY(),(int) point.getX(),(int) point.getY());
|
||||
g2.drawLine((int) previousPoint.getX(), (int) previousPoint.getY(), (int) point.getX(), (int) point.getY());
|
||||
}
|
||||
//Drawing line that follows the mouse:
|
||||
if(tempPoint != null) {
|
||||
Point2D lastPoint = points.get(points.size()-1);
|
||||
g2.drawLine((int) lastPoint.getX(),(int) lastPoint.getY(),(int) tempPoint.getX(),(int) tempPoint.getY());
|
||||
// Drawing line that follows the mouse:
|
||||
if (tempPoint != null)
|
||||
{
|
||||
Point2D lastPoint = points.get(points.size() - 1);
|
||||
g2.drawLine((int) lastPoint.getX(), (int) lastPoint.getY(), (int) tempPoint.getX(), (int) tempPoint.getY());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if one of the lines contains the given point and return the Shape.
|
||||
*
|
||||
* @param point
|
||||
* - The point of your object.
|
||||
* @return if the Shape contains the point.
|
||||
*/
|
||||
public Shape containsPointShape(Point2D point)
|
||||
{
|
||||
for (Shape line : getPath())
|
||||
{
|
||||
if (line.contains(point))
|
||||
{
|
||||
return line;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if one of the lines contains the given point.
|
||||
* @param point - the point you want to containment with.
|
||||
*
|
||||
* @param point
|
||||
* - the point you want to containment with.
|
||||
* @return if the path contains the point.
|
||||
*/
|
||||
public boolean containsPoint(Point2D point) {
|
||||
for(Shape line : getPath()) {
|
||||
if(line.contains(point)) {
|
||||
public boolean containsPoint(Point2D point)
|
||||
{
|
||||
for (Shape line : getPath())
|
||||
{
|
||||
if (line.contains(point))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean intersectsRect(Rectangle2D rect)
|
||||
{
|
||||
for(Shape line : getPath())
|
||||
{
|
||||
if(line.intersects(rect))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get array with line's from the points.
|
||||
*
|
||||
* @return a array with all the lines of the path.
|
||||
*/
|
||||
public ArrayList<Shape> getPath() {
|
||||
public ArrayList<Shape> getPath()
|
||||
{
|
||||
lines.clear();
|
||||
for(int i = 1; i < points.size(); i++) {
|
||||
Point2D previousPoint = points.get(i-1);
|
||||
for (int i = 1; i < points.size(); i++)
|
||||
{
|
||||
Point2D previousPoint = points.get(i - 1);
|
||||
Point2D point = points.get(i);
|
||||
Line2D line = new Line2D.Double((int) previousPoint.getX(),(int) previousPoint.getY(),(int) point.getX(),(int) point.getY());
|
||||
BasicStroke stroke = new BasicStroke(30,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND);
|
||||
Line2D line = new Line2D.Double((int) previousPoint.getX(), (int) previousPoint.getY(), (int) point.getX(), (int) point.getY());
|
||||
BasicStroke stroke = new BasicStroke(30, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
|
||||
lines.add(stroke.createStrokedShape(line));
|
||||
}
|
||||
return lines;
|
||||
return lines;
|
||||
}
|
||||
|
||||
public void addWaypoint(Waypoint w)
|
||||
{
|
||||
waypoints.add(w);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a point to the path.
|
||||
* @param point - the point you want the path to pass.
|
||||
*
|
||||
* @param point
|
||||
* - the point you want the path to pass.
|
||||
*/
|
||||
public void addPoint(Point2D point) {
|
||||
public void addPoint(Point2D point)
|
||||
{
|
||||
points.add(point);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all the path points.
|
||||
*
|
||||
* @return all the points of the path.
|
||||
*/
|
||||
public ArrayList<Point2D> getPoints() {
|
||||
public ArrayList<Point2D> getPoints()
|
||||
{
|
||||
return points;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the temporary point, useful for following the mouse while drawing the path.
|
||||
* @param point - the point of the mouse.
|
||||
* Set the temporary point, useful for following the mouse while drawing the
|
||||
* path.
|
||||
*
|
||||
* @param point
|
||||
* - the point of the mouse.
|
||||
*/
|
||||
public void setTempPoint(Point2D point) {
|
||||
public void setTempPoint(Point2D point)
|
||||
{
|
||||
tempPoint = point;
|
||||
}
|
||||
}
|
||||
}
|
||||
+16
-1
@@ -2,11 +2,16 @@ package Objects;
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
import Agenda.AgendaStage;
|
||||
|
||||
public class Stage extends DrawObject
|
||||
{
|
||||
public Stage(Point2D position)
|
||||
AgendaStage stage;
|
||||
|
||||
public Stage(Point2D position, AgendaStage st)
|
||||
{
|
||||
super("stage", position);
|
||||
stage = st;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -15,4 +20,14 @@ public class Stage extends DrawObject
|
||||
return "Stage";
|
||||
}
|
||||
|
||||
public AgendaStage getStage()
|
||||
{
|
||||
return stage;
|
||||
}
|
||||
|
||||
public void setStage(AgendaStage stage)
|
||||
{
|
||||
this.stage = stage;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user