User prompt
Add random hearts that drop from above like enemy tanks and make them come very rarely
User prompt
Start the game with five lives
User prompt
make healt
User prompt
Make enemy tanks fire only once every 2 seconds
User prompt
Make enemy tanks fire only once every 1 seconds
User prompt
Make enemy tanks fire only once every 2 seconds
User prompt
add a boss that comes after a certain amount of time in the game
User prompt
make enemy bullet speed low
Code edit (1 edits merged)
Please save this source code
User prompt
Frontline Command
Initial prompt
make a war game
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Enemy Shell Class var EnemyShell = Container.expand(function () { var self = Container.call(this); var shell = self.attachAsset('enemyShell', { anchorX: 0.5, anchorY: 0.5 }); self.width = shell.width; self.height = shell.height; self.vx = 0; self.vy = 16; self.update = function () { self.x += self.vx; self.y += self.vy; }; return self; }); // Enemy Tank Class var EnemyTank = Container.expand(function () { var self = Container.call(this); var tank = self.attachAsset('enemyTank', { anchorX: 0.5, anchorY: 0.5 }); self.width = tank.width; self.height = tank.height; // Movement self.speed = 6 + Math.random() * 2 + Math.floor(LK.getScore() / 10); // Escalate with score // Firing self.fireInterval = 60 + Math.floor(Math.random() * 60); // 1-2s self.fireCounter = 0; self.update = function () { self.y += self.speed; self.fireCounter++; if (self.fireCounter >= self.fireInterval) { self.fireCounter = 0; self.fire(); } }; self.fire = function () { var shell = new EnemyShell(); shell.x = self.x; shell.y = self.y + self.height / 2 + shell.height / 2; // Aim at player var dx = player.x - shell.x; var dy = player.y - shell.y; var mag = Math.sqrt(dx * dx + dy * dy); shell.vx = dx / mag * (14 + Math.floor(LK.getScore() / 10)); shell.vy = dy / mag * (14 + Math.floor(LK.getScore() / 10)); enemyShells.push(shell); game.addChild(shell); LK.getSound('enemyFire').play(); }; return self; }); // Explosion effect (for destroyed tanks) var Explosion = Container.expand(function () { var self = Container.call(this); var exp = self.attachAsset('explosion', { anchorX: 0.5, anchorY: 0.5 }); exp.alpha = 0.7; // Animate fade out and destroy tween(exp, { alpha: 0 }, { duration: 350, easing: tween.linear, onFinish: function onFinish() { self.destroy(); } }); return self; }); // Player Shell Class var PlayerShell = Container.expand(function () { var self = Container.call(this); var shell = self.attachAsset('playerShell', { anchorX: 0.5, anchorY: 0.5 }); self.width = shell.width; self.height = shell.height; self.speed = -32; // Upwards self.update = function () { self.y += self.speed; }; return self; }); // Player Tank Class var PlayerTank = Container.expand(function () { var self = Container.call(this); var tank = self.attachAsset('playerTank', { anchorX: 0.5, anchorY: 0.5 }); self.width = tank.width; self.height = tank.height; // Fire cooldown self.canFire = true; self.fireCooldown = 18; // frames (0.3s) self.cooldownCounter = 0; self.update = function () { if (!self.canFire) { self.cooldownCounter++; if (self.cooldownCounter >= self.fireCooldown) { self.canFire = true; self.cooldownCounter = 0; } } }; // Fire a shell self.fire = function () { if (self.canFire) { var shell = new PlayerShell(); shell.x = self.x; shell.y = self.y - self.height / 2 - shell.height / 2; playerShells.push(shell); game.addChild(shell); LK.getSound('fire').play(); self.canFire = false; } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x22272b }); /**** * Game Code ****/ // Sound effects // Explosion: white ellipse (for flash effect) // Enemy shell: orange ellipse // Enemy tank: red box // Player shell: yellow ellipse // Player tank: green box // Game area var GAME_W = 2048; var GAME_H = 2732; // Player var player = new PlayerTank(); player.x = GAME_W / 2; player.y = GAME_H - 350; game.addChild(player); // Arrays for game objects var playerShells = []; var enemyTanks = []; var enemyShells = []; // Score display var scoreTxt = new Text2('0', { size: 120, fill: "#fff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Dragging var dragNode = null; // Spawn enemy timer var enemySpawnInterval = 90; // frames (1.5s) var enemySpawnCounter = 0; // Difficulty escalation function getEnemySpawnInterval() { var s = LK.getScore(); if (s < 10) return 90; if (s < 25) return 70; if (s < 50) return 55; return 40; } // Move handler (drag player tank) function handleMove(x, y, obj) { if (dragNode) { // Clamp to game area, avoid top 100px (menu) var minX = dragNode.width / 2; var maxX = GAME_W - dragNode.width / 2; var minY = 100 + dragNode.height / 2; var maxY = GAME_H - dragNode.height / 2; dragNode.x = Math.max(minX, Math.min(maxX, x)); dragNode.y = Math.max(minY, Math.min(maxY, y)); } } game.move = handleMove; game.down = function (x, y, obj) { // Only drag if touch is on player tank var local = player.toLocal(game.toGlobal({ x: x, y: y })); if (local.x > -player.width / 2 && local.x < player.width / 2 && local.y > -player.height / 2 && local.y < player.height / 2) { dragNode = player; } }; game.up = function (x, y, obj) { dragNode = null; }; // Tap to fire (anywhere) game.tap = function (x, y, obj) { player.fire(); }; // For compatibility, also fire on down if not dragging game.down = function (x, y, obj) { var local = player.toLocal(game.toGlobal({ x: x, y: y })); if (local.x > -player.width / 2 && local.x < player.width / 2 && local.y > -player.height / 2 && local.y < player.height / 2) { dragNode = player; } else { player.fire(); } }; // Main update loop game.update = function () { // Update player player.update(); // Update player shells for (var i = playerShells.length - 1; i >= 0; i--) { var shell = playerShells[i]; shell.update(); // Remove if off screen if (shell.y < -shell.height / 2) { shell.destroy(); playerShells.splice(i, 1); continue; } // Check collision with enemy tanks for (var j = enemyTanks.length - 1; j >= 0; j--) { var enemy = enemyTanks[j]; if (shell.intersects(enemy)) { // Explosion var exp = new Explosion(); exp.x = enemy.x; exp.y = enemy.y; game.addChild(exp); LK.getSound('explode').play(); // Remove both shell.destroy(); playerShells.splice(i, 1); enemy.destroy(); enemyTanks.splice(j, 1); // Score LK.setScore(LK.getScore() + 1); scoreTxt.setText(LK.getScore()); break; } } } // Update enemy tanks for (var i = enemyTanks.length - 1; i >= 0; i--) { var enemy = enemyTanks[i]; enemy.update(); // Remove if off screen if (enemy.y > GAME_H + enemy.height / 2) { enemy.destroy(); enemyTanks.splice(i, 1); continue; } // Check collision with player if (enemy.intersects(player)) { // Explosion var exp = new Explosion(); exp.x = player.x; exp.y = player.y; game.addChild(exp); LK.getSound('explode').play(); LK.effects.flashScreen(0xff0000, 800); LK.showGameOver(); return; } } // Update enemy shells for (var i = enemyShells.length - 1; i >= 0; i--) { var shell = enemyShells[i]; shell.update(); // Remove if off screen if (shell.y > GAME_H + shell.height / 2 || shell.x < -shell.width / 2 || shell.x > GAME_W + shell.width / 2) { shell.destroy(); enemyShells.splice(i, 1); continue; } // Check collision with player if (shell.intersects(player)) { // Explosion var exp = new Explosion(); exp.x = player.x; exp.y = player.y; game.addChild(exp); LK.getSound('explode').play(); LK.effects.flashScreen(0xff0000, 800); LK.showGameOver(); return; } } // Spawn enemies enemySpawnCounter++; if (enemySpawnCounter >= getEnemySpawnInterval()) { enemySpawnCounter = 0; var enemy = new EnemyTank(); // Random x, avoid edges var margin = 200; enemy.x = margin + Math.random() * (GAME_W - 2 * margin); enemy.y = -enemy.height / 2; enemyTanks.push(enemy); game.addChild(enemy); } }; // Set initial score LK.setScore(0); scoreTxt.setText('0');
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,323 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+// Enemy Shell Class
+var EnemyShell = Container.expand(function () {
+ var self = Container.call(this);
+ var shell = self.attachAsset('enemyShell', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.width = shell.width;
+ self.height = shell.height;
+ self.vx = 0;
+ self.vy = 16;
+ self.update = function () {
+ self.x += self.vx;
+ self.y += self.vy;
+ };
+ return self;
+});
+// Enemy Tank Class
+var EnemyTank = Container.expand(function () {
+ var self = Container.call(this);
+ var tank = self.attachAsset('enemyTank', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.width = tank.width;
+ self.height = tank.height;
+ // Movement
+ self.speed = 6 + Math.random() * 2 + Math.floor(LK.getScore() / 10); // Escalate with score
+ // Firing
+ self.fireInterval = 60 + Math.floor(Math.random() * 60); // 1-2s
+ self.fireCounter = 0;
+ self.update = function () {
+ self.y += self.speed;
+ self.fireCounter++;
+ if (self.fireCounter >= self.fireInterval) {
+ self.fireCounter = 0;
+ self.fire();
+ }
+ };
+ self.fire = function () {
+ var shell = new EnemyShell();
+ shell.x = self.x;
+ shell.y = self.y + self.height / 2 + shell.height / 2;
+ // Aim at player
+ var dx = player.x - shell.x;
+ var dy = player.y - shell.y;
+ var mag = Math.sqrt(dx * dx + dy * dy);
+ shell.vx = dx / mag * (14 + Math.floor(LK.getScore() / 10));
+ shell.vy = dy / mag * (14 + Math.floor(LK.getScore() / 10));
+ enemyShells.push(shell);
+ game.addChild(shell);
+ LK.getSound('enemyFire').play();
+ };
+ return self;
+});
+// Explosion effect (for destroyed tanks)
+var Explosion = Container.expand(function () {
+ var self = Container.call(this);
+ var exp = self.attachAsset('explosion', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ exp.alpha = 0.7;
+ // Animate fade out and destroy
+ tween(exp, {
+ alpha: 0
+ }, {
+ duration: 350,
+ easing: tween.linear,
+ onFinish: function onFinish() {
+ self.destroy();
+ }
+ });
+ return self;
+});
+// Player Shell Class
+var PlayerShell = Container.expand(function () {
+ var self = Container.call(this);
+ var shell = self.attachAsset('playerShell', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.width = shell.width;
+ self.height = shell.height;
+ self.speed = -32; // Upwards
+ self.update = function () {
+ self.y += self.speed;
+ };
+ return self;
+});
+// Player Tank Class
+var PlayerTank = Container.expand(function () {
+ var self = Container.call(this);
+ var tank = self.attachAsset('playerTank', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.width = tank.width;
+ self.height = tank.height;
+ // Fire cooldown
+ self.canFire = true;
+ self.fireCooldown = 18; // frames (0.3s)
+ self.cooldownCounter = 0;
+ self.update = function () {
+ if (!self.canFire) {
+ self.cooldownCounter++;
+ if (self.cooldownCounter >= self.fireCooldown) {
+ self.canFire = true;
+ self.cooldownCounter = 0;
+ }
+ }
+ };
+ // Fire a shell
+ self.fire = function () {
+ if (self.canFire) {
+ var shell = new PlayerShell();
+ shell.x = self.x;
+ shell.y = self.y - self.height / 2 - shell.height / 2;
+ playerShells.push(shell);
+ game.addChild(shell);
+ LK.getSound('fire').play();
+ self.canFire = false;
+ }
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x22272b
+});
+
+/****
+* Game Code
+****/
+// Sound effects
+// Explosion: white ellipse (for flash effect)
+// Enemy shell: orange ellipse
+// Enemy tank: red box
+// Player shell: yellow ellipse
+// Player tank: green box
+// Game area
+var GAME_W = 2048;
+var GAME_H = 2732;
+// Player
+var player = new PlayerTank();
+player.x = GAME_W / 2;
+player.y = GAME_H - 350;
+game.addChild(player);
+// Arrays for game objects
+var playerShells = [];
+var enemyTanks = [];
+var enemyShells = [];
+// Score display
+var scoreTxt = new Text2('0', {
+ size: 120,
+ fill: "#fff"
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+// Dragging
+var dragNode = null;
+// Spawn enemy timer
+var enemySpawnInterval = 90; // frames (1.5s)
+var enemySpawnCounter = 0;
+// Difficulty escalation
+function getEnemySpawnInterval() {
+ var s = LK.getScore();
+ if (s < 10) return 90;
+ if (s < 25) return 70;
+ if (s < 50) return 55;
+ return 40;
+}
+// Move handler (drag player tank)
+function handleMove(x, y, obj) {
+ if (dragNode) {
+ // Clamp to game area, avoid top 100px (menu)
+ var minX = dragNode.width / 2;
+ var maxX = GAME_W - dragNode.width / 2;
+ var minY = 100 + dragNode.height / 2;
+ var maxY = GAME_H - dragNode.height / 2;
+ dragNode.x = Math.max(minX, Math.min(maxX, x));
+ dragNode.y = Math.max(minY, Math.min(maxY, y));
+ }
+}
+game.move = handleMove;
+game.down = function (x, y, obj) {
+ // Only drag if touch is on player tank
+ var local = player.toLocal(game.toGlobal({
+ x: x,
+ y: y
+ }));
+ if (local.x > -player.width / 2 && local.x < player.width / 2 && local.y > -player.height / 2 && local.y < player.height / 2) {
+ dragNode = player;
+ }
+};
+game.up = function (x, y, obj) {
+ dragNode = null;
+};
+// Tap to fire (anywhere)
+game.tap = function (x, y, obj) {
+ player.fire();
+};
+// For compatibility, also fire on down if not dragging
+game.down = function (x, y, obj) {
+ var local = player.toLocal(game.toGlobal({
+ x: x,
+ y: y
+ }));
+ if (local.x > -player.width / 2 && local.x < player.width / 2 && local.y > -player.height / 2 && local.y < player.height / 2) {
+ dragNode = player;
+ } else {
+ player.fire();
+ }
+};
+// Main update loop
+game.update = function () {
+ // Update player
+ player.update();
+ // Update player shells
+ for (var i = playerShells.length - 1; i >= 0; i--) {
+ var shell = playerShells[i];
+ shell.update();
+ // Remove if off screen
+ if (shell.y < -shell.height / 2) {
+ shell.destroy();
+ playerShells.splice(i, 1);
+ continue;
+ }
+ // Check collision with enemy tanks
+ for (var j = enemyTanks.length - 1; j >= 0; j--) {
+ var enemy = enemyTanks[j];
+ if (shell.intersects(enemy)) {
+ // Explosion
+ var exp = new Explosion();
+ exp.x = enemy.x;
+ exp.y = enemy.y;
+ game.addChild(exp);
+ LK.getSound('explode').play();
+ // Remove both
+ shell.destroy();
+ playerShells.splice(i, 1);
+ enemy.destroy();
+ enemyTanks.splice(j, 1);
+ // Score
+ LK.setScore(LK.getScore() + 1);
+ scoreTxt.setText(LK.getScore());
+ break;
+ }
+ }
+ }
+ // Update enemy tanks
+ for (var i = enemyTanks.length - 1; i >= 0; i--) {
+ var enemy = enemyTanks[i];
+ enemy.update();
+ // Remove if off screen
+ if (enemy.y > GAME_H + enemy.height / 2) {
+ enemy.destroy();
+ enemyTanks.splice(i, 1);
+ continue;
+ }
+ // Check collision with player
+ if (enemy.intersects(player)) {
+ // Explosion
+ var exp = new Explosion();
+ exp.x = player.x;
+ exp.y = player.y;
+ game.addChild(exp);
+ LK.getSound('explode').play();
+ LK.effects.flashScreen(0xff0000, 800);
+ LK.showGameOver();
+ return;
+ }
+ }
+ // Update enemy shells
+ for (var i = enemyShells.length - 1; i >= 0; i--) {
+ var shell = enemyShells[i];
+ shell.update();
+ // Remove if off screen
+ if (shell.y > GAME_H + shell.height / 2 || shell.x < -shell.width / 2 || shell.x > GAME_W + shell.width / 2) {
+ shell.destroy();
+ enemyShells.splice(i, 1);
+ continue;
+ }
+ // Check collision with player
+ if (shell.intersects(player)) {
+ // Explosion
+ var exp = new Explosion();
+ exp.x = player.x;
+ exp.y = player.y;
+ game.addChild(exp);
+ LK.getSound('explode').play();
+ LK.effects.flashScreen(0xff0000, 800);
+ LK.showGameOver();
+ return;
+ }
+ }
+ // Spawn enemies
+ enemySpawnCounter++;
+ if (enemySpawnCounter >= getEnemySpawnInterval()) {
+ enemySpawnCounter = 0;
+ var enemy = new EnemyTank();
+ // Random x, avoid edges
+ var margin = 200;
+ enemy.x = margin + Math.random() * (GAME_W - 2 * margin);
+ enemy.y = -enemy.height / 2;
+ enemyTanks.push(enemy);
+ game.addChild(enemy);
+ }
+};
+// Set initial score
+LK.setScore(0);
+scoreTxt.setText('0');
\ No newline at end of file