even better

This commit is contained in:
Eric Ratliff
2025-06-25 22:55:16 -05:00
parent 95adad39f0
commit 681feab148

View File

@@ -5,7 +5,7 @@ let hamburgers = [];
let bullets = []; let bullets = [];
let shieldOrb = null; let shieldOrb = null;
let greenOrb = null; let greenOrb = null;
let lives = 3; let lives = 100;
let score = 0; let score = 0;
let gameOver = false; let gameOver = false;
let lastShieldSpawn = 0; let lastShieldSpawn = 0;
@@ -27,11 +27,16 @@ function setup() {
function spawnObjects(numObjects) { function spawnObjects(numObjects) {
for (let i = 0; i < numObjects; i++) { for (let i = 0; i < numObjects; i++) {
if (random() < 0.15) { let rand = random();
if (rand < 0.25) {
pizzas.push(new Pizza()); pizzas.push(new Pizza());
console.log(`Spawned pizza at level ${level}, total pizzas: ${pizzas.length}`); console.log(`Spawned pizza at level ${level}, total pizzas: ${pizzas.length}`);
} else if (rand < 0.25) {
asteroids.push(new Asteroid(null, null, true)); // Golden asteroid
console.log(`Spawned golden asteroid at level ${level}, total asteroids: ${asteroids.length}`);
} else { } else {
asteroids.push(new Asteroid()); asteroids.push(new Asteroid(null, null, false)); // White asteroid
console.log(`Spawned white asteroid at level ${level}, total asteroids: ${asteroids.length}`);
} }
} }
} }
@@ -55,14 +60,14 @@ function draw() {
text("Score: " + score, 50, 60); text("Score: " + score, 50, 60);
text("Level: " + level, 50, 90); text("Level: " + level, 50, 90);
// Handle continuous key input (WASD) // Handle continuous key input (WASD and Arrow Keys)
if (keyIsDown(65)) { // A key if (keyIsDown(65) || keyIsDown(LEFT_ARROW)) { // A or Left Arrow
ship.setRotation(-0.1); ship.setRotation(-0.1);
} }
if (keyIsDown(68)) { // D key if (keyIsDown(68) || keyIsDown(RIGHT_ARROW)) { // D or Right Arrow
ship.setRotation(0.1); ship.setRotation(0.1);
} }
if (keyIsDown(87)) { // W key if (keyIsDown(87) || keyIsDown(UP_ARROW)) { // W or Up Arrow
ship.boosting(true); ship.boosting(true);
} else { } else {
ship.boosting(false); ship.boosting(false);
@@ -232,7 +237,7 @@ function keyPressed() {
} }
} }
if (keyCode === 82 && gameOver) { // R to restart if (keyCode === 82 && gameOver) { // R to restart
lives = 3; lives = 100;
score = 0; score = 0;
level = 1; level = 1;
initialObjects = 5; initialObjects = 5;
@@ -251,10 +256,10 @@ function keyPressed() {
} }
function keyReleased() { function keyReleased() {
if (keyCode === 65 || keyCode === 68) { // A or D key if (keyCode === 65 || keyCode === 68 || keyCode === LEFT_ARROW || keyCode === RIGHT_ARROW) { // A, D, Left, Right
ship.setRotation(0); ship.setRotation(0);
} }
if (keyCode === 87) { // W key if (keyCode === 87 || keyCode === UP_ARROW) { // W or Up Arrow
ship.boosting(false); ship.boosting(false);
} }
} }