/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
coins: 0,
autoCollectors: 0,
coinValue: 1,
autoCollectorCost: 50,
coinValueUpgradeCost: 100,
coinSpawnRateUpgradeCost: 75,
coinSpawnRate: 1
});
/****
* Classes
****/
var AutoCollector = Container.expand(function () {
var self = Container.call(this);
var collectorGraphic = self.attachAsset('collector', {
anchorX: 0.5,
anchorY: 0.5
});
var labelText = new Text2('Auto Collector', {
size: 36,
fill: 0xFFFFFF
});
labelText.anchor.set(0.5, 0.5);
self.addChild(labelText);
self.lastCollection = 0;
self.collectionRate = 1000; // Collect once per second
self.update = function () {
// Check if it's time to collect
if (LK.ticks - self.lastCollection >= self.collectionRate / (1000 / 60)) {
self.collect();
self.lastCollection = LK.ticks;
}
};
self.collect = function () {
// Find the nearest coin and collect it
var nearestCoin = null;
var nearestDistance = Infinity;
for (var i = 0; i < activeCoins.length; i++) {
var coin = activeCoins[i];
var distance = Math.sqrt(Math.pow(coin.x - self.x, 2) + Math.pow(coin.y - self.y, 2));
if (distance < nearestDistance) {
nearestDistance = distance;
nearestCoin = coin;
}
}
if (nearestCoin && nearestDistance < 500) {
// Visual feedback
LK.effects.flashObject(self, 0x00FF00, 200);
// Create a visual connection between collector and coin
var connection = LK.getAsset('collector', {
width: 10,
height: 10,
anchorX: 0.5,
anchorY: 0.5,
x: self.x,
y: self.y,
alpha: 0.5
});
game.addChild(connection);
tween(connection, {
x: nearestCoin.x,
y: nearestCoin.y,
alpha: 0
}, {
duration: 200,
onFinish: function onFinish() {
connection.destroy();
nearestCoin.collect();
}
});
}
};
return self;
});
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphic = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = Math.random() * 2 + 1;
self.value = coinValue;
self.update = function () {
self.y += self.speed;
// Slight horizontal oscillation
self.x += Math.sin(LK.ticks / 20) * 0.5;
// Rotate coin slightly
coinGraphic.rotation += 0.02;
};
self.down = function (x, y, obj) {
self.collect();
};
self.collect = function () {
coins += self.value;
LK.getSound('coin_collect').play();
LK.setScore(Math.floor(coins));
// Create coin collection effect
LK.effects.flashObject(self, 0xFFFFFF, 200);
// Animate coin moving toward wallet
tween(self, {
scaleX: 0,
scaleY: 0,
alpha: 0
}, {
duration: 300,
onFinish: function onFinish() {
self.shouldRemove = true;
}
});
};
return self;
});
var UpgradeButton = Container.expand(function (title, cost, description, onPurchase) {
var self = Container.call(this);
var background = self.attachAsset('collector', {
anchorX: 0.5,
anchorY: 0.5,
width: 380,
height: 120,
tint: 0x4CAF50
});
var titleText = new Text2(title, {
size: 30,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0);
titleText.y = -40;
self.addChild(titleText);
var costText = new Text2(cost + " coins", {
size: 24,
fill: 0xFFFF00
});
costText.anchor.set(0.5, 0);
costText.y = 0;
self.addChild(costText);
var descText = new Text2(description, {
size: 18,
fill: 0xFFFFFF
});
descText.anchor.set(0.5, 0);
descText.y = 30;
self.addChild(descText);
self.cost = cost;
self.title = title;
self.updateCost = function (newCost) {
self.cost = newCost;
costText.setText(newCost + " coins");
};
self.down = function (x, y, obj) {
if (coins >= self.cost) {
// Purchase the upgrade
coins -= self.cost;
LK.setScore(Math.floor(coins));
LK.getSound('upgrade_buy').play();
// Visual feedback
LK.effects.flashObject(self, 0x00FF00, 300);
// Call the provided purchase function
onPurchase();
// Save progress
storage.coins = coins;
} else {
// Not enough coins
LK.effects.flashObject(self, 0xFF0000, 300);
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Game variables
var coins = storage.coins || 0;
var autoCollectors = storage.autoCollectors || 0;
var coinValue = storage.coinValue || 1;
var coinSpawnRate = storage.coinSpawnRate || 1;
var autoCollectorCost = storage.autoCollectorCost || 50;
var coinValueUpgradeCost = storage.coinValueUpgradeCost || 100;
var coinSpawnRateUpgradeCost = storage.coinSpawnRateUpgradeCost || 75;
var activeCoins = [];
var collectors = [];
var lastCoinSpawn = 0;
var coinsCollectedThisSession = 0;
// Create UI elements
var coinsText = new Text2("Coins: " + Math.floor(coins), {
size: 60,
fill: 0xFFFFFF
});
coinsText.anchor.set(0.5, 0);
LK.gui.top.addChild(coinsText);
coinsText.y = 50;
var statsText = new Text2("Session Coins: 0\nAuto Collectors: 0\nCoin Value: 1", {
size: 30,
fill: 0xFFFFFF
});
statsText.anchor.set(0, 0);
statsText.x = 50;
statsText.y = 150;
LK.gui.addChild(statsText);
// Create upgrade buttons
var autoCollectorButton = new UpgradeButton("Auto Collector", autoCollectorCost, "Automatically collects nearby coins", function () {
autoCollectors++;
storage.autoCollectors = autoCollectors;
// Create a new collector
var collector = new AutoCollector();
collector.x = 300 + autoCollectors % 3 * 400;
collector.y = 400 + Math.floor(autoCollectors / 3) * 200;
game.addChild(collector);
collectors.push(collector);
// Increase cost for next purchase
autoCollectorCost = Math.floor(autoCollectorCost * 1.5);
storage.autoCollectorCost = autoCollectorCost;
autoCollectorButton.updateCost(autoCollectorCost);
updateStatsText();
});
autoCollectorButton.x = 2048 / 2 - 400;
autoCollectorButton.y = 2732 - 200;
LK.gui.addChild(autoCollectorButton);
var coinValueButton = new UpgradeButton("Coin Value", coinValueUpgradeCost, "Increases the value of each coin", function () {
coinValue++;
storage.coinValue = coinValue;
// Increase cost for next purchase
coinValueUpgradeCost = Math.floor(coinValueUpgradeCost * 1.7);
storage.coinValueUpgradeCost = coinValueUpgradeCost;
coinValueButton.updateCost(coinValueUpgradeCost);
updateStatsText();
});
coinValueButton.x = 2048 / 2;
coinValueButton.y = 2732 - 200;
LK.gui.addChild(coinValueButton);
var spawnRateButton = new UpgradeButton("Coin Rain", coinSpawnRateUpgradeCost, "Increases coin spawn frequency", function () {
coinSpawnRate += 0.5;
storage.coinSpawnRate = coinSpawnRate;
// Increase cost for next purchase
coinSpawnRateUpgradeCost = Math.floor(coinSpawnRateUpgradeCost * 1.6);
storage.coinSpawnRateUpgradeCost = coinSpawnRateUpgradeCost;
spawnRateButton.updateCost(coinSpawnRateUpgradeCost);
updateStatsText();
});
spawnRateButton.x = 2048 / 2 + 400;
spawnRateButton.y = 2732 - 200;
LK.gui.addChild(spawnRateButton);
// Helper functions
function updateStatsText() {
statsText.setText("Session Coins: " + Math.floor(coinsCollectedThisSession) + "\nAuto Collectors: " + autoCollectors + "\nCoin Value: " + coinValue + "\nCoin Spawn Rate: " + coinSpawnRate.toFixed(1) + "x");
}
function spawnCoin() {
var coin = new Coin();
coin.x = Math.random() * (2048 - 200) + 100; // Keep away from edges
coin.y = -100;
game.addChild(coin);
activeCoins.push(coin);
}
// Initialize existing auto collectors
for (var i = 0; i < autoCollectors; i++) {
var collector = new AutoCollector();
collector.x = 300 + i % 3 * 400;
collector.y = 400 + Math.floor(i / 3) * 200;
game.addChild(collector);
collectors.push(collector);
}
// Set initial score
LK.setScore(Math.floor(coins));
updateStatsText();
// Start background music
LK.playMusic('background_music', {
fade: {
start: 0,
end: 0.4,
duration: 1000
}
});
// Game update loop
game.update = function () {
// Update coins text
coinsText.setText("Coins: " + Math.floor(coins));
// Spawn coins periodically
var spawnInterval = Math.max(60 - coinSpawnRate * 10, 10); // Adjust spawn rate based on upgrade
if (LK.ticks - lastCoinSpawn >= spawnInterval) {
spawnCoin();
lastCoinSpawn = LK.ticks;
}
// Update all coins
for (var i = activeCoins.length - 1; i >= 0; i--) {
var coin = activeCoins[i];
// Check if coin is off-screen or marked for removal
if (coin.y > 2732 + 100 || coin.shouldRemove) {
coin.destroy();
activeCoins.splice(i, 1);
}
}
// Save progress periodically (every 5 seconds)
if (LK.ticks % 300 === 0) {
storage.coins = coins;
}
};
// Game interaction
game.down = function (x, y, obj) {
// Handle clicks on the game area (not on specific objects)
};
// For tracking session coins
LK.setInterval(function () {
coinsCollectedThisSession = coins - storage.coins;
updateStatsText();
}, 1000); ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,317 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+var storage = LK.import("@upit/storage.v1", {
+ coins: 0,
+ autoCollectors: 0,
+ coinValue: 1,
+ autoCollectorCost: 50,
+ coinValueUpgradeCost: 100,
+ coinSpawnRateUpgradeCost: 75,
+ coinSpawnRate: 1
+});
+
+/****
+* Classes
+****/
+var AutoCollector = Container.expand(function () {
+ var self = Container.call(this);
+ var collectorGraphic = self.attachAsset('collector', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var labelText = new Text2('Auto Collector', {
+ size: 36,
+ fill: 0xFFFFFF
+ });
+ labelText.anchor.set(0.5, 0.5);
+ self.addChild(labelText);
+ self.lastCollection = 0;
+ self.collectionRate = 1000; // Collect once per second
+ self.update = function () {
+ // Check if it's time to collect
+ if (LK.ticks - self.lastCollection >= self.collectionRate / (1000 / 60)) {
+ self.collect();
+ self.lastCollection = LK.ticks;
+ }
+ };
+ self.collect = function () {
+ // Find the nearest coin and collect it
+ var nearestCoin = null;
+ var nearestDistance = Infinity;
+ for (var i = 0; i < activeCoins.length; i++) {
+ var coin = activeCoins[i];
+ var distance = Math.sqrt(Math.pow(coin.x - self.x, 2) + Math.pow(coin.y - self.y, 2));
+ if (distance < nearestDistance) {
+ nearestDistance = distance;
+ nearestCoin = coin;
+ }
+ }
+ if (nearestCoin && nearestDistance < 500) {
+ // Visual feedback
+ LK.effects.flashObject(self, 0x00FF00, 200);
+ // Create a visual connection between collector and coin
+ var connection = LK.getAsset('collector', {
+ width: 10,
+ height: 10,
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: self.x,
+ y: self.y,
+ alpha: 0.5
+ });
+ game.addChild(connection);
+ tween(connection, {
+ x: nearestCoin.x,
+ y: nearestCoin.y,
+ alpha: 0
+ }, {
+ duration: 200,
+ onFinish: function onFinish() {
+ connection.destroy();
+ nearestCoin.collect();
+ }
+ });
+ }
+ };
+ return self;
+});
+var Coin = Container.expand(function () {
+ var self = Container.call(this);
+ var coinGraphic = self.attachAsset('coin', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = Math.random() * 2 + 1;
+ self.value = coinValue;
+ self.update = function () {
+ self.y += self.speed;
+ // Slight horizontal oscillation
+ self.x += Math.sin(LK.ticks / 20) * 0.5;
+ // Rotate coin slightly
+ coinGraphic.rotation += 0.02;
+ };
+ self.down = function (x, y, obj) {
+ self.collect();
+ };
+ self.collect = function () {
+ coins += self.value;
+ LK.getSound('coin_collect').play();
+ LK.setScore(Math.floor(coins));
+ // Create coin collection effect
+ LK.effects.flashObject(self, 0xFFFFFF, 200);
+ // Animate coin moving toward wallet
+ tween(self, {
+ scaleX: 0,
+ scaleY: 0,
+ alpha: 0
+ }, {
+ duration: 300,
+ onFinish: function onFinish() {
+ self.shouldRemove = true;
+ }
+ });
+ };
+ return self;
+});
+var UpgradeButton = Container.expand(function (title, cost, description, onPurchase) {
+ var self = Container.call(this);
+ var background = self.attachAsset('collector', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ width: 380,
+ height: 120,
+ tint: 0x4CAF50
+ });
+ var titleText = new Text2(title, {
+ size: 30,
+ fill: 0xFFFFFF
+ });
+ titleText.anchor.set(0.5, 0);
+ titleText.y = -40;
+ self.addChild(titleText);
+ var costText = new Text2(cost + " coins", {
+ size: 24,
+ fill: 0xFFFF00
+ });
+ costText.anchor.set(0.5, 0);
+ costText.y = 0;
+ self.addChild(costText);
+ var descText = new Text2(description, {
+ size: 18,
+ fill: 0xFFFFFF
+ });
+ descText.anchor.set(0.5, 0);
+ descText.y = 30;
+ self.addChild(descText);
+ self.cost = cost;
+ self.title = title;
+ self.updateCost = function (newCost) {
+ self.cost = newCost;
+ costText.setText(newCost + " coins");
+ };
+ self.down = function (x, y, obj) {
+ if (coins >= self.cost) {
+ // Purchase the upgrade
+ coins -= self.cost;
+ LK.setScore(Math.floor(coins));
+ LK.getSound('upgrade_buy').play();
+ // Visual feedback
+ LK.effects.flashObject(self, 0x00FF00, 300);
+ // Call the provided purchase function
+ onPurchase();
+ // Save progress
+ storage.coins = coins;
+ } else {
+ // Not enough coins
+ LK.effects.flashObject(self, 0xFF0000, 300);
+ }
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x87CEEB
+});
+
+/****
+* Game Code
+****/
+// Game variables
+var coins = storage.coins || 0;
+var autoCollectors = storage.autoCollectors || 0;
+var coinValue = storage.coinValue || 1;
+var coinSpawnRate = storage.coinSpawnRate || 1;
+var autoCollectorCost = storage.autoCollectorCost || 50;
+var coinValueUpgradeCost = storage.coinValueUpgradeCost || 100;
+var coinSpawnRateUpgradeCost = storage.coinSpawnRateUpgradeCost || 75;
+var activeCoins = [];
+var collectors = [];
+var lastCoinSpawn = 0;
+var coinsCollectedThisSession = 0;
+// Create UI elements
+var coinsText = new Text2("Coins: " + Math.floor(coins), {
+ size: 60,
+ fill: 0xFFFFFF
+});
+coinsText.anchor.set(0.5, 0);
+LK.gui.top.addChild(coinsText);
+coinsText.y = 50;
+var statsText = new Text2("Session Coins: 0\nAuto Collectors: 0\nCoin Value: 1", {
+ size: 30,
+ fill: 0xFFFFFF
+});
+statsText.anchor.set(0, 0);
+statsText.x = 50;
+statsText.y = 150;
+LK.gui.addChild(statsText);
+// Create upgrade buttons
+var autoCollectorButton = new UpgradeButton("Auto Collector", autoCollectorCost, "Automatically collects nearby coins", function () {
+ autoCollectors++;
+ storage.autoCollectors = autoCollectors;
+ // Create a new collector
+ var collector = new AutoCollector();
+ collector.x = 300 + autoCollectors % 3 * 400;
+ collector.y = 400 + Math.floor(autoCollectors / 3) * 200;
+ game.addChild(collector);
+ collectors.push(collector);
+ // Increase cost for next purchase
+ autoCollectorCost = Math.floor(autoCollectorCost * 1.5);
+ storage.autoCollectorCost = autoCollectorCost;
+ autoCollectorButton.updateCost(autoCollectorCost);
+ updateStatsText();
+});
+autoCollectorButton.x = 2048 / 2 - 400;
+autoCollectorButton.y = 2732 - 200;
+LK.gui.addChild(autoCollectorButton);
+var coinValueButton = new UpgradeButton("Coin Value", coinValueUpgradeCost, "Increases the value of each coin", function () {
+ coinValue++;
+ storage.coinValue = coinValue;
+ // Increase cost for next purchase
+ coinValueUpgradeCost = Math.floor(coinValueUpgradeCost * 1.7);
+ storage.coinValueUpgradeCost = coinValueUpgradeCost;
+ coinValueButton.updateCost(coinValueUpgradeCost);
+ updateStatsText();
+});
+coinValueButton.x = 2048 / 2;
+coinValueButton.y = 2732 - 200;
+LK.gui.addChild(coinValueButton);
+var spawnRateButton = new UpgradeButton("Coin Rain", coinSpawnRateUpgradeCost, "Increases coin spawn frequency", function () {
+ coinSpawnRate += 0.5;
+ storage.coinSpawnRate = coinSpawnRate;
+ // Increase cost for next purchase
+ coinSpawnRateUpgradeCost = Math.floor(coinSpawnRateUpgradeCost * 1.6);
+ storage.coinSpawnRateUpgradeCost = coinSpawnRateUpgradeCost;
+ spawnRateButton.updateCost(coinSpawnRateUpgradeCost);
+ updateStatsText();
+});
+spawnRateButton.x = 2048 / 2 + 400;
+spawnRateButton.y = 2732 - 200;
+LK.gui.addChild(spawnRateButton);
+// Helper functions
+function updateStatsText() {
+ statsText.setText("Session Coins: " + Math.floor(coinsCollectedThisSession) + "\nAuto Collectors: " + autoCollectors + "\nCoin Value: " + coinValue + "\nCoin Spawn Rate: " + coinSpawnRate.toFixed(1) + "x");
+}
+function spawnCoin() {
+ var coin = new Coin();
+ coin.x = Math.random() * (2048 - 200) + 100; // Keep away from edges
+ coin.y = -100;
+ game.addChild(coin);
+ activeCoins.push(coin);
+}
+// Initialize existing auto collectors
+for (var i = 0; i < autoCollectors; i++) {
+ var collector = new AutoCollector();
+ collector.x = 300 + i % 3 * 400;
+ collector.y = 400 + Math.floor(i / 3) * 200;
+ game.addChild(collector);
+ collectors.push(collector);
+}
+// Set initial score
+LK.setScore(Math.floor(coins));
+updateStatsText();
+// Start background music
+LK.playMusic('background_music', {
+ fade: {
+ start: 0,
+ end: 0.4,
+ duration: 1000
+ }
+});
+// Game update loop
+game.update = function () {
+ // Update coins text
+ coinsText.setText("Coins: " + Math.floor(coins));
+ // Spawn coins periodically
+ var spawnInterval = Math.max(60 - coinSpawnRate * 10, 10); // Adjust spawn rate based on upgrade
+ if (LK.ticks - lastCoinSpawn >= spawnInterval) {
+ spawnCoin();
+ lastCoinSpawn = LK.ticks;
+ }
+ // Update all coins
+ for (var i = activeCoins.length - 1; i >= 0; i--) {
+ var coin = activeCoins[i];
+ // Check if coin is off-screen or marked for removal
+ if (coin.y > 2732 + 100 || coin.shouldRemove) {
+ coin.destroy();
+ activeCoins.splice(i, 1);
+ }
+ }
+ // Save progress periodically (every 5 seconds)
+ if (LK.ticks % 300 === 0) {
+ storage.coins = coins;
+ }
+};
+// Game interaction
+game.down = function (x, y, obj) {
+ // Handle clicks on the game area (not on specific objects)
+};
+// For tracking session coins
+LK.setInterval(function () {
+ coinsCollectedThisSession = coins - storage.coins;
+ updateStatsText();
+}, 1000);
\ No newline at end of file