From 7db2ef47e9b44dde18bd28612ca09e61f5bba3dc Mon Sep 17 00:00:00 2001 From: Emanuel Quintino <emanuelquintino@hotmail.com> Date: Mon, 9 Dec 2024 21:20:35 -0300 Subject: [PATCH] remove redundant code --- scripts/game.js | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/scripts/game.js b/scripts/game.js index 93dae12..ea46a0d 100644 --- a/scripts/game.js +++ b/scripts/game.js @@ -141,10 +141,7 @@ class EnemySpaceship { this.baseX; this.element.style.transform = `translate3d(${this.x}px, ${this.y}px, 0)`; - if ( - this.y - this.offScreenTopElementDiscount > spaceContainerHeight || - this.life <= 0 - ) { + if (this.y - this.offScreenTopElementDiscount > spaceContainerHeight) { this.element.remove(); } } @@ -236,22 +233,22 @@ function collisionEnemiesShot() { if (enemy.element.className == "chargeSpecialShot") return; - shootsDOM.forEach((shotDOM) => { - const shotRect = shotDOM.getBoundingClientRect(); + shootsDOM.forEach((shootDOM) => { + const shootRect = shootDOM.getBoundingClientRect(); const enemyRect = enemyDOM.getBoundingClientRect(); let discountCollision = enemy.enemyNumber == 3 ? 40 : 10; if ( - enemyRect.left < shotRect.right && - enemyRect.right > shotRect.left && - enemyRect.top + discountCollision < shotRect.bottom && - enemyRect.bottom - discountCollision > shotRect.top + enemyRect.left < shootRect.right && + enemyRect.right > shootRect.left && + enemyRect.top + discountCollision < shootRect.bottom && + enemyRect.bottom - discountCollision > shootRect.top ) { - shotDOM.remove(); + shootDOM.remove(); enemy.life -= Math.ceil(shootPower * (Math.random() + 1)); // ex: shootPower * 1.2 - setPlayerScore(specialShotIsActive ? 20 : 10); + if (enemy.life <= 0) { enemy.destroyEnemySpaceship(); setPlayerScore(enemy.points); @@ -297,12 +294,7 @@ function collisionEnemiesWithSpaceship() { shootPower = 25; }, timeToEndSpecialShot); } else { - const explosionSound = new Audio("../audios/explosion1.mp3"); - explosionSound.volume = explosionSoundVolume; - explosionSound.play(); - enemy.destroyEnemySpaceship(); - setPlayerDamage(enemy.damage); } }