Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Alien.js #415

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
20 changes: 17 additions & 3 deletions Alien.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const highScoreElement = document.getElementById("highScoreValue");
let currentScore = 0;
let highScore = localStorage.getItem('highScore') ? parseInt(localStorage.getItem('highScore')) : 0;


// Display the initial high score
highScoreElement.textContent = highScore;
let aliensDestroyed = 0; // Track how many aliens have been destroyed
Expand Down Expand Up @@ -107,7 +108,7 @@ let score = 0;
let lives = 3;
let gameActive = false;
let keys = {};
let shootingInterval = null;
let shootingInterval = 2;
let gamePaused = false;
let previousGameState = null;
let level=1;
Expand Down Expand Up @@ -496,7 +497,7 @@ class Bullet {
this.height = 15;
this.x = x;
this.y = y;
this.speed = 7;
this.speed = 5;
}

draw() {
Expand Down Expand Up @@ -907,7 +908,20 @@ function updatePauseButton() {
pauseButton.style.display = 'none';
}
}

function shootBullet() {
if (!shootingTimeout) {
bullets.push(new Bullet(player.x + player.width / 2, player.y)); // Adjust bullet's starting position
shootingTimeout = setInterval(() => {
bullets.push(new Bullet(player.x + player.width / 2, player.y));
}, shootingInterval);
}
}
document.addEventListener("keyup", function(event) {
if (event.code === "Space") {
clearInterval(shootingTimeout);
shootingTimeout = null; // Reset the shooting timeout
}
});
function restoreGameState(e) {
if (previousGameState) {
score = previousGameState.score;
Expand Down