User prompt
Play enemyshoot when enemy shoots
User prompt
Use laser.mp3 sound at hero shooting
User prompt
Can you add laser sounds
User prompt
Seperate the item assets.
User prompt
Seperate the enemy3 and enemy1 as assets.
User prompt
Make it that way
User prompt
Make shield items brighter
User prompt
Define it in the codes
User prompt
Make enemy3 more common
User prompt
Put the ulti button to right corner
User prompt
Put the ulti button to the right corner and make it a little bit bigger
User prompt
Add stronger enemies that need 5 bullets to die but appears more rare
User prompt
Make a ulti button that can be uaed in every 30 seconds
User prompt
More enemies will come in every 50 score
User prompt
Make a armor visual for shield
User prompt
Make shield item light blue
User prompt
Make items blue
User prompt
Add buyable items like shield and beam.
Code edit (1 edits merged)
Please save this source code
User prompt
Enemy Swarm: 2D Shooter
Initial prompt
2d shooting game with multiple enemies
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Enemy type 1: moves straight down var Enemy1 = Container.expand(function () { var self = Container.call(this); var enemySprite = self.attachAsset('enemy1', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 8 + Math.random() * 4; self.update = function () { self.y += self.speed; }; return self; }); // Enemy type 2: moves in sine wave var Enemy2 = Container.expand(function () { var self = Container.call(this); var enemySprite = self.attachAsset('enemy2', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 7 + Math.random() * 3; self.waveAmplitude = 120 + Math.random() * 80; self.waveSpeed = 0.02 + Math.random() * 0.01; self.baseX = 0; self.t = 0; self.update = function () { self.y += self.speed; self.t += self.waveSpeed; self.x = self.baseX + Math.sin(self.t * 6.28) * self.waveAmplitude; }; return self; }); // Enemy bullet class var EnemyBullet = Container.expand(function () { var self = Container.call(this); var bulletSprite = self.attachAsset('enemyBullet', { anchorX: 0.5, anchorY: 0.5 }); self.speedX = 0; self.speedY = 16; self.update = function () { self.x += self.speedX; self.y += self.speedY; }; return self; }); // Hero class var Hero = Container.expand(function () { var self = Container.call(this); var heroSprite = self.attachAsset('hero', { anchorX: 0.5, anchorY: 0.5 }); self.radius = heroSprite.width / 2; self.shootCooldown = 0; self.update = function () { if (self.shootCooldown > 0) self.shootCooldown--; }; return self; }); // Hero bullet class var HeroBullet = Container.expand(function () { var self = Container.call(this); var bulletSprite = self.attachAsset('heroBullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -32; self.update = function () { self.y += self.speed; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x181818 }); /**** * Game Code ****/ // Music // Sound for shooting // Enemy bullet: orange ellipse // Enemy type 2: green ellipse // Enemy type 1: red box // Hero bullet: yellow ellipse // Hero asset: blue box // Play background music LK.playMusic('bgmusic'); // Score display var scoreTxt = new Text2('0', { size: 120, fill: "#fff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Game variables var hero = new Hero(); game.addChild(hero); hero.x = 2048 / 2; hero.y = 2732 - 350; var heroBullets = []; var enemies = []; var enemyBullets = []; var dragNode = null; var lastHeroIntersecting = false; var score = 0; var spawnTick = 0; var enemyShootTick = 0; // Helper: spawn enemy function spawnEnemy() { var type = Math.random() < 0.5 ? 1 : 2; var enemy; if (type === 1) { enemy = new Enemy1(); enemy.x = 200 + Math.random() * (2048 - 400); enemy.y = -80; } else { enemy = new Enemy2(); enemy.baseX = 200 + Math.random() * (2048 - 400); enemy.x = enemy.baseX; enemy.y = -80; enemy.t = Math.random() * 2; } enemies.push(enemy); game.addChild(enemy); } // Helper: spawn enemy bullet function spawnEnemyBullet(enemy, targetX, targetY) { var bullet = new EnemyBullet(); bullet.x = enemy.x; bullet.y = enemy.y + 60; // Aim at hero var dx = targetX - bullet.x; var dy = targetY - bullet.y; var len = Math.sqrt(dx * dx + dy * dy); if (len > 0) { bullet.speedX = dx / len * 18; bullet.speedY = dy / len * 18; } enemyBullets.push(bullet); game.addChild(bullet); LK.getSound('enemyShoot').play(); } // Move handler for dragging hero function handleMove(x, y, obj) { if (dragNode) { // Clamp hero inside screen var hw = dragNode.width / 2; var hh = dragNode.height / 2; var nx = Math.max(hw, Math.min(2048 - hw, x)); var ny = Math.max(hh + 100, Math.min(2732 - hh, y)); dragNode.x = nx; dragNode.y = ny; } } // Touch down: start dragging hero game.down = function (x, y, obj) { // Only allow drag if touch is on hero var local = hero.toLocal(game.toGlobal({ x: x, y: y })); if (Math.abs(local.x) <= hero.width / 2 && Math.abs(local.y) <= hero.height / 2) { dragNode = hero; } }; // Touch up: stop dragging game.up = function (x, y, obj) { dragNode = null; }; // Touch move: move hero game.move = function (x, y, obj) { handleMove(x, y, obj); }; // Main game update game.update = function () { // Update hero hero.update(); // Hero shooting (auto-fire) if (hero.shootCooldown <= 0) { var bullet = new HeroBullet(); bullet.x = hero.x; bullet.y = hero.y - hero.height / 2 - 20; heroBullets.push(bullet); game.addChild(bullet); hero.shootCooldown = 10; LK.getSound('shoot').play(); } // Update hero bullets for (var i = heroBullets.length - 1; i >= 0; i--) { var b = heroBullets[i]; b.update(); // Remove if off screen if (b.y < -60) { b.destroy(); heroBullets.splice(i, 1); continue; } // Check collision with enemies for (var j = enemies.length - 1; j >= 0; j--) { var e = enemies[j]; if (b.intersects(e)) { // Enemy hit LK.getSound('enemyHit').play(); score += 1; scoreTxt.setText(score); // Flash enemy LK.effects.flashObject(e, 0xffffff, 200); // Remove both b.destroy(); heroBullets.splice(i, 1); e.destroy(); enemies.splice(j, 1); break; } } } // Update enemies for (var i = enemies.length - 1; i >= 0; i--) { var e = enemies[i]; e.update(); // Remove if off screen if (e.y > 2732 + 100) { e.destroy(); enemies.splice(i, 1); continue; } // Enemy shoots randomly if (Math.random() < 0.008) { spawnEnemyBullet(e, hero.x, hero.y); } // Check collision with hero if (e.intersects(hero)) { // Hero hit LK.getSound('heroHit').play(); LK.effects.flashScreen(0xff0000, 800); LK.showGameOver(); return; } } // Update enemy bullets for (var i = enemyBullets.length - 1; i >= 0; i--) { var b = enemyBullets[i]; b.update(); // Remove if off screen if (b.y < -60 || b.y > 2732 + 60 || b.x < -60 || b.x > 2048 + 60) { b.destroy(); enemyBullets.splice(i, 1); continue; } // Check collision with hero if (b.intersects(hero)) { LK.getSound('heroHit').play(); LK.effects.flashScreen(0xff0000, 800); LK.showGameOver(); return; } } // Spawn enemies spawnTick++; var spawnInterval = Math.max(18, 60 - Math.floor(score / 10) * 4); // Faster as score increases if (spawnTick >= spawnInterval) { spawnEnemy(); spawnTick = 0; } };
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,280 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+// Enemy type 1: moves straight down
+var Enemy1 = Container.expand(function () {
+ var self = Container.call(this);
+ var enemySprite = self.attachAsset('enemy1', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 8 + Math.random() * 4;
+ self.update = function () {
+ self.y += self.speed;
+ };
+ return self;
+});
+// Enemy type 2: moves in sine wave
+var Enemy2 = Container.expand(function () {
+ var self = Container.call(this);
+ var enemySprite = self.attachAsset('enemy2', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 7 + Math.random() * 3;
+ self.waveAmplitude = 120 + Math.random() * 80;
+ self.waveSpeed = 0.02 + Math.random() * 0.01;
+ self.baseX = 0;
+ self.t = 0;
+ self.update = function () {
+ self.y += self.speed;
+ self.t += self.waveSpeed;
+ self.x = self.baseX + Math.sin(self.t * 6.28) * self.waveAmplitude;
+ };
+ return self;
+});
+// Enemy bullet class
+var EnemyBullet = Container.expand(function () {
+ var self = Container.call(this);
+ var bulletSprite = self.attachAsset('enemyBullet', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speedX = 0;
+ self.speedY = 16;
+ self.update = function () {
+ self.x += self.speedX;
+ self.y += self.speedY;
+ };
+ return self;
+});
+// Hero class
+var Hero = Container.expand(function () {
+ var self = Container.call(this);
+ var heroSprite = self.attachAsset('hero', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.radius = heroSprite.width / 2;
+ self.shootCooldown = 0;
+ self.update = function () {
+ if (self.shootCooldown > 0) self.shootCooldown--;
+ };
+ return self;
+});
+// Hero bullet class
+var HeroBullet = Container.expand(function () {
+ var self = Container.call(this);
+ var bulletSprite = self.attachAsset('heroBullet', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = -32;
+ self.update = function () {
+ self.y += self.speed;
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x181818
+});
+
+/****
+* Game Code
+****/
+// Music
+// Sound for shooting
+// Enemy bullet: orange ellipse
+// Enemy type 2: green ellipse
+// Enemy type 1: red box
+// Hero bullet: yellow ellipse
+// Hero asset: blue box
+// Play background music
+LK.playMusic('bgmusic');
+// Score display
+var scoreTxt = new Text2('0', {
+ size: 120,
+ fill: "#fff"
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+// Game variables
+var hero = new Hero();
+game.addChild(hero);
+hero.x = 2048 / 2;
+hero.y = 2732 - 350;
+var heroBullets = [];
+var enemies = [];
+var enemyBullets = [];
+var dragNode = null;
+var lastHeroIntersecting = false;
+var score = 0;
+var spawnTick = 0;
+var enemyShootTick = 0;
+// Helper: spawn enemy
+function spawnEnemy() {
+ var type = Math.random() < 0.5 ? 1 : 2;
+ var enemy;
+ if (type === 1) {
+ enemy = new Enemy1();
+ enemy.x = 200 + Math.random() * (2048 - 400);
+ enemy.y = -80;
+ } else {
+ enemy = new Enemy2();
+ enemy.baseX = 200 + Math.random() * (2048 - 400);
+ enemy.x = enemy.baseX;
+ enemy.y = -80;
+ enemy.t = Math.random() * 2;
+ }
+ enemies.push(enemy);
+ game.addChild(enemy);
+}
+// Helper: spawn enemy bullet
+function spawnEnemyBullet(enemy, targetX, targetY) {
+ var bullet = new EnemyBullet();
+ bullet.x = enemy.x;
+ bullet.y = enemy.y + 60;
+ // Aim at hero
+ var dx = targetX - bullet.x;
+ var dy = targetY - bullet.y;
+ var len = Math.sqrt(dx * dx + dy * dy);
+ if (len > 0) {
+ bullet.speedX = dx / len * 18;
+ bullet.speedY = dy / len * 18;
+ }
+ enemyBullets.push(bullet);
+ game.addChild(bullet);
+ LK.getSound('enemyShoot').play();
+}
+// Move handler for dragging hero
+function handleMove(x, y, obj) {
+ if (dragNode) {
+ // Clamp hero inside screen
+ var hw = dragNode.width / 2;
+ var hh = dragNode.height / 2;
+ var nx = Math.max(hw, Math.min(2048 - hw, x));
+ var ny = Math.max(hh + 100, Math.min(2732 - hh, y));
+ dragNode.x = nx;
+ dragNode.y = ny;
+ }
+}
+// Touch down: start dragging hero
+game.down = function (x, y, obj) {
+ // Only allow drag if touch is on hero
+ var local = hero.toLocal(game.toGlobal({
+ x: x,
+ y: y
+ }));
+ if (Math.abs(local.x) <= hero.width / 2 && Math.abs(local.y) <= hero.height / 2) {
+ dragNode = hero;
+ }
+};
+// Touch up: stop dragging
+game.up = function (x, y, obj) {
+ dragNode = null;
+};
+// Touch move: move hero
+game.move = function (x, y, obj) {
+ handleMove(x, y, obj);
+};
+// Main game update
+game.update = function () {
+ // Update hero
+ hero.update();
+ // Hero shooting (auto-fire)
+ if (hero.shootCooldown <= 0) {
+ var bullet = new HeroBullet();
+ bullet.x = hero.x;
+ bullet.y = hero.y - hero.height / 2 - 20;
+ heroBullets.push(bullet);
+ game.addChild(bullet);
+ hero.shootCooldown = 10;
+ LK.getSound('shoot').play();
+ }
+ // Update hero bullets
+ for (var i = heroBullets.length - 1; i >= 0; i--) {
+ var b = heroBullets[i];
+ b.update();
+ // Remove if off screen
+ if (b.y < -60) {
+ b.destroy();
+ heroBullets.splice(i, 1);
+ continue;
+ }
+ // Check collision with enemies
+ for (var j = enemies.length - 1; j >= 0; j--) {
+ var e = enemies[j];
+ if (b.intersects(e)) {
+ // Enemy hit
+ LK.getSound('enemyHit').play();
+ score += 1;
+ scoreTxt.setText(score);
+ // Flash enemy
+ LK.effects.flashObject(e, 0xffffff, 200);
+ // Remove both
+ b.destroy();
+ heroBullets.splice(i, 1);
+ e.destroy();
+ enemies.splice(j, 1);
+ break;
+ }
+ }
+ }
+ // Update enemies
+ for (var i = enemies.length - 1; i >= 0; i--) {
+ var e = enemies[i];
+ e.update();
+ // Remove if off screen
+ if (e.y > 2732 + 100) {
+ e.destroy();
+ enemies.splice(i, 1);
+ continue;
+ }
+ // Enemy shoots randomly
+ if (Math.random() < 0.008) {
+ spawnEnemyBullet(e, hero.x, hero.y);
+ }
+ // Check collision with hero
+ if (e.intersects(hero)) {
+ // Hero hit
+ LK.getSound('heroHit').play();
+ LK.effects.flashScreen(0xff0000, 800);
+ LK.showGameOver();
+ return;
+ }
+ }
+ // Update enemy bullets
+ for (var i = enemyBullets.length - 1; i >= 0; i--) {
+ var b = enemyBullets[i];
+ b.update();
+ // Remove if off screen
+ if (b.y < -60 || b.y > 2732 + 60 || b.x < -60 || b.x > 2048 + 60) {
+ b.destroy();
+ enemyBullets.splice(i, 1);
+ continue;
+ }
+ // Check collision with hero
+ if (b.intersects(hero)) {
+ LK.getSound('heroHit').play();
+ LK.effects.flashScreen(0xff0000, 800);
+ LK.showGameOver();
+ return;
+ }
+ }
+ // Spawn enemies
+ spawnTick++;
+ var spawnInterval = Math.max(18, 60 - Math.floor(score / 10) * 4); // Faster as score increases
+ if (spawnTick >= spawnInterval) {
+ spawnEnemy();
+ spawnTick = 0;
+ }
+};
\ No newline at end of file
A power core with electricity and blue lights. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
A blue space ship with laser gun and powerful engines. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
A shiny purple crystal. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
A red winged alien with exoskeleton. . No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
A tiny green alien with spikes. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
A strong yellow-white alien with horns. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
A king yellow alien with black and white stripes and wings. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
Neboula background. In-Game asset. 2d. High contrast. No shadows. Cinematic deep
A blue button. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
A dark green alien with a gray orb above it. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
A dark green alien boss with two gray orbs around it. On top it has a green crown. Has light gray stripes. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
A futuristic scoreboard tablet with blue and cyan colors. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat