/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var SpinWheel = Container.expand(function (segments, isCharacterWheel) { var self = Container.call(this); var wheelBg = self.attachAsset('wheelBackground', { anchorX: 0.5, anchorY: 0.5 }); self.segments = []; self.segmentAngle = Math.PI * 2 / segments.length; self.spinning = false; self.currentRotation = 0; self.selectedIndex = 0; // Create segments for (var i = 0; i < segments.length; i++) { var segment = new WheelSegment(segments[i], null, isCharacterWheel); var angle = i * self.segmentAngle; var radius = 200; segment.x = Math.cos(angle - Math.PI / 2) * radius; segment.y = Math.sin(angle - Math.PI / 2) * radius; segment.rotation = angle; self.addChild(segment); self.segments.push(segment); } var center = self.attachAsset('wheelCenter', { anchorX: 0.5, anchorY: 0.5 }); self.spin = function () { if (self.spinning) return; self.spinning = true; var spinAmount = Math.PI * 2 * (3 + Math.random() * 3); // 3-6 full rotations var finalRotation = self.currentRotation + spinAmount; tween(self, { rotation: finalRotation }, { duration: 2000 + Math.random() * 1000, easing: tween.easeOut, onFinish: function onFinish() { self.spinning = false; self.currentRotation = finalRotation % (Math.PI * 2); // Calculate selected segment var normalizedRotation = (Math.PI * 2 - self.currentRotation) % (Math.PI * 2); self.selectedIndex = Math.floor(normalizedRotation / self.segmentAngle); if (self.selectedIndex >= segments.length) self.selectedIndex = 0; } }); }; self.getSelectedItem = function () { return segments[self.selectedIndex]; }; return self; }); var WheelSegment = Container.expand(function (text, color, isCharacter) { var self = Container.call(this); var segmentBg = self.attachAsset(isCharacter ? 'characterSegment' : 'itemSegment', { anchorX: 0.5, anchorY: 0.5 }); var segmentText = new Text2(text, { size: 24, fill: 0xFFFFFF }); segmentText.anchor.set(0.5, 0.5); self.addChild(segmentText); return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x2c2c54 }); /**** * Game Code ****/ // Character and item lists var characters = ['Noobini', 'Lirili', 'Tim', 'Fluri', 'Talpa', 'Svinina', 'Pipi', 'Trippi', 'Tung tung', 'Gangster']; var items = ['Pizzanini', 'Larila', 'Cheese', 'Flura', 'Di fero', 'Bombardino', 'Kiwi', 'Corni', 'Troppi', 'Sahur', 'Footera']; // Create wheels var characterWheel = new SpinWheel(characters, true); characterWheel.x = 2048 / 2 - 350; characterWheel.y = 2732 / 2; game.addChild(characterWheel); var itemWheel = new SpinWheel(items, false); itemWheel.x = 2048 / 2 + 350; itemWheel.y = 2732 / 2; game.addChild(itemWheel); // Create pointers var characterPointer = game.addChild(LK.getAsset('pointer', { anchorX: 0.5, anchorY: 1 })); characterPointer.x = characterWheel.x; characterPointer.y = characterWheel.y - 330; var itemPointer = game.addChild(LK.getAsset('pointer', { anchorX: 0.5, anchorY: 1 })); itemPointer.x = itemWheel.x; itemPointer.y = itemWheel.y - 330; // UI Elements var instructionTxt = new Text2('Tap to Spin!', { size: 60, fill: 0xFFD700 }); instructionTxt.anchor.set(0.5, 0); instructionTxt.x = 2048 / 2; instructionTxt.y = 2732 - 200; game.addChild(instructionTxt); var resultTxt = new Text2('', { size: 50, fill: 0xFFFFFF }); resultTxt.anchor.set(0.5, 0.5); resultTxt.x = 2048 / 2; resultTxt.y = 2732 / 2 + 400; game.addChild(resultTxt); // Game variables var canSpin = true; var bothWheelsFinished = false; var characterFinished = false; var itemFinished = false; function checkBothWheelsFinished() { if (characterFinished && itemFinished) { bothWheelsFinished = true; canSpin = true; var selectedCharacter = characterWheel.getSelectedItem(); var selectedItem = itemWheel.getSelectedItem(); // Just show the fun combination resultTxt.setText(selectedCharacter + ' + ' + selectedItem); resultTxt.tint = 0xffffff; LK.getSound('match').play(); // Add a nice tween animation to the result text tween(resultTxt, { scaleX: 1.2, scaleY: 1.2 }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { tween(resultTxt, { scaleX: 1, scaleY: 1 }, { duration: 200, easing: tween.easeOut }); } }); // Reset flags characterFinished = false; itemFinished = false; bothWheelsFinished = false; } } game.down = function (x, y, obj) { if (canSpin && !characterWheel.spinning && !itemWheel.spinning) { canSpin = false; resultTxt.setText(''); // Spin both wheels characterWheel.spin(); itemWheel.spin(); LK.getSound('spin').play(); // Update instruction instructionTxt.setText('Spinning...'); } }; game.update = function () { // Check if character wheel finished spinning if (!characterWheel.spinning && !characterFinished && !canSpin) { characterFinished = true; checkBothWheelsFinished(); } // Check if item wheel finished spinning if (!itemWheel.spinning && !itemFinished && !canSpin) { itemFinished = true; checkBothWheelsFinished(); } // Update instruction text if (canSpin && !characterWheel.spinning && !itemWheel.spinning) { instructionTxt.setText('Tap to Spin!'); } };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var SpinWheel = Container.expand(function (segments, isCharacterWheel) {
var self = Container.call(this);
var wheelBg = self.attachAsset('wheelBackground', {
anchorX: 0.5,
anchorY: 0.5
});
self.segments = [];
self.segmentAngle = Math.PI * 2 / segments.length;
self.spinning = false;
self.currentRotation = 0;
self.selectedIndex = 0;
// Create segments
for (var i = 0; i < segments.length; i++) {
var segment = new WheelSegment(segments[i], null, isCharacterWheel);
var angle = i * self.segmentAngle;
var radius = 200;
segment.x = Math.cos(angle - Math.PI / 2) * radius;
segment.y = Math.sin(angle - Math.PI / 2) * radius;
segment.rotation = angle;
self.addChild(segment);
self.segments.push(segment);
}
var center = self.attachAsset('wheelCenter', {
anchorX: 0.5,
anchorY: 0.5
});
self.spin = function () {
if (self.spinning) return;
self.spinning = true;
var spinAmount = Math.PI * 2 * (3 + Math.random() * 3); // 3-6 full rotations
var finalRotation = self.currentRotation + spinAmount;
tween(self, {
rotation: finalRotation
}, {
duration: 2000 + Math.random() * 1000,
easing: tween.easeOut,
onFinish: function onFinish() {
self.spinning = false;
self.currentRotation = finalRotation % (Math.PI * 2);
// Calculate selected segment
var normalizedRotation = (Math.PI * 2 - self.currentRotation) % (Math.PI * 2);
self.selectedIndex = Math.floor(normalizedRotation / self.segmentAngle);
if (self.selectedIndex >= segments.length) self.selectedIndex = 0;
}
});
};
self.getSelectedItem = function () {
return segments[self.selectedIndex];
};
return self;
});
var WheelSegment = Container.expand(function (text, color, isCharacter) {
var self = Container.call(this);
var segmentBg = self.attachAsset(isCharacter ? 'characterSegment' : 'itemSegment', {
anchorX: 0.5,
anchorY: 0.5
});
var segmentText = new Text2(text, {
size: 24,
fill: 0xFFFFFF
});
segmentText.anchor.set(0.5, 0.5);
self.addChild(segmentText);
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2c2c54
});
/****
* Game Code
****/
// Character and item lists
var characters = ['Noobini', 'Lirili', 'Tim', 'Fluri', 'Talpa', 'Svinina', 'Pipi', 'Trippi', 'Tung tung', 'Gangster'];
var items = ['Pizzanini', 'Larila', 'Cheese', 'Flura', 'Di fero', 'Bombardino', 'Kiwi', 'Corni', 'Troppi', 'Sahur', 'Footera'];
// Create wheels
var characterWheel = new SpinWheel(characters, true);
characterWheel.x = 2048 / 2 - 350;
characterWheel.y = 2732 / 2;
game.addChild(characterWheel);
var itemWheel = new SpinWheel(items, false);
itemWheel.x = 2048 / 2 + 350;
itemWheel.y = 2732 / 2;
game.addChild(itemWheel);
// Create pointers
var characterPointer = game.addChild(LK.getAsset('pointer', {
anchorX: 0.5,
anchorY: 1
}));
characterPointer.x = characterWheel.x;
characterPointer.y = characterWheel.y - 330;
var itemPointer = game.addChild(LK.getAsset('pointer', {
anchorX: 0.5,
anchorY: 1
}));
itemPointer.x = itemWheel.x;
itemPointer.y = itemWheel.y - 330;
// UI Elements
var instructionTxt = new Text2('Tap to Spin!', {
size: 60,
fill: 0xFFD700
});
instructionTxt.anchor.set(0.5, 0);
instructionTxt.x = 2048 / 2;
instructionTxt.y = 2732 - 200;
game.addChild(instructionTxt);
var resultTxt = new Text2('', {
size: 50,
fill: 0xFFFFFF
});
resultTxt.anchor.set(0.5, 0.5);
resultTxt.x = 2048 / 2;
resultTxt.y = 2732 / 2 + 400;
game.addChild(resultTxt);
// Game variables
var canSpin = true;
var bothWheelsFinished = false;
var characterFinished = false;
var itemFinished = false;
function checkBothWheelsFinished() {
if (characterFinished && itemFinished) {
bothWheelsFinished = true;
canSpin = true;
var selectedCharacter = characterWheel.getSelectedItem();
var selectedItem = itemWheel.getSelectedItem();
// Just show the fun combination
resultTxt.setText(selectedCharacter + ' + ' + selectedItem);
resultTxt.tint = 0xffffff;
LK.getSound('match').play();
// Add a nice tween animation to the result text
tween(resultTxt, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(resultTxt, {
scaleX: 1,
scaleY: 1
}, {
duration: 200,
easing: tween.easeOut
});
}
});
// Reset flags
characterFinished = false;
itemFinished = false;
bothWheelsFinished = false;
}
}
game.down = function (x, y, obj) {
if (canSpin && !characterWheel.spinning && !itemWheel.spinning) {
canSpin = false;
resultTxt.setText('');
// Spin both wheels
characterWheel.spin();
itemWheel.spin();
LK.getSound('spin').play();
// Update instruction
instructionTxt.setText('Spinning...');
}
};
game.update = function () {
// Check if character wheel finished spinning
if (!characterWheel.spinning && !characterFinished && !canSpin) {
characterFinished = true;
checkBothWheelsFinished();
}
// Check if item wheel finished spinning
if (!itemWheel.spinning && !itemFinished && !canSpin) {
itemFinished = true;
checkBothWheelsFinished();
}
// Update instruction text
if (canSpin && !characterWheel.spinning && !itemWheel.spinning) {
instructionTxt.setText('Tap to Spin!');
}
};