/**** * Classes ****/ // Gold class: falling collectible var Gold = Container.expand(function () { var self = Container.call(this); var goldAsset = self.attachAsset('gold', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10 + Math.random() * 8; // randomize speed a bit self.lastY = 0; self.update = function () { self.lastY = self.y; self.y += self.speed; }; return self; }); // Miner class: player character var Miner = Container.expand(function () { var self = Container.call(this); var minerAsset = self.attachAsset('miner', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () {}; return self; }); // Game variables // Rock class: falling obstacle var Rock = Container.expand(function () { var self = Container.call(this); var rockAsset = self.attachAsset('rock', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 12 + Math.random() * 8; self.lastY = 0; self.update = function () { self.lastY = self.y; self.y += self.speed; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ // Game variables var miner = new Miner(); var golds = []; var rocks = []; var score = 0; var lives = 3; var lastGoldSpawn = 0; var lastRockSpawn = 0; var goldSpawnInterval = 60; // frames var rockSpawnInterval = 90; // frames // Add miner to game, position at bottom center game.addChild(miner); miner.x = 2048 / 2; miner.y = 2732 - 180; // Score and lives display var scoreTxt = new Text2('0', { size: 120, fill: 0xFFD700 }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); var livesTxt = new Text2('❤❤❤', { size: 100, fill: 0xFF4444 }); livesTxt.anchor.set(1, 0); LK.gui.topRight.addChild(livesTxt); // Dragging logic var dragging = false; game.down = function (x, y, obj) { // Only allow drag if touch is on miner or below if (y > miner.y - 120) { dragging = true; miner.x = Math.max(80, Math.min(2048 - 80, x)); } }; game.move = function (x, y, obj) { if (dragging) { miner.x = Math.max(80, Math.min(2048 - 80, x)); } }; game.up = function (x, y, obj) { dragging = false; }; // Update function: spawn, move, check collisions game.update = function () { // Spawn gold if (LK.ticks - lastGoldSpawn > goldSpawnInterval) { var g = new Gold(); g.x = 120 + Math.random() * (2048 - 240); g.y = -80; g.lastY = g.y; golds.push(g); game.addChild(g); lastGoldSpawn = LK.ticks; } // Spawn rocks if (LK.ticks - lastRockSpawn > rockSpawnInterval) { var r = new Rock(); r.x = 120 + Math.random() * (2048 - 240); r.y = -80; r.lastY = r.y; rocks.push(r); game.addChild(r); lastRockSpawn = LK.ticks; } // Update golds for (var i = golds.length - 1; i >= 0; i--) { var g = golds[i]; g.update(); // Check if caught by miner if (!g.caught && g.lastY < miner.y - 40 && g.y >= miner.y - 40 && Math.abs(g.x - miner.x) < 120) { g.caught = true; score += 1; scoreTxt.setText(score); g.destroy(); golds.splice(i, 1); continue; } // Missed gold (falls below screen) if (g.y > 2732 + 80) { g.destroy(); golds.splice(i, 1); lives -= 1; updateLives(); if (lives <= 0) { LK.showGameOver(); return; } } } // Update rocks for (var j = rocks.length - 1; j >= 0; j--) { var r = rocks[j]; r.update(); // Hit by miner if (!r.hit && r.lastY < miner.y - 40 && r.y >= miner.y - 40 && Math.abs(r.x - miner.x) < 120) { r.hit = true; lives -= 1; updateLives(); r.destroy(); rocks.splice(j, 1); if (lives <= 0) { LK.showGameOver(); return; } continue; } // Remove rock if off screen if (r.y > 2732 + 80) { r.destroy(); rocks.splice(j, 1); } } }; // Update lives display function updateLives() { var s = ''; for (var i = 0; i < lives; i++) s += '❤'; livesTxt.setText(s); }
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,176 @@
-/****
+/****
+* Classes
+****/
+// Gold class: falling collectible
+var Gold = Container.expand(function () {
+ var self = Container.call(this);
+ var goldAsset = self.attachAsset('gold', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 10 + Math.random() * 8; // randomize speed a bit
+ self.lastY = 0;
+ self.update = function () {
+ self.lastY = self.y;
+ self.y += self.speed;
+ };
+ return self;
+});
+// Miner class: player character
+var Miner = Container.expand(function () {
+ var self = Container.call(this);
+ var minerAsset = self.attachAsset('miner', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.update = function () {};
+ return self;
+});
+// Game variables
+// Rock class: falling obstacle
+var Rock = Container.expand(function () {
+ var self = Container.call(this);
+ var rockAsset = self.attachAsset('rock', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 12 + Math.random() * 8;
+ self.lastY = 0;
+ self.update = function () {
+ self.lastY = self.y;
+ self.y += self.speed;
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
backgroundColor: 0x000000
-});
\ No newline at end of file
+});
+
+/****
+* Game Code
+****/
+// Game variables
+var miner = new Miner();
+var golds = [];
+var rocks = [];
+var score = 0;
+var lives = 3;
+var lastGoldSpawn = 0;
+var lastRockSpawn = 0;
+var goldSpawnInterval = 60; // frames
+var rockSpawnInterval = 90; // frames
+// Add miner to game, position at bottom center
+game.addChild(miner);
+miner.x = 2048 / 2;
+miner.y = 2732 - 180;
+// Score and lives display
+var scoreTxt = new Text2('0', {
+ size: 120,
+ fill: 0xFFD700
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+var livesTxt = new Text2('❤❤❤', {
+ size: 100,
+ fill: 0xFF4444
+});
+livesTxt.anchor.set(1, 0);
+LK.gui.topRight.addChild(livesTxt);
+// Dragging logic
+var dragging = false;
+game.down = function (x, y, obj) {
+ // Only allow drag if touch is on miner or below
+ if (y > miner.y - 120) {
+ dragging = true;
+ miner.x = Math.max(80, Math.min(2048 - 80, x));
+ }
+};
+game.move = function (x, y, obj) {
+ if (dragging) {
+ miner.x = Math.max(80, Math.min(2048 - 80, x));
+ }
+};
+game.up = function (x, y, obj) {
+ dragging = false;
+};
+// Update function: spawn, move, check collisions
+game.update = function () {
+ // Spawn gold
+ if (LK.ticks - lastGoldSpawn > goldSpawnInterval) {
+ var g = new Gold();
+ g.x = 120 + Math.random() * (2048 - 240);
+ g.y = -80;
+ g.lastY = g.y;
+ golds.push(g);
+ game.addChild(g);
+ lastGoldSpawn = LK.ticks;
+ }
+ // Spawn rocks
+ if (LK.ticks - lastRockSpawn > rockSpawnInterval) {
+ var r = new Rock();
+ r.x = 120 + Math.random() * (2048 - 240);
+ r.y = -80;
+ r.lastY = r.y;
+ rocks.push(r);
+ game.addChild(r);
+ lastRockSpawn = LK.ticks;
+ }
+ // Update golds
+ for (var i = golds.length - 1; i >= 0; i--) {
+ var g = golds[i];
+ g.update();
+ // Check if caught by miner
+ if (!g.caught && g.lastY < miner.y - 40 && g.y >= miner.y - 40 && Math.abs(g.x - miner.x) < 120) {
+ g.caught = true;
+ score += 1;
+ scoreTxt.setText(score);
+ g.destroy();
+ golds.splice(i, 1);
+ continue;
+ }
+ // Missed gold (falls below screen)
+ if (g.y > 2732 + 80) {
+ g.destroy();
+ golds.splice(i, 1);
+ lives -= 1;
+ updateLives();
+ if (lives <= 0) {
+ LK.showGameOver();
+ return;
+ }
+ }
+ }
+ // Update rocks
+ for (var j = rocks.length - 1; j >= 0; j--) {
+ var r = rocks[j];
+ r.update();
+ // Hit by miner
+ if (!r.hit && r.lastY < miner.y - 40 && r.y >= miner.y - 40 && Math.abs(r.x - miner.x) < 120) {
+ r.hit = true;
+ lives -= 1;
+ updateLives();
+ r.destroy();
+ rocks.splice(j, 1);
+ if (lives <= 0) {
+ LK.showGameOver();
+ return;
+ }
+ continue;
+ }
+ // Remove rock if off screen
+ if (r.y > 2732 + 80) {
+ r.destroy();
+ rocks.splice(j, 1);
+ }
+ }
+};
+// Update lives display
+function updateLives() {
+ var s = '';
+ for (var i = 0; i < lives; i++) s += '❤';
+ livesTxt.setText(s);
+}
\ No newline at end of file