User prompt
Create a special space where we can fill our souls
User prompt
Create a beautiful background.
User prompt
Enemies only come from above
User prompt
Please fix the bug: 'TypeError: taskTexts[i].setColor is not a function' in or related to this line: 'taskTexts[i].setColor(color);' Line Number: 334
User prompt
Put the character's health bar under
User prompt
give us some tasks and show these tasks on top
User prompt
Reduces enemies' health and range
Code edit (1 edits merged)
Please save this source code
User prompt
Top Cop: Police Pursuit
Initial prompt
make a gun game and um top top camera and then uh and then and then uh sound effects and uh police and uh and
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ var Background = Container.expand(function () { var self = Container.call(this); // Create sky gradient var skyGradient = new Container(); // Create several bands of sky color var skyColors = [0x1a3c80, 0x3a5c9f, 0x5a7cbf, 0x7a9cdf, 0x9abcff]; var bandHeight = 2732 / skyColors.length; for (var i = 0; i < skyColors.length; i++) { var skyBand = LK.getAsset('skyBand' + i, { width: 2048, height: bandHeight, color: skyColors[i], shape: 'box', y: i * bandHeight }); skyGradient.addChild(skyBand); } self.addChild(skyGradient); // Create buildings var buildings = new Container(); self.addChild(buildings); // Far buildings (darker) var buildingColors = [0x222a40, 0x323a50, 0x424a60]; var buildingCount = 15; for (var i = 0; i < buildingCount; i++) { var buildingWidth = 100 + Math.random() * 150; var buildingHeight = 300 + Math.random() * 400; var building = LK.getAsset('building_far_' + i, { width: buildingWidth, height: buildingHeight, color: buildingColors[Math.floor(Math.random() * buildingColors.length)], shape: 'box', x: i * (2048 / buildingCount), y: 2732 - buildingHeight, anchorY: 0 }); buildings.addChild(building); } // Near buildings (slightly lighter) var nearBuildingColors = [0x303a50, 0x404a60, 0x505a70]; var nearBuildingCount = 10; for (var i = 0; i < nearBuildingCount; i++) { var buildingWidth = 180 + Math.random() * 150; var buildingHeight = 500 + Math.random() * 600; var building = LK.getAsset('building_near_' + i, { width: buildingWidth, height: buildingHeight, color: nearBuildingColors[Math.floor(Math.random() * nearBuildingColors.length)], shape: 'box', x: i * (2048 / nearBuildingCount), y: 2732 - buildingHeight, anchorY: 0 }); buildings.addChild(building); } // Add some windows to buildings (as small yellow rectangles) for (var b = 0; b < buildings.children.length; b++) { var building = buildings.children[b]; var windowCount = Math.floor(building.width / 30) * Math.floor(building.height / 40); // Limit window count for performance windowCount = Math.min(windowCount, 20); for (var w = 0; w < windowCount; w++) { var windowSize = 10 + Math.random() * 10; var windowX = Math.random() * (building.width - windowSize); var windowY = Math.random() * (building.height - windowSize); // Only add some windows (randomized lighting effect) if (Math.random() > 0.4) { var windowLight = LK.getAsset('window_' + b + '_' + w, { width: windowSize, height: windowSize, color: Math.random() > 0.7 ? 0xffcc66 : 0x888888, // Some windows lit, some not shape: 'box', x: building.x + windowX, y: building.y + windowY }); self.addChild(windowLight); } } } // Add clouds var clouds = new Container(); self.clouds = clouds; self.addChild(clouds); var cloudCount = 6; for (var i = 0; i < cloudCount; i++) { var cloudWidth = 200 + Math.random() * 300; var cloudHeight = 100 + Math.random() * 100; var cloud = LK.getAsset('cloud_' + i, { width: cloudWidth, height: cloudHeight, color: 0xddddff, shape: 'ellipse', x: Math.random() * 2048, y: 200 + Math.random() * 400, alpha: 0.7 }); // Add some variation to clouds with slight scaling cloud.scaleX = 0.8 + Math.random() * 0.4; cloud.scaleY = 0.8 + Math.random() * 0.4; // Store cloud speed for animation cloud.speedX = 0.2 + Math.random() * 0.3; clouds.addChild(cloud); } // Update function to animate clouds self.update = function () { // Move clouds horizontally for (var i = 0; i < clouds.children.length; i++) { var cloud = clouds.children[i]; cloud.x += cloud.speedX; // Loop clouds when they move off screen if (cloud.x > 2048 + cloud.width) { cloud.x = -cloud.width; cloud.y = 200 + Math.random() * 400; } } }; return self; }); var Bullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 12; self.direction = { x: 0, y: -1 }; // Default upward self.lifespan = 120; // 2 seconds at 60fps self.age = 0; self.damage = 1; self.update = function () { self.x += self.direction.x * self.speed; self.y += self.direction.y * self.speed; self.age++; if (self.age > self.lifespan) { self.markForDeletion = true; } }; return self; }); var Criminal = Container.expand(function () { var self = Container.call(this); var criminalGraphics = self.attachAsset('criminal', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 2; self.health = 2; // Reduced from 3 self.shootCooldown = 0; self.shootDelay = 120; // Frames between shots self.attackRange = 300; // Reduced from 500 self.movePattern = Math.floor(Math.random() * 3); // 0: direct, 1: zigzag, 2: circle self.moveTimer = 0; self.update = function () { // Target the player var dx = player.x - self.x; var dy = player.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); // Movement based on pattern if (distance > 100) { // Keep some distance var moveX = 0; var moveY = 0; switch (self.movePattern) { case 0: // Direct moveX = dx / distance; moveY = dy / distance; break; case 1: // Zigzag self.moveTimer++; moveX = dx / distance + Math.sin(self.moveTimer * 0.1) * 0.5; moveY = dy / distance; break; case 2: // Circle self.moveTimer++; moveX = dx / distance + Math.sin(self.moveTimer * 0.05) * 0.8; moveY = dy / distance + Math.cos(self.moveTimer * 0.05) * 0.8; break; } self.x += moveX * self.speed; self.y += moveY * self.speed; } // Shooting logic if (distance < self.attackRange) { if (self.shootCooldown <= 0) { // Create enemy bullet var bullet = new Bullet(); bullet.x = self.x; bullet.y = self.y; // Calculate direction toward player var dirX = dx / distance; var dirY = dy / distance; bullet.direction = { x: dirX, y: dirY }; // Mark as enemy bullet bullet.isEnemyBullet = true; // Add to game's bullets array bullets.push(bullet); game.addChild(bullet); // Reset cooldown with some randomness self.shootCooldown = self.shootDelay + Math.random() * 60; } } if (self.shootCooldown > 0) { self.shootCooldown--; } }; self.takeDamage = function () { self.health--; LK.effects.flashObject(self, 0xFF0000, 300); if (self.health <= 0) { LK.getSound('criminal_down').play(); LK.setScore(LK.getScore() + 1); self.markForDeletion = true; // Track criminal elimination task var eliminateTask = tasks.find(function (task) { return task.id === 'eliminate'; }); if (eliminateTask && !eliminateTask.completed) { eliminateTask.count++; if (eliminateTask.count >= eliminateTask.target) { eliminateTask.completed = true; LK.effects.flashObject(taskTexts[1], 0x00FF00, 1000); } updateTaskDisplay(); } } }; return self; }); var EmergencyCall = Container.expand(function () { var self = Container.call(this); var callGraphics = self.attachAsset('emergencyCall', { anchorX: 0.5, anchorY: 0.5 }); self.lifetime = 600; // 10 seconds at 60fps self.age = 0; self.flashInterval = 30; self.update = function () { self.age++; // Flash effect if (self.age % self.flashInterval === 0) { if (callGraphics.alpha === 1) { tween(callGraphics, { alpha: 0.3 }, { duration: 500 }); } else { tween(callGraphics, { alpha: 1 }, { duration: 500 }); } } // Expire after lifetime if (self.age > self.lifetime) { self.markForDeletion = true; } }; self.down = function () { // Responding to call LK.getSound('radiochatter').play(); // Spawn criminals from top of screen, using emergency call's X position spawnCriminals(self.x, 0, 2 + Math.floor(Math.random() * 3)); self.markForDeletion = true; // Increase score for responding LK.setScore(LK.getScore() + 2); // Track emergency call response task var respondTask = tasks.find(function (task) { return task.id === 'respond'; }); if (respondTask && !respondTask.completed) { respondTask.count++; if (respondTask.count >= respondTask.target) { respondTask.completed = true; LK.effects.flashObject(taskTexts[0], 0x00FF00, 1000); } updateTaskDisplay(); } }; return self; }); var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.health = 100; self.maxHealth = 100; self.shootCooldown = 0; self.shootDelay = 15; // Frames between shots self.canMove = true; // Health bar setup var healthBarBg = self.attachAsset('healthBarBackground', { anchorX: 0.5, anchorY: 0, y: 120 }); var healthBarFill = self.attachAsset('healthBar', { anchorX: 0.5, anchorY: 0, y: 122 }); self.updateHealthBar = function () { var healthPercentage = self.health / self.maxHealth; healthBarFill.scale.x = healthPercentage; // Center the health bar healthBarFill.x = -100 * (1 - healthPercentage); }; self.takeDamage = function (amount) { self.health -= amount; if (self.health <= 0) { self.health = 0; LK.effects.flashScreen(0xFF0000, 1000); LK.showGameOver(); } self.updateHealthBar(); }; self.shoot = function () { if (self.shootCooldown <= 0) { var bullet = new Bullet(); bullet.x = self.x; bullet.y = self.y - 40; // Add to game's bullets array bullets.push(bullet); game.addChild(bullet); // Play gun sound LK.getSound('gunshot').play(); // Reset cooldown self.shootCooldown = self.shootDelay; } }; self.update = function () { if (self.shootCooldown > 0) { self.shootCooldown--; } }; self.down = function (x, y, obj) { self.shoot(); }; // Initialize health bar self.updateHealthBar(); return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x1a3c80 }); /**** * Game Code ****/ // Game variables var player; var bullets = []; var criminals = []; var emergencyCalls = []; var gameActive = true; var dragOffset = { x: 0, y: 0 }; var gameLevel = 1; var spawnTimer = 0; var maxCriminals = 10; var emergencyCallTimer = 0; // Game tasks var tasks = [{ id: 'respond', text: 'Respond to emergency calls', count: 0, target: 5, completed: false }, { id: 'eliminate', text: 'Eliminate criminals', count: 0, target: 15, completed: false }, { id: 'survive', text: 'Survive to level 3', count: 1, target: 3, completed: false }]; // Setup task UI var taskContainer = new Container(); taskContainer.x = 40; taskContainer.y = 180; LK.gui.left.addChild(taskContainer); var taskTitle = new Text2('TASKS:', { size: 50, fill: 0xFFFFFF }); taskContainer.addChild(taskTitle); // Create text for each task var taskTexts = []; for (var i = 0; i < tasks.length; i++) { var taskText = new Text2('• ' + tasks[i].text + ' (0/' + tasks[i].target + ')', { size: 40, fill: 0xCCCCCC }); taskText.y = 60 + i * 50; taskContainer.addChild(taskText); taskTexts.push(taskText); } // Function to update task UI function updateTaskDisplay() { for (var i = 0; i < tasks.length; i++) { var task = tasks[i]; var color = task.completed ? 0x00FF00 : 0xCCCCCC; taskTexts[i].setText('• ' + task.text + ' (' + task.count + '/' + task.target + ')'); taskTexts[i].fill = color; } } // Setup UI var scoreTxt = new Text2('Score: 0', { size: 70, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); var levelTxt = new Text2('Level: 1', { size: 70, fill: 0xFFFFFF }); levelTxt.anchor.set(0.5, 0); levelTxt.y = 80; LK.gui.top.addChild(levelTxt); // Create and add beautiful background var background = new Background(); game.addChild(background); // Initialize player player = new Player(); player.x = 2048 / 2; player.y = 2732 / 2; game.addChild(player); // Play background music LK.playMusic('background_music'); // Spawn criminals at a position function spawnCriminals(x, y, count) { for (var i = 0; i < count; i++) { if (criminals.length < maxCriminals) { var criminal = new Criminal(); // Randomize spawn position only at top of screen var spawnX = Math.random() * (2048 - 100) + 50; var spawnY = -50; // Start above the screen criminal.x = spawnX; criminal.y = spawnY; criminals.push(criminal); game.addChild(criminal); } } } // Create an emergency call at a random position function createEmergencyCall() { var call = new EmergencyCall(); call.x = Math.random() * (2048 - 200) + 100; // Keep away from edges call.y = Math.random() * (2732 - 200) + 100; // Keep away from edges emergencyCalls.push(call); game.addChild(call); // Play siren sound LK.getSound('siren').play(); } // Check if a level up should occur function checkLevelUp() { var score = LK.getScore(); var newLevel = Math.floor(score / 10) + 1; if (newLevel > gameLevel) { gameLevel = newLevel; levelTxt.setText('Level: ' + gameLevel); // Increase difficulty maxCriminals = 10 + gameLevel * 2; // Bonus for reaching new level player.health = Math.min(player.maxHealth, player.health + 20); player.updateHealthBar(); // Visual feedback LK.effects.flashScreen(0x00FF00, 500); // Track survival task progress var surviveTask = tasks.find(function (task) { return task.id === 'survive'; }); if (surviveTask && !surviveTask.completed) { surviveTask.count = gameLevel; if (surviveTask.count >= surviveTask.target) { surviveTask.completed = true; LK.effects.flashObject(taskTexts[2], 0x00FF00, 1000); } updateTaskDisplay(); } } } // Game drag handling game.down = function (x, y, obj) { if (!player.canMove) return; // Calculate offset for dragging dragOffset.x = player.x - x; dragOffset.y = player.y - y; player.shoot(); }; game.move = function (x, y, obj) { if (!player.canMove) return; // Move player with drag player.x = x + dragOffset.x; player.y = y + dragOffset.y; // Keep player in bounds player.x = Math.max(50, Math.min(2048 - 50, player.x)); player.y = Math.max(50, Math.min(2732 - 50, player.y)); }; game.up = function () { // Add any logic needed when touch/click is released }; // Game update loop game.update = function () { if (!gameActive) return; // Update background elements background.update(); // Update score display scoreTxt.setText('Score: ' + LK.getScore()); // Update player player.update(); // Update bullets for (var i = bullets.length - 1; i >= 0; i--) { var bullet = bullets[i]; bullet.update(); // Check for off-screen bullets if (bullet.x < 0 || bullet.x > 2048 || bullet.y < 0 || bullet.y > 2732 || bullet.markForDeletion) { bullet.destroy(); bullets.splice(i, 1); continue; } // Check for bullet collisions if (bullet.isEnemyBullet) { // Enemy bullets hit player if (bullet.intersects(player)) { player.takeDamage(10); bullet.destroy(); bullets.splice(i, 1); continue; } } else { // Player bullets hit criminals for (var j = criminals.length - 1; j >= 0; j--) { if (bullet.intersects(criminals[j])) { criminals[j].takeDamage(); bullet.destroy(); bullets.splice(i, 1); break; } } } } // Update criminals for (var k = criminals.length - 1; k >= 0; k--) { var criminal = criminals[k]; criminal.update(); // Check for criminal-player collision if (criminal.intersects(player)) { player.takeDamage(5); LK.effects.flashObject(player, 0xFF0000, 500); // Push player away from criminal var dx = player.x - criminal.x; var dy = player.y - criminal.y; var dist = Math.sqrt(dx * dx + dy * dy); if (dist > 0) { player.x += dx / dist * 30; player.y += dy / dist * 30; } } // Remove dead criminals if (criminal.markForDeletion) { criminal.destroy(); criminals.splice(k, 1); } } // Update emergency calls for (var m = emergencyCalls.length - 1; m >= 0; m--) { emergencyCalls[m].update(); if (emergencyCalls[m].markForDeletion) { emergencyCalls[m].destroy(); emergencyCalls.splice(m, 1); } } // Spawn logic spawnTimer++; if (spawnTimer > 180 && criminals.length < maxCriminals) { // Every 3 seconds spawnCriminals(Math.random() * 2048, 0, 1 + Math.floor(Math.random() * gameLevel)); spawnTimer = 0; } // Emergency call logic emergencyCallTimer++; if (emergencyCallTimer > 600 && emergencyCalls.length < 3) { // Every 10 seconds createEmergencyCall(); emergencyCallTimer = 0; } // Check for level up checkLevelUp(); // Check if all tasks are completed var allTasksCompleted = tasks.every(function (task) { return task.completed; }); if (allTasksCompleted && gameActive) { // Show mission complete message var missionComplete = new Text2('ALL TASKS COMPLETED!', { size: 100, fill: 0x00FF00 }); missionComplete.anchor.set(0.5, 0.5); missionComplete.x = 2048 / 2; missionComplete.y = 2732 / 2; game.addChild(missionComplete); // Give player bonus health and a visual indication player.health = player.maxHealth; player.updateHealthBar(); LK.effects.flashScreen(0x00FF00, 1000); // Create new tasks with higher requirements for continued gameplay tasks = [{ id: 'respond', text: 'Respond to emergency calls', count: 0, target: 10, completed: false }, { id: 'eliminate', text: 'Eliminate criminals', count: 0, target: 30, completed: false }, { id: 'survive', text: 'Survive to level 5', count: gameLevel, target: 5, completed: false }]; // Update task display for (var i = 0; i < tasks.length; i++) { taskTexts[i].setText('• ' + tasks[i].text + ' (0/' + tasks[i].target + ')'); taskTexts[i].fill = 0xCCCCCC; } // Remove the mission complete text after 3 seconds LK.setTimeout(function () { missionComplete.destroy(); updateTaskDisplay(); }, 3000); } };
===================================================================
--- original.js
+++ change.js
@@ -6,8 +6,127 @@
/****
* Classes
****/
+var Background = Container.expand(function () {
+ var self = Container.call(this);
+ // Create sky gradient
+ var skyGradient = new Container();
+ // Create several bands of sky color
+ var skyColors = [0x1a3c80, 0x3a5c9f, 0x5a7cbf, 0x7a9cdf, 0x9abcff];
+ var bandHeight = 2732 / skyColors.length;
+ for (var i = 0; i < skyColors.length; i++) {
+ var skyBand = LK.getAsset('skyBand' + i, {
+ width: 2048,
+ height: bandHeight,
+ color: skyColors[i],
+ shape: 'box',
+ y: i * bandHeight
+ });
+ skyGradient.addChild(skyBand);
+ }
+ self.addChild(skyGradient);
+ // Create buildings
+ var buildings = new Container();
+ self.addChild(buildings);
+ // Far buildings (darker)
+ var buildingColors = [0x222a40, 0x323a50, 0x424a60];
+ var buildingCount = 15;
+ for (var i = 0; i < buildingCount; i++) {
+ var buildingWidth = 100 + Math.random() * 150;
+ var buildingHeight = 300 + Math.random() * 400;
+ var building = LK.getAsset('building_far_' + i, {
+ width: buildingWidth,
+ height: buildingHeight,
+ color: buildingColors[Math.floor(Math.random() * buildingColors.length)],
+ shape: 'box',
+ x: i * (2048 / buildingCount),
+ y: 2732 - buildingHeight,
+ anchorY: 0
+ });
+ buildings.addChild(building);
+ }
+ // Near buildings (slightly lighter)
+ var nearBuildingColors = [0x303a50, 0x404a60, 0x505a70];
+ var nearBuildingCount = 10;
+ for (var i = 0; i < nearBuildingCount; i++) {
+ var buildingWidth = 180 + Math.random() * 150;
+ var buildingHeight = 500 + Math.random() * 600;
+ var building = LK.getAsset('building_near_' + i, {
+ width: buildingWidth,
+ height: buildingHeight,
+ color: nearBuildingColors[Math.floor(Math.random() * nearBuildingColors.length)],
+ shape: 'box',
+ x: i * (2048 / nearBuildingCount),
+ y: 2732 - buildingHeight,
+ anchorY: 0
+ });
+ buildings.addChild(building);
+ }
+ // Add some windows to buildings (as small yellow rectangles)
+ for (var b = 0; b < buildings.children.length; b++) {
+ var building = buildings.children[b];
+ var windowCount = Math.floor(building.width / 30) * Math.floor(building.height / 40);
+ // Limit window count for performance
+ windowCount = Math.min(windowCount, 20);
+ for (var w = 0; w < windowCount; w++) {
+ var windowSize = 10 + Math.random() * 10;
+ var windowX = Math.random() * (building.width - windowSize);
+ var windowY = Math.random() * (building.height - windowSize);
+ // Only add some windows (randomized lighting effect)
+ if (Math.random() > 0.4) {
+ var windowLight = LK.getAsset('window_' + b + '_' + w, {
+ width: windowSize,
+ height: windowSize,
+ color: Math.random() > 0.7 ? 0xffcc66 : 0x888888,
+ // Some windows lit, some not
+ shape: 'box',
+ x: building.x + windowX,
+ y: building.y + windowY
+ });
+ self.addChild(windowLight);
+ }
+ }
+ }
+ // Add clouds
+ var clouds = new Container();
+ self.clouds = clouds;
+ self.addChild(clouds);
+ var cloudCount = 6;
+ for (var i = 0; i < cloudCount; i++) {
+ var cloudWidth = 200 + Math.random() * 300;
+ var cloudHeight = 100 + Math.random() * 100;
+ var cloud = LK.getAsset('cloud_' + i, {
+ width: cloudWidth,
+ height: cloudHeight,
+ color: 0xddddff,
+ shape: 'ellipse',
+ x: Math.random() * 2048,
+ y: 200 + Math.random() * 400,
+ alpha: 0.7
+ });
+ // Add some variation to clouds with slight scaling
+ cloud.scaleX = 0.8 + Math.random() * 0.4;
+ cloud.scaleY = 0.8 + Math.random() * 0.4;
+ // Store cloud speed for animation
+ cloud.speedX = 0.2 + Math.random() * 0.3;
+ clouds.addChild(cloud);
+ }
+ // Update function to animate clouds
+ self.update = function () {
+ // Move clouds horizontally
+ for (var i = 0; i < clouds.children.length; i++) {
+ var cloud = clouds.children[i];
+ cloud.x += cloud.speedX;
+ // Loop clouds when they move off screen
+ if (cloud.x > 2048 + cloud.width) {
+ cloud.x = -cloud.width;
+ cloud.y = 200 + Math.random() * 400;
+ }
+ }
+ };
+ return self;
+});
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
@@ -249,9 +368,9 @@
/****
* Initialize Game
****/
var game = new LK.Game({
- backgroundColor: 0x333333
+ backgroundColor: 0x1a3c80
});
/****
* Game Code
@@ -333,8 +452,11 @@
});
levelTxt.anchor.set(0.5, 0);
levelTxt.y = 80;
LK.gui.top.addChild(levelTxt);
+// Create and add beautiful background
+var background = new Background();
+game.addChild(background);
// Initialize player
player = new Player();
player.x = 2048 / 2;
player.y = 2732 / 2;
@@ -416,8 +538,10 @@
};
// Game update loop
game.update = function () {
if (!gameActive) return;
+ // Update background elements
+ background.update();
// Update score display
scoreTxt.setText('Score: ' + LK.getScore());
// Update player
player.update();