Body Class
public abstract class Body {
public Double x, y;
public Double distance(Body b) { // This calculates the distance between
// centers.
Double xd = (b.x + b.width() / 2) - (x + width() / 2);
Double yd = (b.y + b.height() / 2) - (y + height() / 2);
return Math.sqrt(xd * xd + yd * yd);
}
public Boolean collide(Body b) { // This determines if two bodies have
// collided.
return pointIn(b.x, b.y) || pointIn(b.x + b.width(), b.y)
|| pointIn(b.x, b.y + b.height())
|| pointIn(b.x + b.width(), b.y + b.height())
|| b.pointIn(x, y);
}
public Boolean pointIn(Double xp, Double yp) { // This determines if a
// point is within this
// body.
return x }
public static int mapx(Game h, GameComponent canvas, double x) {
return (int) Math.round(x);
}
public static int mapy(Game h, GameComponent canvas, double y) {
return (int) Math.round
;
}
public abstract void draw(Game h, GameComponent canvas);
public abstract void step(Game bw, GameComponent canvas);
public abstract Double width();
public abstract Double height();
}







