User prompt
Move the all colors button left by 100 units
User prompt
I SAID THAT MOVE THE ERASER BUTTON AND NOT THE 'all colors button'!
User prompt
Move the eraser button right by 100 units
User prompt
Move the 'all colors button' left by 5 units
User prompt
Move the 'all colors button' left by 10 units
User prompt
Move the 'all colors button' left by 100 units
User prompt
Move the 'all colors button' left by 100 units and down 50 units
User prompt
Move the 'all colors button' left by 100 units and down 50 units
User prompt
Move all colors button left by 100 units and down 50 units
User prompt
The color selector targeting is not quite accurate, refine it
User prompt
Update ColorPalette background panel size to 1881x1899
User prompt
Update ColorPalette background panel size to 1881x1910
User prompt
Update ColorPalette background panel size to 1881x1919
User prompt
Update ColorPalette background panel size to 1881x1900
User prompt
Update ColorPalette background panel size to 1881x1950
User prompt
Ensure the 256 color palette background size is 1900x2000
User prompt
Scale up the 256 color palette size to fit the color tool windt
User prompt
Scale up the 256 color palette size by 3x
User prompt
Rearrange the 256 color palette colors to vector rainbow gradient
User prompt
Rearrange colors to vector rainbow gradient
User prompt
I mean a 256 colored palette with gradient of colors
User prompt
Could you add 'all color change' palette in the colortool? If this button selected then show up in the center of the map a full palette with a selector circle
User prompt
Swap green and Navy Blue Place
User prompt
Write the color names under this text:
User prompt
Display color names in the history menu
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1", { savedEggs: [] }); /**** * Classes ****/ var BrushStroke = Container.expand(function (color, size) { var self = Container.call(this); var stroke = self.attachAsset('brushStroke', { anchorX: 0.5, anchorY: 0.5, scaleX: size / 30, scaleY: size / 30 }); stroke.tint = color; return self; }); var Button = Container.expand(function (label, color) { var self = Container.call(this); var background = self.attachAsset('buttonBg', { anchorX: 0.5, anchorY: 0.5 }); var text = new Text2(label, { size: 30, fill: 0xFFFFFF }); text.anchor.set(0.5, 0.5); self.addChild(text); if (color !== undefined) { background.tint = color; } self.down = function () { tween(background, { scaleX: 0.9, scaleY: 0.9 }, { duration: 100 }); }; self.up = function () { tween(background, { scaleX: 1, scaleY: 1 }, { duration: 100 }); }; return self; }); var ColorButton = Container.expand(function (color) { var self = Container.call(this); var button = self.attachAsset('colorButton', { anchorX: 0.5, anchorY: 0.5 }); button.tint = color; self.color = color; self.down = function () { tween(button, { scaleX: 0.9, scaleY: 0.9 }, { duration: 100 }); }; self.up = function () { tween(button, { scaleX: 1, scaleY: 1 }, { duration: 100 }); }; return self; }); var CompletedEgg = Container.expand(function (baseColor) { var self = Container.call(this); var eggGraphic = self.attachAsset('completedEgg', { anchorX: 0.5, anchorY: 0.5 }); eggGraphic.tint = baseColor || 0xFFFFFF; // Add some random decoration to make each egg look unique for (var i = 0; i < 5; i++) { var glitter = self.attachAsset('glitter', { anchorX: 0.5, anchorY: 0.5, x: (Math.random() - 0.5) * 80, y: (Math.random() - 0.5) * 120 }); glitter.tint = 0xFFD700 + Math.floor(Math.random() * 0x555555); } return self; }); var EasterEgg = Container.expand(function () { var self = Container.call(this); var eggBase = self.attachAsset('eggBase', { anchorX: 0.5, anchorY: 0.5 }); var designContainer = new Container(); self.designContainer = designContainer; // Make accessible outside self.addChild(designContainer); self.addDesign = function (x, y, designElement) { var localPosition = designContainer.toLocal({ x: x, y: y }, game); designElement.x = localPosition.x; designElement.y = localPosition.y; designContainer.addChild(designElement); }; self.clearDesigns = function () { while (designContainer.children.length > 0) { designContainer.removeChild(designContainer.children[0]); } }; self.rotate = function (angle) { eggBase.rotation += angle; designContainer.rotation += angle; }; self.captureDesign = function () { // In a real implementation, this would create a snapshot of the egg // For this simplified version, we just create a new completed egg with the same tint var completedEgg = new CompletedEgg(eggBase.tint); return completedEgg; }; return self; }); var Sticker = Container.expand(function (type, scale) { var self = Container.call(this); var stickerAsset; if (type === 'star') { stickerAsset = self.attachAsset('stickerStar', { anchorX: 0.5, anchorY: 0.5, scaleX: scale, scaleY: scale }); } else if (type === 'heart') { stickerAsset = self.attachAsset('stickerHeart', { anchorX: 0.5, anchorY: 0.5, scaleX: scale, scaleY: scale }); } self.down = function () { tween(stickerAsset, { scaleX: scale * 0.9, scaleY: scale * 0.9 }, { duration: 100 }); }; self.up = function () { tween(stickerAsset, { scaleX: scale, scaleY: scale }, { duration: 100 }); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0xAFEEEE // Light turquoise background color }); /**** * Game Code ****/ // Define color palette var colors = [0x000000, // Black (moved to left) // Red 0xFF0000, // Orange 0xFF7F00, // Yellow 0xFFFF00, // Hot Pink 0xFF69B4, // Gold 0xFFD700, // Brown 0xA52A2A, // Maroon 0x800000, // Olive 0x808000, 0xFFFFFF, // White (moved to right) // Green 0x00FF00, // Blue 0x0000FF, // Indigo 0x4B0082, // Violet 0x9400D3, // Cyan 0x00FFFF, // Blue Violet 0x8A2BE2, // Gray 0x808080, // Lime Green 0x32CD32, // Teal 0x008080, // Navy Blue 0x000080]; // Define brush sizes var brushSizes = [10, 20, 30]; // Initialize game variables var currentColor = colors[0]; var currentBrushSize = brushSizes[1]; var currentEraserSize = 50; var currentTool = 'brush'; var isPainting = false; var lastX, lastY; var selectedColorButton = null; // Ensure savedEggs is properly initialized in storage var savedEggs = []; if (storage.savedEggs && Array.isArray(storage.savedEggs)) { savedEggs = storage.savedEggs; } else { storage.savedEggs = []; } // Create main egg var easterEgg = new EasterEgg(); easterEgg.x = 2048 / 2; easterEgg.y = 2732 / 2 - 200; game.addChild(easterEgg); // Create UI components // Tool panel var toolPanel = LK.getAsset('toolPanel', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2 - 5, y: 2732 - 100 // Moved up by 20 units }); game.addChild(toolPanel); // Color panel var colorPanel = LK.getAsset('colorPanel', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 - 345 // Moved down by 5 units }); game.addChild(colorPanel); // Add color buttons var colorButtons = []; for (var i = 0; i < colors.length; i++) { var colorButton = new ColorButton(colors[i]); // Position in two rows (10 in first row, 10 in second row) if (i < 10) { // First row colorButton.x = i * 130 + 160; // Changed spacing from 145 to 130, moved left by 10 units colorButton.y = 2732 - 410; // First row - moved up by 10 units } else { // Second row colorButton.x = (i - 10) * 130 + 160; // Changed spacing from 145 to 130, moved left by 10 units colorButton.y = 2732 - 280; // Second row } game.addChild(colorButton); colorButtons.push(colorButton); // Scale up by 2x tween(colorButton, { scaleX: 2, scaleY: 2 }, { duration: 300 }); // Add click handler (function (color, button) { colorButton.down = function () { tween(colorButton, { scaleX: 1.8, scaleY: 1.8 }, { duration: 100 }); currentColor = color; }; colorButton.up = function () { tween(colorButton, { scaleX: 2, scaleY: 2 }, { duration: 100 }); // Stop any animations on previously selected button if (selectedColorButton) { tween.stop(selectedColorButton); tween(selectedColorButton, { scaleX: 2, scaleY: 2 }, { duration: 100 }); } // Set new selected button selectedColorButton = button; // Start pulsing animation function pulseButton() { tween(selectedColorButton, { scaleX: 2.2, scaleY: 2.2 }, { duration: 500, easing: tween.easeInOut, onFinish: function onFinish() { tween(selectedColorButton, { scaleX: 1.8, scaleY: 1.8 }, { duration: 500, easing: tween.easeInOut, onFinish: pulseButton }); } }); } // Start the pulsing animation pulseButton(); }; })(colors[i], colorButton); } // Create tool buttons // Calculate button width including scale factor var buttonWidth = 120 * 2; // 120px width * 2 scale var buttonSpacing = 25; // 25 units apart var startX = 300; // Starting X position // Create tool buttons var brushButton = new Button("Brush", 0x6495ED); brushButton.x = startX - 75; // Moved left by 25 more units brushButton.y = 2732 - 100; // Moved up by 20 units game.addChild(brushButton); tween(brushButton, { scaleX: 2.2, scaleY: 2 }, { duration: 300 }); brushButton.down = function () { tween(brushButton, { scaleX: 1.98, scaleY: 1.8 }, { duration: 100 }); }; brushButton.up = function () { tween(brushButton, { scaleX: 2.2, scaleY: 2 }, { duration: 100 }); currentTool = 'brush'; }; var stickerStarButton = new Button("Star", 0xFFD700); stickerStarButton.x = startX + (buttonWidth + buttonSpacing) * 1 - 75; // Moved left by 25 more units stickerStarButton.y = 2732 - 100; // Moved up by 20 units game.addChild(stickerStarButton); tween(stickerStarButton, { scaleX: 2.2, scaleY: 2 }, { duration: 300 }); stickerStarButton.down = function () { tween(stickerStarButton, { scaleX: 1.98, scaleY: 1.8 }, { duration: 100 }); }; stickerStarButton.up = function () { tween(stickerStarButton, { scaleX: 2.2, scaleY: 2 }, { duration: 100 }); currentTool = 'star'; }; var stickerHeartButton = new Button("Heart", 0xFF0000); stickerHeartButton.x = startX + (buttonWidth + buttonSpacing) * 2 - 75; // Moved left by 25 more units stickerHeartButton.y = 2732 - 100; // Moved up by 20 units game.addChild(stickerHeartButton); tween(stickerHeartButton, { scaleX: 2.2, scaleY: 2 }, { duration: 300 }); stickerHeartButton.down = function () { tween(stickerHeartButton, { scaleX: 1.98, scaleY: 1.8 }, { duration: 100 }); }; stickerHeartButton.up = function () { tween(stickerHeartButton, { scaleX: 2.2, scaleY: 2 }, { duration: 100 }); currentTool = 'heart'; }; var rotateLeftButton = new Button("< Rotate", 0x9370DB); rotateLeftButton.x = startX + (buttonWidth + buttonSpacing) * 3 - 75; // Moved left by 25 more units rotateLeftButton.y = 2732 - 100; // Moved up by 20 units game.addChild(rotateLeftButton); tween(rotateLeftButton, { scaleX: 2.2, scaleY: 2 }, { duration: 300 }); rotateLeftButton.down = function () { tween(rotateLeftButton, { scaleX: 1.98, scaleY: 1.8 }, { duration: 100 }); }; rotateLeftButton.up = function () { tween(rotateLeftButton, { scaleX: 2.2, scaleY: 2 }, { duration: 100 }); easterEgg.rotate(-Math.PI / 8); }; // Add a thin grey vertical divider between rotate buttons var divider = LK.getAsset('buttonBg', { anchorX: 0.5, anchorY: 0.5, x: startX + (buttonWidth + buttonSpacing) * 3.5 - 75, // Position between the two rotate buttons y: 2732 - 100, // Same Y as buttons scaleX: 0.05, // Make it thin scaleY: 2 // Same height as buttons }); divider.tint = 0xe6e6fa; // Light lavender color game.addChild(divider); var rotateRightButton = new Button("Rotate >", 0x9370DB); rotateRightButton.x = startX + (buttonWidth + buttonSpacing) * 4 - 75; // Moved left by 25 more units rotateRightButton.y = 2732 - 100; // Moved up by 20 units game.addChild(rotateRightButton); tween(rotateRightButton, { scaleX: 2.2, scaleY: 2 }, { duration: 300 }); rotateRightButton.down = function () { tween(rotateRightButton, { scaleX: 1.98, scaleY: 1.8 }, { duration: 100 }); }; rotateRightButton.up = function () { tween(rotateRightButton, { scaleX: 2.2, scaleY: 2 }, { duration: 100 }); easterEgg.rotate(Math.PI / 8); }; var saveButton = new Button("Save", 0x32CD32); saveButton.x = startX + (buttonWidth + buttonSpacing) * 5 - 75; // Moved left by 25 more units saveButton.y = 2732 - 100; // Moved up by 20 units game.addChild(saveButton); tween(saveButton, { scaleX: 2.2, scaleY: 2 }, { duration: 300 }); saveButton.down = function () { tween(saveButton, { scaleX: 1.98, scaleY: 1.8 }, { duration: 100 }); }; saveButton.up = function () { tween(saveButton, { scaleX: 2.2, scaleY: 2 }, { duration: 100 }); // Save the current egg design var completedEgg = easterEgg.captureDesign(); // Get color name based on color value var colorName = "Unknown"; if (currentColor === 0x000000) { colorName = "Black"; } else if (currentColor === 0xFF0000) { colorName = "Red"; } else if (currentColor === 0xFF7F00) { colorName = "Orange"; } else if (currentColor === 0xFFFF00) { colorName = "Yellow"; } else if (currentColor === 0xFF69B4) { colorName = "Hot Pink"; } else if (currentColor === 0xFFD700) { colorName = "Gold"; } else if (currentColor === 0xA52A2A) { colorName = "Brown"; } else if (currentColor === 0x800000) { colorName = "Maroon"; } else if (currentColor === 0x808000) { colorName = "Olive"; } else if (currentColor === 0xFFFFFF) { colorName = "White"; } else if (currentColor === 0x00FF00) { colorName = "Green"; } else if (currentColor === 0x0000FF) { colorName = "Blue"; } else if (currentColor === 0x4B0082) { colorName = "Indigo"; } else if (currentColor === 0x9400D3) { colorName = "Violet"; } else if (currentColor === 0x00FFFF) { colorName = "Cyan"; } else if (currentColor === 0x8A2BE2) { colorName = "Blue Violet"; } else if (currentColor === 0x808080) { colorName = "Gray"; } else if (currentColor === 0x32CD32) { colorName = "Lime Green"; } else if (currentColor === 0x008080) { colorName = "Teal"; } else if (currentColor === 0x000080) { colorName = "Navy Blue"; } // Add to saved eggs var newEggData = { x: 150 + savedEggs.length % 4 * 180, y: 2732 - 600 - Math.floor(savedEggs.length / 4) * 220, color: currentColor, colorName: colorName }; // Ensure savedEggs is properly initialized as an array if (!Array.isArray(savedEggs)) { savedEggs = []; } // Add the new egg data to our array savedEggs.push(newEggData); // Update storage with a copy of the array storage.savedEggs = savedEggs.slice(); // Play save sound LK.getSound('saveSound').play(); // Add the egg to the basket display displaySavedEggs(); // Increment score LK.setScore(LK.getScore() + 1); // Clear the current egg for a new design easterEgg.clearDesigns(); }; var eraserButton = new Button("Eraser", 0x808080); eraserButton.x = colorPanel.x + colorPanel.width / 2 - 145; // Moved left by 25 units eraserButton.y = colorPanel.y - colorPanel.height / 2 + 85; // Moved down by 25 units game.addChild(eraserButton); tween(eraserButton, { scaleX: 2.2, scaleY: 2 }, { duration: 300 }); eraserButton.down = function () { tween(eraserButton, { scaleX: 1.98, scaleY: 1.8 }, { duration: 100 }); }; eraserButton.up = function () { tween(eraserButton, { scaleX: 2.2, scaleY: 2 }, { duration: 100 }); currentTool = 'eraser'; }; var clearButton = new Button("Clear", 0xFF6347); clearButton.x = startX + (buttonWidth + buttonSpacing) * 6 - 75; // Moved next to save button clearButton.y = 2732 - 100; // Moved up by 20 units game.addChild(clearButton); tween(clearButton, { scaleX: 2.2, scaleY: 2 }, { duration: 300 }); clearButton.down = function () { tween(clearButton, { scaleX: 1.98, scaleY: 1.8 }, { duration: 100 }); }; clearButton.up = function () { tween(clearButton, { scaleX: 2.2, scaleY: 2 }, { duration: 100 }); easterEgg.clearDesigns(); LK.getSound('clearSound').play(); }; // Function to toggle eraser tool function toggleEraserThicknessSlider(visible) { // Set eraser as current tool when enabled if (visible) { currentTool = 'eraser'; } } // Create basket display var basket = LK.getAsset('basket', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 - 800 // Moved up by 60 units to make room for two rows of color buttons }); game.addChild(basket); // Title text var titleText = new Text2("Easter Egg Artist", { size: 100, fill: 0x8B4513 // Dark brown }); titleText.anchor.set(0.5, 0); titleText.x = 2048 / 2; titleText.y = 50; game.addChild(titleText); // Score display var scoreText = new Text2("Eggs: 0", { size: 60, fill: 0x4B0082 // Indigo }); scoreText.anchor.set(0, 0); scoreText.x = 120; scoreText.y = 120; game.addChild(scoreText); // Function to display saved eggs function displaySavedEggs() { // Remove any existing displayed eggs for (var i = game.children.length - 1; i >= 0; i--) { if (game.children[i].isCompletedEgg || game.children[i].isEggLabel) { game.removeChild(game.children[i]); } } // Display saved eggs for (var i = 0; i < savedEggs.length; i++) { var eggData = savedEggs[i]; var displayedEgg = new CompletedEgg(eggData.color); displayedEgg.x = eggData.x; displayedEgg.y = eggData.y; displayedEgg.isCompletedEgg = true; game.addChild(displayedEgg); // Add color name label below the egg var colorLabel = new Text2(eggData.colorName || "Unknown", { size: 30, fill: 0x000000 }); colorLabel.anchor.set(0.5, 0); colorLabel.x = eggData.x; colorLabel.y = eggData.y + 100; colorLabel.isEggLabel = true; game.addChild(colorLabel); } } // Display any saved eggs displaySavedEggs(); // Game event handlers game.down = function (x, y) { if (y < 2732 - 350) { isPainting = true; lastX = x; lastY = y; if (currentTool === 'brush') { var brushStroke = new BrushStroke(currentColor, currentBrushSize); easterEgg.addDesign(x, y, brushStroke); LK.getSound('brushSound').play(); } else if (currentTool === 'star' || currentTool === 'heart') { var sticker = new Sticker(currentTool, 1.2); easterEgg.addDesign(x, y, sticker); LK.getSound('stickerSound').play(); } else if (currentTool === 'eraser') { // Remove the last design element if (easterEgg.designContainer && easterEgg.designContainer.children.length > 0) { easterEgg.designContainer.removeChild(easterEgg.designContainer.children[easterEgg.designContainer.children.length - 1]); LK.getSound('brushSound').play(); // Play sound for eraser too } } } }; game.move = function (x, y) { if (isPainting && (currentTool === 'brush' || currentTool === 'eraser')) { // Calculate distance between last point and current point var dx = x - lastX; var dy = y - lastY; var distance = Math.sqrt(dx * dx + dy * dy); // Get current size based on tool var currentSize = currentTool === 'brush' ? currentBrushSize : currentEraserSize; // Get current color based on tool var strokeColor = currentTool === 'brush' ? currentColor : 0xFFFFFF; // Get alpha based on tool (0 for eraser to make it invisible) var strokeAlpha = currentTool === 'brush' ? 1 : 0; // Play brush sound occasionally while using eraser if (currentTool === 'eraser' && Math.random() < 0.05) { LK.getSound('brushSound').play(); } // If distance is greater than half the size, add intermediate points if (distance > currentSize / 2) { var steps = Math.ceil(distance / (currentSize / 2)); for (var i = 1; i <= steps; i++) { var pointX = lastX + dx * i / steps; var pointY = lastY + dy * i / steps; if (currentTool === 'eraser') { // For eraser, remove the last design element if (easterEgg.designContainer && easterEgg.designContainer.children.length > 0) { easterEgg.designContainer.removeChild(easterEgg.designContainer.children[easterEgg.designContainer.children.length - 1]); } } else { var stroke = new BrushStroke(strokeColor, currentSize); stroke.alpha = strokeAlpha; easterEgg.addDesign(pointX, pointY, stroke); } } } else { if (currentTool === 'eraser') { // For eraser, remove the last design element if (easterEgg.designContainer && easterEgg.designContainer.children.length > 0) { easterEgg.designContainer.removeChild(easterEgg.designContainer.children[easterEgg.designContainer.children.length - 1]); } } else { var stroke = new BrushStroke(strokeColor, currentSize); stroke.alpha = strokeAlpha; easterEgg.addDesign(x, y, stroke); } } lastX = x; lastY = y; } }; game.up = function () { isPainting = false; }; // Update function game.update = function () { // Update score display scoreText.setText("Eggs: " + LK.getScore()); }; // Start background music LK.playMusic('easterMusic', { fade: { start: 0, end: 0.2, duration: 1000 } }); // Initialize first color button as selected with animation if (colorButtons.length > 0) { var _pulseSelectedButton = function pulseSelectedButton() { tween(selectedColorButton, { scaleX: 2.2, scaleY: 2.2 }, { duration: 500, easing: tween.easeInOut, onFinish: function onFinish() { tween(selectedColorButton, { scaleX: 1.8, scaleY: 1.8 }, { duration: 500, easing: tween.easeInOut, onFinish: _pulseSelectedButton }); } }); }; // Start the initial pulsing animation selectedColorButton = colorButtons[0]; // Start pulsing animation for first color button _pulseSelectedButton(); }
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
savedEggs: []
});
/****
* Classes
****/
var BrushStroke = Container.expand(function (color, size) {
var self = Container.call(this);
var stroke = self.attachAsset('brushStroke', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: size / 30,
scaleY: size / 30
});
stroke.tint = color;
return self;
});
var Button = Container.expand(function (label, color) {
var self = Container.call(this);
var background = self.attachAsset('buttonBg', {
anchorX: 0.5,
anchorY: 0.5
});
var text = new Text2(label, {
size: 30,
fill: 0xFFFFFF
});
text.anchor.set(0.5, 0.5);
self.addChild(text);
if (color !== undefined) {
background.tint = color;
}
self.down = function () {
tween(background, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100
});
};
self.up = function () {
tween(background, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
};
return self;
});
var ColorButton = Container.expand(function (color) {
var self = Container.call(this);
var button = self.attachAsset('colorButton', {
anchorX: 0.5,
anchorY: 0.5
});
button.tint = color;
self.color = color;
self.down = function () {
tween(button, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100
});
};
self.up = function () {
tween(button, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
};
return self;
});
var CompletedEgg = Container.expand(function (baseColor) {
var self = Container.call(this);
var eggGraphic = self.attachAsset('completedEgg', {
anchorX: 0.5,
anchorY: 0.5
});
eggGraphic.tint = baseColor || 0xFFFFFF;
// Add some random decoration to make each egg look unique
for (var i = 0; i < 5; i++) {
var glitter = self.attachAsset('glitter', {
anchorX: 0.5,
anchorY: 0.5,
x: (Math.random() - 0.5) * 80,
y: (Math.random() - 0.5) * 120
});
glitter.tint = 0xFFD700 + Math.floor(Math.random() * 0x555555);
}
return self;
});
var EasterEgg = Container.expand(function () {
var self = Container.call(this);
var eggBase = self.attachAsset('eggBase', {
anchorX: 0.5,
anchorY: 0.5
});
var designContainer = new Container();
self.designContainer = designContainer; // Make accessible outside
self.addChild(designContainer);
self.addDesign = function (x, y, designElement) {
var localPosition = designContainer.toLocal({
x: x,
y: y
}, game);
designElement.x = localPosition.x;
designElement.y = localPosition.y;
designContainer.addChild(designElement);
};
self.clearDesigns = function () {
while (designContainer.children.length > 0) {
designContainer.removeChild(designContainer.children[0]);
}
};
self.rotate = function (angle) {
eggBase.rotation += angle;
designContainer.rotation += angle;
};
self.captureDesign = function () {
// In a real implementation, this would create a snapshot of the egg
// For this simplified version, we just create a new completed egg with the same tint
var completedEgg = new CompletedEgg(eggBase.tint);
return completedEgg;
};
return self;
});
var Sticker = Container.expand(function (type, scale) {
var self = Container.call(this);
var stickerAsset;
if (type === 'star') {
stickerAsset = self.attachAsset('stickerStar', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: scale,
scaleY: scale
});
} else if (type === 'heart') {
stickerAsset = self.attachAsset('stickerHeart', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: scale,
scaleY: scale
});
}
self.down = function () {
tween(stickerAsset, {
scaleX: scale * 0.9,
scaleY: scale * 0.9
}, {
duration: 100
});
};
self.up = function () {
tween(stickerAsset, {
scaleX: scale,
scaleY: scale
}, {
duration: 100
});
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xAFEEEE // Light turquoise background color
});
/****
* Game Code
****/
// Define color palette
var colors = [0x000000,
// Black (moved to left)
// Red
0xFF0000,
// Orange
0xFF7F00,
// Yellow
0xFFFF00,
// Hot Pink
0xFF69B4,
// Gold
0xFFD700,
// Brown
0xA52A2A,
// Maroon
0x800000,
// Olive
0x808000, 0xFFFFFF,
// White (moved to right)
// Green
0x00FF00,
// Blue
0x0000FF,
// Indigo
0x4B0082,
// Violet
0x9400D3,
// Cyan
0x00FFFF,
// Blue Violet
0x8A2BE2,
// Gray
0x808080,
// Lime Green
0x32CD32,
// Teal
0x008080,
// Navy Blue
0x000080];
// Define brush sizes
var brushSizes = [10, 20, 30];
// Initialize game variables
var currentColor = colors[0];
var currentBrushSize = brushSizes[1];
var currentEraserSize = 50;
var currentTool = 'brush';
var isPainting = false;
var lastX, lastY;
var selectedColorButton = null;
// Ensure savedEggs is properly initialized in storage
var savedEggs = [];
if (storage.savedEggs && Array.isArray(storage.savedEggs)) {
savedEggs = storage.savedEggs;
} else {
storage.savedEggs = [];
}
// Create main egg
var easterEgg = new EasterEgg();
easterEgg.x = 2048 / 2;
easterEgg.y = 2732 / 2 - 200;
game.addChild(easterEgg);
// Create UI components
// Tool panel
var toolPanel = LK.getAsset('toolPanel', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2 - 5,
y: 2732 - 100 // Moved up by 20 units
});
game.addChild(toolPanel);
// Color panel
var colorPanel = LK.getAsset('colorPanel', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 - 345 // Moved down by 5 units
});
game.addChild(colorPanel);
// Add color buttons
var colorButtons = [];
for (var i = 0; i < colors.length; i++) {
var colorButton = new ColorButton(colors[i]);
// Position in two rows (10 in first row, 10 in second row)
if (i < 10) {
// First row
colorButton.x = i * 130 + 160; // Changed spacing from 145 to 130, moved left by 10 units
colorButton.y = 2732 - 410; // First row - moved up by 10 units
} else {
// Second row
colorButton.x = (i - 10) * 130 + 160; // Changed spacing from 145 to 130, moved left by 10 units
colorButton.y = 2732 - 280; // Second row
}
game.addChild(colorButton);
colorButtons.push(colorButton);
// Scale up by 2x
tween(colorButton, {
scaleX: 2,
scaleY: 2
}, {
duration: 300
});
// Add click handler
(function (color, button) {
colorButton.down = function () {
tween(colorButton, {
scaleX: 1.8,
scaleY: 1.8
}, {
duration: 100
});
currentColor = color;
};
colorButton.up = function () {
tween(colorButton, {
scaleX: 2,
scaleY: 2
}, {
duration: 100
});
// Stop any animations on previously selected button
if (selectedColorButton) {
tween.stop(selectedColorButton);
tween(selectedColorButton, {
scaleX: 2,
scaleY: 2
}, {
duration: 100
});
}
// Set new selected button
selectedColorButton = button;
// Start pulsing animation
function pulseButton() {
tween(selectedColorButton, {
scaleX: 2.2,
scaleY: 2.2
}, {
duration: 500,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(selectedColorButton, {
scaleX: 1.8,
scaleY: 1.8
}, {
duration: 500,
easing: tween.easeInOut,
onFinish: pulseButton
});
}
});
}
// Start the pulsing animation
pulseButton();
};
})(colors[i], colorButton);
}
// Create tool buttons
// Calculate button width including scale factor
var buttonWidth = 120 * 2; // 120px width * 2 scale
var buttonSpacing = 25; // 25 units apart
var startX = 300; // Starting X position
// Create tool buttons
var brushButton = new Button("Brush", 0x6495ED);
brushButton.x = startX - 75; // Moved left by 25 more units
brushButton.y = 2732 - 100; // Moved up by 20 units
game.addChild(brushButton);
tween(brushButton, {
scaleX: 2.2,
scaleY: 2
}, {
duration: 300
});
brushButton.down = function () {
tween(brushButton, {
scaleX: 1.98,
scaleY: 1.8
}, {
duration: 100
});
};
brushButton.up = function () {
tween(brushButton, {
scaleX: 2.2,
scaleY: 2
}, {
duration: 100
});
currentTool = 'brush';
};
var stickerStarButton = new Button("Star", 0xFFD700);
stickerStarButton.x = startX + (buttonWidth + buttonSpacing) * 1 - 75; // Moved left by 25 more units
stickerStarButton.y = 2732 - 100; // Moved up by 20 units
game.addChild(stickerStarButton);
tween(stickerStarButton, {
scaleX: 2.2,
scaleY: 2
}, {
duration: 300
});
stickerStarButton.down = function () {
tween(stickerStarButton, {
scaleX: 1.98,
scaleY: 1.8
}, {
duration: 100
});
};
stickerStarButton.up = function () {
tween(stickerStarButton, {
scaleX: 2.2,
scaleY: 2
}, {
duration: 100
});
currentTool = 'star';
};
var stickerHeartButton = new Button("Heart", 0xFF0000);
stickerHeartButton.x = startX + (buttonWidth + buttonSpacing) * 2 - 75; // Moved left by 25 more units
stickerHeartButton.y = 2732 - 100; // Moved up by 20 units
game.addChild(stickerHeartButton);
tween(stickerHeartButton, {
scaleX: 2.2,
scaleY: 2
}, {
duration: 300
});
stickerHeartButton.down = function () {
tween(stickerHeartButton, {
scaleX: 1.98,
scaleY: 1.8
}, {
duration: 100
});
};
stickerHeartButton.up = function () {
tween(stickerHeartButton, {
scaleX: 2.2,
scaleY: 2
}, {
duration: 100
});
currentTool = 'heart';
};
var rotateLeftButton = new Button("< Rotate", 0x9370DB);
rotateLeftButton.x = startX + (buttonWidth + buttonSpacing) * 3 - 75; // Moved left by 25 more units
rotateLeftButton.y = 2732 - 100; // Moved up by 20 units
game.addChild(rotateLeftButton);
tween(rotateLeftButton, {
scaleX: 2.2,
scaleY: 2
}, {
duration: 300
});
rotateLeftButton.down = function () {
tween(rotateLeftButton, {
scaleX: 1.98,
scaleY: 1.8
}, {
duration: 100
});
};
rotateLeftButton.up = function () {
tween(rotateLeftButton, {
scaleX: 2.2,
scaleY: 2
}, {
duration: 100
});
easterEgg.rotate(-Math.PI / 8);
};
// Add a thin grey vertical divider between rotate buttons
var divider = LK.getAsset('buttonBg', {
anchorX: 0.5,
anchorY: 0.5,
x: startX + (buttonWidth + buttonSpacing) * 3.5 - 75,
// Position between the two rotate buttons
y: 2732 - 100,
// Same Y as buttons
scaleX: 0.05,
// Make it thin
scaleY: 2 // Same height as buttons
});
divider.tint = 0xe6e6fa; // Light lavender color
game.addChild(divider);
var rotateRightButton = new Button("Rotate >", 0x9370DB);
rotateRightButton.x = startX + (buttonWidth + buttonSpacing) * 4 - 75; // Moved left by 25 more units
rotateRightButton.y = 2732 - 100; // Moved up by 20 units
game.addChild(rotateRightButton);
tween(rotateRightButton, {
scaleX: 2.2,
scaleY: 2
}, {
duration: 300
});
rotateRightButton.down = function () {
tween(rotateRightButton, {
scaleX: 1.98,
scaleY: 1.8
}, {
duration: 100
});
};
rotateRightButton.up = function () {
tween(rotateRightButton, {
scaleX: 2.2,
scaleY: 2
}, {
duration: 100
});
easterEgg.rotate(Math.PI / 8);
};
var saveButton = new Button("Save", 0x32CD32);
saveButton.x = startX + (buttonWidth + buttonSpacing) * 5 - 75; // Moved left by 25 more units
saveButton.y = 2732 - 100; // Moved up by 20 units
game.addChild(saveButton);
tween(saveButton, {
scaleX: 2.2,
scaleY: 2
}, {
duration: 300
});
saveButton.down = function () {
tween(saveButton, {
scaleX: 1.98,
scaleY: 1.8
}, {
duration: 100
});
};
saveButton.up = function () {
tween(saveButton, {
scaleX: 2.2,
scaleY: 2
}, {
duration: 100
});
// Save the current egg design
var completedEgg = easterEgg.captureDesign();
// Get color name based on color value
var colorName = "Unknown";
if (currentColor === 0x000000) {
colorName = "Black";
} else if (currentColor === 0xFF0000) {
colorName = "Red";
} else if (currentColor === 0xFF7F00) {
colorName = "Orange";
} else if (currentColor === 0xFFFF00) {
colorName = "Yellow";
} else if (currentColor === 0xFF69B4) {
colorName = "Hot Pink";
} else if (currentColor === 0xFFD700) {
colorName = "Gold";
} else if (currentColor === 0xA52A2A) {
colorName = "Brown";
} else if (currentColor === 0x800000) {
colorName = "Maroon";
} else if (currentColor === 0x808000) {
colorName = "Olive";
} else if (currentColor === 0xFFFFFF) {
colorName = "White";
} else if (currentColor === 0x00FF00) {
colorName = "Green";
} else if (currentColor === 0x0000FF) {
colorName = "Blue";
} else if (currentColor === 0x4B0082) {
colorName = "Indigo";
} else if (currentColor === 0x9400D3) {
colorName = "Violet";
} else if (currentColor === 0x00FFFF) {
colorName = "Cyan";
} else if (currentColor === 0x8A2BE2) {
colorName = "Blue Violet";
} else if (currentColor === 0x808080) {
colorName = "Gray";
} else if (currentColor === 0x32CD32) {
colorName = "Lime Green";
} else if (currentColor === 0x008080) {
colorName = "Teal";
} else if (currentColor === 0x000080) {
colorName = "Navy Blue";
}
// Add to saved eggs
var newEggData = {
x: 150 + savedEggs.length % 4 * 180,
y: 2732 - 600 - Math.floor(savedEggs.length / 4) * 220,
color: currentColor,
colorName: colorName
};
// Ensure savedEggs is properly initialized as an array
if (!Array.isArray(savedEggs)) {
savedEggs = [];
}
// Add the new egg data to our array
savedEggs.push(newEggData);
// Update storage with a copy of the array
storage.savedEggs = savedEggs.slice();
// Play save sound
LK.getSound('saveSound').play();
// Add the egg to the basket display
displaySavedEggs();
// Increment score
LK.setScore(LK.getScore() + 1);
// Clear the current egg for a new design
easterEgg.clearDesigns();
};
var eraserButton = new Button("Eraser", 0x808080);
eraserButton.x = colorPanel.x + colorPanel.width / 2 - 145; // Moved left by 25 units
eraserButton.y = colorPanel.y - colorPanel.height / 2 + 85; // Moved down by 25 units
game.addChild(eraserButton);
tween(eraserButton, {
scaleX: 2.2,
scaleY: 2
}, {
duration: 300
});
eraserButton.down = function () {
tween(eraserButton, {
scaleX: 1.98,
scaleY: 1.8
}, {
duration: 100
});
};
eraserButton.up = function () {
tween(eraserButton, {
scaleX: 2.2,
scaleY: 2
}, {
duration: 100
});
currentTool = 'eraser';
};
var clearButton = new Button("Clear", 0xFF6347);
clearButton.x = startX + (buttonWidth + buttonSpacing) * 6 - 75; // Moved next to save button
clearButton.y = 2732 - 100; // Moved up by 20 units
game.addChild(clearButton);
tween(clearButton, {
scaleX: 2.2,
scaleY: 2
}, {
duration: 300
});
clearButton.down = function () {
tween(clearButton, {
scaleX: 1.98,
scaleY: 1.8
}, {
duration: 100
});
};
clearButton.up = function () {
tween(clearButton, {
scaleX: 2.2,
scaleY: 2
}, {
duration: 100
});
easterEgg.clearDesigns();
LK.getSound('clearSound').play();
};
// Function to toggle eraser tool
function toggleEraserThicknessSlider(visible) {
// Set eraser as current tool when enabled
if (visible) {
currentTool = 'eraser';
}
}
// Create basket display
var basket = LK.getAsset('basket', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 - 800 // Moved up by 60 units to make room for two rows of color buttons
});
game.addChild(basket);
// Title text
var titleText = new Text2("Easter Egg Artist", {
size: 100,
fill: 0x8B4513 // Dark brown
});
titleText.anchor.set(0.5, 0);
titleText.x = 2048 / 2;
titleText.y = 50;
game.addChild(titleText);
// Score display
var scoreText = new Text2("Eggs: 0", {
size: 60,
fill: 0x4B0082 // Indigo
});
scoreText.anchor.set(0, 0);
scoreText.x = 120;
scoreText.y = 120;
game.addChild(scoreText);
// Function to display saved eggs
function displaySavedEggs() {
// Remove any existing displayed eggs
for (var i = game.children.length - 1; i >= 0; i--) {
if (game.children[i].isCompletedEgg || game.children[i].isEggLabel) {
game.removeChild(game.children[i]);
}
}
// Display saved eggs
for (var i = 0; i < savedEggs.length; i++) {
var eggData = savedEggs[i];
var displayedEgg = new CompletedEgg(eggData.color);
displayedEgg.x = eggData.x;
displayedEgg.y = eggData.y;
displayedEgg.isCompletedEgg = true;
game.addChild(displayedEgg);
// Add color name label below the egg
var colorLabel = new Text2(eggData.colorName || "Unknown", {
size: 30,
fill: 0x000000
});
colorLabel.anchor.set(0.5, 0);
colorLabel.x = eggData.x;
colorLabel.y = eggData.y + 100;
colorLabel.isEggLabel = true;
game.addChild(colorLabel);
}
}
// Display any saved eggs
displaySavedEggs();
// Game event handlers
game.down = function (x, y) {
if (y < 2732 - 350) {
isPainting = true;
lastX = x;
lastY = y;
if (currentTool === 'brush') {
var brushStroke = new BrushStroke(currentColor, currentBrushSize);
easterEgg.addDesign(x, y, brushStroke);
LK.getSound('brushSound').play();
} else if (currentTool === 'star' || currentTool === 'heart') {
var sticker = new Sticker(currentTool, 1.2);
easterEgg.addDesign(x, y, sticker);
LK.getSound('stickerSound').play();
} else if (currentTool === 'eraser') {
// Remove the last design element
if (easterEgg.designContainer && easterEgg.designContainer.children.length > 0) {
easterEgg.designContainer.removeChild(easterEgg.designContainer.children[easterEgg.designContainer.children.length - 1]);
LK.getSound('brushSound').play(); // Play sound for eraser too
}
}
}
};
game.move = function (x, y) {
if (isPainting && (currentTool === 'brush' || currentTool === 'eraser')) {
// Calculate distance between last point and current point
var dx = x - lastX;
var dy = y - lastY;
var distance = Math.sqrt(dx * dx + dy * dy);
// Get current size based on tool
var currentSize = currentTool === 'brush' ? currentBrushSize : currentEraserSize;
// Get current color based on tool
var strokeColor = currentTool === 'brush' ? currentColor : 0xFFFFFF;
// Get alpha based on tool (0 for eraser to make it invisible)
var strokeAlpha = currentTool === 'brush' ? 1 : 0;
// Play brush sound occasionally while using eraser
if (currentTool === 'eraser' && Math.random() < 0.05) {
LK.getSound('brushSound').play();
}
// If distance is greater than half the size, add intermediate points
if (distance > currentSize / 2) {
var steps = Math.ceil(distance / (currentSize / 2));
for (var i = 1; i <= steps; i++) {
var pointX = lastX + dx * i / steps;
var pointY = lastY + dy * i / steps;
if (currentTool === 'eraser') {
// For eraser, remove the last design element
if (easterEgg.designContainer && easterEgg.designContainer.children.length > 0) {
easterEgg.designContainer.removeChild(easterEgg.designContainer.children[easterEgg.designContainer.children.length - 1]);
}
} else {
var stroke = new BrushStroke(strokeColor, currentSize);
stroke.alpha = strokeAlpha;
easterEgg.addDesign(pointX, pointY, stroke);
}
}
} else {
if (currentTool === 'eraser') {
// For eraser, remove the last design element
if (easterEgg.designContainer && easterEgg.designContainer.children.length > 0) {
easterEgg.designContainer.removeChild(easterEgg.designContainer.children[easterEgg.designContainer.children.length - 1]);
}
} else {
var stroke = new BrushStroke(strokeColor, currentSize);
stroke.alpha = strokeAlpha;
easterEgg.addDesign(x, y, stroke);
}
}
lastX = x;
lastY = y;
}
};
game.up = function () {
isPainting = false;
};
// Update function
game.update = function () {
// Update score display
scoreText.setText("Eggs: " + LK.getScore());
};
// Start background music
LK.playMusic('easterMusic', {
fade: {
start: 0,
end: 0.2,
duration: 1000
}
});
// Initialize first color button as selected with animation
if (colorButtons.length > 0) {
var _pulseSelectedButton = function pulseSelectedButton() {
tween(selectedColorButton, {
scaleX: 2.2,
scaleY: 2.2
}, {
duration: 500,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(selectedColorButton, {
scaleX: 1.8,
scaleY: 1.8
}, {
duration: 500,
easing: tween.easeInOut,
onFinish: _pulseSelectedButton
});
}
});
}; // Start the initial pulsing animation
selectedColorButton = colorButtons[0];
// Start pulsing animation for first color button
_pulseSelectedButton();
}