/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Sparkle = Container.expand(function () {
var self = Container.call(this);
var sparkleGraphics = self.attachAsset('sparkle', {
anchorX: 0.5,
anchorY: 0.5
});
self.lifetime = 60;
self.maxLifetime = 60;
self.update = function () {
self.lifetime--;
self.alpha = self.lifetime / self.maxLifetime;
self.scaleX = self.scaleY = 0.5 + self.lifetime / self.maxLifetime * 0.5;
if (self.lifetime <= 0) {
self.destroy();
for (var i = sparkles.length - 1; i >= 0; i--) {
if (sparkles[i] === self) {
sparkles.splice(i, 1);
break;
}
}
}
};
return self;
});
var SpinWheel = Container.expand(function () {
var self = Container.call(this);
var wheelBase = self.attachAsset('wheelBase', {
anchorX: 0.5,
anchorY: 0.5
});
// Create segments
var segments = [];
var princesses = ['Belle', 'Cinderella', 'Tiana', 'Ariel'];
var colors = [0xFFE135, 0x87CEEB, 0x90EE90, 0xDDA0DD];
for (var i = 0; i < 4; i++) {
var segment = new WheelSegment(colors[i], princesses[i]);
var angle = i * Math.PI * 2 / 4;
segment.x = Math.cos(angle) * 120;
segment.y = Math.sin(angle) * 120;
segment.rotation = angle + Math.PI / 4;
segments.push(segment);
self.addChild(segment);
}
self.segments = segments;
self.isSpinning = false;
self.currentRotation = 0;
self.targetRotation = 0;
self.spinSpeed = 0;
self.spin = function () {
if (self.isSpinning) return;
self.isSpinning = true;
var spins = 5 + Math.random() * 3; // 5-8 full rotations
var finalAngle = Math.random() * Math.PI * 2;
self.targetRotation = self.currentRotation + spins * Math.PI * 2 + finalAngle;
self.spinSpeed = 0.3;
LK.getSound('spin').play();
};
self.update = function () {
if (self.isSpinning) {
var diff = self.targetRotation - self.currentRotation;
if (Math.abs(diff) > 0.1) {
self.currentRotation += diff * self.spinSpeed;
self.rotation = self.currentRotation;
self.spinSpeed *= 0.98; // Gradual slowdown
} else {
self.currentRotation = self.targetRotation;
self.rotation = self.currentRotation;
self.isSpinning = false;
self.onSpinComplete();
}
}
};
self.onSpinComplete = function () {
LK.getSound('stop').play();
// Determine which princess was selected
var normalizedAngle = (self.currentRotation % (Math.PI * 2) + Math.PI * 2) % (Math.PI * 2);
var segmentIndex = Math.floor((normalizedAngle + Math.PI / 4) / (Math.PI * 2) * 4) % 4;
var selectedPrincess = self.segments[segmentIndex].princessName;
// Determine if it's correct (Belle and Cinderella are "correct")
var isCorrect = selectedPrincess === 'Belle' || selectedPrincess === 'Cinderella';
if (isCorrect) {
LK.setScore(LK.getScore() + 100);
LK.getSound('correct').play();
resultText.setText('Perfect! ' + selectedPrincess + ' is fabulous!');
resultText.tint = 0x00FF00;
} else {
LK.setScore(LK.getScore() + 10);
LK.getSound('wrong').play();
resultText.setText('Nice try! Got ' + selectedPrincess + '.');
resultText.tint = 0xFFFFFF;
}
scoreText.setText(LK.getScore());
// Create sparkles
for (var i = 0; i < 8; i++) {
var sparkle = new Sparkle();
var angle = i / 8 * Math.PI * 2;
sparkle.x = self.x + Math.cos(angle) * 350;
sparkle.y = self.y + Math.sin(angle) * 350;
sparkles.push(sparkle);
game.addChild(sparkle);
}
// Show instruction after a delay
LK.setTimeout(function () {
instructionText.alpha = 1;
}, 2000);
};
self.down = function (x, y, obj) {
self.spin();
instructionText.alpha = 0;
resultText.setText('Spinning...');
resultText.tint = 0xFFFFFF;
};
return self;
});
var WheelSegment = Container.expand(function (color, princessName) {
var self = Container.call(this);
var segmentGraphics = self.attachAsset(color === 0xFFE135 ? 'wheelSegment1' : color === 0x87CEEB ? 'wheelSegment2' : color === 0x90EE90 ? 'wheelSegment3' : 'wheelSegment4', {
anchorX: 0.5,
anchorY: 0.5
});
var princessText = new Text2(princessName, {
size: 36,
fill: 0xFFFFFF
});
princessText.anchor.set(0.5, 0.5);
princessText.x = 0;
princessText.y = 0;
self.addChild(princessText);
self.princessName = princessName;
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xFF69B4
});
/****
* Game Code
****/
var sparkles = [];
// Create wheel
var wheel = game.addChild(new SpinWheel());
wheel.x = 2048 / 2;
wheel.y = 1366;
// Create pointer
var pointer = game.addChild(LK.getAsset('pointer', {
anchorX: 0.5,
anchorY: 0.8
}));
pointer.x = 2048 / 2;
pointer.y = 1066;
// Create title
var titleText = new Text2('Princess Costume Wheel', {
size: 80,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 2048 / 2;
titleText.y = 400;
game.addChild(titleText);
// Create instruction text
var instructionText = new Text2('Tap the wheel to spin!', {
size: 60,
fill: 0xFFFFFF
});
instructionText.anchor.set(0.5, 0.5);
instructionText.x = 2048 / 2;
instructionText.y = 2200;
game.addChild(instructionText);
// Create result text
var resultText = new Text2('Discover your princess costume!', {
size: 50,
fill: 0xFFFFFF
});
resultText.anchor.set(0.5, 0.5);
resultText.x = 2048 / 2;
resultText.y = 2400;
game.addChild(resultText);
// Create score display
var scoreText = new Text2('0', {
size: 80,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
scoreText.y = 150;
// Initialize score
scoreText.setText(LK.getScore());
game.update = function () {
// Handle sparkle animations and cleanup
for (var i = sparkles.length - 1; i >= 0; i--) {
var sparkle = sparkles[i];
if (sparkle.parent === null) {
sparkles.splice(i, 1);
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,208 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Sparkle = Container.expand(function () {
+ var self = Container.call(this);
+ var sparkleGraphics = self.attachAsset('sparkle', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.lifetime = 60;
+ self.maxLifetime = 60;
+ self.update = function () {
+ self.lifetime--;
+ self.alpha = self.lifetime / self.maxLifetime;
+ self.scaleX = self.scaleY = 0.5 + self.lifetime / self.maxLifetime * 0.5;
+ if (self.lifetime <= 0) {
+ self.destroy();
+ for (var i = sparkles.length - 1; i >= 0; i--) {
+ if (sparkles[i] === self) {
+ sparkles.splice(i, 1);
+ break;
+ }
+ }
+ }
+ };
+ return self;
+});
+var SpinWheel = Container.expand(function () {
+ var self = Container.call(this);
+ var wheelBase = self.attachAsset('wheelBase', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Create segments
+ var segments = [];
+ var princesses = ['Belle', 'Cinderella', 'Tiana', 'Ariel'];
+ var colors = [0xFFE135, 0x87CEEB, 0x90EE90, 0xDDA0DD];
+ for (var i = 0; i < 4; i++) {
+ var segment = new WheelSegment(colors[i], princesses[i]);
+ var angle = i * Math.PI * 2 / 4;
+ segment.x = Math.cos(angle) * 120;
+ segment.y = Math.sin(angle) * 120;
+ segment.rotation = angle + Math.PI / 4;
+ segments.push(segment);
+ self.addChild(segment);
+ }
+ self.segments = segments;
+ self.isSpinning = false;
+ self.currentRotation = 0;
+ self.targetRotation = 0;
+ self.spinSpeed = 0;
+ self.spin = function () {
+ if (self.isSpinning) return;
+ self.isSpinning = true;
+ var spins = 5 + Math.random() * 3; // 5-8 full rotations
+ var finalAngle = Math.random() * Math.PI * 2;
+ self.targetRotation = self.currentRotation + spins * Math.PI * 2 + finalAngle;
+ self.spinSpeed = 0.3;
+ LK.getSound('spin').play();
+ };
+ self.update = function () {
+ if (self.isSpinning) {
+ var diff = self.targetRotation - self.currentRotation;
+ if (Math.abs(diff) > 0.1) {
+ self.currentRotation += diff * self.spinSpeed;
+ self.rotation = self.currentRotation;
+ self.spinSpeed *= 0.98; // Gradual slowdown
+ } else {
+ self.currentRotation = self.targetRotation;
+ self.rotation = self.currentRotation;
+ self.isSpinning = false;
+ self.onSpinComplete();
+ }
+ }
+ };
+ self.onSpinComplete = function () {
+ LK.getSound('stop').play();
+ // Determine which princess was selected
+ var normalizedAngle = (self.currentRotation % (Math.PI * 2) + Math.PI * 2) % (Math.PI * 2);
+ var segmentIndex = Math.floor((normalizedAngle + Math.PI / 4) / (Math.PI * 2) * 4) % 4;
+ var selectedPrincess = self.segments[segmentIndex].princessName;
+ // Determine if it's correct (Belle and Cinderella are "correct")
+ var isCorrect = selectedPrincess === 'Belle' || selectedPrincess === 'Cinderella';
+ if (isCorrect) {
+ LK.setScore(LK.getScore() + 100);
+ LK.getSound('correct').play();
+ resultText.setText('Perfect! ' + selectedPrincess + ' is fabulous!');
+ resultText.tint = 0x00FF00;
+ } else {
+ LK.setScore(LK.getScore() + 10);
+ LK.getSound('wrong').play();
+ resultText.setText('Nice try! Got ' + selectedPrincess + '.');
+ resultText.tint = 0xFFFFFF;
+ }
+ scoreText.setText(LK.getScore());
+ // Create sparkles
+ for (var i = 0; i < 8; i++) {
+ var sparkle = new Sparkle();
+ var angle = i / 8 * Math.PI * 2;
+ sparkle.x = self.x + Math.cos(angle) * 350;
+ sparkle.y = self.y + Math.sin(angle) * 350;
+ sparkles.push(sparkle);
+ game.addChild(sparkle);
+ }
+ // Show instruction after a delay
+ LK.setTimeout(function () {
+ instructionText.alpha = 1;
+ }, 2000);
+ };
+ self.down = function (x, y, obj) {
+ self.spin();
+ instructionText.alpha = 0;
+ resultText.setText('Spinning...');
+ resultText.tint = 0xFFFFFF;
+ };
+ return self;
+});
+var WheelSegment = Container.expand(function (color, princessName) {
+ var self = Container.call(this);
+ var segmentGraphics = self.attachAsset(color === 0xFFE135 ? 'wheelSegment1' : color === 0x87CEEB ? 'wheelSegment2' : color === 0x90EE90 ? 'wheelSegment3' : 'wheelSegment4', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var princessText = new Text2(princessName, {
+ size: 36,
+ fill: 0xFFFFFF
+ });
+ princessText.anchor.set(0.5, 0.5);
+ princessText.x = 0;
+ princessText.y = 0;
+ self.addChild(princessText);
+ self.princessName = princessName;
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0xFF69B4
+});
+
+/****
+* Game Code
+****/
+var sparkles = [];
+// Create wheel
+var wheel = game.addChild(new SpinWheel());
+wheel.x = 2048 / 2;
+wheel.y = 1366;
+// Create pointer
+var pointer = game.addChild(LK.getAsset('pointer', {
+ anchorX: 0.5,
+ anchorY: 0.8
+}));
+pointer.x = 2048 / 2;
+pointer.y = 1066;
+// Create title
+var titleText = new Text2('Princess Costume Wheel', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+titleText.anchor.set(0.5, 0.5);
+titleText.x = 2048 / 2;
+titleText.y = 400;
+game.addChild(titleText);
+// Create instruction text
+var instructionText = new Text2('Tap the wheel to spin!', {
+ size: 60,
+ fill: 0xFFFFFF
+});
+instructionText.anchor.set(0.5, 0.5);
+instructionText.x = 2048 / 2;
+instructionText.y = 2200;
+game.addChild(instructionText);
+// Create result text
+var resultText = new Text2('Discover your princess costume!', {
+ size: 50,
+ fill: 0xFFFFFF
+});
+resultText.anchor.set(0.5, 0.5);
+resultText.x = 2048 / 2;
+resultText.y = 2400;
+game.addChild(resultText);
+// Create score display
+var scoreText = new Text2('0', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+scoreText.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreText);
+scoreText.y = 150;
+// Initialize score
+scoreText.setText(LK.getScore());
+game.update = function () {
+ // Handle sparkle animations and cleanup
+ for (var i = sparkles.length - 1; i >= 0; i--) {
+ var sparkle = sparkles[i];
+ if (sparkle.parent === null) {
+ sparkles.splice(i, 1);
+ }
+ }
+};
\ No newline at end of file