Skip to content

Commit

Permalink
remove redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
EmanuelQuintino committed Dec 10, 2024
1 parent e31d9c2 commit 7db2ef4
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions scripts/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 7db2ef4

Please sign in to comment.