xxxxxxxxxx
40
let myCar;
let car2;
function setup() {
createCanvas(1200, 1000);
myCar = new Car();
car2 = new Car();
}
function draw() {
background(220);
myCar.show();
myCar.move();
if (frameCount > 120) {
car2.show();
car2.move();
}
}
class Car {
constructor() {
this.x = 0;
}
show() {
rect(this.x, 200, 100, 10);
}
move() {
this.x++;
if (this.x > width) {
this.x = 0;
}
}
} // end of car class