Escucha, estoy haciendo un juevo en javascript y por algun motivo los proyectiles no se disparan correctamente. Haz que disparen, y asegurate de no usar clases, ni objetos dentro de la funcion let playerX, playerY; let playerSpeed; let projectiles = []; let enemiesX = []; let enemiesY = []; let enemiesSpeed = []; let totalEnemies = 30; let enemyCount = 0; let gameStarted = false; let gameOver = false; let gameWin = false; let pelotitasX = []; let pelotitasY = []; let pelotitasActive = []; let menuVisible = true; let creditsVisible = false; let spaceImg, shipImg, asteroidImg; // Variables para el cálculo parabólico let h, k, f, j; let px, py, vx, vy; let active = false; function preload() { spaceImg = loadImage('assets/space.png'); shipImg = loadImage('assets/ship.png'); asteroidImg = loadImage('assets/asteroid.png'); } function setup() { createCanvas(windowWidth, windowHeight); resetGame(); playerSpeed = width * 0.005; } function draw() { background(spaceImg); if (menuVisible) { showMenu(); } else if (creditsVisible) { showCredits(); } else if (gameStarted) { movePlayer(); displayPlayer(); updateEnemies(); displayEnemies(); displayProjectiles(); checkCollisions(); if (enemyCount >= totalEnemies) { gameWin = true; gameStarted = false; } if (checkPlayerCollision()) { gameOver = true; gameStarted = false; } displayScore(); } else { if (gameOver) { showGameOver(); } else if (gameWin) { showGameWin(); drawPelotitas(); } } } function windowResized() { resizeCanvas(windowWidth, windowHeight); resetGame(); } function keyPressed() { if ((gameOver || gameWin) && keyCode === ENTER) { resetGame(); gameStarted = true; gameOver = false; gameWin = false; } } function mousePressed() { if (menuVisible && mouseX > width / 2 - 50 && mouseX < width / 2 + 50 && mouseY > height / 2 && mouseY < height / 2 + 50) { startGame(); } else if (menuVisible && mouseX > width / 2 - 50 && mouseX < width / 2 + 50 && mouseY > height / 2 + 60 && mouseY < height / 2 + 110) { creditsVisible = true; menuVisible = false; } else if (creditsVisible) { creditsVisible = false; menuVisible = true; } else if (gameStarted && !active) { active = true; px = playerX; py = playerY; vx = width * 0.6; vy = height * 0.4; h = playerX; k = width / 2; f = height / 3; j = parabolic(); } } function startGame() { gameStarted = true; menuVisible = false; creditsVisible = false; resetGame(); } function resetGame() { playerX = width / 2; playerY = height - 50; enemyCount = 0; projectiles = []; enemiesX = []; enemiesY = []; enemiesSpeed = []; for (let i = 0; i < 5; i++) { enemiesX[i] = random(width); enemiesY[i] = 0; enemiesSpeed[i] = random(1, 3); } } function movePlayer() { if (keyIsDown(LEFT_ARROW) || keyIsDown(65)) { playerX -= playerSpeed; } if (keyIsDown(RIGHT_ARROW) || keyIsDown(68)) { playerX += playerSpeed; } playerX = constrain(playerX, 0, width); } function displayPlayer() { image(shipImg, playerX, playerY, width * 0.05, width * 0.05); } function updateEnemies() { for (let i = 0; i < enemiesX.length; i++) { enemiesY[i] += enemiesSpeed[i]; if (enemiesY[i] > height) { enemiesY[i] = 0; enemiesX[i] = random(width); } } } function displayEnemies() { for (let i = 0; i < enemiesX.length; i++) { image(asteroidImg, enemiesX[i], enemiesY[i], width * 0.05, width * 0.05); } } function updateProjectiles() { while(active && mouseIsPressed){ circle(px, py, width * 0.02); py -=3 } if(!onScreen(px || py)){ active=false } } function displayProjectiles() { if (active) ellipse(px, py, width * 0.02); } function parabolic() { return (vy - py) / (pow(h - k, 2)); } function calculate(x) { return f + j * pow((x - h), 2); } function onScreen(x, y) { return x >= 0 && x <= width && y >= 0 && y <= height; } function checkCollisions() { for (let i = projectiles.length - 1; i >= 0; i--) { for (let j = enemiesX.length - 1; j >= 0; j--) { if (dist(px, py, enemiesX[j], enemiesY[j]) < width * 0.05) { enemiesY[j] = 0; enemiesX[j] = random(width); projectiles.splice(i, 1); enemyCount++; } } } } function checkPlayerCollision() { for (let i = 0; i < enemiesX.length; i++) { if (dist(playerX, playerY, enemiesX[i], enemiesY[i]) < width * 0.05) return true; } return false; } function drawPelotitas() { for (let i = 0; i < 20; i++) { let x = pelotitasX[i]; let y = calculate(x); ellipse(x, y, width * 0.03); } } function displayScore() { textSize(width * 0.03); fill(255); text("Enemies Eliminados: " + enemyCount, width / 2, 30); } function showMenu() { textSize(width * 0.05); textAlign(CENTER); fill(255); text("Menu Principal", width / 2, height / 2 - 100); textSize(width * 0.03); rect(width / 2 - 50, height / 2, 100, 50); text("Jugar", width / 2, height / 2 + 30); rect(width / 2 - 50, height / 2 + 60, 100, 50); text("Créditos", width / 2, height / 2 + 90); } function showCredits() { textSize(width * 0.04); textAlign(CENTER); fill(255); text("Juego desarrollado por Ramiro Solá y Tomás Guerrero", width / 2, height / 2); text("Presiona cualquier tecla para volver", width / 2, height / 2 + 30); } function showGameOver() { textSize(width * 0.05); textAlign(CENTER); fill(255, 0, 0); text("Game Over", width / 2, height / 2 - 40); textSize(width * 0.03); text("Presiona Enter para Reintentar", width / 2, height / 2); } function showGameWin() { textSize(width * 0.05); textAlign(CENTER); fill(0, 255, 0); text("You Win!", width / 2, height / 2 - 40); textSize(width * 0.03); text("Presiona Enter para Jugar de Nuevo", width / 2, height / 2); }
function that: add two numbers together ```python def add(a, b): return a + b add(1, 2) ``` function that: Escucha, estoy haciendo un juevo en javascript y por algun motivo los proyectiles no se disparan correctamente. Haz que disparen, y asegurate de no usar clases, ni objetos dentro de la funcion let playerX, playerY; let playerSpeed; let projectiles = []; let enemiesX = []; let enemiesY = []; let enemiesSpeed = []; let totalEnemies = 30; let enemyCount = 0; let gameStarted = false; let gameOver = false; let gameWin = false; let pelotitasX = []; let pelotitasY = []; let pelotitasActive = []; let menuVisible = true; let creditsVisible = false; let spaceImg, shipImg, asteroidImg; // Variables para el cálculo parabólico let h, k, f, j; let px, py, vx, vy; let active = false; function preload() { spaceImg = loadImage('assets/space.png'); shipImg = loadImage('assets/ship.png'); asteroidImg = loadImage('assets/asteroid.png'); } function setup() { createCanvas(windowWidth, windowHeight); resetGame(); playerSpeed = width * 0.005; } function draw() { background(spaceImg); if (menuVisible) { showMenu(); } else if (creditsVisible) { showCredits(); } else if (gameStarted) { movePlayer(); displayPlayer(); updateEnemies(); displayEnemies(); displayProjectiles(); checkCollisions(); if (enemyCount >= totalEnemies) { gameWin = true; gameStarted = false; } if (checkPlayerCollision()) { gameOver = true; gameStarted = false; } displayScore(); } else { if (gameOver) { showGameOver(); } else if (gameWin) { showGameWin(); drawPelotitas(); } } } function windowResized() { resizeCanvas(windowWidth, windowHeight); resetGame(); } function keyPressed() { if ((gameOver || gameWin) && keyCode === ENTER) { resetGame(); gameStarted = true; gameOver = false; gameWin = false; } } function mousePressed() { if (menuVisible && mouseX > width / 2 - 50 && mouseX < width / 2 + 50 && mouseY > height / 2 && mouseY < height / 2 + 50) { startGame(); } else if (menuVisible && mouseX > width / 2 - 50 && mouseX < width / 2 + 50 && mouseY > height / 2 + 60 && mouseY < height / 2 + 110) { creditsVisible = true; menuVisible = false; } else if (creditsVisible) { creditsVisible = false; menuVisible = true; } else if (gameStarted && !active) { active = true; px = playerX; py = playerY; vx = width * 0.6; vy = height * 0.4; h = playerX; k = width / 2; f = height / 3; j = parabolic(); } } function startGame() { gameStarted = true; menuVisible = false; creditsVisible = false; resetGame(); } function resetGame() { playerX = width / 2; playerY = height - 50; enemyCount = 0; projectiles = []; enemiesX = []; enemiesY = []; enemiesSpeed = []; for (let i = 0; i < 5; i++) { enemiesX[i] = random(width); enemiesY[i] = 0; enemiesSpeed[i] = random(1, 3); } } function movePlayer() { if (keyIsDown(LEFT_ARROW) || keyIsDown(65)) { playerX -= playerSpeed; } if (keyIsDown(RIGHT_ARROW) || keyIsDown(68)) { playerX += playerSpeed; } playerX = constrain(playerX, 0, width); } function displayPlayer() { image(shipImg, playerX, playerY, width * 0.05, width * 0.05); } function updateEnemies() { for (let i = 0; i < enemiesX.length; i++) { enemiesY[i] += enemiesSpeed[i]; if (enemiesY[i] > height) { enemiesY[i] = 0; enemiesX[i] = random(width); } } } function displayEnemies() { for (let i = 0; i < enemiesX.length; i++) { image(asteroidImg, enemiesX[i], enemiesY[i], width * 0.05, width * 0.05); } } function updateProjectiles() { while(active && mouseIsPressed){ circle(px, py, width * 0.02); py -=3 } if(!onScreen(px || py)){ active=false } } function displayProjectiles() { if (active) ellipse(px, py, width * 0.02); } function parabolic() { return (vy - py) / (pow(h - k, 2)); } function calculate(x) { return f + j * pow((x - h), 2); } function onScreen(x, y) { return x >= 0 && x <= width && y >= 0 && y <= height; } function checkCollisions() { for (let i = projectiles.length - 1; i >= 0; i--) { for (let j = enemiesX.length - 1; j >= 0; j--) { if (dist(px, py, enemiesX[j], enemiesY[j]) < width * 0.05) { enemiesY[j] = 0; enemiesX[j] = random(width); projectiles.splice(i, 1); enemyCount++; } } } } function checkPlayerCollision() { for (let i = 0; i < enemiesX.length; i++) { if (dist(playerX, playerY, enemiesX[i], enemiesY[i]) < width * 0.05) return true; } return false; } function drawPelotitas() { for (let i = 0; i < 20; i++) { let x = pelotitasX[i]; let y = calculate(x); ellipse(x, y, width * 0.03); } } function displayScore() { textSize(width * 0.03); fill(255); text("Enemies Eliminados: " + enemyCount, width / 2, 30); } function showMenu() { textSize(width * 0.05); textAlign(CENTER); fill(255); text("Menu Principal", width / 2, height / 2 - 100); textSize(width * 0.03); rect(width / 2 - 50, height / 2, 100, 50); text("Jugar", width / 2, height / 2 + 30); rect(width / 2 - 50, height / 2 + 60, 100, 50); text("Créditos", width / 2, height / 2 + 90); } function showCredits() { textSize(width * 0.04); textAlign(CENTER); fill(255); text("Juego desarrollado por Ramiro Solá y Tomás Guerrero", width / 2, height / 2); text("Presiona cualquier tecla para volver", width / 2, height / 2 + 30); } function showGameOver() { textSize(width * 0.05); textAlign(CENTER); fill(255, 0, 0); text("Game Over", width / 2, height / 2 - 40); textSize(width * 0.03); text("Presiona Enter para Reintentar", width / 2, height / 2); } function showGameWin() { textSize(width * 0.05); textAlign(CENTER); fill(0, 255, 0); text("You Win!", width / 2, height / 2 - 40); textSize(width * 0.03); text("Presiona Enter para Jugar de Nuevo", width / 2, height / 2); } ```Javascript