User prompt
When the score hits 50, remove all the asteroids and enemies and spawn a boss
User prompt
If any of the enemies reaches the bottom of the screen, the game over appears
User prompt
make the stars move faster
User prompt
Make the hero move slower
Code edit (1 edits merged)
Please save this source code
User prompt
make the hero have a limited maximum spee
User prompt
remove the wave introduction text
User prompt
make more asteroids
User prompt
make the bullets move much faster
User prompt
make the stars move faster
User prompt
make the stars move aster
User prompt
the wave number should always increase by 1
User prompt
add more stars in the background
User prompt
before each wave, introduce with text which wave number it i
Code edit (1 edits merged)
Please save this source code
User prompt
the enemies should move around more
User prompt
make the enemies move in random directions from left to right while avoiding each other and the asteroids
User prompt
Each wave should be introduced as one more than the wave before
User prompt
The wave number should increase by one after each wave
User prompt
The same number of enemies as the wave number, should appear after the wave is introduced. The next wave should only be introduced and appear when all the enemies in the wave before have been destroyed
User prompt
The enemies in the wave should appear after the wave is introduced
User prompt
The first wave is wave 1, the second wave is wave 2, the third wave is wave 3 and continues as such
User prompt
The first wave is always 'wave 1'
Code edit (1 edits merged)
Please save this source code
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
/****
* 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();
}
};
});
// Boss class
var Boss = Container.expand(function () {
var self = Container.call(this);
var bossGraphics = self.attachAsset('boss', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2;
self.update = function () {
self.y += self.speed;
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 = -30;
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.horizontalSpeed = Math.random() * 4 - 2; // Random speed between -2 and 2
self.update = function () {
self.y += self.speed;
self.x += self.horizontalSpeed;
if (self.x < 0) {
self.x = 0;
self.horizontalSpeed = Math.random() * 4 - 2; // Random speed between -2 and 2
} else if (self.x > 2048) {
self.x = 2048;
self.horizontalSpeed = Math.random() * 4 - 2; // Random speed between -2 and 2
}
if (self.y > 2732) {
self.destroy();
}
for (var i = 0; i < enemies.length; i++) {
if (enemies[i] != self && enemies[i].intersects(self)) {
self.horizontalSpeed = -self.horizontalSpeed;
break;
}
}
for (var i = 0; i < asteroids.length; i++) {
if (asteroids[i].intersects(self)) {
self.horizontalSpeed = -self.horizontalSpeed;
break;
}
}
};
});
// 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 = 3;
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 = 30;
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);
// 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 = 0;
// 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 (enemiesInWave == 0) {
for (var i = 0; i < 3; i++) {
var enemy = new Enemy();
enemy.x = Math.random() * 2048;
enemy.y = -50;
enemies.push(enemy);
game.addChild(enemy);
}
enemiesInWave = 3;
}
}
// 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();
} else if (enemies[j].y >= 2732) {
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());
// Check if the score has hit 50
if (LK.getScore() == 50) {
// Remove all the asteroids and enemies
for (var i = asteroids.length - 1; i >= 0; i--) {
asteroids[i].destroy();
asteroids.splice(i, 1);
}
for (var i = enemies.length - 1; i >= 0; i--) {
enemies[i].destroy();
enemies.splice(i, 1);
}
// Spawn a boss
var boss = new Boss();
boss.x = 2048 / 2;
boss.y = -50;
game.addChild(boss);
}
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 % 30 == 0) {
spawnAsteroid();
}
if (LK.ticks % 120 == 0) {
spawnEnemy();
}
if (LK.ticks % 5 == 0) {
spawnStar();
}
}; ===================================================================
--- original.js
+++ change.js
@@ -17,8 +17,23 @@
self.destroy();
}
};
});
+// Boss class
+var Boss = Container.expand(function () {
+ var self = Container.call(this);
+ var bossGraphics = self.attachAsset('boss', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 2;
+ self.update = function () {
+ self.y += self.speed;
+ if (self.y > 2732) {
+ self.destroy();
+ }
+ };
+});
// Bullet class
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
@@ -284,8 +299,25 @@
enemiesInWave--;
// Increase the score and update the score text
LK.setScore(LK.getScore() + 1);
scoreTxt.setText('Score: ' + LK.getScore());
+ // Check if the score has hit 50
+ if (LK.getScore() == 50) {
+ // Remove all the asteroids and enemies
+ for (var i = asteroids.length - 1; i >= 0; i--) {
+ asteroids[i].destroy();
+ asteroids.splice(i, 1);
+ }
+ for (var i = enemies.length - 1; i >= 0; i--) {
+ enemies[i].destroy();
+ enemies.splice(i, 1);
+ }
+ // Spawn a boss
+ var boss = new Boss();
+ boss.x = 2048 / 2;
+ boss.y = -50;
+ game.addChild(boss);
+ }
break;
}
}
}
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.