User prompt
show how many bullets are left in the bottom right of the screen
User prompt
Make there be a limit of bullets that can be fired before the ship has to reload
User prompt
when a bullet hits the enemies, make a smaller explosion appear where they collided
User prompt
make the hero continue to shoot bullets
User prompt
make the enemies fire their own bullets
User prompt
make the enemies move from side to side while avoiding the asteroids
User prompt
Make the asteroids rotate and move faster
User prompt
when the hero collides with an asteroid, the hero vanishes off the screen
User prompt
Delay the game over trigger so that it appears 3 seconds after the hero dies
User prompt
If the hero collides with an asteroid make an explosion appear where they met
User prompt
move the hero further upwards
User prompt
Increase the speed of the asteroids
User prompt
Make the hero only be able to move from side to side
User prompt
rotate the bullets 45 degrees to the right
User prompt
rotate the enemies 90 degrees to the left
User prompt
rotate the enemies by 45 degrees to the right
User prompt
make the asteroids continuously rotate
User prompt
make the enemies move from left to right in random patterns while slowly moving downwards
User prompt
Please fix the bug: 'ReferenceError: enemyBullets is not defined' in or related to this line: 'for (var m = enemyBullets.length - 1; m >= 0; m--) {' Line Number: 180
User prompt
make the enemies fire bullets at the hero
User prompt
make the enemies fire bullets at the hero
Initial prompt
Up down space shooter game
/****
* 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.direction = Math.random() < 0.5 ? -1 : 1; // Randomly set direction to left (-1) or right (1)
self.update = function () {
self.y += self.speed;
self.x += self.direction * 5; // Move the enemy to the side based on the direction
// If the enemy hits the side of the screen, reverse direction
if (self.x < 0 || self.x > 2048) {
self.direction *= -1;
}
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.update = function () {
// Hero update logic
};
});
/****
* 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;
// 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) {
shootBullet();
};
// 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 {
// Check if the enemy collides with any asteroid
for (var m = asteroids.length - 1; m >= 0; m--) {
if (enemies[j].intersects(asteroids[m])) {
// Destroy the enemy and the asteroid
enemies[j].destroy();
asteroids[m].destroy();
enemies.splice(j, 1);
asteroids.splice(m, 1);
break;
}
}
}
}
// 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])) {
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
@@ -42,10 +42,16 @@
anchorY: 0.5
});
enemyGraphics.rotation = -0.785398; // Rotate by 90 degrees to the left
self.speed = 7;
+ self.direction = Math.random() < 0.5 ? -1 : 1; // Randomly set direction to left (-1) or right (1)
self.update = function () {
self.y += self.speed;
+ self.x += self.direction * 5; // Move the enemy to the side based on the direction
+ // If the enemy hits the side of the screen, reverse direction
+ if (self.x < 0 || self.x > 2048) {
+ self.direction *= -1;
+ }
if (self.y > 2732) {
self.destroy();
}
};
@@ -158,8 +164,20 @@
enemies[j].update();
if (enemies[j].intersects(hero)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
+ } else {
+ // Check if the enemy collides with any asteroid
+ for (var m = asteroids.length - 1; m >= 0; m--) {
+ if (enemies[j].intersects(asteroids[m])) {
+ // Destroy the enemy and the asteroid
+ enemies[j].destroy();
+ asteroids[m].destroy();
+ enemies.splice(j, 1);
+ asteroids.splice(m, 1);
+ break;
+ }
+ }
}
}
// Update bullets
for (var k = bullets.length - 1; k >= 0; k--) {
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.