function setup(){
createCanvas(600,400)
trilha.play()
}
function draw(){
background(0)
b()
p()
c()
s()
preload()
}
//ball
let xb = 300
let yb = 200
let db = 15
let rb = db / 2
let vxb = 6
let vyb = 6
function b(){
circle(xb,yb,db)
xb += vxb
yb += vyb
if(xb + rb > width ||
xb - rb < 0){
vxb *= -1
}
if(yb + rb > height ||
yb - rb < 0){
vyb *= -1
}
}
//player
let xp = 5
let yp = 150
let ap = 10
let lp = 90
let collision = false
function p(){
rect(xp,yp,ap,lp)
if(keyIsDown(UP_ARROW)) {
yp -= 10
}
if(keyIsDown(DOWN_ARROW)) {
yp += 10
}
collision = collideRectCircle(xp, yp, ap, lp, xb, yb, rb)
if (collision){
vxb *= -1
}
}
//computer
let xc = 581
let yc = 150
let vyc
function c(){
rect(xc,yc,ap,lp)
vyc = yb - yc - ap /2 - 30
yc += vyb
collision = collideRectCircle(xc, yc, ap, lp, xb, yb, rb)
if (collision){
vxb *= -1
}
}
//score
let sp = 0
let sc = 0
function s(){
stroke(255)
textAlign(CENTER)
textSize(16)
fill(color(255, 140, 0))
rect(150, 10, 40, 20)
fill(255)
text(sp, 170, 26)
fill(color(255, 140, 0))
rect(450, 10, 40, 20)
fill(255)
text(sc, 470, 26)
if(xb > 590){
sp += 1
}
if(xb < 10){
sc += 1
}
}
//sound
let raquetada
let ponto
let trilha
function preload(){
raquetada = loadSound("raquetada.mp3")
ponto = loadSound("pontos.mp3")
trilha = loadSound("trilha.mp3")
}