Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion 02-arkanoid-game/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,26 @@
DESTROYED: 0
}

// Efecto de audio colisión bloque pelota
const audioContext = new (window.AudioContext || window.webkitAudioContext)();

function playBeep() {
const oscillator = audioContext.createOscillator();
const gainNode = audioContext.createGain();

oscillator.connect(gainNode);
gainNode.connect(audioContext.destination);

oscillator.frequency.setValueAtTime(800, audioContext.currentTime);
oscillator.type = 'square';

gainNode.gain.setValueAtTime(0.3, audioContext.currentTime);
gainNode.gain.exponentialRampToValueAtTime(0.01, audioContext.currentTime + 0.1);

oscillator.start(audioContext.currentTime);
oscillator.stop(audioContext.currentTime + 0.1);
}

for (let c = 0; c < brickColumnCount; c++) {
bricks[c] = [] // inicializamos con un array vacio
for (let r = 0; r < brickRowCount; r++) {
Expand Down Expand Up @@ -136,7 +156,7 @@
function drawUI() {
ctx.fillText(`FPS: ${framesPerSec}`, 5, 10)
}

//Detección de colisión
function collisionDetection() {
for (let c = 0; c < brickColumnCount; c++) {
for (let r = 0; r < brickRowCount; r++) {
Expand All @@ -154,6 +174,7 @@
if (isBallSameXAsBrick && isBallSameYAsBrick) {
dy = -dy
currentBrick.status = BRICK_STATUS.DESTROYED
playBeep()
}
}
}
Expand Down Expand Up @@ -214,6 +235,7 @@

function keyDownHandler(event) {
const { key } = event
audioContext.resume() // Reiniciamos evento de audio en la interacción del usuario
if (key === 'Right' || key === 'ArrowRight' || key.toLowerCase() === 'd') {
rightPressed = true
} else if (key === 'Left' || key === 'ArrowLeft' || key.toLowerCase() === 'a') {
Expand Down