/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Button = Container.expand(function (text, callback) {
var self = Container.call(this);
self.callback = callback;
self.isSelected = false;
self.buttonBg = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
self.buttonText = new Text2(text, {
size: 40,
fill: 0xFFFFFF
});
self.buttonText.anchor.set(0.5, 0.5);
self.addChild(self.buttonText);
self.setSelected = function (selected) {
self.isSelected = selected;
if (selected) {
self.buttonBg.tint = 0x888888;
} else {
self.buttonBg.tint = 0x444444;
}
};
self.down = function (x, y, obj) {
LK.getSound('Edit').play();
if (self.callback) {
self.callback();
}
};
return self;
});
var Sword = Container.expand(function () {
var self = Container.call(this);
// Current selections
self.currentBlade = 'round';
self.currentColor = 'silver';
self.currentPattern = 'plain';
self.currentLength = 'medium';
self.currentHandleColor = 'brown';
self.isWielded = false;
self.currentHandColor = 'light';
self.blade = null;
self.handle = null;
self.hand = null;
self.patterns = [];
self.updateSword = function () {
// Clear existing components
if (self.blade) {
self.blade.destroy();
}
if (self.handle) {
self.handle.destroy();
}
if (self.hand) {
self.hand.destroy();
}
for (var i = 0; i < self.patterns.length; i++) {
self.patterns[i].destroy();
}
self.patterns = [];
// Create handle
var handleAsset = self.currentLength + 'Handle';
if (self.currentLength === 'short') {
handleAsset = self.currentHandleColor === 'gold' ? 'handleShortGold' : 'handleShort';
} else if (self.currentLength === 'medium') {
handleAsset = self.currentHandleColor === 'gold' ? 'handleMediumGold' : 'handleMedium';
} else {
handleAsset = self.currentHandleColor === 'gold' ? 'handleLongGold' : 'handleLong';
}
self.handle = self.attachAsset(handleAsset, {
anchorX: 0.5,
anchorY: 0
});
self.handle.y = 100;
// Create hand if wielded
if (self.isWielded) {
self.hand = self.attachAsset('hand', {
anchorX: 0.5,
anchorY: 0
});
self.hand.y = self.handle.y + self.handle.height - 20;
// Apply hand color tints
if (self.currentHandColor === 'light') {
self.hand.tint = 0xfdbcb4;
} else if (self.currentHandColor === 'medium-light') {
self.hand.tint = 0xeea979;
} else if (self.currentHandColor === 'medium') {
self.hand.tint = 0xc68642;
} else if (self.currentHandColor === 'medium-dark') {
self.hand.tint = 0x8d5524;
} else {
self.hand.tint = 0x5c3317;
}
}
// Add handle patterns
if (self.currentPattern === 'horizontal') {
var stripeCount = Math.floor(self.handle.height / 40);
for (var i = 0; i < stripeCount; i++) {
var stripe = self.attachAsset('horizontalStripe', {
anchorX: 0.5,
anchorY: 0.5
});
stripe.y = self.handle.y + i * 40 + 20;
self.patterns.push(stripe);
}
} else if (self.currentPattern === 'vertical') {
for (var j = 0; j < 6; j++) {
var vStripe = self.attachAsset('verticalStripe', {
anchorX: 0.5,
anchorY: 0
});
vStripe.x = (j - 2.5) * 12;
vStripe.y = self.handle.y;
vStripe.height = self.handle.height;
self.patterns.push(vStripe);
}
}
// Create blade
var bladeAsset = self.currentBlade + 'Blade';
self.blade = self.attachAsset(bladeAsset, {
anchorX: 0.5,
anchorY: 1
});
self.blade.y = 100;
// Apply color
if (self.currentColor === 'gold') {
self.blade.tint = 0xFFD700;
} else if (self.currentColor === 'diamond') {
self.blade.tint = 0x0000ff;
} else {
self.blade.tint = 0xC0C0C0;
}
};
self.setBlade = function (blade) {
self.currentBlade = blade;
self.updateSword();
};
self.setColor = function (color) {
self.currentColor = color;
self.updateSword();
};
self.setPattern = function (pattern) {
self.currentPattern = pattern;
self.updateSword();
};
self.setLength = function (length) {
self.currentLength = length;
self.updateSword();
};
self.setHandleColor = function (handleColor) {
self.currentHandleColor = handleColor;
self.updateSword();
};
self.setWielded = function (wielded) {
self.isWielded = wielded;
self.updateSword();
};
self.setHandColor = function (handColor) {
self.currentHandColor = handColor;
self.updateSword();
};
// Initialize with default sword
self.updateSword();
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2c3e50
});
/****
* Game Code
****/
// Create main sword display
// Blade shapes
// Handle components
// Pattern overlays
// UI Buttons
var sword = game.addChild(new Sword());
sword.x = 1024;
sword.y = 600;
// UI Elements
var titleText = new Text2('Blade Forge', {
size: 80,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0);
titleText.x = 1024;
titleText.y = 100;
game.addChild(titleText);
// Button arrays for each category
var bladeButtons = [];
var colorButtons = [];
var patternButtons = [];
var lengthButtons = [];
// Category labels
var bladeLabelText = new Text2('Blade Shape', {
size: 50,
fill: 0xECF0F1
});
bladeLabelText.anchor.set(0, 0.5);
bladeLabelText.x = 100;
bladeLabelText.y = 800;
var colorLabelText = new Text2('Blade Color', {
size: 50,
fill: 0xECF0F1
});
colorLabelText.anchor.set(0, 0.5);
colorLabelText.x = 100;
colorLabelText.y = 1100;
game.addChild(colorLabelText);
var handleColorLabelText = new Text2('Handle Color', {
size: 50,
fill: 0xECF0F1
});
handleColorLabelText.anchor.set(0, 0.5);
handleColorLabelText.x = 100;
handleColorLabelText.y = 1400;
game.addChild(handleColorLabelText);
var patternLabelText = new Text2('Handle Pattern', {
size: 50,
fill: 0xECF0F1
});
patternLabelText.anchor.set(0, 0.5);
patternLabelText.x = 100;
patternLabelText.y = 1700;
game.addChild(patternLabelText);
var lengthLabelText = new Text2('Handle Length', {
size: 50,
fill: 0xECF0F1
});
lengthLabelText.anchor.set(0, 0.5);
lengthLabelText.x = 100;
lengthLabelText.y = 2000;
game.addChild(lengthLabelText);
var wieldedLabelText = new Text2('Wielded', {
size: 50,
fill: 0xECF0F1
});
wieldedLabelText.anchor.set(0, 0.5);
wieldedLabelText.x = 100;
wieldedLabelText.y = 2300;
game.addChild(wieldedLabelText);
var handColorLabelText = new Text2('Hand Color', {
size: 50,
fill: 0xECF0F1
});
handColorLabelText.anchor.set(0, 0.5);
handColorLabelText.x = 100;
handColorLabelText.y = 2600;
game.addChild(handColorLabelText);
game.addChild(bladeLabelText);
var patternLabelText = new Text2('Handle Pattern', {
size: 50,
fill: 0xECF0F1
});
patternLabelText.anchor.set(0, 0.5);
patternLabelText.x = 100;
game.addChild(patternLabelText);
var lengthLabelText = new Text2('Handle Length', {
size: 50,
fill: 0xECF0F1
});
lengthLabelText.anchor.set(0, 0.5);
lengthLabelText.x = 100;
game.addChild(lengthLabelText);
var wieldedLabelText = new Text2('Wielded', {
size: 50,
fill: 0xECF0F1
});
wieldedLabelText.anchor.set(0, 0.5);
wieldedLabelText.x = 100;
game.addChild(wieldedLabelText);
var handColorLabelText = new Text2('Hand Color', {
size: 50,
fill: 0xECF0F1
});
handColorLabelText.anchor.set(0, 0.5);
handColorLabelText.x = 100;
game.addChild(handColorLabelText);
// Create blade shape buttons
var bladeOptions = ['Round', 'Triangle', 'Spiked', 'Pentagon', 'Pentagon Hole'];
var bladeValues = ['round', 'triangle', 'spikedRound', 'pentagon', 'pentagonHole'];
for (var i = 0; i < bladeOptions.length; i++) {
var bladeBtn = game.addChild(new Button(bladeOptions[i], function (value) {
return function () {
sword.setBlade(value);
updateButtonSelection(bladeButtons, bladeBtn);
};
}(bladeValues[i])));
bladeBtn.x = 400 + i * 250;
bladeBtn.y = 880;
bladeButtons.push(bladeBtn);
}
// Create color buttons
var colorOptions = ['Silver', 'Gold', 'Diamond'];
var colorValues = ['silver', 'gold', 'diamond'];
for (var j = 0; j < colorOptions.length; j++) {
var colorBtn = game.addChild(new Button(colorOptions[j], function (value) {
return function () {
sword.setColor(value);
updateButtonSelection(colorButtons, colorBtn);
};
}(colorValues[j])));
colorBtn.x = 400 + j * 250;
colorBtn.y = 1180;
colorButtons.push(colorBtn);
}
// Create handle color buttons
var handleColorButtons = [];
var handleColorOptions = ['Brown', 'Gold'];
var handleColorValues = ['brown', 'gold'];
for (var m = 0; m < handleColorOptions.length; m++) {
var handleColorBtn = game.addChild(new Button(handleColorOptions[m], function (value) {
return function () {
sword.setHandleColor(value);
updateButtonSelection(handleColorButtons, handleColorBtn);
};
}(handleColorValues[m])));
handleColorBtn.x = 400 + m * 250;
handleColorBtn.y = 1480;
handleColorButtons.push(handleColorBtn);
}
// Create pattern buttons
var patternOptions = ['Plain', 'Horizontal', 'Vertical'];
var patternValues = ['plain', 'horizontal', 'vertical'];
for (var k = 0; k < patternOptions.length; k++) {
var patternBtn = game.addChild(new Button(patternOptions[k], function (value) {
return function () {
sword.setPattern(value);
updateButtonSelection(patternButtons, patternBtn);
};
}(patternValues[k])));
patternBtn.x = 400 + k * 250;
patternBtn.y = 1780;
patternButtons.push(patternBtn);
}
// Create length buttons
var lengthOptions = ['Short', 'Medium', 'Long'];
var lengthValues = ['short', 'medium', 'long'];
for (var l = 0; l < lengthOptions.length; l++) {
var lengthBtn = game.addChild(new Button(lengthOptions[l], function (value) {
return function () {
sword.setLength(value);
updateButtonSelection(lengthButtons, lengthBtn);
};
}(lengthValues[l])));
lengthBtn.x = 400 + l * 250;
lengthBtn.y = 2080;
lengthButtons.push(lengthBtn);
}
// Reset button
// Create wielded toggle buttons
var wieldedButtons = [];
var wieldedOptions = ['No', 'Yes'];
var wieldedValues = [false, true];
for (var n = 0; n < wieldedOptions.length; n++) {
var wieldedBtn = game.addChild(new Button(wieldedOptions[n], function (value) {
return function () {
sword.setWielded(value);
updateButtonSelection(wieldedButtons, wieldedBtn);
};
}(wieldedValues[n])));
wieldedBtn.x = 400 + n * 250;
wieldedBtn.y = 2380;
wieldedButtons.push(wieldedBtn);
}
// Create hand color buttons
var handColorButtons = [];
var handColorOptions = ['Light', 'Med-Light', 'Medium', 'Med-Dark', 'Dark'];
var handColorValues = ['light', 'medium-light', 'medium', 'medium-dark', 'dark'];
for (var o = 0; o < handColorOptions.length; o++) {
var handColorBtn = game.addChild(new Button(handColorOptions[o], function (value) {
return function () {
sword.setHandColor(value);
updateButtonSelection(handColorButtons, handColorBtn);
};
}(handColorValues[o])));
handColorBtn.x = 400 + o * 250;
handColorBtn.y = 2680;
handColorButtons.push(handColorBtn);
}
var resetBtn = game.addChild(new Button('Reset', function () {
sword.setBlade('round');
sword.setColor('silver');
sword.setPattern('plain');
sword.setLength('medium');
sword.setHandleColor('brown');
sword.setWielded(false);
sword.setHandColor('light');
// Reset button selections
updateButtonSelection(bladeButtons, bladeButtons[0]);
updateButtonSelection(colorButtons, colorButtons[0]);
updateButtonSelection(handleColorButtons, handleColorButtons[0]);
updateButtonSelection(patternButtons, patternButtons[0]);
updateButtonSelection(lengthButtons, lengthButtons[1]);
updateButtonSelection(wieldedButtons, wieldedButtons[0]);
updateButtonSelection(handColorButtons, handColorButtons[0]);
}));
resetBtn.x = 1024;
resetBtn.y = 2980;
// Helper function to update button selections
function updateButtonSelection(buttonArray, selectedButton) {
for (var i = 0; i < buttonArray.length; i++) {
buttonArray[i].setSelected(false);
}
selectedButton.setSelected(true);
}
// Initialize default selections
updateButtonSelection(bladeButtons, bladeButtons[0]);
updateButtonSelection(colorButtons, colorButtons[0]);
updateButtonSelection(handleColorButtons, handleColorButtons[0]);
updateButtonSelection(patternButtons, patternButtons[0]);
updateButtonSelection(lengthButtons, lengthButtons[1]);
updateButtonSelection(wieldedButtons, wieldedButtons[0]);
updateButtonSelection(handColorButtons, handColorButtons[0]);
// Start sword bobbing animation
function startSwordBobbing() {
tween(sword, {
y: sword.y - 20
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(sword, {
y: sword.y + 20
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: startSwordBobbing
});
}
});
}
startSwordBobbing();
game.update = function () {
// Game tick logic if needed
}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Button = Container.expand(function (text, callback) {
var self = Container.call(this);
self.callback = callback;
self.isSelected = false;
self.buttonBg = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
self.buttonText = new Text2(text, {
size: 40,
fill: 0xFFFFFF
});
self.buttonText.anchor.set(0.5, 0.5);
self.addChild(self.buttonText);
self.setSelected = function (selected) {
self.isSelected = selected;
if (selected) {
self.buttonBg.tint = 0x888888;
} else {
self.buttonBg.tint = 0x444444;
}
};
self.down = function (x, y, obj) {
LK.getSound('Edit').play();
if (self.callback) {
self.callback();
}
};
return self;
});
var Sword = Container.expand(function () {
var self = Container.call(this);
// Current selections
self.currentBlade = 'round';
self.currentColor = 'silver';
self.currentPattern = 'plain';
self.currentLength = 'medium';
self.currentHandleColor = 'brown';
self.isWielded = false;
self.currentHandColor = 'light';
self.blade = null;
self.handle = null;
self.hand = null;
self.patterns = [];
self.updateSword = function () {
// Clear existing components
if (self.blade) {
self.blade.destroy();
}
if (self.handle) {
self.handle.destroy();
}
if (self.hand) {
self.hand.destroy();
}
for (var i = 0; i < self.patterns.length; i++) {
self.patterns[i].destroy();
}
self.patterns = [];
// Create handle
var handleAsset = self.currentLength + 'Handle';
if (self.currentLength === 'short') {
handleAsset = self.currentHandleColor === 'gold' ? 'handleShortGold' : 'handleShort';
} else if (self.currentLength === 'medium') {
handleAsset = self.currentHandleColor === 'gold' ? 'handleMediumGold' : 'handleMedium';
} else {
handleAsset = self.currentHandleColor === 'gold' ? 'handleLongGold' : 'handleLong';
}
self.handle = self.attachAsset(handleAsset, {
anchorX: 0.5,
anchorY: 0
});
self.handle.y = 100;
// Create hand if wielded
if (self.isWielded) {
self.hand = self.attachAsset('hand', {
anchorX: 0.5,
anchorY: 0
});
self.hand.y = self.handle.y + self.handle.height - 20;
// Apply hand color tints
if (self.currentHandColor === 'light') {
self.hand.tint = 0xfdbcb4;
} else if (self.currentHandColor === 'medium-light') {
self.hand.tint = 0xeea979;
} else if (self.currentHandColor === 'medium') {
self.hand.tint = 0xc68642;
} else if (self.currentHandColor === 'medium-dark') {
self.hand.tint = 0x8d5524;
} else {
self.hand.tint = 0x5c3317;
}
}
// Add handle patterns
if (self.currentPattern === 'horizontal') {
var stripeCount = Math.floor(self.handle.height / 40);
for (var i = 0; i < stripeCount; i++) {
var stripe = self.attachAsset('horizontalStripe', {
anchorX: 0.5,
anchorY: 0.5
});
stripe.y = self.handle.y + i * 40 + 20;
self.patterns.push(stripe);
}
} else if (self.currentPattern === 'vertical') {
for (var j = 0; j < 6; j++) {
var vStripe = self.attachAsset('verticalStripe', {
anchorX: 0.5,
anchorY: 0
});
vStripe.x = (j - 2.5) * 12;
vStripe.y = self.handle.y;
vStripe.height = self.handle.height;
self.patterns.push(vStripe);
}
}
// Create blade
var bladeAsset = self.currentBlade + 'Blade';
self.blade = self.attachAsset(bladeAsset, {
anchorX: 0.5,
anchorY: 1
});
self.blade.y = 100;
// Apply color
if (self.currentColor === 'gold') {
self.blade.tint = 0xFFD700;
} else if (self.currentColor === 'diamond') {
self.blade.tint = 0x0000ff;
} else {
self.blade.tint = 0xC0C0C0;
}
};
self.setBlade = function (blade) {
self.currentBlade = blade;
self.updateSword();
};
self.setColor = function (color) {
self.currentColor = color;
self.updateSword();
};
self.setPattern = function (pattern) {
self.currentPattern = pattern;
self.updateSword();
};
self.setLength = function (length) {
self.currentLength = length;
self.updateSword();
};
self.setHandleColor = function (handleColor) {
self.currentHandleColor = handleColor;
self.updateSword();
};
self.setWielded = function (wielded) {
self.isWielded = wielded;
self.updateSword();
};
self.setHandColor = function (handColor) {
self.currentHandColor = handColor;
self.updateSword();
};
// Initialize with default sword
self.updateSword();
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2c3e50
});
/****
* Game Code
****/
// Create main sword display
// Blade shapes
// Handle components
// Pattern overlays
// UI Buttons
var sword = game.addChild(new Sword());
sword.x = 1024;
sword.y = 600;
// UI Elements
var titleText = new Text2('Blade Forge', {
size: 80,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0);
titleText.x = 1024;
titleText.y = 100;
game.addChild(titleText);
// Button arrays for each category
var bladeButtons = [];
var colorButtons = [];
var patternButtons = [];
var lengthButtons = [];
// Category labels
var bladeLabelText = new Text2('Blade Shape', {
size: 50,
fill: 0xECF0F1
});
bladeLabelText.anchor.set(0, 0.5);
bladeLabelText.x = 100;
bladeLabelText.y = 800;
var colorLabelText = new Text2('Blade Color', {
size: 50,
fill: 0xECF0F1
});
colorLabelText.anchor.set(0, 0.5);
colorLabelText.x = 100;
colorLabelText.y = 1100;
game.addChild(colorLabelText);
var handleColorLabelText = new Text2('Handle Color', {
size: 50,
fill: 0xECF0F1
});
handleColorLabelText.anchor.set(0, 0.5);
handleColorLabelText.x = 100;
handleColorLabelText.y = 1400;
game.addChild(handleColorLabelText);
var patternLabelText = new Text2('Handle Pattern', {
size: 50,
fill: 0xECF0F1
});
patternLabelText.anchor.set(0, 0.5);
patternLabelText.x = 100;
patternLabelText.y = 1700;
game.addChild(patternLabelText);
var lengthLabelText = new Text2('Handle Length', {
size: 50,
fill: 0xECF0F1
});
lengthLabelText.anchor.set(0, 0.5);
lengthLabelText.x = 100;
lengthLabelText.y = 2000;
game.addChild(lengthLabelText);
var wieldedLabelText = new Text2('Wielded', {
size: 50,
fill: 0xECF0F1
});
wieldedLabelText.anchor.set(0, 0.5);
wieldedLabelText.x = 100;
wieldedLabelText.y = 2300;
game.addChild(wieldedLabelText);
var handColorLabelText = new Text2('Hand Color', {
size: 50,
fill: 0xECF0F1
});
handColorLabelText.anchor.set(0, 0.5);
handColorLabelText.x = 100;
handColorLabelText.y = 2600;
game.addChild(handColorLabelText);
game.addChild(bladeLabelText);
var patternLabelText = new Text2('Handle Pattern', {
size: 50,
fill: 0xECF0F1
});
patternLabelText.anchor.set(0, 0.5);
patternLabelText.x = 100;
game.addChild(patternLabelText);
var lengthLabelText = new Text2('Handle Length', {
size: 50,
fill: 0xECF0F1
});
lengthLabelText.anchor.set(0, 0.5);
lengthLabelText.x = 100;
game.addChild(lengthLabelText);
var wieldedLabelText = new Text2('Wielded', {
size: 50,
fill: 0xECF0F1
});
wieldedLabelText.anchor.set(0, 0.5);
wieldedLabelText.x = 100;
game.addChild(wieldedLabelText);
var handColorLabelText = new Text2('Hand Color', {
size: 50,
fill: 0xECF0F1
});
handColorLabelText.anchor.set(0, 0.5);
handColorLabelText.x = 100;
game.addChild(handColorLabelText);
// Create blade shape buttons
var bladeOptions = ['Round', 'Triangle', 'Spiked', 'Pentagon', 'Pentagon Hole'];
var bladeValues = ['round', 'triangle', 'spikedRound', 'pentagon', 'pentagonHole'];
for (var i = 0; i < bladeOptions.length; i++) {
var bladeBtn = game.addChild(new Button(bladeOptions[i], function (value) {
return function () {
sword.setBlade(value);
updateButtonSelection(bladeButtons, bladeBtn);
};
}(bladeValues[i])));
bladeBtn.x = 400 + i * 250;
bladeBtn.y = 880;
bladeButtons.push(bladeBtn);
}
// Create color buttons
var colorOptions = ['Silver', 'Gold', 'Diamond'];
var colorValues = ['silver', 'gold', 'diamond'];
for (var j = 0; j < colorOptions.length; j++) {
var colorBtn = game.addChild(new Button(colorOptions[j], function (value) {
return function () {
sword.setColor(value);
updateButtonSelection(colorButtons, colorBtn);
};
}(colorValues[j])));
colorBtn.x = 400 + j * 250;
colorBtn.y = 1180;
colorButtons.push(colorBtn);
}
// Create handle color buttons
var handleColorButtons = [];
var handleColorOptions = ['Brown', 'Gold'];
var handleColorValues = ['brown', 'gold'];
for (var m = 0; m < handleColorOptions.length; m++) {
var handleColorBtn = game.addChild(new Button(handleColorOptions[m], function (value) {
return function () {
sword.setHandleColor(value);
updateButtonSelection(handleColorButtons, handleColorBtn);
};
}(handleColorValues[m])));
handleColorBtn.x = 400 + m * 250;
handleColorBtn.y = 1480;
handleColorButtons.push(handleColorBtn);
}
// Create pattern buttons
var patternOptions = ['Plain', 'Horizontal', 'Vertical'];
var patternValues = ['plain', 'horizontal', 'vertical'];
for (var k = 0; k < patternOptions.length; k++) {
var patternBtn = game.addChild(new Button(patternOptions[k], function (value) {
return function () {
sword.setPattern(value);
updateButtonSelection(patternButtons, patternBtn);
};
}(patternValues[k])));
patternBtn.x = 400 + k * 250;
patternBtn.y = 1780;
patternButtons.push(patternBtn);
}
// Create length buttons
var lengthOptions = ['Short', 'Medium', 'Long'];
var lengthValues = ['short', 'medium', 'long'];
for (var l = 0; l < lengthOptions.length; l++) {
var lengthBtn = game.addChild(new Button(lengthOptions[l], function (value) {
return function () {
sword.setLength(value);
updateButtonSelection(lengthButtons, lengthBtn);
};
}(lengthValues[l])));
lengthBtn.x = 400 + l * 250;
lengthBtn.y = 2080;
lengthButtons.push(lengthBtn);
}
// Reset button
// Create wielded toggle buttons
var wieldedButtons = [];
var wieldedOptions = ['No', 'Yes'];
var wieldedValues = [false, true];
for (var n = 0; n < wieldedOptions.length; n++) {
var wieldedBtn = game.addChild(new Button(wieldedOptions[n], function (value) {
return function () {
sword.setWielded(value);
updateButtonSelection(wieldedButtons, wieldedBtn);
};
}(wieldedValues[n])));
wieldedBtn.x = 400 + n * 250;
wieldedBtn.y = 2380;
wieldedButtons.push(wieldedBtn);
}
// Create hand color buttons
var handColorButtons = [];
var handColorOptions = ['Light', 'Med-Light', 'Medium', 'Med-Dark', 'Dark'];
var handColorValues = ['light', 'medium-light', 'medium', 'medium-dark', 'dark'];
for (var o = 0; o < handColorOptions.length; o++) {
var handColorBtn = game.addChild(new Button(handColorOptions[o], function (value) {
return function () {
sword.setHandColor(value);
updateButtonSelection(handColorButtons, handColorBtn);
};
}(handColorValues[o])));
handColorBtn.x = 400 + o * 250;
handColorBtn.y = 2680;
handColorButtons.push(handColorBtn);
}
var resetBtn = game.addChild(new Button('Reset', function () {
sword.setBlade('round');
sword.setColor('silver');
sword.setPattern('plain');
sword.setLength('medium');
sword.setHandleColor('brown');
sword.setWielded(false);
sword.setHandColor('light');
// Reset button selections
updateButtonSelection(bladeButtons, bladeButtons[0]);
updateButtonSelection(colorButtons, colorButtons[0]);
updateButtonSelection(handleColorButtons, handleColorButtons[0]);
updateButtonSelection(patternButtons, patternButtons[0]);
updateButtonSelection(lengthButtons, lengthButtons[1]);
updateButtonSelection(wieldedButtons, wieldedButtons[0]);
updateButtonSelection(handColorButtons, handColorButtons[0]);
}));
resetBtn.x = 1024;
resetBtn.y = 2980;
// Helper function to update button selections
function updateButtonSelection(buttonArray, selectedButton) {
for (var i = 0; i < buttonArray.length; i++) {
buttonArray[i].setSelected(false);
}
selectedButton.setSelected(true);
}
// Initialize default selections
updateButtonSelection(bladeButtons, bladeButtons[0]);
updateButtonSelection(colorButtons, colorButtons[0]);
updateButtonSelection(handleColorButtons, handleColorButtons[0]);
updateButtonSelection(patternButtons, patternButtons[0]);
updateButtonSelection(lengthButtons, lengthButtons[1]);
updateButtonSelection(wieldedButtons, wieldedButtons[0]);
updateButtonSelection(handColorButtons, handColorButtons[0]);
// Start sword bobbing animation
function startSwordBobbing() {
tween(sword, {
y: sword.y - 20
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(sword, {
y: sword.y + 20
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: startSwordBobbing
});
}
});
}
startSwordBobbing();
game.update = function () {
// Game tick logic if needed
};