xxxxxxxxxx
65
let bacon;
let newcat;
let sparky;
function preload(){
kitn = loadImage("cat.jpg");
kiten = loadImage("cat.jpeg");
}
function setup() {
createCanvas(800, 600);
bacon = new Cat(30 , 50, kitn, 100,100 );
sparky = new Cat(random(width), random(height), kitn, 75,75)
newcat = new Cat(200, 100, kiten, 50,50);
textSize(36);
}
function draw() {
background(220);
bacon.drawCat();
bacon.moveCat();
newcat.drawCat();
newcat.moveCat();
sparky.drawCat();
sparky.moveCat();
}
class Cat {
constructor( x, y, pic, xsize, ysize) {
this.x = x;
this.y = y;
this.pic = pic;
this.xsize = xsize;
this.ysize = ysize;
}
drawCat() {
image(this.pic , this.x, this.y, this.xsize, this.ysize);
}
moveCat(){
this.x = this.x + 1;
this.y = mouseY;
}
}