Polygons for Hit Detection
import java.awt.*;
int[] xs = {100,200,100,0};
int[] ys = {100, 200, 300, 200};
Polygon p = new Polygon(xs, ys, 4);
int x;
void setup()
{
size(500,500);
x = width;
}
void draw()
{
background(255);
if (p.contains(x, 150, 20, 20))
fill(255,0,0);
else if (p.contains(x, 170))
fill(0, 0, 255);
else
fill(0,255,0);
beginShape();
vertex(100, 100);
vertex(200, 200);
vertex(100, 300);
vertex(0,200);
endShape(CLOSE);
fill(0,0,255,50);
if (frameCount % 100 == 0)
x--;
if (x < 0)
x = width;
rect(x--, 150, 20, 20);
}