xxxxxxxxxx
79
let bot;
function setup() {
createCanvas(windowWidth, windowHeight);
bot = new Robot(width / 2, height / 2, 400, 200);
}
class Robot {
constructor(x, y, w, h) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
this.glow = 0;
this.direction = 1;
}
show() {
rectMode(CENTER);
stroke(0);
// head shadow
fill(219, 28, 15);
rect(this.x, this.y, this.w, this.h, 25, 15, 25, 20);
// head
noStroke();
fill(242, 52, 39);
rect(this.x-4, this.y, this.w-8, this.h, 25, 15, 25, 20);
translate(this.x, this.y);
// outside eyes
noStroke();
fill(219, 28, 15);
ellipse(0 - this.w/4.1, 0 , this.w * 0.27, this.h * 0.93);
ellipse(0 + this.w/3.9, 0, this.w * 0.27, this.h * 0.97);
// eyes
stroke(0);
fill(250, 229, 0);
ellipse(0 - this.w/4, 0 , this.w * 0.25, this.h * 0.9);
ellipse(0 + this.w/4, 0, this.w * 0.25, this.h * 0.95);
// inside eyes
noStroke();
fill(250, 246, 0, this.glow);
ellipse(0-this.w/3.75, 0, this.w *0.2, this.h *0.85);
ellipse(0+this.w/4.32, 0, this.w *0.2, this.h *0.9 );
}
shine(){
this.glow = this.glow + (5*this.direction);
if(this.glow > 255 || this.glow < 0){
this.direction = this.direction * -1;
}
}
hover(){
this.y = this.y + (random(0,0.2)*this.direction);
this.x = this.x + (random(-0.08,0.08)*this.direction);
if(this.y>this.y+60 || this.y < this.y - 60){
this.direction = this.direction * -1;
}
}
jump(){
if(mouseIsPressed){
this.y -= 10;
setTimeout(()=>{for(let i = 0; i < 10; i++){
this.y += 1;
}
},100)
}
}
}
function draw() {
background(10);
bot.show();
bot.shine();
// bot.hover();
bot.jump();
}