xxxxxxxxxx
63
var vehicle;
var food = [];
var poison = [];
function setup() {
createCanvas(640, 360);
textSize(15);
noStroke();
vehicle = new Vehicle(random(width), random(height), random(8, 16));
for (var i = 0; i < 10; i++) {
var x = random(width);
var y = random(height);
food.push(createVector(x, y));
}
for (var i = 0; i < 20; i++) {
var x = random(width);
var y = random(height);
poison.push(createVector(x, y));
}
}
function draw() {
background((vehicle.position.x/width) * 255 , (vehicle.position.x/width) * 255, vehicle.velocity.x/vehicle.velocity.y);
print(vehicle.health);
var target = createVector(width / 2, height / 2);
var mouse = createVector(mouseX, mouseY);
fill(127);
stroke(200);
strokeWeight(2);
ellipse(target.x, target.y, 48, 48);
for (var i = 0; i < food.length; i++) {
fill(0, 255, 0);
noStroke();
ellipse(food[i].x, food[i].y, 8, 8);
}
for (var i = 0; i < poison.length; i++) {
fill(255, 0, 0);
noStroke();
ellipse(poison[i].x, poison[i].y, 8, 8);
}
if (food.length > 0) {
vehicle.eat(food);
}
if (poison.length > 0) {
vehicle.Flee(poison);
}
if (food.length == 0) {
vehicle.seek(target);
}
vehicle.update();
vehicle.display();
}