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 = 3;
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));
reloadTxt.visible = false; // Hide the reload sign
} else if (self.reloadCounter > 0) {
reloadTxt.visible = true; // Show the reload sign
}
}
};
});
// Star class
var Star = Container.expand(function () {
var self = Container.call(this);
var starGraphics = self.attachAsset('star', {
anchorX: 0.5,
anchorY: 0.5
});
// Set a random brightness for each star
starGraphics.alpha = Math.random();
self.speed = 5;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
/****
* 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);
// Create a Text2 object to display the score at the top of the screen
var scoreTxt = new Text2('Score: 0', {
size: 100,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0); // Anchor to the top center
LK.gui.top.addChild(scoreTxt);
// Create a Text2 object to display the reload sign
var reloadTxt = new Text2('RELOADING...', {
size: 100,
fill: "#ff0000"
});
reloadTxt.anchor.set(0.5, 0.5); // Anchor to the center
reloadTxt.visible = false; // Initially hidden
LK.gui.center.addChild(reloadTxt);
// Create a Text2 object to display the wave introduction sign
var waveIntroTxt = new Text2('Wave 1', {
size: 100,
fill: "#ffffff"
});
waveIntroTxt.anchor.set(0.5, 0.5); // Anchor to the center
waveIntroTxt.visible = false; // Initially hidden
LK.gui.center.addChild(waveIntroTxt);
// Initialize arrays for asteroids, enemies, bullets and stars
var asteroids = [];
var enemies = [];
var bullets = [];
var stars = [];
// Initialize a variable to keep track of the number of enemies in the current wave
var enemiesInWave = 1;
// Function to spawn stars
function spawnStar() {
var star = new Star();
star.x = Math.random() * 2048;
star.y = -50;
stars.push(star);
game.addChild(star);
}
// 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() {
// Only spawn a new wave of enemies if all enemies from the previous wave have been destroyed
if (enemies.length == 0) {
waveIntroTxt.setText('Wave ' + enemiesInWave); // Update the wave number
waveIntroTxt.visible = true; // Show the wave introduction sign
LK.setTimeout(function () {
waveIntroTxt.visible = false; // Hide the wave introduction sign after 2 seconds
for (var i = 0; i < enemiesInWave + 1; i++) {
var enemy = new Enemy();
enemy.x = Math.random() * 2048;
enemy.y = -50 - Math.random() * 500; // Randomize the y position within a range of 500 pixels
enemies.push(enemy);
game.addChild(enemy);
}
if (enemies.length == 0) {
enemiesInWave++;
}
}, 2000); // Wait for 2 seconds before the wave begins
}
}
// 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);
// Decrease the number of enemies in the current wave
enemiesInWave--;
// Increase the score and update the score text
LK.setScore(LK.getScore() + 1);
scoreTxt.setText('Score: ' + LK.getScore());
break;
}
}
}
// Update stars
for (var m = stars.length - 1; m >= 0; m--) {
stars[m].update();
if (stars[m].y > 2732) {
stars[m].destroy();
stars.splice(m, 1);
}
}
// Spawn asteroids, enemies and stars periodically
if (LK.ticks % 60 == 0) {
spawnAsteroid();
}
if (LK.ticks % 120 == 0) {
spawnEnemy();
}
if (LK.ticks % 10 == 0) {
spawnStar();
}
}; ===================================================================
--- original.js
+++ change.js
@@ -166,9 +166,9 @@
var enemies = [];
var bullets = [];
var stars = [];
// Initialize a variable to keep track of the number of enemies in the current wave
-var enemiesInWave = 0;
+var enemiesInWave = 1;
// Function to spawn stars
function spawnStar() {
var star = new Star();
star.x = Math.random() * 2048;
@@ -210,9 +210,11 @@
enemy.y = -50 - Math.random() * 500; // Randomize the y position within a range of 500 pixels
enemies.push(enemy);
game.addChild(enemy);
}
- enemiesInWave++;
+ if (enemies.length == 0) {
+ enemiesInWave++;
+ }
}, 2000); // Wait for 2 seconds before the wave begins
}
}
// Handle game move event
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.