User prompt
Score and goal should be in the top left corner of the screen
User prompt
level and seconds should be in the top right corner of the screen
User prompt
Score and requested score should be in the upper left corner
User prompt
The level text should be at the top right of the screen.
User prompt
When the rope is empty it should go up faster
User prompt
There should be sections that get harder as you level up.
User prompt
When the rope is empty it should go up faster
User prompt
There should be more gold, more diamonds and more rocks on the screen.
User prompt
the rope should go further down
User prompt
make the background brown
User prompt
make the background light brown
Code edit (1 edits merged)
Please save this source code
User prompt
Gold Miner Classic
Initial prompt
can you make a gold miner game?
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Claw class
var Claw = Container.expand(function () {
var self = Container.call(this);
// Arm
var arm = self.attachAsset('clawArm', {
anchorX: 0.5,
anchorY: 0,
x: 0,
y: 0
});
// Claw head
var head = self.attachAsset('clawHead', {
anchorX: 0.5,
anchorY: 0,
x: 0,
y: arm.height
});
// State
self.swingAngle = 0; // in radians
self.swingDir = 1; // 1 or -1
self.swingSpeed = 0.025; // radians per tick
self.swingMax = Math.PI / 3; // 60 deg left/right
self.state = 'swing'; // 'swing', 'extend', 'retract', 'grabbed'
self.length = arm.height; // current arm length
self.baseLength = arm.height;
self.maxLength = 1700; // how far the claw can extend (increased for longer rope)
self.speed = 32; // pixels per tick when extending
self.retractSpeed = 32; // default retract speed
self.grabbedObj = null; // reference to grabbed object
// Update arm and head positions based on length and angle
self.updateClaw = function () {
var dx = Math.sin(self.swingAngle) * self.length;
var dy = Math.cos(self.swingAngle) * self.length;
arm.rotation = -self.swingAngle;
arm.height = self.length;
head.x = dx;
head.y = dy;
head.rotation = -self.swingAngle;
if (self.grabbedObj) {
self.grabbedObj.x = self.x + dx;
self.grabbedObj.y = self.y + dy + head.height / 2;
}
};
// Called every tick
self.update = function () {
if (self.state === 'swing') {
self.swingAngle += self.swingDir * self.swingSpeed;
if (self.swingAngle > self.swingMax) {
self.swingAngle = self.swingMax;
self.swingDir = -1;
}
if (self.swingAngle < -self.swingMax) {
self.swingAngle = -self.swingMax;
self.swingDir = 1;
}
} else if (self.state === 'extend') {
self.length += self.speed;
if (self.length >= self.maxLength) {
self.length = self.maxLength;
self.state = 'retract';
}
} else if (self.state === 'retract') {
self.length -= self.retractSpeed;
if (self.length <= self.baseLength) {
self.length = self.baseLength;
self.state = 'swing';
if (self.grabbedObj) {
// Drop object at top
self.grabbedObj.onCollected();
self.grabbedObj = null;
}
}
} else if (self.state === 'grabbed') {
// Wait for retract to finish
self.length -= self.retractSpeed;
if (self.length <= self.baseLength) {
self.length = self.baseLength;
self.state = 'swing';
if (self.grabbedObj) {
self.grabbedObj.onCollected();
self.grabbedObj = null;
}
}
}
self.updateClaw();
};
// Start extending
self.startExtend = function () {
if (self.state === 'swing') {
self.state = 'extend';
LK.getSound('grab').play();
}
};
// Called when an object is grabbed
self.grabObject = function (obj) {
self.grabbedObj = obj;
self.state = 'grabbed';
// Set retract speed based on object type
self.retractSpeed = obj.retractSpeed;
LK.getSound(obj.grabSound).play();
};
// Called when nothing is grabbed (hit ground)
self.miss = function () {
self.state = 'retract';
self.retractSpeed = 64; //{L} // Faster retract when empty
};
return self;
});
// Base class for all underground objects
var UndergroundObject = Container.expand(function () {
var self = Container.call(this);
self.value = 0;
self.retractSpeed = 32;
self.grabSound = 'grab';
self.collectedSound = 'collect';
self.collected = false;
// Called when collected
self.onCollected = function () {
if (self.collected) return;
self.collected = true;
LK.getSound(self.collectedSound).play();
self.visible = false;
if (typeof self.onScore === 'function') self.onScore();
self.destroy();
};
return self;
});
// Rock
var Rock = UndergroundObject.expand(function () {
var self = UndergroundObject.call(this);
var rock = self.attachAsset('rock', {
anchorX: 0.5,
anchorY: 0.5
});
self.value = 50;
self.retractSpeed = 6; // very slow
self.grabSound = 'rockhit';
self.collectedSound = 'rockhit';
return self;
});
// Small gold nugget
var GoldSmall = UndergroundObject.expand(function () {
var self = UndergroundObject.call(this);
var gold = self.attachAsset('goldSmall', {
anchorX: 0.5,
anchorY: 0.5
});
self.value = 250;
self.retractSpeed = 24; // medium
self.grabSound = 'grab';
self.collectedSound = 'collect';
return self;
});
// Gold nugget
var Gold = UndergroundObject.expand(function () {
var self = UndergroundObject.call(this);
var gold = self.attachAsset('gold', {
anchorX: 0.5,
anchorY: 0.5
});
self.value = 500;
self.retractSpeed = 12; // slow
self.grabSound = 'grab';
self.collectedSound = 'collect';
return self;
});
// Gem
var Gem = UndergroundObject.expand(function () {
var self = UndergroundObject.call(this);
var gem = self.attachAsset('gem', {
anchorX: 0.5,
anchorY: 0.5
});
self.value = 800;
self.retractSpeed = 32; // fast
self.grabSound = 'grab';
self.collectedSound = 'collect';
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x8B5A2B // brown
});
/****
* Game Code
****/
// Music
// Sound for hitting rock
// Sound for collecting
// Sound for grabbing
// Gem (ellipse)
// Rock (ellipse)
// Small gold nugget
// Gold nugget (ellipse)
// Claw head (ellipse)
// Claw arm (rectangle)
// Game constants
var GAME_WIDTH = 2048;
var GAME_HEIGHT = 2732;
var GROUND_Y = 700; // y position where underground objects start
var LEVEL_TIME = 60; // seconds
var LEVEL_GOAL = 1500; // gold needed to win
// Level and difficulty progression
var level = 1;
var maxLevel = 10;
var objects = [];
var claw = null;
var score = 0;
var timer = 0;
var timeLeft = LEVEL_TIME;
var goal = LEVEL_GOAL;
var gameActive = true;
// GUI
var scoreTxt = new Text2('0', {
size: 120,
fill: 0xFFF8C0
});
scoreTxt.anchor.set(0, 0);
LK.gui.top.addChild(scoreTxt);
scoreTxt.x = 100;
scoreTxt.y = 0;
// Goal text
var goalTxt = new Text2('Goal: ' + goal, {
size: 80,
fill: 0xFFE066
});
goalTxt.anchor.set(0, 0);
LK.gui.top.addChild(goalTxt);
goalTxt.x = 100;
goalTxt.y = 120;
var timerTxt = new Text2('60', {
size: 100,
fill: 0xFFFFFF
});
timerTxt.anchor.set(1, 0);
LK.gui.top.addChild(timerTxt);
timerTxt.y = 120;
// Level text
var levelTxt = new Text2('Level: ' + level, {
size: 80,
fill: 0xB0E0E6
});
levelTxt.anchor.set(1, 0);
LK.gui.top.addChild(levelTxt);
levelTxt.y = 0;
// Place GUI elements, but not in top left 100x100
timerTxt.x = LK.gui.top.width - 120;
levelTxt.x = LK.gui.top.width - 120;
// Place claw at top center
claw = new Claw();
claw.x = GAME_WIDTH / 2;
claw.y = 0;
game.addChild(claw);
// Underground object spawn positions
function spawnObjects() {
// Clear previous
for (var i = 0; i < objects.length; i++) {
objects[i].destroy();
}
objects = [];
// Difficulty scaling
var bigGoldCount = 4 + Math.floor(level / 2);
var smallGoldCount = 6 + level;
var rockCount = 6 + level * 2;
var gemCount = 3 + Math.floor(level / 2);
// Gold (big)
for (var i = 0; i < bigGoldCount; i++) {
var g = new Gold();
g.x = 400 + i % 4 * 350 + Math.floor(i / 4) * 200;
g.y = GROUND_Y + 600 + i % 4 * 120 + Math.floor(i / 4) * 300;
g.onScore = function () {
score += this.value;
LK.setScore(score);
scoreTxt.setText(score);
};
game.addChild(g);
objects.push(g);
}
// Gold (small)
for (var i = 0; i < smallGoldCount; i++) {
var gs = new GoldSmall();
gs.x = 250 + i % 6 * 250 + Math.floor(i / 6) * 200;
gs.y = GROUND_Y + 300 + i % 6 * 180 + Math.floor(i / 6) * 250;
gs.onScore = function () {
score += this.value;
LK.setScore(score);
scoreTxt.setText(score);
};
game.addChild(gs);
objects.push(gs);
}
// Rocks
for (var i = 0; i < rockCount; i++) {
var r = new Rock();
r.x = 500 + i % 8 * 180 + Math.floor(i / 8) * 200;
r.y = GROUND_Y + 800 + i % 8 * 100 + Math.floor(i / 8) * 200;
r.onScore = function () {
score += this.value;
LK.setScore(score);
scoreTxt.setText(score);
};
game.addChild(r);
objects.push(r);
}
// Gems
for (var i = 0; i < gemCount; i++) {
var gem = new Gem();
gem.x = 1200 + i % 4 * 200 + Math.floor(i / 4) * 200;
gem.y = GROUND_Y + 1000 + i % 4 * 120 + Math.floor(i / 4) * 200;
gem.onScore = function () {
score += this.value;
LK.setScore(score);
scoreTxt.setText(score);
};
game.addChild(gem);
objects.push(gem);
}
}
spawnObjects();
// Timer
timer = LK.setInterval(function () {
if (!gameActive) return;
timeLeft -= 1;
if (timeLeft < 0) timeLeft = 0;
timerTxt.setText(timeLeft);
if (timeLeft === 0) {
gameActive = false;
// Game over
LK.effects.flashScreen(0x000000, 800);
LK.showGameOver();
}
}, 1000);
// Touch/click to drop claw
game.down = function (x, y, obj) {
if (!gameActive) return;
if (claw.state === 'swing') {
claw.startExtend();
}
};
// Main update loop
game.update = function () {
if (!gameActive) return;
// Claw update handled in class
// If claw is extending, check for collision with objects
if (claw.state === 'extend') {
// Get claw head position
var dx = Math.sin(claw.swingAngle) * claw.length;
var dy = Math.cos(claw.swingAngle) * claw.length;
var cx = claw.x + dx;
var cy = claw.y + dy + 30; // 30: half head height
// Check for collision with any object
for (var i = 0; i < objects.length; i++) {
var obj = objects[i];
if (obj.collected) continue;
// Simple circle collision
var dist = Math.sqrt((obj.x - cx) * (obj.x - cx) + (obj.y - cy) * (obj.y - cy));
var r = 60; // approx radius
if (dist < r + 40) {
// Grab object
claw.grabObject(obj);
break;
}
}
// If reached max length and nothing grabbed, retract
if (claw.length >= claw.maxLength && claw.state === 'extend') {
claw.miss();
}
}
// Win condition
if (score >= goal && gameActive) {
gameActive = false;
LK.effects.flashScreen(0xffff00, 800);
// Level up logic
if (level < maxLevel) {
level += 1;
// Increase goal and decrease time for next level
goal = LEVEL_GOAL + level * 800;
timeLeft = LEVEL_TIME - Math.min(level * 3, 30); // reduce time, but not below 30s
goalTxt.setText('Goal: ' + goal);
timerTxt.setText(timeLeft);
levelTxt.setText('Level: ' + level);
score = 0;
LK.setScore(score);
scoreTxt.setText(score);
// Respawn objects for new level
spawnObjects();
gameActive = true;
} else {
LK.showYouWin();
}
}
};
// Play background music
LK.playMusic('goldminerbg', {
fade: {
start: 0,
end: 1,
duration: 1000
}
}); ===================================================================
--- original.js
+++ change.js
@@ -228,26 +228,26 @@
fill: 0xFFF8C0
});
scoreTxt.anchor.set(0, 0);
LK.gui.top.addChild(scoreTxt);
-scoreTxt.x = 120;
+scoreTxt.x = 100;
scoreTxt.y = 0;
-var timerTxt = new Text2('60', {
- size: 100,
- fill: 0xFFFFFF
-});
-timerTxt.anchor.set(1, 0);
-LK.gui.top.addChild(timerTxt);
-timerTxt.y = 120;
// Goal text
var goalTxt = new Text2('Goal: ' + goal, {
size: 80,
fill: 0xFFE066
});
goalTxt.anchor.set(0, 0);
LK.gui.top.addChild(goalTxt);
-goalTxt.x = 120;
+goalTxt.x = 100;
goalTxt.y = 120;
+var timerTxt = new Text2('60', {
+ size: 100,
+ fill: 0xFFFFFF
+});
+timerTxt.anchor.set(1, 0);
+LK.gui.top.addChild(timerTxt);
+timerTxt.y = 120;
// Level text
var levelTxt = new Text2('Level: ' + level, {
size: 80,
fill: 0xB0E0E6
gold. In-Game asset. 2d. High contrast. No shadows
diamond. In-Game asset. 2d. High contrast. No shadows
big rock. In-Game asset. 2d. High contrast. No shadows
upright long rope. In-Game asset. 2d. High contrast. No shadows
double pointed hook. In-Game asset. 2d. High contrast. No shadows
big piece of gold. In-Game asset. 2d. High contrast. No shadows
dynamite. In-Game asset. 2d. High contrast. No shadows
pig. In-Game asset. 2d. High contrast. No shadows
soru işareti olan bir torba. In-Game asset. 2d. High contrast. No shadows
Pig with dollar in mouth. In-Game asset. 2d. High contrast. No shadows
tnt yazılı varil. In-Game asset. 2d. High contrast. No shadows