Files
sunny9898/task8/_ref/noc-examples-processing-master/chp09_ga/EvolveFlowField/Obstacle.pde
louiscklaw 5637fbf94f update,
2025-02-01 02:07:58 +08:00

40 lines
698 B
Plaintext

// The Nature of Code
// Daniel Shiffman
// http://natureofcode.com
// Pathfinding w/ Genetic Algorithms
// A class for an obstacle, just a simple rectangle that is drawn
// and can check if a creature touches it
// Also using this class for starting point and target position
class Obstacle {
Rectangle r;
Obstacle(int x, int y, int w, int h) {
r = new Rectangle(x,y,w,h);
}
Obstacle(Rectangle r_) {
r = r_;
}
void display() {
stroke(0);
fill(175);
rectMode(CORNER);
rect(r.x,r.y,r.width,r.height);
}
boolean contains(PVector spot) {
if (r.contains((int)spot.x,(int)spot.y)) {
return true;
} else {
return false;
}
}
}