xxxxxxxxxx
90
function preload() {
sofia = loadImage("image/sofi.png");
flowers = loadImage("image/flower.png")
}
gameObject = function(){
this.x=0;
this.y=0;
this.w=20;
// this.a=0.0;
this.col=0;
this.checkCol=function(obj1,obj2){
if (obj1.x+obj1.w>obj2.x && obj1.x<(obj2.x+obj2.w) && obj1.y+obj1.w>obj2.y && obj1.y<(obj2.y+obj2.w/2)) {
this.col=1;
} else {
this.col=0;
}
return this.col;
}
}
let easing = 0.05;
//let a=0;
let cube=new gameObject();
let ball=new gameObject();
function setup() {
createCanvas(400, 300);
cube.x=width/2;
ball.w=50;
}
function draw() {
background(0,0,220);
// push();
// translate(cube.x,cube.y);
// rotate(cube.a);
image(flowers,cube.x,cube.y, 50,50);
cube.a=cube.a+0.1;
cube.y=cube.y+5
if (cube.y>height){
cube.y=0;
cube.x=random(width);
}
let targetX = mouseX;
let dx = targetX - ball.x;
ball.x += dx * easing;
let targetY = mouseY;
let dy = targetY - ball.y;
ball.y += dy * easing;
if (cube.checkCol(cube,ball)==1){
fill(255,255,0);
cube.y=random(100)*-1;
cube.x=random(width);
}
image( sofia, ball.x, ball.y, ball.w, ball.w);
}