xxxxxxxxxx
94
let x2, y2;
let radius1 = 10;
let radius = 30;
let a2 = 50;
let x = 100;
let y = 100;
let directionX = 3;
let directionY = 4.5;
let paddle_width = 150; //constant
let paddle_height = 30; //constant
var coral = (240, 128, 128);
var topBarX = 200;
var bottomBarX = 200;
function setup() {
createCanvas(400, 400);
background(253, 245, 230)
rectMode(CENTER)
noStroke();
}
function draw() {
background(253, 245, 230);
ellipse(x, y, 20, 20);
x += directionX;
y += directionY;
if (x >= width || x <= 0) {
directionX = -directionX;
}
// Bar top
fill(240, 128, 128);
rect(topBarX, 80, paddle_width, paddle_height);
if (mouseY <= height / 4) {
topBarX = mouseX
}
// Bouncing off Bartop
if (y < paddle_height + 80 && y> 80 && x > topBarX - paddle_width / 2 && x < topBarX + paddle_width / 2) {
directionY = -directionY;
fill(240, 128, 128);
print(y);
}
//Bar Bottom
fill(65, 105, 225);
rect(bottomBarX, 320, paddle_width, paddle_height);
if (mouseY >= 3 / 4 * height) {
bottomBarX = mouseX;
}
//Bouncing off Bar Bottom
if (y > height - 80 - paddle_height && y < height - 80 && x > bottomBarX - paddle_width / 2 && x < bottomBarX + paddle_width / 2) {
//fill(65, 105, 225);
directionY = -directionY;
fill(65, 105, 225);
print(y);
}
//Game Over and Color banner
if (y <= 0 || y >= height) {
// fill(230, 50, mouseX, 6);
// //translate(300, 180, 400, 300);
// x2 = radius * sin(20);
// y2 = radius * cos(a2);
ellipse(x2 + 180, y2 + 170, random(200, 400), random(200, 400));
fill(0);
textAlign(CENTER);
textSize(50);
textFont('Ocr A');
text('GAME OVER!', width / 2, height / 2);
}
}