platform - 7

// platform-7

var cx;
var cy;
var r = 24;
var sign = 1; //  -1 or 1
var px;
var py;
var pw = 30;
var ph = 10;
var cy_max;

function setup() {
  var cnv = createCanvas(400, 300);
  cnv.position(60, 200);
  cx = width/2;
  cy = height/2;
  px = width/2;
  py = height*0.8;
} //setup

function draw() {
  background(192);

  strokeWeight(1);
  stroke(0);
  fill(255, 0, 0);
  cy = cy + sign;
  if (cy <= 0 + r) {
    sign = 1;
  }

// if the bat is NOT below the ball
  if ((px+pw < cx-r) || (px-pw > cx+r)) {
    cy_max = height - r + 100; ////////////////////////
  } else {
    cy_max = py - r;
  }

  if (cy >= cy_max) {
    sign = -1;
  }

  ellipseMode(RADIUS);
  ellipse(cx, cy, r, r);

  if (px > 0 + pw) {
    if (keyIsDown(LEFT_ARROW)) {
      px = px -1;
    }
  }
  if (px < width - pw - 1) {
    if (keyIsDown(RIGHT_ARROW)) {
      px = px + 1;
    }
  }
  fill(0, 192, 0);
  rectMode(RADIUS);
  rect(px, py + ph, pw, ph);
} //draw