xxxxxxxxxx
195
//variaveis da bolinhakkk
let xBol = 300
let yBol = 200
let dBol = 15
//variaveis da movimentaçao da bolinhakkkk
let velxBol = 6
let velyBol = 6
let raio = dBol / 2
//variaveis da raquetekkkkkk
let xRect = 0
let yRect = 160
let wRect = 10
let hRect = 60
let hit = false
let error = 0
//variaveis da raquete do oponentekkkkk
let xRect2 = 600 - wRect
let yRect2 = 180
let velyRect2;
//placar
let pts = 0;
let pts2 = 0;
//sons do jogo
let aiMamae;
let borda
let cavalo;
let fezPonto;
let fontella;
let ping;
let quero;
let tomei;
let trilha;
function preload() {
aiMamae = loadSound("ai-mamae.mp3");
borda = loadSound("borda.mp3");
cavalo = loadSound("cavalo.mp3");
fezPonto = loadSound("fez-ponto.mp3");
fontella = loadSound("fontella-viado.mp3");
ping = loadSound("ping.mp3");
quero = loadSound("quero-fazer-coco.mp3");
tomei = loadSound("tomei-ponto.mp3");
trilha = loadSound("trilha-sonora.mp3");
}
function setup(){
createCanvas(600, 400);
trilha.loop();
}
function draw() {
background(0);
showBol();
moveBol();
collideBol();
showRect(xRect, yRect);
moveRect();
collideRect(xRect, yRect);
showRect(xRect2, yRect2); //Rect2
moveRect2();
collideRect(xRect2, yRect2);
showPts();
addPts();
sons();
stuckBol();
}
function showBol(){
circle (xBol, yBol, dBol);
}
function moveBol(){
xBol += velxBol;
yBol += velyBol;
}
function collideBol(){
if (xBol + raio > width || xBol - raio < 0){
velxBol *= -1
borda.play();
}
if (yBol + raio > height || yBol - raio < 0){
velyBol *= -1
borda.play();
}
}
function showRect(x, y){
rect (x, y, wRect, hRect);
}
function moveRect(){
if (keyIsDown(87)){
if (canMoveUp()){
yRect -= 10
}
}
if (keyIsDown(83)){
if (canMoveDown()){
yRect += 10
}
}
}
function canMoveUp(){
return yRect >= 10;
}
function canMoveDown(){
return yRect - hRect <= 270;
}
function collideRect(x, y){
hit =
collideRectCircle(x, y, wRect, hRect, xBol, yBol, raio);
if (hit){
velxBol *= -1;
ping.play();
}
}
function moveRect2(){
velyRect2 = yBol - yRect2 - wRect / 2 - 30;
yRect2 += velyRect2 + error;
calcError();
}
function calcError(){
if (pts2 >= pts){
error += 1
if (error >= 39) {
error = 40
}
} else {
error -= 1
if (error <= 35){
error = 35
}
}
}
function showPts(){
textAlign (CENTER)
textSize (24)
fill (color (107,142,35))
rect(230, 7, 40, 30)
fill (color (107,142,35))
rect(330, 7, 40, 30)
fill (225)
text(pts, 250, 30)
text(pts2, 350, 30)
}
function addPts(){
if (xBol > 590){
pts += 1;
fezPonto.play();
}
if (xBol < 10){
pts2 += 1;
tomei.play();
}
}
function sons(){
if (keyIsDown(65)){
aiMamae.play();
}
if (keyIsDown(67)){
cavalo.play();
}
if (keyIsDown(70)){
fontella.play();
}
if (keyIsDown(81)){
quero.play();
}
}
function stuckBol(){
if (xBol - raio < 0){
xBol = 10
}
}