xxxxxxxxxx
69
function preload() {
soundFormats('mp3', 'ogg');
hit = loadSound('ouch.mp3');
p1w = loadSound('player1.mp3');
p2w = loadSound('player2.mp3');
}
let p1;
let p2;
let win;
let pw;
function setup() {
//hit.setVolume(0.1);
//mySound.play();
//hit.play();
createCanvas(680, 680);
p1 = 0;
p2 = 0;
win = 0;
pw = 0;
}
function draw() {
background(220);
textSize(40);
text('Player 1 Score:' + p1, 20, 40);
text('Player 2 Score:' + p2, 20, 120);
if(p1 == 5 && win <= 50) {
//p1 = 0;
//p2 = 0;
pw = 1;
win++;
}
if(p2 == 5 && win <= 50) {
//p1 = 0;
//p2 = 0;
pw = 2;
win++;
}
if(win > 0 && pw > 0){
text('Player ' + pw + ' Wins!', 20, 300);
}
//text(win, 20, 200);
if(win > 50){
p1 = 0;
p2 = 0;
win = 0;
}
//if(pw == 1) p1w.play();
//if(pw == 2) p2w.play();
}
function keyTyped() {
if(key === 'A') {
hit.play();
p2++;
} else if(key === 'B') {
hit.play();
p1++;
}
}