game const
This commit is contained in:
parent
51ad741744
commit
3a62d19979
1 changed files with 12 additions and 6 deletions
|
@ -26,14 +26,22 @@ function initializeGame() {
|
||||||
let highScore = localStorage.getItem("highScore") ? parseInt(localStorage.getItem("highScore")) : 0;
|
let highScore = localStorage.getItem("highScore") ? parseInt(localStorage.getItem("highScore")) : 0;
|
||||||
updateHighScore();
|
updateHighScore();
|
||||||
|
|
||||||
|
const BASE_PDF_SPEED = 1;
|
||||||
|
const LEVEL_INCREASE_PDF_SPEED = 0.2;
|
||||||
|
const BASE_SPAWN_INTERVAL_MS = 1250; // milliseconds before a new enemy spawns
|
||||||
|
const LEVEL_INCREASE_FACTOR_MS = 25; // milliseconds to decrease the spawn interval per level
|
||||||
|
const MAX_SPAWN_RATE_REDUCTION_MS = 800; // Max milliseconds from the base spawn interval
|
||||||
|
|
||||||
|
|
||||||
const keysPressed = {};
|
const keysPressed = {};
|
||||||
const pdfs = [];
|
const pdfs = [];
|
||||||
const projectiles = [];
|
const projectiles = [];
|
||||||
let score = 0;
|
let score = 0;
|
||||||
let level = 1;
|
let level = 1;
|
||||||
let pdfSpeed = 0.5;
|
let pdfSpeed = BASE_PDF_SPEED;
|
||||||
let gameOver = false;
|
let gameOver = false;
|
||||||
|
|
||||||
|
|
||||||
function handleKeys() {
|
function handleKeys() {
|
||||||
if (keysPressed["ArrowLeft"]) {
|
if (keysPressed["ArrowLeft"]) {
|
||||||
playerX -= 10;
|
playerX -= 10;
|
||||||
|
@ -188,7 +196,7 @@ function initializeGame() {
|
||||||
updateScore();
|
updateScore();
|
||||||
updateLives();
|
updateLives();
|
||||||
levelElement.textContent = "Level: " + level;
|
levelElement.textContent = "Level: " + level;
|
||||||
pdfSpeed = 1;
|
pdfSpeed = BASE_PDF_SPEED;
|
||||||
clearTimeout(spawnPdfTimeout); // Clear the existing spawnPdfTimeout
|
clearTimeout(spawnPdfTimeout); // Clear the existing spawnPdfTimeout
|
||||||
setTimeout(updateGame, 1000 / 60);
|
setTimeout(updateGame, 1000 / 60);
|
||||||
spawnPdfInterval();
|
spawnPdfInterval();
|
||||||
|
@ -204,7 +212,7 @@ function initializeGame() {
|
||||||
if (newLevel > level) {
|
if (newLevel > level) {
|
||||||
level = newLevel;
|
level = newLevel;
|
||||||
levelElement.textContent = "Level: " + level;
|
levelElement.textContent = "Level: " + level;
|
||||||
pdfSpeed += 0.2;
|
pdfSpeed += LEVEL_INCREASE_PDF_SPEED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,9 +235,7 @@ function initializeGame() {
|
||||||
|
|
||||||
let spawnPdfTimeout;
|
let spawnPdfTimeout;
|
||||||
|
|
||||||
const BASE_SPAWN_INTERVAL_MS = 1250; // milliseconds before a new enemy spawns
|
|
||||||
const LEVEL_INCREASE_FACTOR_MS = 0; // milliseconds to decrease the spawn interval per level
|
|
||||||
const MAX_SPAWN_RATE_REDUCTION_MS = 800; // Max milliseconds from the base spawn interval
|
|
||||||
|
|
||||||
function spawnPdfInterval() {
|
function spawnPdfInterval() {
|
||||||
console.log("spawnPdfInterval");
|
console.log("spawnPdfInterval");
|
||||||
|
|
Loading…
Reference in a new issue