User prompt
Let's give the area for controlling. It should be separated from gameplay area
User prompt
Please fix the bug: 'ReferenceError: timerTxt is not defined' in or related to this line: 'timerTxt.setText(t.toFixed(1));' Line Number: 286
User prompt
No need any timer and level will be ended when the target finished. The target for level 1 - 10, level 2 - 15 and the others will be increased 5 more than previous level's target. Let's power ups: fire rate/ fire style (Double triple like that) and shield. Let's turn off mouse control and adjust control button and place lane for them. For background change it for jungle
User prompt
Let's add the controller left and right. And change hero figure to Tank and enemy to soldier
User prompt
game ends when kill 10 enemy
User prompt
howcan u add move
Code edit (1 edits merged)
Please save this source code
User prompt
Pistol Road: Run & Survive
Initial prompt
i want to creat rpg game there are enemies try to stop me to reach end i have pistol to shoot them mai character has 3 lives if they reach me one of them delete enemy drop fast 2 sec length of road 20 sec
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Enemy class var Enemy = Container.expand(function () { var self = Container.call(this); var enemySprite = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.width = enemySprite.width; self.height = enemySprite.height; self.speed = 12; // Downwards, can be increased by game speed self.alive = true; self.update = function () { self.y += self.speed * gameSpeed; }; 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.width = heroSprite.width; self.height = heroSprite.height; self.shootCooldown = 0; // frames until next allowed shot // Shoot method self.shoot = function () { if (self.shootCooldown > 0) return; var bullet = new HeroBullet(); bullet.x = self.x; bullet.y = self.y - self.height / 2 - bullet.height / 2; heroBullets.push(bullet); game.addChild(bullet); self.shootCooldown = 12; // 0.2s at 60fps LK.getSound('shoot').play(); }; // Called every tick 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.width = bulletSprite.width; self.height = bulletSprite.height; self.speed = -36; // Upwards self.update = function () { self.y += self.speed; }; return self; }); // Speed boost drop class var SpeedBoost = Container.expand(function () { var self = Container.call(this); var boostSprite = self.attachAsset('speedBoost', { anchorX: 0.5, anchorY: 0.5 }); self.width = boostSprite.width; self.height = boostSprite.height; self.speed = 10; self.update = function () { self.y += self.speed * gameSpeed; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x111111 }); /**** * Game Code ****/ // Music // Sound effects // Road (background) // Speed boost drop // Enemy // Hero bullet // Hero (player) // --- Global variables --- var hero; var heroBullets = []; var enemies = []; var boosts = []; var lives = 3; var gameTime = 0; // ms var gameDuration = 20000; // 20 seconds var gameSpeed = 1; // Multiplier, affected by boosts var boostActive = false; var boostTimer = 0; var lastEnemySpawnTick = 0; var enemySpawnInterval = 48; // frames (0.8s at 60fps) var score = 0; var finished = false; // --- Road background --- var road = LK.getAsset('road', { anchorX: 0.5, anchorY: 0 }); road.x = 2048 / 2; road.y = 0; game.addChild(road); // --- Hero --- hero = new Hero(); hero.x = 2048 / 2; hero.y = 2732 - 350; game.addChild(hero); // --- GUI: Lives --- var livesTxt = new Text2('♥♥♥', { size: 90, fill: 0xFF4D4D }); livesTxt.anchor.set(0.5, 0); LK.gui.top.addChild(livesTxt); // --- GUI: Timer --- var timerTxt = new Text2('20.0', { size: 90, fill: 0xFFFFFF }); timerTxt.anchor.set(0.5, 0); LK.gui.topRight.addChild(timerTxt); // --- GUI: Score --- var scoreTxt = new Text2('0', { size: 90, fill: 0xFFE066 }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // --- Music --- LK.playMusic('bgmusic'); // --- Helper: Update GUI --- function updateLivesDisplay() { var s = ''; for (var i = 0; i < lives; i++) s += '♥'; livesTxt.setText(s); } function updateTimerDisplay() { var t = Math.max(0, (gameDuration - gameTime) / 1000); timerTxt.setText(t.toFixed(1)); } function updateScoreDisplay() { scoreTxt.setText(score); } // --- Touch controls: Move hero, shoot --- var dragHero = false; function clampHero(x, y) { // Clamp hero inside road var minX = road.x - road.width / 2 + hero.width / 2 + 20; var maxX = road.x + road.width / 2 - hero.width / 2 - 20; var minY = 200 + hero.height / 2; var maxY = 2732 - hero.height / 2 - 40; hero.x = Math.max(minX, Math.min(maxX, x)); hero.y = Math.max(minY, Math.min(maxY, y)); } game.down = function (x, y, obj) { // If touch is on hero, drag; else, shoot var local = hero.toLocal(game.toGlobal({ x: x, y: y })); if (local.x >= -hero.width / 2 && local.x <= hero.width / 2 && local.y >= -hero.height / 2 && local.y <= hero.height / 2) { dragHero = true; } else { hero.shoot(); } }; game.move = function (x, y, obj) { if (dragHero) { clampHero(x, y); } }; game.up = function (x, y, obj) { dragHero = false; }; // --- Enemy spawn logic --- function spawnEnemy() { // Enemies spawn randomly within road var enemy = new Enemy(); var minX = road.x - road.width / 2 + enemy.width / 2 + 20; var maxX = road.x + road.width / 2 - enemy.width / 2 - 20; enemy.x = minX + Math.random() * (maxX - minX); enemy.y = -enemy.height / 2 - 10; // Randomize speed a bit enemy.speed = 10 + Math.random() * 6; enemies.push(enemy); game.addChild(enemy); } // --- Boost logic --- function spawnBoost(x, y) { var boost = new SpeedBoost(); boost.x = x; boost.y = y; boosts.push(boost); game.addChild(boost); } // --- Game update --- game.update = function () { if (finished) return; // --- Timer --- gameTime += 1000 / 60; updateTimerDisplay(); // --- Win condition --- if (gameTime >= gameDuration) { finished = true; LK.showYouWin(); return; } // --- Boost logic --- if (boostActive) { boostTimer -= 1000 / 60; if (boostTimer <= 0) { boostActive = false; gameSpeed = 1; } } // --- Enemy spawn --- if (LK.ticks - lastEnemySpawnTick >= enemySpawnInterval) { spawnEnemy(); lastEnemySpawnTick = LK.ticks; } // --- Update hero --- hero.update(); // --- 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 < -b.height) { b.destroy(); heroBullets.splice(i, 1); } } // --- 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 + e.height) { e.destroy(); enemies.splice(i, 1); continue; } // Check collision with hero if (e.alive && e.intersects(hero)) { // Lose a life, destroy enemy lives--; updateLivesDisplay(); LK.getSound('hit').play(); LK.effects.flashObject(hero, 0xff0000, 400); e.alive = false; e.destroy(); enemies.splice(i, 1); // Game over? if (lives <= 0) { finished = true; LK.showGameOver(); return; } continue; } // Check collision with hero bullets for (var j = heroBullets.length - 1; j >= 0; j--) { var b = heroBullets[j]; if (e.alive && b.intersects(e)) { // Enemy down e.alive = false; e.destroy(); enemies.splice(i, 1); b.destroy(); heroBullets.splice(j, 1); score++; updateScoreDisplay(); LK.getSound('enemyDown').play(); // Win if 10 enemies killed if (score >= 10) { finished = true; LK.showYouWin(); return; } // Chance to drop boost (30%) if (Math.random() < 0.3) { spawnBoost(e.x, e.y); } break; } } } // --- Update boosts --- for (var i = boosts.length - 1; i >= 0; i--) { var boost = boosts[i]; boost.update(); // Remove if off screen if (boost.y > 2732 + boost.height) { boost.destroy(); boosts.splice(i, 1); continue; } // Check collision with hero if (boost.intersects(hero)) { // Activate speed boost boostActive = true; boostTimer = 2000; // 2 seconds gameSpeed = 2.2; LK.getSound('boost').play(); LK.effects.flashObject(hero, 0x44e07b, 400); boost.destroy(); boosts.splice(i, 1); } } }; // --- Initial GUI update --- updateLivesDisplay(); updateTimerDisplay(); updateScoreDisplay();
===================================================================
--- original.js
+++ change.js
@@ -290,8 +290,14 @@
heroBullets.splice(j, 1);
score++;
updateScoreDisplay();
LK.getSound('enemyDown').play();
+ // Win if 10 enemies killed
+ if (score >= 10) {
+ finished = true;
+ LK.showYouWin();
+ return;
+ }
// Chance to drop boost (30%)
if (Math.random() < 0.3) {
spawnBoost(e.x, e.y);
}
Let's remove background and resize it bigger
Make it view from sky and change color of rifle to black and brown
Change towards to right
change it mecha-style heart for hero lives. In-Game asset. 2d. High contrast. No shadows. mechaart
fire button for tank game controller. Fire button in mecha style. In-Game asset. 2d. High contrast. No shadows
green line with army style. In-Game asset. 2d. High contrast. No shadows
make shorter horizontal wing
make it vertical
remove dollar emblem from it
exclamantation. In-Game asset. 2d. High contrast. No shadows
black market which sells weapon. In-Game asset. 2d. High contrast. No shadows
blur brown