54
1
7mo
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Equipment class (for both sword and armor)
var Equipment = Container.expand(function () {
var self = Container.call(this);
self.type = 'sword'; // or 'armor'
self.level = 0;
self.maxLevel = 15;
self.broken = false;
self.asset = null;
self.flame = null;
self.setType = function (type) {
self.type = type;
self.updateVisual();
};
self.setLevel = function (level) {
self.level = level;
self.updateVisual();
};
self.breakItem = function () {
self.broken = true;
self.updateVisual();
};
self.repair = function () {
self.broken = false;
self.updateVisual();
};
self.updateVisual = function () {
// Remove old asset
if (self.asset) {
self.removeChild(self.asset);
self.asset.destroy();
self.asset = null;
}
if (self.flame) {
self.removeChild(self.flame);
self.flame.destroy();
self.flame = null;
}
var assetId;
if (self.type === 'sword') {
if (self.broken) assetId = 'sword_basic';else if (self.level >= 15) assetId = 'sword_red';else if (self.level >= 10) assetId = 'sword_gold';else if (self.level >= 5) assetId = 'sword_blue';else assetId = 'sword_basic';
} else {
if (self.broken) assetId = 'armor_basic';else if (self.level >= 15) assetId = 'armor_red';else if (self.level >= 10) assetId = 'armor_gold';else if (self.level >= 5) assetId = 'armor_blue';else assetId = 'armor_basic';
}
self.asset = self.attachAsset(assetId, {
anchorX: 0.5,
anchorY: 0.5
});
// Add flame effect for +15
if (!self.broken && self.level >= 15) {
self.flame = new Container();
var flameShape = LK.getAsset('sword_red', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.2,
scaleY: 1.2
});
flameShape.alpha = 0.4;
self.flame.addChild(flameShape);
self.flame.x = 0;
self.flame.y = 0;
self.addChild(self.flame);
// Animate flame
tween(self.flame, {
alpha: 0.2
}, {
duration: 400,
easing: tween.sineInOut,
onFinish: function onFinish() {
tween(self.flame, {
alpha: 0.4
}, {
duration: 400,
easing: tween.sineInOut,
onFinish: function onFinish() {
// Loop
if (self.flame) self.updateVisual();
}
});
}
});
}
// If broken, gray out
if (self.broken) {
self.asset.alpha = 0.3;
} else {
self.asset.alpha = 1;
}
};
self.updateVisual();
return self;
});
// Button class
var UIButton = Container.expand(function () {
var self = Container.call(this);
self.bg = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
self.label = new Text2('Button', {
size: 60,
fill: "#fff"
});
self.label.anchor.set(0.5, 0.5);
self.addChild(self.label);
self.setText = function (txt) {
self.label.setText(txt);
};
self.setColor = function (color) {
self.bg.tint = color;
};
self.down = function (x, y, obj) {
// Visual feedback
tween(self.bg, {
scaleX: 0.95,
scaleY: 0.95
}, {
duration: 60
});
};
self.up = function (x, y, obj) {
tween(self.bg, {
scaleX: 1,
scaleY: 1
}, {
duration: 60
});
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x181818
});
/****
* Game Code
****/
// Tween plugin
// SFX
// Button
// Stones and gold
// Equipment shapes
// --- State ---
var gold = 1000;
var stones = 20;
var selectedEquip = 'sword'; // 'sword' or 'armor'
var swordLevel = 0;
var armorLevel = 0;
var swordBroken = false;
var armorBroken = false;
// --- UI Elements ---
var sword = new Equipment();
sword.setType('sword');
sword.x = 2048 / 2 - 250;
sword.y = 1100;
var armor = new Equipment();
armor.setType('armor');
armor.x = 2048 / 2 + 250;
armor.y = 1100;
var swordLabel = new Text2('', {
size: 60,
fill: "#fff"
});
swordLabel.anchor.set(0.5, 0.5);
swordLabel.x = sword.x;
swordLabel.y = sword.y + 120;
var armorLabel = new Text2('', {
size: 60,
fill: "#fff"
});
armorLabel.anchor.set(0.5, 0.5);
armorLabel.x = armor.x;
armorLabel.y = armor.y + 120;
// Select buttons
var swordSelectBtn = new UIButton();
swordSelectBtn.setText("Sword");
var armorSelectBtn = new UIButton();
armorSelectBtn.setText("Armor");
var upgradeBtn = new UIButton();
upgradeBtn.setText("Upgrade");
swordSelectBtn.x = sword.x;
swordSelectBtn.y = sword.y + 250;
armorSelectBtn.x = armor.x;
armorSelectBtn.y = armor.y + 250;
// Upgrade button
upgradeBtn.x = 2048 / 2;
upgradeBtn.y = 1800;
// Resource display
var goldIcon = LK.getAsset('gold', {
anchorX: 0.5,
anchorY: 0.5
});
goldIcon.x = 2048 / 2 - 200;
goldIcon.y = 300;
var goldText = new Text2('', {
size: 60,
fill: 0xFFD700
});
goldText.anchor.set(0, 0.5);
goldText.x = goldIcon.x + 50;
goldText.y = goldIcon.y;
var stoneIcon = LK.getAsset('stone', {
anchorX: 0.5,
anchorY: 0.5
});
stoneIcon.x = 2048 / 2 + 100;
stoneIcon.y = 300;
var stoneText = new Text2('', {
size: 60,
fill: 0x6EC6FF
});
stoneText.anchor.set(0, 0.5);
stoneText.x = stoneIcon.x + 50;
stoneText.y = stoneIcon.y;
// Info text
var infoText = new Text2('', {
size: 54,
fill: "#fff"
});
infoText.anchor.set(0.5, 0.5);
infoText.x = 2048 / 2;
infoText.y = 400;
// Progress bar
var progressBarBg = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.2,
scaleY: 0.4
});
progressBarBg.tint = 0x222222;
progressBarBg.x = 2048 / 2;
progressBarBg.y = 1550;
var progressBar = LK.getAsset('button', {
anchorX: 0,
anchorY: 0.5,
scaleX: 0,
scaleY: 0.4
});
progressBar.tint = 0x3a8fff;
progressBar.x = 2048 / 2 - 250;
progressBar.y = 1550;
// --- Add to game ---
game.addChild(sword);
game.addChild(armor);
game.addChild(swordLabel);
game.addChild(armorLabel);
game.addChild(swordSelectBtn);
game.addChild(armorSelectBtn);
game.addChild(upgradeBtn);
game.addChild(goldIcon);
game.addChild(goldText);
game.addChild(stoneIcon);
game.addChild(stoneText);
game.addChild(infoText);
game.addChild(progressBarBg);
game.addChild(progressBar);
// --- Helper Functions ---
function getEquipLevel(type) {
return type === 'sword' ? swordLevel : armorLevel;
}
function setEquipLevel(type, lvl) {
if (type === 'sword') swordLevel = lvl;else armorLevel = lvl;
}
function isEquipBroken(type) {
return type === 'sword' ? swordBroken : armorBroken;
}
function setEquipBroken(type, val) {
if (type === 'sword') swordBroken = val;else armorBroken = val;
}
function getEquipObj(type) {
return type === 'sword' ? sword : armor;
}
function getUpgradeCost(level) {
// Cost increases with level
return {
gold: 50 + level * 30,
stone: 1 + Math.floor(level / 3)
};
}
function getUpgradeChance(level) {
// +0: 100%, +1: 90%, +2: 80%, ... +10: 30%, +15: 10%
if (level < 1) return 1;
if (level < 5) return 1 - level * 0.1; // 90%, 80%, 70%, 60%
if (level < 10) return 0.5 - (level - 5) * 0.08; // 42%, 34%, 26%, 18%, 10%
if (level < 15) return 0.3 - (level - 10) * 0.04; // 26%, 22%, 18%, 14%, 10%
return 0.1;
}
function getFailType(level) {
// At +0~+4: only downgrade, +5+: 50% downgrade, 50% break
if (level < 5) return 'down';
return Math.random() < 0.5 ? 'down' : 'break';
}
function getLevelColor(level) {
if (level >= 15) return "#ff2222";
if (level >= 10) return "#ffd700";
if (level >= 5) return "#3a8fff";
return "#fff";
}
function getLevelText(level, broken) {
if (broken) return "Broken";
if (level === 0) return "+0";
return "+" + level;
}
function updateUI() {
// Equipment visuals
sword.setLevel(swordLevel);
sword.broken = swordBroken;
sword.updateVisual();
armor.setLevel(armorLevel);
armor.broken = armorBroken;
armor.updateVisual();
// Labels
swordLabel.setText(getLevelText(swordLevel, swordBroken));
swordLabel.setStyle({
fill: getLevelColor(swordLevel)
});
armorLabel.setText(getLevelText(armorLevel, armorBroken));
armorLabel.setStyle({
fill: getLevelColor(armorLevel)
});
// Resource
goldText.setText(gold.toString());
stoneText.setText(stones.toString());
// Info
var selLevel = getEquipLevel(selectedEquip);
var selBroken = isEquipBroken(selectedEquip);
var cost = getUpgradeCost(selLevel);
var chance = getUpgradeChance(selLevel);
if (selBroken) {
infoText.setText("Equipment is broken! Tap 'Upgrade' to repair.");
} else if (selLevel >= 15) {
infoText.setText("Maximum level! Cannot upgrade further.");
} else {
infoText.setText("Level: +" + selLevel + " | Success: " + Math.round(chance * 100) + "%\nCost: " + cost.gold + " gold, " + cost.stone + " stone");
}
// Progress bar
progressBar.scaleX = 0;
}
function showResult(text, color) {
infoText.setText(text);
infoText.setStyle({
fill: color
});
tween(infoText, {
alpha: 0.2
}, {
duration: 200,
onFinish: function onFinish() {
tween(infoText, {
alpha: 1
}, {
duration: 200
});
}
});
}
function animateProgressBar(success, cb) {
progressBar.tint = success ? 0x3a8fff : 0xff2222;
tween(progressBar, {
scaleX: 1
}, {
duration: 600,
easing: tween.cubicOut,
onFinish: function onFinish() {
tween(progressBar, {
scaleX: 0
}, {
duration: 200,
onFinish: cb
});
}
});
}
// --- Button Events ---
swordSelectBtn.down = function (x, y, obj) {
selectedEquip = 'sword';
swordSelectBtn.setColor(0x3a8fff);
armorSelectBtn.setColor(0x444444);
updateUI();
};
armorSelectBtn.down = function (x, y, obj) {
selectedEquip = 'armor';
armorSelectBtn.setColor(0x3a8fff);
swordSelectBtn.setColor(0x444444);
updateUI();
};
upgradeBtn.down = function (x, y, obj) {
var equip = selectedEquip;
var level = getEquipLevel(equip);
var broken = isEquipBroken(equip);
var cost = getUpgradeCost(level);
var chance = getUpgradeChance(level);
LK.getSound('upgrade_click').play();
if (broken) {
// Repair: pay half cost, reset to +0
if (gold >= Math.floor(cost.gold / 2) && stones >= Math.max(1, Math.floor(cost.stone / 2))) {
gold -= Math.floor(cost.gold / 2);
stones -= Math.max(1, Math.floor(cost.stone / 2));
setEquipLevel(equip, 0);
setEquipBroken(equip, false);
showResult("Equipment repaired! Level reset.", "#3a8fff");
LK.getSound('upgrade_success').play();
updateUI();
} else {
showResult("Not enough resources to repair!", "#ff2222");
LK.getSound('upgrade_fail').play();
}
return;
}
if (level >= 15) {
showResult("Maximum level!", "#ffd700");
return;
}
if (gold < cost.gold || stones < cost.stone) {
showResult("Not enough gold or stone!", "#ff2222");
LK.getSound('upgrade_fail').play();
return;
}
// Deduct cost
gold -= cost.gold;
stones -= cost.stone;
updateUI();
// Animate progress bar, then resolve
animateProgressBar(true, function () {
var roll = Math.random();
if (roll < chance) {
// Success
setEquipLevel(equip, level + 1);
showResult("Success! +" + (level + 1), "#3a8fff");
LK.getSound('upgrade_success').play();
// Flash effect
LK.effects.flashObject(getEquipObj(equip), 0x3a8fff, 400);
// Particle burst effect on success
if (typeof LK.effects.particleBurst === "function") {
// Centered on equipment
var equipObj = getEquipObj(equip);
var globalPos = equipObj.parent.toGlobal(equipObj.position);
LK.effects.particleBurst({
x: globalPos.x,
y: globalPos.y,
color: 0x3a8fff,
count: 32,
duration: 900,
size: 32,
spread: Math.PI * 2
});
}
// Firework effect on successful upgrade
if (typeof LK.effects.firework === "function") {
LK.effects.firework({
x: globalPos.x,
y: globalPos.y - 200,
color: 0x3a8fff,
count: 24,
duration: 1200,
size: 48
});
}
} else {
// Fail
var failType = getFailType(level);
if (failType === 'down') {
setEquipLevel(equip, Math.max(0, level - 1));
showResult("Failed! Level decreased.", "#ff2222");
LK.getSound('upgrade_fail').play();
LK.effects.flashObject(getEquipObj(equip), 0x222222, 400);
} else {
setEquipBroken(equip, true);
showResult("Equipment broken!", "#ff2222");
LK.getSound('upgrade_break').play();
LK.effects.flashObject(getEquipObj(equip), 0xff2222, 600);
// Red break effect on break
if (typeof LK.effects.breakEffect === "function") {
var equipObj = getEquipObj(equip);
var globalPos = equipObj.parent.toGlobal(equipObj.position);
LK.effects.breakEffect({
x: globalPos.x,
y: globalPos.y,
color: 0xff2222,
shards: 12,
duration: 700
});
}
}
}
updateUI();
});
};
// --- Initial UI State ---
swordSelectBtn.setColor(0x3a8fff);
armorSelectBtn.setColor(0x444444);
updateUI();
// --- Game update (idle resource gain) ---
game.update = function () {
// Idle: gain 1 gold every 60 ticks (~1s), 1 stone every 300 ticks (~5s)
if (LK.ticks % 60 === 0) {
gold += 1;
goldText.setText(gold.toString());
}
if (LK.ticks % 300 === 0) {
stones += 1;
stoneText.setText(stones.toString());
}
};
// --- Touch: allow tapping equipment to show effect ---
sword.down = function (x, y, obj) {
LK.effects.flashObject(sword, 0x3a8fff, 200);
};
armor.down = function (x, y, obj) {
LK.effects.flashObject(armor, 0x3a8fff, 200);
};
// --- Add gold button on right side ---
var goldBtn = new UIButton();
goldBtn.setText("+1 Gold");
goldBtn.x = 2048 - 300;
goldBtn.y = 300;
goldBtn.setColor(0xFFD700);
goldBtn.down = function (x, y, obj) {
gold += 1;
goldText.setText(gold.toString());
LK.effects.flashObject(goldBtn, 0xffd700, 200);
};
game.addChild(goldBtn);
// --- Add Repair button for broken items ---
var repairBtn = new UIButton();
repairBtn.setText("Repair (100)");
repairBtn.x = 2048 / 2;
repairBtn.y = 2000;
repairBtn.setColor(0xff2222);
repairBtn.down = function (x, y, obj) {
var equip = selectedEquip;
var broken = isEquipBroken(equip);
if (!broken) {
showResult("Item is not broken!", "#3a8fff");
LK.effects.flashObject(repairBtn, 0x3a8fff, 200);
return;
}
if (gold < 100) {
showResult("Not enough gold to repair!", "#ff2222");
LK.effects.flashObject(repairBtn, 0xff2222, 200);
return;
}
gold -= 100;
setEquipLevel(equip, 0);
setEquipBroken(equip, false);
showResult("Item repaired! Level reset.", "#3a8fff");
LK.getSound('upgrade_success').play();
updateUI();
LK.effects.flashObject(getEquipObj(equip), 0x3a8fff, 400);
LK.effects.flashObject(repairBtn, 0x3a8fff, 200);
goldText.setText(gold.toString());
};
game.addChild(repairBtn); /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Equipment class (for both sword and armor)
var Equipment = Container.expand(function () {
var self = Container.call(this);
self.type = 'sword'; // or 'armor'
self.level = 0;
self.maxLevel = 15;
self.broken = false;
self.asset = null;
self.flame = null;
self.setType = function (type) {
self.type = type;
self.updateVisual();
};
self.setLevel = function (level) {
self.level = level;
self.updateVisual();
};
self.breakItem = function () {
self.broken = true;
self.updateVisual();
};
self.repair = function () {
self.broken = false;
self.updateVisual();
};
self.updateVisual = function () {
// Remove old asset
if (self.asset) {
self.removeChild(self.asset);
self.asset.destroy();
self.asset = null;
}
if (self.flame) {
self.removeChild(self.flame);
self.flame.destroy();
self.flame = null;
}
var assetId;
if (self.type === 'sword') {
if (self.broken) assetId = 'sword_basic';else if (self.level >= 15) assetId = 'sword_red';else if (self.level >= 10) assetId = 'sword_gold';else if (self.level >= 5) assetId = 'sword_blue';else assetId = 'sword_basic';
} else {
if (self.broken) assetId = 'armor_basic';else if (self.level >= 15) assetId = 'armor_red';else if (self.level >= 10) assetId = 'armor_gold';else if (self.level >= 5) assetId = 'armor_blue';else assetId = 'armor_basic';
}
self.asset = self.attachAsset(assetId, {
anchorX: 0.5,
anchorY: 0.5
});
// Add flame effect for +15
if (!self.broken && self.level >= 15) {
self.flame = new Container();
var flameShape = LK.getAsset('sword_red', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.2,
scaleY: 1.2
});
flameShape.alpha = 0.4;
self.flame.addChild(flameShape);
self.flame.x = 0;
self.flame.y = 0;
self.addChild(self.flame);
// Animate flame
tween(self.flame, {
alpha: 0.2
}, {
duration: 400,
easing: tween.sineInOut,
onFinish: function onFinish() {
tween(self.flame, {
alpha: 0.4
}, {
duration: 400,
easing: tween.sineInOut,
onFinish: function onFinish() {
// Loop
if (self.flame) self.updateVisual();
}
});
}
});
}
// If broken, gray out
if (self.broken) {
self.asset.alpha = 0.3;
} else {
self.asset.alpha = 1;
}
};
self.updateVisual();
return self;
});
// Button class
var UIButton = Container.expand(function () {
var self = Container.call(this);
self.bg = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
self.label = new Text2('Button', {
size: 60,
fill: "#fff"
});
self.label.anchor.set(0.5, 0.5);
self.addChild(self.label);
self.setText = function (txt) {
self.label.setText(txt);
};
self.setColor = function (color) {
self.bg.tint = color;
};
self.down = function (x, y, obj) {
// Visual feedback
tween(self.bg, {
scaleX: 0.95,
scaleY: 0.95
}, {
duration: 60
});
};
self.up = function (x, y, obj) {
tween(self.bg, {
scaleX: 1,
scaleY: 1
}, {
duration: 60
});
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x181818
});
/****
* Game Code
****/
// Tween plugin
// SFX
// Button
// Stones and gold
// Equipment shapes
// --- State ---
var gold = 1000;
var stones = 20;
var selectedEquip = 'sword'; // 'sword' or 'armor'
var swordLevel = 0;
var armorLevel = 0;
var swordBroken = false;
var armorBroken = false;
// --- UI Elements ---
var sword = new Equipment();
sword.setType('sword');
sword.x = 2048 / 2 - 250;
sword.y = 1100;
var armor = new Equipment();
armor.setType('armor');
armor.x = 2048 / 2 + 250;
armor.y = 1100;
var swordLabel = new Text2('', {
size: 60,
fill: "#fff"
});
swordLabel.anchor.set(0.5, 0.5);
swordLabel.x = sword.x;
swordLabel.y = sword.y + 120;
var armorLabel = new Text2('', {
size: 60,
fill: "#fff"
});
armorLabel.anchor.set(0.5, 0.5);
armorLabel.x = armor.x;
armorLabel.y = armor.y + 120;
// Select buttons
var swordSelectBtn = new UIButton();
swordSelectBtn.setText("Sword");
var armorSelectBtn = new UIButton();
armorSelectBtn.setText("Armor");
var upgradeBtn = new UIButton();
upgradeBtn.setText("Upgrade");
swordSelectBtn.x = sword.x;
swordSelectBtn.y = sword.y + 250;
armorSelectBtn.x = armor.x;
armorSelectBtn.y = armor.y + 250;
// Upgrade button
upgradeBtn.x = 2048 / 2;
upgradeBtn.y = 1800;
// Resource display
var goldIcon = LK.getAsset('gold', {
anchorX: 0.5,
anchorY: 0.5
});
goldIcon.x = 2048 / 2 - 200;
goldIcon.y = 300;
var goldText = new Text2('', {
size: 60,
fill: 0xFFD700
});
goldText.anchor.set(0, 0.5);
goldText.x = goldIcon.x + 50;
goldText.y = goldIcon.y;
var stoneIcon = LK.getAsset('stone', {
anchorX: 0.5,
anchorY: 0.5
});
stoneIcon.x = 2048 / 2 + 100;
stoneIcon.y = 300;
var stoneText = new Text2('', {
size: 60,
fill: 0x6EC6FF
});
stoneText.anchor.set(0, 0.5);
stoneText.x = stoneIcon.x + 50;
stoneText.y = stoneIcon.y;
// Info text
var infoText = new Text2('', {
size: 54,
fill: "#fff"
});
infoText.anchor.set(0.5, 0.5);
infoText.x = 2048 / 2;
infoText.y = 400;
// Progress bar
var progressBarBg = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.2,
scaleY: 0.4
});
progressBarBg.tint = 0x222222;
progressBarBg.x = 2048 / 2;
progressBarBg.y = 1550;
var progressBar = LK.getAsset('button', {
anchorX: 0,
anchorY: 0.5,
scaleX: 0,
scaleY: 0.4
});
progressBar.tint = 0x3a8fff;
progressBar.x = 2048 / 2 - 250;
progressBar.y = 1550;
// --- Add to game ---
game.addChild(sword);
game.addChild(armor);
game.addChild(swordLabel);
game.addChild(armorLabel);
game.addChild(swordSelectBtn);
game.addChild(armorSelectBtn);
game.addChild(upgradeBtn);
game.addChild(goldIcon);
game.addChild(goldText);
game.addChild(stoneIcon);
game.addChild(stoneText);
game.addChild(infoText);
game.addChild(progressBarBg);
game.addChild(progressBar);
// --- Helper Functions ---
function getEquipLevel(type) {
return type === 'sword' ? swordLevel : armorLevel;
}
function setEquipLevel(type, lvl) {
if (type === 'sword') swordLevel = lvl;else armorLevel = lvl;
}
function isEquipBroken(type) {
return type === 'sword' ? swordBroken : armorBroken;
}
function setEquipBroken(type, val) {
if (type === 'sword') swordBroken = val;else armorBroken = val;
}
function getEquipObj(type) {
return type === 'sword' ? sword : armor;
}
function getUpgradeCost(level) {
// Cost increases with level
return {
gold: 50 + level * 30,
stone: 1 + Math.floor(level / 3)
};
}
function getUpgradeChance(level) {
// +0: 100%, +1: 90%, +2: 80%, ... +10: 30%, +15: 10%
if (level < 1) return 1;
if (level < 5) return 1 - level * 0.1; // 90%, 80%, 70%, 60%
if (level < 10) return 0.5 - (level - 5) * 0.08; // 42%, 34%, 26%, 18%, 10%
if (level < 15) return 0.3 - (level - 10) * 0.04; // 26%, 22%, 18%, 14%, 10%
return 0.1;
}
function getFailType(level) {
// At +0~+4: only downgrade, +5+: 50% downgrade, 50% break
if (level < 5) return 'down';
return Math.random() < 0.5 ? 'down' : 'break';
}
function getLevelColor(level) {
if (level >= 15) return "#ff2222";
if (level >= 10) return "#ffd700";
if (level >= 5) return "#3a8fff";
return "#fff";
}
function getLevelText(level, broken) {
if (broken) return "Broken";
if (level === 0) return "+0";
return "+" + level;
}
function updateUI() {
// Equipment visuals
sword.setLevel(swordLevel);
sword.broken = swordBroken;
sword.updateVisual();
armor.setLevel(armorLevel);
armor.broken = armorBroken;
armor.updateVisual();
// Labels
swordLabel.setText(getLevelText(swordLevel, swordBroken));
swordLabel.setStyle({
fill: getLevelColor(swordLevel)
});
armorLabel.setText(getLevelText(armorLevel, armorBroken));
armorLabel.setStyle({
fill: getLevelColor(armorLevel)
});
// Resource
goldText.setText(gold.toString());
stoneText.setText(stones.toString());
// Info
var selLevel = getEquipLevel(selectedEquip);
var selBroken = isEquipBroken(selectedEquip);
var cost = getUpgradeCost(selLevel);
var chance = getUpgradeChance(selLevel);
if (selBroken) {
infoText.setText("Equipment is broken! Tap 'Upgrade' to repair.");
} else if (selLevel >= 15) {
infoText.setText("Maximum level! Cannot upgrade further.");
} else {
infoText.setText("Level: +" + selLevel + " | Success: " + Math.round(chance * 100) + "%\nCost: " + cost.gold + " gold, " + cost.stone + " stone");
}
// Progress bar
progressBar.scaleX = 0;
}
function showResult(text, color) {
infoText.setText(text);
infoText.setStyle({
fill: color
});
tween(infoText, {
alpha: 0.2
}, {
duration: 200,
onFinish: function onFinish() {
tween(infoText, {
alpha: 1
}, {
duration: 200
});
}
});
}
function animateProgressBar(success, cb) {
progressBar.tint = success ? 0x3a8fff : 0xff2222;
tween(progressBar, {
scaleX: 1
}, {
duration: 600,
easing: tween.cubicOut,
onFinish: function onFinish() {
tween(progressBar, {
scaleX: 0
}, {
duration: 200,
onFinish: cb
});
}
});
}
// --- Button Events ---
swordSelectBtn.down = function (x, y, obj) {
selectedEquip = 'sword';
swordSelectBtn.setColor(0x3a8fff);
armorSelectBtn.setColor(0x444444);
updateUI();
};
armorSelectBtn.down = function (x, y, obj) {
selectedEquip = 'armor';
armorSelectBtn.setColor(0x3a8fff);
swordSelectBtn.setColor(0x444444);
updateUI();
};
upgradeBtn.down = function (x, y, obj) {
var equip = selectedEquip;
var level = getEquipLevel(equip);
var broken = isEquipBroken(equip);
var cost = getUpgradeCost(level);
var chance = getUpgradeChance(level);
LK.getSound('upgrade_click').play();
if (broken) {
// Repair: pay half cost, reset to +0
if (gold >= Math.floor(cost.gold / 2) && stones >= Math.max(1, Math.floor(cost.stone / 2))) {
gold -= Math.floor(cost.gold / 2);
stones -= Math.max(1, Math.floor(cost.stone / 2));
setEquipLevel(equip, 0);
setEquipBroken(equip, false);
showResult("Equipment repaired! Level reset.", "#3a8fff");
LK.getSound('upgrade_success').play();
updateUI();
} else {
showResult("Not enough resources to repair!", "#ff2222");
LK.getSound('upgrade_fail').play();
}
return;
}
if (level >= 15) {
showResult("Maximum level!", "#ffd700");
return;
}
if (gold < cost.gold || stones < cost.stone) {
showResult("Not enough gold or stone!", "#ff2222");
LK.getSound('upgrade_fail').play();
return;
}
// Deduct cost
gold -= cost.gold;
stones -= cost.stone;
updateUI();
// Animate progress bar, then resolve
animateProgressBar(true, function () {
var roll = Math.random();
if (roll < chance) {
// Success
setEquipLevel(equip, level + 1);
showResult("Success! +" + (level + 1), "#3a8fff");
LK.getSound('upgrade_success').play();
// Flash effect
LK.effects.flashObject(getEquipObj(equip), 0x3a8fff, 400);
// Particle burst effect on success
if (typeof LK.effects.particleBurst === "function") {
// Centered on equipment
var equipObj = getEquipObj(equip);
var globalPos = equipObj.parent.toGlobal(equipObj.position);
LK.effects.particleBurst({
x: globalPos.x,
y: globalPos.y,
color: 0x3a8fff,
count: 32,
duration: 900,
size: 32,
spread: Math.PI * 2
});
}
// Firework effect on successful upgrade
if (typeof LK.effects.firework === "function") {
LK.effects.firework({
x: globalPos.x,
y: globalPos.y - 200,
color: 0x3a8fff,
count: 24,
duration: 1200,
size: 48
});
}
} else {
// Fail
var failType = getFailType(level);
if (failType === 'down') {
setEquipLevel(equip, Math.max(0, level - 1));
showResult("Failed! Level decreased.", "#ff2222");
LK.getSound('upgrade_fail').play();
LK.effects.flashObject(getEquipObj(equip), 0x222222, 400);
} else {
setEquipBroken(equip, true);
showResult("Equipment broken!", "#ff2222");
LK.getSound('upgrade_break').play();
LK.effects.flashObject(getEquipObj(equip), 0xff2222, 600);
// Red break effect on break
if (typeof LK.effects.breakEffect === "function") {
var equipObj = getEquipObj(equip);
var globalPos = equipObj.parent.toGlobal(equipObj.position);
LK.effects.breakEffect({
x: globalPos.x,
y: globalPos.y,
color: 0xff2222,
shards: 12,
duration: 700
});
}
}
}
updateUI();
});
};
// --- Initial UI State ---
swordSelectBtn.setColor(0x3a8fff);
armorSelectBtn.setColor(0x444444);
updateUI();
// --- Game update (idle resource gain) ---
game.update = function () {
// Idle: gain 1 gold every 60 ticks (~1s), 1 stone every 300 ticks (~5s)
if (LK.ticks % 60 === 0) {
gold += 1;
goldText.setText(gold.toString());
}
if (LK.ticks % 300 === 0) {
stones += 1;
stoneText.setText(stones.toString());
}
};
// --- Touch: allow tapping equipment to show effect ---
sword.down = function (x, y, obj) {
LK.effects.flashObject(sword, 0x3a8fff, 200);
};
armor.down = function (x, y, obj) {
LK.effects.flashObject(armor, 0x3a8fff, 200);
};
// --- Add gold button on right side ---
var goldBtn = new UIButton();
goldBtn.setText("+1 Gold");
goldBtn.x = 2048 - 300;
goldBtn.y = 300;
goldBtn.setColor(0xFFD700);
goldBtn.down = function (x, y, obj) {
gold += 1;
goldText.setText(gold.toString());
LK.effects.flashObject(goldBtn, 0xffd700, 200);
};
game.addChild(goldBtn);
// --- Add Repair button for broken items ---
var repairBtn = new UIButton();
repairBtn.setText("Repair (100)");
repairBtn.x = 2048 / 2;
repairBtn.y = 2000;
repairBtn.setColor(0xff2222);
repairBtn.down = function (x, y, obj) {
var equip = selectedEquip;
var broken = isEquipBroken(equip);
if (!broken) {
showResult("Item is not broken!", "#3a8fff");
LK.effects.flashObject(repairBtn, 0x3a8fff, 200);
return;
}
if (gold < 100) {
showResult("Not enough gold to repair!", "#ff2222");
LK.effects.flashObject(repairBtn, 0xff2222, 200);
return;
}
gold -= 100;
setEquipLevel(equip, 0);
setEquipBroken(equip, false);
showResult("Item repaired! Level reset.", "#3a8fff");
LK.getSound('upgrade_success').play();
updateUI();
LK.effects.flashObject(getEquipObj(equip), 0x3a8fff, 400);
LK.effects.flashObject(repairBtn, 0x3a8fff, 200);
goldText.setText(gold.toString());
};
game.addChild(repairBtn);
Basic sword. In-Game asset. 2d. High contrast. No shadows
Blue light sword. In-Game asset. 2d. High contrast. No shadows
Stone volcanic. In-Game asset. 2d. High contrast. No shadows
Basic armor. In-Game asset. 2d. High contrast. No shadows
Armor light blue neon. In-Game asset. 2d. High contrast.
Armor grand red neon. In-Game asset. 2d. High contrast. No shadows
Stone effect button. In-Game asset. 2d. High contrast. No shadows
Game coin. In-Game asset. 2d. High contrast. No shadows
Armor grand master gold neon. In-Game asset. 2d. High contrast. No shadows
Sword, effect master red neon. In-Game asset. 2d. High contrast. No shadows
Sword, effect grand master neon. In-Game asset. 2d. High contrast. No shadows