User prompt
Arrange the lava tiles in sequence order
User prompt
Increase the deapth text to picture
Code edit (2 edits merged)
Please save this source code
User prompt
Gems should disappear when collected
Code edit (1 edits merged)
Please save this source code
User prompt
Make the score text big
User prompt
Move everything to the centre as it is now
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot set properties of undefined (setting 'x')' in or related to this line: 'depthText.x = 2048 / 2 + 50; // Slightly moved towards the center' Line Number: 291
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot set properties of undefined (setting 'x')' in or related to this line: 'depthText.x = 2048 / 2 + 50; // Slightly moved towards the center' Line Number: 291
User prompt
Move little to the centre
User prompt
Move deapth and score to the Right centre
User prompt
Fix the bug with tiles
User prompt
Ensure all gems collection
User prompt
Fix the bug
User prompt
Make gem disappear when collected
User prompt
Fix the bug
User prompt
After some certain depth the minner is not able to collect gem . please fix it
User prompt
Restrict upward movement for miner
User prompt
Fix the minner movement bug left and right
User prompt
When player touches the lava the screen should flash red and. Okay danger sound ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Fix all bugs
User prompt
Make levels for certain depth
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1", { highScore: 0 }); /**** * Classes ****/ var Miner = Container.expand(function () { var self = Container.call(this); self.sprite = self.attachAsset('miner', { anchorX: 0.5, anchorY: 0.5 }); self.gridX = 0; self.gridY = 0; self.moving = false; self.moveTo = function (x, y) { if (self.moving) { return false; } var oldX = self.gridX; var oldY = self.gridY; self.gridX = x; self.gridY = y; self.moving = true; tween(self, { x: x * TILE_SIZE, y: y * TILE_SIZE }, { duration: 100, easing: tween.easeOut, onFinish: function onFinish() { self.moving = false; } }); return true; }; return self; }); var Monster = Container.expand(function (startX, startY, patrolRange) { var self = Container.call(this); self.sprite = self.attachAsset('monster', { anchorX: 0.5, anchorY: 0.5 }); self.gridX = startX; self.gridY = startY; self.patrolRange = patrolRange || 3; self.startX = startX; self.moving = false; self.direction = 1; // 1 right, -1 left self.update = function () { if (self.moving) { return; } if (Math.abs(self.gridX - self.startX) >= self.patrolRange) { self.direction *= -1; } var nextX = self.gridX + self.direction; if (isValidMove(nextX, self.gridY)) { self.moveTo(nextX, self.gridY); } else { self.direction *= -1; } }; self.moveTo = function (x, y) { self.moving = true; self.gridX = x; self.gridY = y; tween(self, { x: x * TILE_SIZE, y: y * TILE_SIZE }, { duration: 300, easing: tween.linear, onFinish: function onFinish() { self.moving = false; } }); }; return self; }); var StatusBar = Container.expand(function (type, width, height) { var self = Container.call(this); self.maxValue = 100; self.currentValue = 100; var borderAsset = type + 'Border'; var fillerAsset = type; self.border = self.attachAsset(borderAsset, { anchorX: 0, anchorY: 0 }); self.filler = self.attachAsset(fillerAsset, { anchorX: 0, anchorY: 0, x: 2, y: 2 }); self.setValue = function (value) { self.currentValue = Math.max(0, Math.min(self.maxValue, value)); var percentage = self.currentValue / self.maxValue; self.filler.scale.x = percentage; }; return self; }); var Tile = Container.expand(function (type, x, y) { var self = Container.call(this); self.type = type; self.gridX = x; self.gridY = y; self.revealed = false; var assetId; switch (type) { case 'wall': assetId = 'wall'; break; case 'dirt': assetId = 'dirt'; break; case 'gemCommon': assetId = 'gemCommon'; break; case 'gemRare': assetId = 'gemRare'; break; case 'gemEpic': assetId = 'gemEpic'; break; case 'lava': assetId = 'lava'; break; default: assetId = 'dirt'; break; } self.sprite = self.attachAsset(assetId, { anchorX: 0.5, anchorY: 0.5 }); self.reveal = function () { if (self.revealed) { return; } self.revealed = true; if (self.type === 'dirt') { tween(self.sprite, { alpha: 0 }, { duration: 300, onFinish: function onFinish() { self.sprite.visible = false; } }); } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ function increaseDifficulty() { // Example: Increase monster speed or spawn rate for (var i = 0; i < monsters.length; i++) { monsters[i].patrolRange += 1; // Increase patrol range } // Example: Increase oxygen decrease rate OXYGEN_DECREASE_RATE += 0.01; } // Removed durability asset initialization // Constants var GRID_WIDTH = 15; var GRID_HEIGHT = 100; var TILE_SIZE = 80; var VIEWPORT_HEIGHT = 20; // Number of rows visible at once var OXYGEN_DECREASE_RATE = 0.1; var DRILL_DECREASE_AMOUNT = 5; var MAX_DEPTH = 95; // Maximum depth to consider for win condition // Game variables var grid = []; var miner; var score = 0; var depth = 0; var monsters = []; var viewportOffset = -2; var oxygenBar; var durabilityBar; var scoreText; var depthText; var gameActive = true; // Initialize game elements game.setBackgroundColor(0x222222); // Add touch control for miner movement var startX, startY, endX, endY; game.down = function (x, y, obj) { startX = x; startY = y; }; game.up = function (x, y, obj) { endX = x; endY = y; handleSwipe(); }; function handleSwipe() { var dx = endX - startX; var dy = endY - startY; var absDx = Math.abs(dx); var absDy = Math.abs(dy); if (absDx > absDy) { // Horizontal swipe if (dx > 0) { handleMovement(1, 0); // Swipe right } else { handleMovement(-1, 0); // Swipe left } } else { // Vertical swipe if (dy > 0) { handleMovement(0, 1); // Swipe down } else { handleMovement(0, -1); // Swipe up } } } function initGame() { // Reset game variables grid = []; monsters = []; score = 0; depth = 0; viewportOffset = 0; gameActive = true; // Generate the grid generateGrid(); // Create miner miner = new Miner(); miner.x = Math.floor(GRID_WIDTH / 2) * TILE_SIZE; miner.y = 0; miner.gridX = Math.floor(GRID_WIDTH / 2); miner.gridY = 0; game.addChild(miner); // Spawn monsters spawnMonsters(); // Create UI createUI(); // Start background music LK.playMusic('bgMusic'); } function createUI() { // Health bar healthBar = new StatusBar('health'); healthBar.x = 20; healthBar.y = 20; LK.gui.topLeft.addChild(healthBar); // Removed durability bar from the UI // Score text scoreText = new Text2("Score: 0", { size: 40, fill: 0xFFFFFF }); scoreText.anchor.set(0.5, 0); scoreText.x = 2048 / 2 + 50; // Slightly moved towards the center scoreText.y = 100; // Positioned below the top LK.gui.top.addChild(scoreText); // Depth text depthText = new Text2("Depth: 0m", { size: 40, fill: 0xFFFFFF }); depthText.anchor.set(0.5, 0); depthText.x = 2048 / 2 + 50; // Slightly moved towards the center depthText.y = 150; // Positioned below the score text LK.gui.top.addChild(depthText); // Restart button var restartButton = new Text2("Restart", { size: 40, fill: 0xFFFFFF }); restartButton.anchor.set(0.5, 0); restartButton.x = 2048 / 2; // Centered horizontally restartButton.y = 100; // Positioned below the depth text restartButton.interactive = true; restartButton.buttonMode = true; restartButton.on('pointerdown', function () { initGame(); // Restart the game when the button is pressed }); LK.gui.top.addChild(restartButton); // Movement buttons var buttonSize = 80; var buttonOffset = 20; // Left button var leftButton = new Text2("<", { size: 40, fill: 0xFFFFFF }); leftButton.anchor.set(0.5, 0.5); leftButton.x = 2048 / 2 - buttonSize * 2.5; // Adjusted position leftButton.y = 2732 - buttonOffset - buttonSize * 2.5; leftButton.interactive = true; leftButton.buttonMode = true; leftButton.on('pointerdown', function () { if (gameActive) { handleMovement(-1, 0); } }); LK.gui.bottomLeft.addChild(leftButton); // Right button var rightButton = new Text2(">", { size: 40, fill: 0xFFFFFF }); rightButton.anchor.set(0.5, 0.5); rightButton.x = 2048 - buttonOffset - buttonSize; // Positioned on the right side rightButton.y = 2732 - buttonOffset - buttonSize * 2.5; rightButton.interactive = true; rightButton.buttonMode = true; rightButton.on('pointerdown', function () { if (gameActive) { handleMovement(1, 0); } }); LK.gui.bottomRight.addChild(rightButton); // Control button on the right side var controlButton = new Text2("C", { size: 40, fill: 0xFFFFFF }); controlButton.anchor.set(0.5, 0.5); controlButton.x = 2048 - buttonOffset - buttonSize; // Positioned on the right side controlButton.y = 2732 - buttonOffset - buttonSize * 1.5; controlButton.interactive = true; controlButton.buttonMode = true; controlButton.on('pointerdown', function () { console.log("Control button pressed"); }); LK.gui.bottomRight.addChild(controlButton); // Up button var upButton = new Text2("^", { size: 40, fill: 0xFFFFFF }); upButton.anchor.set(0.5, 0.5); upButton.x = 2048 / 2; // Adjusted position upButton.y = 2732 - buttonOffset - buttonSize * 3.5; upButton.interactive = true; upButton.buttonMode = true; upButton.on('pointerdown', function () { if (gameActive) { handleMovement(0, -1); } }); LK.gui.bottomLeft.addChild(upButton); // Down button var downButton = new Text2("v", { size: 40, fill: 0xFFFFFF }); downButton.anchor.set(0.5, 0.5); downButton.x = 2048 / 2; // Adjusted position downButton.y = 2732 - buttonOffset - buttonSize * 1.5; downButton.interactive = true; downButton.buttonMode = true; downButton.on('pointerdown', function () { if (gameActive) { handleMovement(0, 1); } }); LK.gui.bottomLeft.addChild(downButton); } function generateGrid() { // Clear existing grid for (var i = 0; i < grid.length; i++) { for (var j = 0; j < grid[i].length; j++) { if (grid[i][j] && grid[i][j].parent) { grid[i][j].parent.removeChild(grid[i][j]); } } } // Generate new grid for (var y = 0; y < GRID_HEIGHT; y++) { grid[y] = []; for (var x = 0; x < GRID_WIDTH; x++) { var type = 'dirt'; // Edge walls if (x === 0 || x === GRID_WIDTH - 1) { type = 'wall'; } // Random walls else if (y > 0 && Math.random() < 0.1) { type = 'wall'; } // Gems (more valuable as you go deeper) else if (Math.random() < 0.05) { if (y > 60) { type = 'gemEpic'; } else if (y > 30) { type = 'gemRare'; } else { type = 'gemCommon'; } } // Lava (more common as you go deeper) else if (y > 10 && Math.random() < 0.02 + y / 1000) { type = 'lava'; } var tile = new Tile(type, x, y); tile.x = x * TILE_SIZE; tile.y = y * TILE_SIZE; grid[y][x] = tile; game.addChild(tile); // Initial tiles should be visible if (y < 2) { tile.reveal(); } } } } function spawnMonsters() { // Add monsters at various depths for (var i = 0; i < 10; i++) { var depth = 10 + i * 8; var x = 1 + Math.floor(Math.random() * (GRID_WIDTH - 2)); var monster = new Monster(x, depth, 3 + Math.floor(i / 3)); monster.x = x * TILE_SIZE; monster.y = depth * TILE_SIZE; monsters.push(monster); game.addChild(monster); } } function updateViewport() { var targetOffset = Math.max(0, miner.gridY - Math.floor(VIEWPORT_HEIGHT / 2)); if (targetOffset !== viewportOffset) { viewportOffset = targetOffset; // Adjust all elements based on new viewport for (var y = 0; y < GRID_HEIGHT; y++) { for (var x = 0; x < GRID_WIDTH; x++) { if (grid[y] && grid[y][x]) { grid[y][x].y = (y - viewportOffset) * TILE_SIZE; } } } // Adjust monsters for (var i = 0; i < monsters.length; i++) { monsters[i].y = (monsters[i].gridY - viewportOffset) * TILE_SIZE; } // Adjust miner miner.y = (miner.gridY - viewportOffset) * TILE_SIZE; } } function isValidMove(x, y) { // Check bounds if (x < 0 || x >= GRID_WIDTH || y < 0 || y >= GRID_HEIGHT) { return false; } // Check if position is valid if (!grid[y] || !grid[y][x]) { return false; } // Can't move through walls if (grid[y][x].type === 'wall') { return false; } return true; } function handleTileInteraction(x, y) { if (!grid[y] || !grid[y][x] || !gameActive) { return; } var tile = grid[y][x]; // Reveal the tile tile.reveal(); // Collect gems if (tile.type.includes('gem')) { var gemValue = 0; var oxygenBoost = 0; if (tile.type === 'gemCommon') { gemValue = 10; oxygenBoost = 5; } else if (tile.type === 'gemRare') { gemValue = 25; oxygenBoost = 10; } else if (tile.type === 'gemEpic') { gemValue = 50; oxygenBoost = 20; } score += gemValue; scoreText.setText("Score: " + score); // Increase health level by 40% healthBar.setValue(healthBar.currentValue + healthBar.maxValue * 0.4); // Increase health by 40% of max value // Play gem collection sound LK.getSound('gemCollect').play(); // Change tile to dirt after collection tile.type = 'dirt'; tile.sprite.alpha = 0; // Set alpha to 0 to simulate removal tile.revealed = true; // Ensure the tile is marked as revealed } // Check for lava if (tile.type === 'lava') { LK.getSound('danger').play(); // Play danger sound LK.effects.flashScreen(0xFF0000, 1000); // Flash screen red endGame(false); // End game } // Removed durability-related logic // Update depth if this is a new deepest point if (y > depth) { depth = y; depthText.setText("Depth: " + depth + "m"); // Level progression based on depth if (depth > 0 && depth % 10 === 0) { // Increase difficulty or change level settings increaseDifficulty(); } // Check win condition // Removed restriction for miner movement beyond maximum depth } } function checkMonsterCollision() { for (var i = 0; i < monsters.length; i++) { if (monsters[i].gridX === miner.gridX && monsters[i].gridY === miner.gridY) { LK.getSound('danger').play(); LK.effects.flashScreen(0xFF0000, 1000); endGame(false); break; } } } function endGame(win) { gameActive = false; // Update high score if needed if (score > storage.highScore) { storage.highScore = score; } if (win) { LK.showYouWin(); } else { LK.showGameOver(); } } function handleMovement(dx, dy) { if (!gameActive || miner.moving) { return; } var newX = miner.gridX + dx; var newY = miner.gridY + dy; if (isValidMove(newX, newY) && dy >= 0) { if (miner.moveTo(newX, newY)) { handleTileInteraction(newX, newY); miner.x = newX * TILE_SIZE; miner.y = newY * TILE_SIZE; } } } game.update = function () { if (!gameActive) { return; } // Update viewport position updateViewport(); // Update health level healthBar.setValue(healthBar.currentValue - OXYGEN_DECREASE_RATE); if (healthBar.currentValue <= 0) { endGame(false); } // Update monsters for (var i = 0; i < monsters.length; i++) { monsters[i].update(); } // Check for monster collisions checkMonsterCollision(); // Reveal nearby tiles for (var dy = -1; dy <= 1; dy++) { for (var dx = -1; dx <= 1; dx++) { var nx = miner.gridX + dx; var ny = miner.gridY + dy; if (nx >= 0 && nx < GRID_WIDTH && ny >= 0 && ny < GRID_HEIGHT && grid[ny] && grid[ny][nx]) { grid[ny][nx].reveal(); } } } }; // Initialize the game initGame();
===================================================================
--- original.js
+++ change.js
@@ -192,9 +192,9 @@
var miner;
var score = 0;
var depth = 0;
var monsters = [];
-var viewportOffset = 1;
+var viewportOffset = -2;
var oxygenBar;
var durabilityBar;
var scoreText;
var depthText;
Miner. Single Game Texture. In-Game asset. 2d. Blank background. No shadows
Underground monster. Single Game Texture. In-Game asset. 2d. Blank background. No shadows
Gold coin. Single Game Texture. In-Game asset. 2d. Blank background. No shadows
Emarald. Single Game Texture. In-Game asset. 2d. Blank background. No shadows