Code edit (1 edits merged)
Please save this source code
User prompt
game not working
User prompt
Updated Basic Enemy Animation Spawn Animation: The enemy smoothly fades in or scales up upon entering the screen. Downward Movement: Moves straight down at a fixed speed. Side-to-Side Drift: Slightly drifts left and right while descending, making it harder to hit. Destroy on Exit: Gets removed when it moves off-screen. Wave-Based Spawning: A finite number of basic enemy ships spawn per wave. Wave Transition: After all enemies in a wave are destroyed, the next wave starts with a short delay. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
improve
User prompt
Improved Basic Enemy Animation Spawn Animation: The enemy fades in or scales up when entering the screen. Downward Movement: The enemy moves straight down at a fixed speed. Side-to-Side Drift: The enemy drifts slightly left and right while moving down, making it harder to hit. Destroy on Exit: The enemy is removed when off-screen. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
mproved Basic Enemy Animation Spawn Animation: The enemy fades in or scales up when entering the screen. Downward Movement: The enemy moves straight down at a fixed speed. Side-to-Side Drift: The enemy drifts slightly left and right while moving down, making it harder to hit. Destroy on Exit: The enemy is removed when off-screen. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Create a 2D space shooter game where the player pilots a high-tech spacecraft to defend the galaxy from waves of alien invaders and powerful bosses. The game should have classic arcade gameplay with modern visuals, smooth animations, and immersive sound effects. Game Features: Core Gameplay: The player's spaceship automatically shoots while the player controls movement (drag/swipe or joystick). Enemies appear in waves with increasing difficulty. Each level ends with a boss fight, requiring strategy to defeat. Enemy Types: Basic Drones – Weak but attack in numbers. Heavy Fighters – Move slowly but deal high damage. Fast Attackers – Swift movement, difficult to hit. Alien Motherships – Large bosses with unique attack patterns. Upgrades & Power-Ups: Weapon Upgrades – Spread shots, homing missiles, laser beams. Shields – Temporary invincibility. Speed Boosts – Increases maneuverability. Bombs – Destroys all enemies on screen. Graphics & Effects: Neon-style futuristic spaceship designs. Explosions and particle effects for impacts. Dynamic backgrounds with stars, asteroids, and cosmic elements. Game Modes: Endless Mode – Survive as long as possible. Story Mode – Complete missions to unlock new ships and weapons. Boss Rush Mode – Face all bosses in succession. Monetization (Optional): Rewarded ads for extra lives, power-ups. In-app purchases for new ships, skins, and weapons. Sound & Music: Futuristic, intense background music. Laser shooting and explosion sound effects.
Initial prompt
Galactic Defender: Alien Invasion
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Class for enemy ships with wave-based spawning and better animation var EnemyShip = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemyShip', { anchorX: 0.5, anchorY: 0.5 }); // Spawn animation: Fade in & Scale up enemyGraphics.scale.set(0); enemyGraphics.alpha = 0; tween(enemyGraphics.scale, { x: 1, y: 1 }, { duration: 500 }); tween(enemyGraphics, { alpha: 1 }, { duration: 500 }); self.speed = 3 + Math.random() * 2; // Slight variation in speed self.driftAmount = 3; // Side drift range self.driftSpeed = 50 + Math.random() * 20; // Slight variation in drift speed self.update = function () { self.y += self.speed; self.x += Math.sin(LK.ticks / self.driftSpeed) * self.driftAmount; // Destroy if off-screen with fade-out effect if (self.y > 2732 + enemyGraphics.height / 2) { tween(enemyGraphics, { alpha: 0 }, { duration: 500, onFinish: function onFinish() { self.destroy(); enemyShips.splice(enemyShips.indexOf(self), 1); } }); } }; }); // Class for player bullets with proper destruction var PlayerBullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('playerBullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -15; self.update = function () { self.y += self.speed; if (self.y < -bulletGraphics.height) { self.destroy(); playerBullets.splice(playerBullets.indexOf(self), 1); } }; }); // Class for the player's ship with shooting cooldown var PlayerShip = Container.expand(function () { var self = Container.call(this); var shipGraphics = self.attachAsset('playerShip', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.canShoot = true; // Prevents spam shooting self.shootCooldown = 300; // 300ms cooldown self.shoot = function () { if (self.canShoot) { var bullet = new PlayerBullet(); bullet.x = self.x; bullet.y = self.y - shipGraphics.height / 2; game.addChild(bullet); playerBullets.push(bullet); self.canShoot = false; setTimeout(function () { self.canShoot = true; }, self.shootCooldown); } }; self.update = function () { for (var i = 0; i < enemyShips.length; i++) { if (self.intersects(enemyShips[i])) { LK.showGameOver(); } } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ /**** * Game Logic ****/ var playerBullets = []; var enemyShips = []; var player = game.addChild(new PlayerShip()); player.x = 2048 / 2; player.y = 2732 - 200; // Score Display var scoreText = new Text2('0', { size: 150, fill: 0xFFFFFF }); scoreText.anchor.set(0.5, 0); LK.gui.top.addChild(scoreText); // Wave Variables var waveNumber = 1; var enemiesPerWave = 5; var enemiesSpawned = 0; // Function to spawn enemies in waves function spawnEnemy() { if (enemiesSpawned < enemiesPerWave) { var enemy = new EnemyShip(); enemy.x = Math.random() * 2048; enemy.y = -100; game.addChild(enemy); enemyShips.push(enemy); enemiesSpawned++; } else if (enemyShips.length === 0) { // Start next wave when all enemies are destroyed setTimeout(function () { waveNumber++; enemiesPerWave += 2; // Increase difficulty each wave enemiesSpawned = 0; }, 1000); } } // Game update loop game.update = function () { // Update player bullets for (var i = playerBullets.length - 1; i >= 0; i--) { playerBullets[i].update(); } // Update enemy ships for (var j = enemyShips.length - 1; j >= 0; j--) { enemyShips[j].update(); } // Check for collisions between player bullets and enemy ships for (var k = playerBullets.length - 1; k >= 0; k--) { for (var l = enemyShips.length - 1; l >= 0; l--) { if (playerBullets[k] && enemyShips[l] && playerBullets[k].intersects(enemyShips[l])) { tween(enemyShips[l], { alpha: 0 }, { duration: 300, onFinish: function onFinish() { enemyShips[l].destroy(); enemyShips.splice(l, 1); } }); playerBullets[k].destroy(); playerBullets.splice(k, 1); // Update score LK.setScore(LK.getScore() + 1); scoreText.setText(LK.getScore()); break; } } } // Spawn enemies periodically if (LK.ticks % 60 === 0) { spawnEnemy(); } }; // Handle player movement game.move = function (x, y, obj) { player.x = x; }; // Handle shooting game.down = function (x, y, obj) { player.shoot(); };
===================================================================
--- original.js
+++ change.js
@@ -5,30 +5,37 @@
/****
* Classes
****/
-// Class for enemy ships
+// Class for enemy ships with wave-based spawning and better animation
var EnemyShip = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemyShip', {
anchorX: 0.5,
anchorY: 0.5
});
- // Spawn animation: scale up from 0 to 1
+ // Spawn animation: Fade in & Scale up
enemyGraphics.scale.set(0);
+ enemyGraphics.alpha = 0;
tween(enemyGraphics.scale, {
x: 1,
y: 1
}, {
duration: 500
});
- self.speed = 5;
+ tween(enemyGraphics, {
+ alpha: 1
+ }, {
+ duration: 500
+ });
+ self.speed = 3 + Math.random() * 2; // Slight variation in speed
+ self.driftAmount = 3; // Side drift range
+ self.driftSpeed = 50 + Math.random() * 20; // Slight variation in drift speed
self.update = function () {
self.y += self.speed;
- // Side-to-side drift: move left and right while moving down
- self.x += Math.sin(LK.ticks / 30) * 2;
+ self.x += Math.sin(LK.ticks / self.driftSpeed) * self.driftAmount;
+ // Destroy if off-screen with fade-out effect
if (self.y > 2732 + enemyGraphics.height / 2) {
- // Destroy animation: fade out before destroying
tween(enemyGraphics, {
alpha: 0
}, {
duration: 500,
@@ -39,9 +46,9 @@
});
}
};
});
-// Class for player bullets
+// Class for player bullets with proper destruction
var PlayerBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('playerBullet', {
anchorX: 0.5,
@@ -55,29 +62,34 @@
playerBullets.splice(playerBullets.indexOf(self), 1);
}
};
});
-//<Assets used in the game will automatically appear here>
-// Class for the player's ship
+// Class for the player's ship with shooting cooldown
var PlayerShip = Container.expand(function () {
var self = Container.call(this);
var shipGraphics = self.attachAsset('playerShip', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
+ self.canShoot = true; // Prevents spam shooting
+ self.shootCooldown = 300; // 300ms cooldown
self.shoot = function () {
- var bullet = new PlayerBullet();
- bullet.x = self.x;
- bullet.y = self.y - shipGraphics.height / 2;
- game.addChild(bullet);
- playerBullets.push(bullet);
+ if (self.canShoot) {
+ var bullet = new PlayerBullet();
+ bullet.x = self.x;
+ bullet.y = self.y - shipGraphics.height / 2;
+ game.addChild(bullet);
+ playerBullets.push(bullet);
+ self.canShoot = false;
+ setTimeout(function () {
+ self.canShoot = true;
+ }, self.shootCooldown);
+ }
};
self.update = function () {
- // Check if the player's ship intersects with any enemy ship
for (var i = 0; i < enemyShips.length; i++) {
if (self.intersects(enemyShips[i])) {
- // If the player's ship intersects with an enemy ship, end the game
LK.showGameOver();
}
}
};
@@ -86,36 +98,50 @@
/****
* Initialize Game
****/
var game = new LK.Game({
- backgroundColor: 0x000000 //Init game with black background
+ backgroundColor: 0x000000
});
/****
* Game Code
****/
-//<Assets used in the game will automatically appear here>
-// Arrays to keep track of game objects
+/****
+* Game Logic
+****/
var playerBullets = [];
var enemyShips = [];
-// Create player ship
var player = game.addChild(new PlayerShip());
player.x = 2048 / 2;
player.y = 2732 - 200;
-// Create a score display
+// Score Display
var scoreText = new Text2('0', {
size: 150,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
-// Function to spawn enemies
+// Wave Variables
+var waveNumber = 1;
+var enemiesPerWave = 5;
+var enemiesSpawned = 0;
+// Function to spawn enemies in waves
function spawnEnemy() {
- var enemy = new EnemyShip();
- enemy.x = Math.random() * 2048;
- enemy.y = -100;
- game.addChild(enemy);
- enemyShips.push(enemy);
+ if (enemiesSpawned < enemiesPerWave) {
+ var enemy = new EnemyShip();
+ enemy.x = Math.random() * 2048;
+ enemy.y = -100;
+ game.addChild(enemy);
+ enemyShips.push(enemy);
+ enemiesSpawned++;
+ } else if (enemyShips.length === 0) {
+ // Start next wave when all enemies are destroyed
+ setTimeout(function () {
+ waveNumber++;
+ enemiesPerWave += 2; // Increase difficulty each wave
+ enemiesSpawned = 0;
+ }, 1000);
+ }
}
// Game update loop
game.update = function () {
// Update player bullets
@@ -128,14 +154,21 @@
}
// Check for collisions between player bullets and enemy ships
for (var k = playerBullets.length - 1; k >= 0; k--) {
for (var l = enemyShips.length - 1; l >= 0; l--) {
- if (playerBullets[k].intersects(enemyShips[l])) {
+ if (playerBullets[k] && enemyShips[l] && playerBullets[k].intersects(enemyShips[l])) {
+ tween(enemyShips[l], {
+ alpha: 0
+ }, {
+ duration: 300,
+ onFinish: function onFinish() {
+ enemyShips[l].destroy();
+ enemyShips.splice(l, 1);
+ }
+ });
playerBullets[k].destroy();
- enemyShips[l].destroy();
playerBullets.splice(k, 1);
- enemyShips.splice(l, 1);
- // Update the score
+ // Update score
LK.setScore(LK.getScore() + 1);
scoreText.setText(LK.getScore());
break;
}
@@ -145,9 +178,9 @@
if (LK.ticks % 60 === 0) {
spawnEnemy();
}
};
-// Handle player ship movement
+// Handle player movement
game.move = function (x, y, obj) {
player.x = x;
};
// Handle shooting
A 2D top-down view of a futuristic player spaceship with a streamlined silver and blue body, glowing thrusters, and dual laser cannons. The design is sleek and modern for a space shooter game. Single Game Texture. 2d. Blank background. High contrast. No shadows
A 2D top-down view of an alien spaceship with a dark metallic body, glowing red energy cores, and sharp angular wings. The design is sleek and futuristic, suitable for a space shooter game.. Single Game Texture. 2d. Blank background. High contrast. No shadows
A 2D top-down view of a futuristic energy bullet for a space shooter game. The bullet is a glowing blue plasma projectile with a sleek, elongated shape and a slight energy trail behind it. The design is simple, bright, and high-speed-looking, suitable for fast-paced shooting gameplay. Single Game Texture. In-Game asset. Blank background. High contrast. No shadows
A 2D top-down view of a futuristic energy bullet for a space shooter game. The bullet is a glowing red plasma projectile elongated shape and a slight energy trail behind it. The design is simple, bright, and high-speed-looking, suitable for fast-paced shooting gameplay. Single Game Texture. In-Game asset. Blank background. High contrast. No shadows
A vibrant and dynamic 2D space background for a top-down space shooter game. The scene features a deep, dark space filled with glowing nebulae in shades of blue and purple, scattered distant stars, and swirling cosmic dust. A subtle parallax effect is suggested with faintly glowing planets and asteroids in the background. The atmosphere is slightly mysterious and futuristic, with soft light gradients to create depth. The overall tone is immersive but does not distract from gameplay, ensuring clear visibility of player and enemy ships.. Single Game Texture. Blank background. High contrast. No shadows
A vibrant and dynamic 2D space background for a top-down space shooter game. The scene features a deep, dark space filled with glowing nebulae in shades of blue and purple, scattered distant stars, and swirling cosmic dust. A subtle parallax effect is suggested with faintly glowing planets and asteroids in the background. The atmosphere is slightly mysterious and futuristic, with soft light gradients to create depth. The overall tone is immersive but does not distract from gameplay, ensuring clear visibility of player and enemy ships.. Single Game Texture. Blank background. High contrast. No shadows
powerup boll. Single Game Texture. Blank background. High contrast. No shadows