xxxxxxxxxx
37
let vehicle;
let offset = 40;
let desired=null;
function setup() {
createCanvas(640, 240);
vehicle = new Vehicle(width / 2, height / 2);
}
function draw() {
background(255);
stroke(0);
noFill();
rectMode(CENTER);
rect(width / 2, height / 2, width - offset * 2, height - offset * 2);
if (this.position.x <offset) {
desired = createVector (this.maxspeed, this.velocity.y);
} else if (this.position.y > width -offset) {
desired = createVector (-this.maxspeed, this.velocity.y);
}
if (this.position.y < offset){
desired = createVector (this.velocity.x, this.maxspeed);
} else if (this.position.y > height - offset) {
desired = createVector (this.velocity.x,-this.maxspeed);
}
// Call the appropriate steering behaviors for our agents
vehicle.boundaries(offset);
vehicle.update();
vehicle.show();
}