45 lines
729 B
JavaScript
45 lines
729 B
JavaScript
const vehicles = [];
|
|
const IMG_SIZE = 400;
|
|
let message = '';
|
|
|
|
const images = {};
|
|
|
|
function setup() {
|
|
// createCanvas(400, 300);
|
|
createCanvas(window.innerWidth, window.innerHeight);
|
|
|
|
vehicles.push(new Car(4));
|
|
}
|
|
|
|
function draw() {
|
|
background(255);
|
|
|
|
for (let i = 0; i < vehicles.length; i += 1) {
|
|
vehicles[i].draw(i * IMG_SIZE, 0, IMG_SIZE);
|
|
}
|
|
|
|
fill(0);
|
|
textFont('Arial', 20);
|
|
textAlign(CENTER);
|
|
text(message, width / 2, IMG_SIZE);
|
|
}
|
|
|
|
function mousePressed() {
|
|
const index = floor(mouseX / IMG_SIZE);
|
|
message = vehicles[index]?.getDescription() ?? 'None'; // polymorphism!
|
|
}
|
|
|
|
// CLASSES
|
|
|
|
class Car {
|
|
constructor(passengers) {
|
|
// ...
|
|
}
|
|
|
|
getDescription() {
|
|
// PLACEHOLDER
|
|
}
|
|
|
|
draw() {}
|
|
}
|