xxxxxxxxxx
47
let pokemons = [];
let names = ['pika', 'bob', 'patty', 'candy', 'john'];
function setup() {
createCanvas(400, 400);
}
function draw() {
background(40);
for(let p of pokemons){
p.show();
p.talk();
p.move();
}
}
class Pokemon {
constructor(x,y, r, g, b, name){
this.x = x;
this.y = y;
this.radi = random(5, 20);
this.r = r;
this.g = g;
this.b = b;
this.name = name
}
show(){
fill(this.r, this.g, this.b);
circle(this.x, this.y, this.radi);
}
talk(){
text(names[this.name], this.x + 20,this.y + 20);
}
move(){
this.x += random(-3,3);
this.y += random(-3,3);
}
}
function mouseClicked(){
let name = floor(random(names.length-1));
let poky = new Pokemon(mouseX, mouseY, mouseY+50, mouseX+20, mouseX, name);
pokemons.push(poky);
}