User prompt
The wave number appearing on the screen should start at one and increase by one after every enemy in the new wave has been destroyed
User prompt
After each wave, the wave number should increase by one
User prompt
The wave after, should have only one more enemy than the wave before dd
User prompt
The wave number should only increase by one after each wave
User prompt
Only 4 enemies should appear in each wave, no more
Code edit (1 edits merged)
Please save this source code
User prompt
The next wave should only appear after all of the enemies in the first wave are destroyed and the new wave is introduced
User prompt
The enemies in the wave shouldn't be next to each other in a perfect line
User prompt
Make a sign in the middle introduce the wave before each wave begins
User prompt
Make all 5 enemies appear in the wave
User prompt
All of the enemies in the wave should appear within 5 seconds of the wave starting
User prompt
The enemies shouldn't be in a line next to each other, instead make them appear at different times and places at the top of the screenn
User prompt
Make the enemies move more slowly
User prompt
Make the enemies enter from the top of the screen rather than appearing in the middle when the game begins
User prompt
Make each enemy in a wave appear in a random place
User prompt
Make the enemies appear in waves of 5 and only make the next wave appear once all of the enemies in the wave before are destroyed
User prompt
Make the stars vary in brightness to make them more realistic
User prompt
Make stars appear in the background which are moving to create an illusion that the space ship is moving
User prompt
Increase the size of the score count at the top of the screenn
User prompt
Make a score appear at the top of the screen which increases every time an enemy is destroyed
User prompt
Show a reload sign in the middle of the screen when the spacshipp has to reload
User prompt
In the bottom right corner of the screen, show how many bullets the spaceship has left before it needs to reload
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot set properties of undefined (setting 'update')' in or related to this line: 'self.update = function () {' Line Number: 110
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot set properties of undefined (setting 'update')' in or related to this line: 'self.update = function () {' Line Number: 110
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot set properties of undefined (setting 'update')' in or related to this line: 'self.update = function () {' Line Number: 113
/**** * Classes ****/ // Asteroid class var Asteroid = Container.expand(function () { var self = Container.call(this); var asteroidGraphics = self.attachAsset('asteroid', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 15; self.rotationSpeed = 0.02; self.update = function () { self.y += self.speed; self.rotation += self.rotationSpeed; if (self.y > 2732) { self.destroy(); } }; }); // Bullet class var Bullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5, rotation: 0.785398 // Rotate by 45 degrees to the right }); self.speed = -15; self.update = function () { self.y += self.speed; if (self.y < 0) { self.destroy(); } }; }); // Enemy class var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); enemyGraphics.rotation = -0.785398; // Rotate by 90 degrees to the left self.speed = 7; self.update = function () { self.y += self.speed; if (self.y > 2732) { self.destroy(); } }; }); // Explosion class var Explosion = Container.expand(function () { var self = Container.call(this); var explosionGraphics = self.attachAsset('explosion', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Reduce the size of the explosion over time self.scale.x -= 0.01; self.scale.y -= 0.01; // Once the explosion has disappeared, destroy it if (self.scale.x <= 0 || self.scale.y <= 0) { self.destroy(); } }; }); //<Assets used in the game will automatically appear here> // Hero class var Hero = Container.expand(function () { var self = Container.call(this); var heroGraphics = self.attachAsset('hero', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.bulletLimit = 10; // Limit of bullets that can be fired before reloading self.bulletsFired = 0; // Number of bullets fired since last reload self.reloadTime = 180; // Time to reload in ticks (3 seconds) self.reloadCounter = 0; // Counter for reload time self.canShoot = true; // Whether the hero can shoot or not self.update = function () { // If the hero has fired the maximum number of bullets, start the reload counter if (self.bulletsFired >= self.bulletLimit) { self.canShoot = false; self.reloadCounter++; // If the reload time has passed, reset the counter and the number of bullets fired if (self.reloadCounter >= self.reloadTime) { self.bulletsFired = 0; self.reloadCounter = 0; self.canShoot = true; bulletCountTxt.setText('Bullets: ' + (self.bulletLimit - self.bulletsFired)); } } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize hero var hero = game.addChild(new Hero()); hero.x = 2048 / 2; hero.y = 2732 - 400; // Create a Text2 object to display the number of bullets left before reloading var bulletCountTxt = new Text2('Bullets: ' + (hero.bulletLimit - hero.bulletsFired), { size: 50, fill: "#ffffff" }); bulletCountTxt.anchor.set(1, 1); // Anchor to the bottom right corner LK.gui.bottomRight.addChild(bulletCountTxt); // Initialize arrays for asteroids, enemies, and bullets var asteroids = []; var enemies = []; var bullets = []; // Function to handle hero movement function handleMove(x, y, obj) { hero.x = x; } // Function to shoot bullets function shootBullet() { var bullet = new Bullet(); bullet.x = hero.x; bullet.y = hero.y - 50; bullets.push(bullet); game.addChild(bullet); } // Function to spawn asteroids function spawnAsteroid() { var asteroid = new Asteroid(); asteroid.x = Math.random() * 2048; asteroid.y = -50; asteroids.push(asteroid); game.addChild(asteroid); } // Function to spawn enemies function spawnEnemy() { var enemy = new Enemy(); enemy.x = Math.random() * 2048; enemy.y = -50; enemies.push(enemy); game.addChild(enemy); } // Handle game move event game.move = handleMove; // Handle game down event to shoot bullets game.down = function (x, y, obj) { if (hero.canShoot) { shootBullet(); hero.bulletsFired++; bulletCountTxt.setText('Bullets: ' + (hero.bulletLimit - hero.bulletsFired)); } }; // Update game logic game.update = function () { // Update asteroids for (var i = asteroids.length - 1; i >= 0; i--) { asteroids[i].update(); if (asteroids[i].intersects(hero)) { LK.effects.flashScreen(0xff0000, 1000); // Create an explosion at the point of collision var explosion = new Explosion(); explosion.x = hero.x; explosion.y = hero.y; game.addChild(explosion); // Make the hero vanish off the screen hero.x = -1000; hero.y = -1000; LK.setTimeout(function () { LK.showGameOver(); }, 3000); } } // Update enemies for (var j = enemies.length - 1; j >= 0; j--) { enemies[j].update(); if (enemies[j].intersects(hero)) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } } // Update bullets for (var k = bullets.length - 1; k >= 0; k--) { bullets[k].update(); for (var l = enemies.length - 1; l >= 0; l--) { if (bullets[k].intersects(enemies[l])) { // Create a smaller explosion at the point of collision var smallExplosion = new Explosion(); smallExplosion.x = bullets[k].x; smallExplosion.y = bullets[k].y; smallExplosion.scale.x = 0.5; smallExplosion.scale.y = 0.5; game.addChild(smallExplosion); bullets[k].destroy(); enemies[l].destroy(); bullets.splice(k, 1); enemies.splice(l, 1); break; } } } // Spawn asteroids and enemies periodically if (LK.ticks % 60 == 0) { spawnAsteroid(); } if (LK.ticks % 120 == 0) { spawnEnemy(); } };
===================================================================
--- original.js
+++ change.js
@@ -90,21 +90,13 @@
if (self.reloadCounter >= self.reloadTime) {
self.bulletsFired = 0;
self.reloadCounter = 0;
self.canShoot = true;
+ bulletCountTxt.setText('Bullets: ' + (self.bulletLimit - self.bulletsFired));
}
}
};
});
-// Bullet Counter class
-var BulletCounter = Text2.expand(function (text, style) {
- var self = Text2.call(this, text, style);
- self.update = function () {
- if (hero) {
- self.setText('Bullets: ' + (hero.bulletLimit - hero.bulletsFired));
- }
- };
-});
/****
* Initialize Game
****/
@@ -118,11 +110,15 @@
// Initialize hero
var hero = game.addChild(new Hero());
hero.x = 2048 / 2;
hero.y = 2732 - 400;
-// Initialize bullet counter
-var bulletCounter = new BulletCounter();
-LK.gui.bottomRight.addChild(bulletCounter);
+// Create a Text2 object to display the number of bullets left before reloading
+var bulletCountTxt = new Text2('Bullets: ' + (hero.bulletLimit - hero.bulletsFired), {
+ size: 50,
+ fill: "#ffffff"
+});
+bulletCountTxt.anchor.set(1, 1); // Anchor to the bottom right corner
+LK.gui.bottomRight.addChild(bulletCountTxt);
// Initialize arrays for asteroids, enemies, and bullets
var asteroids = [];
var enemies = [];
var bullets = [];
@@ -160,8 +156,9 @@
game.down = function (x, y, obj) {
if (hero.canShoot) {
shootBullet();
hero.bulletsFired++;
+ bulletCountTxt.setText('Bullets: ' + (hero.bulletLimit - hero.bulletsFired));
}
};
// Update game logic
game.update = function () {
@@ -210,10 +207,8 @@
break;
}
}
}
- // Update bullet counter
- bulletCounter.update();
// Spawn asteroids and enemies periodically
if (LK.ticks % 60 == 0) {
spawnAsteroid();
}
asteroid. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Single enemy spaceship flying straight downwards viewed from above in colour. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Single futuristic spaceship flying straight upwards viewed from above in colour without any background. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Single space torpedo flying upwards in colour. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
explosion in colour. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
large enemy space ship with massive cannons flying downwards viewed from on top in colour. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.