Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

joguin de pong #295

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Empty file added index.html
Empty file.
152 changes: 152 additions & 0 deletions scketch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@

//variáveis da bolinha
let xBolinha = 300;
let yBolinha = 200;
let diametro = 15;
let raio = diametro / 2 ;

//velocidade da bolinha
let velocidadeXBolinha = 3;
let velocidadeYBolinha = 3;

//sons do jogo
let raquetada
let ponto


function preload(){

trilha = loadSound("trilha.mp3");
ponto = loadSound("ponto.mp3");
raquetada = loadSound("raquetada.mp3");

}


//variáveis da raquete
let xRaquete = 5;
let yRaquete = 150;
let raqueteComprimento = 10;
let raqueteAltura = 90;
let colidiu = false;

//Placar do jogo
let meusPontos = 0;
let pontosDoOponente = 0;

//variaveis do oponente
let xRaqueteOponente = 585
let yRaqueteOponente = 150
let velocidadeYOponente;

function setup() {
createCanvas(600, 400);
trilha.loop()
}

function draw() {
background(0);
mostraBolinha();
movimentaBolinha();
verificaColisaoBorda();
movimentaMinhaRaquete();
verificaColisaoRaquete(xRaquete, yRaquete);
mostraRaquete(xRaquete, yRaquete);
mostraRaquete(xRaqueteOponente, yRaqueteOponente);
movimenteRaqueteOponente();
verificaColisaoRaquete(xRaqueteOponente, yRaqueteOponente)
incluiPlacar();
marcaPonto();




}

function mostraBolinha(){
circle(xBolinha, yBolinha, diametro);
}

function movimentaBolinha(){
xBolinha += velocidadeXBolinha;
yBolinha += velocidadeYBolinha;
}

function verificaColisaoBorda(){
if (xBolinha + raio> width ||
xBolinha - raio< 0){
velocidadeXBolinha *= -1;
}
if (yBolinha + raio> height ||
yBolinha - raio < 0){
velocidadeYBolinha *= -1;
}
}
function mostraRaquete(x,y){
rect (x, y, raqueteComprimento, raqueteAltura)
}



function movimentaRaqueteOponente() {
if (keyIsDown(87)) {
yRaqueteOponente -= 10;
}
if (keyIsDown(83)) {
yRaqueteOponente += 10;

}
}

function movimentaMinhaRaquete() {
if (keyIsDown(UP_ARROW)) {
yRaquete -= 10;
}
if (keyIsDown(DOWN_ARROW)) {
yRaquete += 10;

}
}

function verificaColisaoRaquete(x, y) {
colidiu = collideRectCircle(x, y, raqueteComprimento, raqueteAltura, xBolinha, yBolinha, raio);
if (colidiu) {
velocidadeXBolinha *= -1;
raquetada.play()
}
}

function movimenteRaqueteOponente(){
velocidadeYOponente = yBolinha - yRaqueteOponente - raqueteComprimento /2 -30;
yRaqueteOponente += velocidadeYOponente

}
function incluiPlacar(){
stroke(255);
textAlign(CENTER);
textSize(16);
fill(color(255, 140, 0));
rect(150, 10, 40, 20);
fill(255);
text(meusPontos, 170, 26);
fill(color(255, 140, 0));
rect(450, 10, 40, 20);
fill(255);
text(pontosDoOponente, 470, 26);
}


function marcaPonto() {
if (xBolinha > 591) {
meusPontos += 1;
ponto.play()
}
if (xBolinha < 9) {
pontosDoOponente += 1;
ponto.play()
}
}




Empty file added style.css
Empty file.