/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var ProgressDisplay = Container.expand(function () {
var self = Container.call(this);
// Progress bar background
var progressBg = self.attachAsset('progressBackground', {
anchorX: 0.5,
anchorY: 0.5
});
// Progress bar fill
var progressFill = self.attachAsset('progressBar', {
anchorX: 0,
anchorY: 0.5,
width: 0
});
progressFill.x = -200; // Center aligned
// Progress text
var progressText = new Text2('0%', {
size: 40,
fill: 0xFFFFFF
});
progressText.anchor.set(0.5, 0.5);
progressText.y = -40;
self.addChild(progressText);
self.updateProgress = function (percentage) {
var clampedPercentage = Math.max(0, Math.min(100, percentage));
progressFill.width = clampedPercentage / 100 * 400;
progressText.setText(Math.floor(clampedPercentage) + '%');
// Celebration effect when reaching milestones
if (clampedPercentage >= 25 && clampedPercentage < 26) {
LK.effects.flashObject(self, 0x4ecdc4, 500);
}
if (clampedPercentage >= 50 && clampedPercentage < 51) {
LK.effects.flashObject(self, 0xf9ca24, 500);
}
if (clampedPercentage >= 75 && clampedPercentage < 76) {
LK.effects.flashObject(self, 0xf0932b, 500);
}
if (clampedPercentage >= 100) {
LK.effects.flashScreen(0x4ecdc4, 1000);
LK.showYouWin();
}
};
return self;
});
var ScratchSurface = Container.expand(function () {
var self = Container.call(this);
// Create colorful background patterns
var backgrounds = [];
var colors = [0xff6b6b, 0x4ecdc4, 0x45b7d1, 0xf9ca24, 0xf0932b, 0xeb4d4b, 0x6c5ce7, 0xa29bfe];
// Create colorful pattern background
for (var i = 0; i < 32; i++) {
for (var j = 0; j < 43; j++) {
var colorIndex = (i + j) % colors.length;
var bgTile = LK.getAsset('colorfulBackground', {
width: 64,
height: 64,
color: colors[colorIndex]
});
bgTile.x = i * 64;
bgTile.y = j * 64;
self.addChild(bgTile);
backgrounds.push(bgTile);
}
}
// Create scratch overlay
var overlay = self.attachAsset('scratchOverlay', {
x: 0,
y: 0
});
// Track scratched areas
self.scratchedPixels = [];
self.totalPixels = 2048 * 2732;
self.scratchedCount = 0;
// Scratch method
self.scratch = function (x, y, brushSize) {
brushSize = brushSize || 60;
var radius = brushSize / 2;
// Create scratch hole by manipulating overlay alpha
var scratchArea = LK.getAsset('scratchBrush', {
width: brushSize,
height: brushSize,
anchorX: 0.5,
anchorY: 0.5
});
scratchArea.x = x;
scratchArea.y = y;
scratchArea.blendMode = 'erase';
overlay.addChild(scratchArea);
// Track progress
var pixelsScratched = Math.PI * radius * radius;
self.scratchedCount += pixelsScratched;
// Play scratch sound occasionally
if (Math.random() < 0.1) {
LK.getSound('scratch').play();
}
};
self.getScratchPercentage = function () {
return Math.min(100, self.scratchedCount / self.totalPixels * 100 * 50); // Multiplied by 50 to make progress more visible
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a1a1a
});
/****
* Game Code
****/
// Game variables
var scratchSurface;
var progressDisplay;
var isScratching = false;
var lastScratchX = 0;
var lastScratchY = 0;
var brushSize = 60;
// Initialize game elements
scratchSurface = game.addChild(new ScratchSurface());
scratchSurface.x = 0;
scratchSurface.y = 0;
// Progress display
progressDisplay = game.addChild(new ProgressDisplay());
progressDisplay.x = 1024;
progressDisplay.y = 100;
// Instructions text
var instructionText = new Text2('Scratch the surface to reveal the art!', {
size: 60,
fill: 0xFFFFFF
});
instructionText.anchor.set(0.5, 0.5);
instructionText.x = 1024;
instructionText.y = 200;
game.addChild(instructionText);
// Fade out instructions after 3 seconds
LK.setTimeout(function () {
tween(instructionText, {
alpha: 0
}, {
duration: 1000
});
}, 3000);
// Brush size controls
var brushSizeText = new Text2('Brush Size: Medium', {
size: 40,
fill: 0xCCCCCC
});
brushSizeText.anchor.set(0.5, 0.5);
LK.gui.bottom.addChild(brushSizeText);
brushSizeText.y = -100;
// Touch/mouse handlers
function handleScratch(x, y) {
if (isScratching) {
// Interpolate between last position and current to create smooth scratching
var distance = Math.sqrt(Math.pow(x - lastScratchX, 2) + Math.pow(y - lastScratchY, 2));
var steps = Math.max(1, Math.floor(distance / 10));
for (var i = 0; i <= steps; i++) {
var interpX = lastScratchX + (x - lastScratchX) * (i / steps);
var interpY = lastScratchY + (y - lastScratchY) * (i / steps);
scratchSurface.scratch(interpX, interpY, brushSize);
}
}
lastScratchX = x;
lastScratchY = y;
}
game.down = function (x, y, obj) {
isScratching = true;
lastScratchX = x;
lastScratchY = y;
scratchSurface.scratch(x, y, brushSize);
};
game.move = function (x, y, obj) {
if (isScratching) {
handleScratch(x, y);
}
};
game.up = function (x, y, obj) {
isScratching = false;
};
// Brush size cycling (tap bottom area to change)
LK.gui.bottom.down = function (x, y, obj) {
if (brushSize === 30) {
brushSize = 60;
brushSizeText.setText('Brush Size: Medium');
} else if (brushSize === 60) {
brushSize = 90;
brushSizeText.setText('Brush Size: Large');
} else {
brushSize = 30;
brushSizeText.setText('Brush Size: Small');
}
// Visual feedback
tween(brushSizeText, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 200,
onFinish: function onFinish() {
tween(brushSizeText, {
scaleX: 1,
scaleY: 1
}, {
duration: 200
});
}
});
};
// Update progress
var progressUpdateTimer = 0;
game.update = function () {
progressUpdateTimer++;
// Update progress every 30 frames (0.5 seconds)
if (progressUpdateTimer >= 30) {
var scratchPercentage = scratchSurface.getScratchPercentage();
progressDisplay.updateProgress(scratchPercentage);
progressUpdateTimer = 0;
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,227 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var ProgressDisplay = Container.expand(function () {
+ var self = Container.call(this);
+ // Progress bar background
+ var progressBg = self.attachAsset('progressBackground', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Progress bar fill
+ var progressFill = self.attachAsset('progressBar', {
+ anchorX: 0,
+ anchorY: 0.5,
+ width: 0
+ });
+ progressFill.x = -200; // Center aligned
+ // Progress text
+ var progressText = new Text2('0%', {
+ size: 40,
+ fill: 0xFFFFFF
+ });
+ progressText.anchor.set(0.5, 0.5);
+ progressText.y = -40;
+ self.addChild(progressText);
+ self.updateProgress = function (percentage) {
+ var clampedPercentage = Math.max(0, Math.min(100, percentage));
+ progressFill.width = clampedPercentage / 100 * 400;
+ progressText.setText(Math.floor(clampedPercentage) + '%');
+ // Celebration effect when reaching milestones
+ if (clampedPercentage >= 25 && clampedPercentage < 26) {
+ LK.effects.flashObject(self, 0x4ecdc4, 500);
+ }
+ if (clampedPercentage >= 50 && clampedPercentage < 51) {
+ LK.effects.flashObject(self, 0xf9ca24, 500);
+ }
+ if (clampedPercentage >= 75 && clampedPercentage < 76) {
+ LK.effects.flashObject(self, 0xf0932b, 500);
+ }
+ if (clampedPercentage >= 100) {
+ LK.effects.flashScreen(0x4ecdc4, 1000);
+ LK.showYouWin();
+ }
+ };
+ return self;
+});
+var ScratchSurface = Container.expand(function () {
+ var self = Container.call(this);
+ // Create colorful background patterns
+ var backgrounds = [];
+ var colors = [0xff6b6b, 0x4ecdc4, 0x45b7d1, 0xf9ca24, 0xf0932b, 0xeb4d4b, 0x6c5ce7, 0xa29bfe];
+ // Create colorful pattern background
+ for (var i = 0; i < 32; i++) {
+ for (var j = 0; j < 43; j++) {
+ var colorIndex = (i + j) % colors.length;
+ var bgTile = LK.getAsset('colorfulBackground', {
+ width: 64,
+ height: 64,
+ color: colors[colorIndex]
+ });
+ bgTile.x = i * 64;
+ bgTile.y = j * 64;
+ self.addChild(bgTile);
+ backgrounds.push(bgTile);
+ }
+ }
+ // Create scratch overlay
+ var overlay = self.attachAsset('scratchOverlay', {
+ x: 0,
+ y: 0
+ });
+ // Track scratched areas
+ self.scratchedPixels = [];
+ self.totalPixels = 2048 * 2732;
+ self.scratchedCount = 0;
+ // Scratch method
+ self.scratch = function (x, y, brushSize) {
+ brushSize = brushSize || 60;
+ var radius = brushSize / 2;
+ // Create scratch hole by manipulating overlay alpha
+ var scratchArea = LK.getAsset('scratchBrush', {
+ width: brushSize,
+ height: brushSize,
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ scratchArea.x = x;
+ scratchArea.y = y;
+ scratchArea.blendMode = 'erase';
+ overlay.addChild(scratchArea);
+ // Track progress
+ var pixelsScratched = Math.PI * radius * radius;
+ self.scratchedCount += pixelsScratched;
+ // Play scratch sound occasionally
+ if (Math.random() < 0.1) {
+ LK.getSound('scratch').play();
+ }
+ };
+ self.getScratchPercentage = function () {
+ return Math.min(100, self.scratchedCount / self.totalPixels * 100 * 50); // Multiplied by 50 to make progress more visible
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x1a1a1a
+});
+
+/****
+* Game Code
+****/
+// Game variables
+var scratchSurface;
+var progressDisplay;
+var isScratching = false;
+var lastScratchX = 0;
+var lastScratchY = 0;
+var brushSize = 60;
+// Initialize game elements
+scratchSurface = game.addChild(new ScratchSurface());
+scratchSurface.x = 0;
+scratchSurface.y = 0;
+// Progress display
+progressDisplay = game.addChild(new ProgressDisplay());
+progressDisplay.x = 1024;
+progressDisplay.y = 100;
+// Instructions text
+var instructionText = new Text2('Scratch the surface to reveal the art!', {
+ size: 60,
+ fill: 0xFFFFFF
+});
+instructionText.anchor.set(0.5, 0.5);
+instructionText.x = 1024;
+instructionText.y = 200;
+game.addChild(instructionText);
+// Fade out instructions after 3 seconds
+LK.setTimeout(function () {
+ tween(instructionText, {
+ alpha: 0
+ }, {
+ duration: 1000
+ });
+}, 3000);
+// Brush size controls
+var brushSizeText = new Text2('Brush Size: Medium', {
+ size: 40,
+ fill: 0xCCCCCC
+});
+brushSizeText.anchor.set(0.5, 0.5);
+LK.gui.bottom.addChild(brushSizeText);
+brushSizeText.y = -100;
+// Touch/mouse handlers
+function handleScratch(x, y) {
+ if (isScratching) {
+ // Interpolate between last position and current to create smooth scratching
+ var distance = Math.sqrt(Math.pow(x - lastScratchX, 2) + Math.pow(y - lastScratchY, 2));
+ var steps = Math.max(1, Math.floor(distance / 10));
+ for (var i = 0; i <= steps; i++) {
+ var interpX = lastScratchX + (x - lastScratchX) * (i / steps);
+ var interpY = lastScratchY + (y - lastScratchY) * (i / steps);
+ scratchSurface.scratch(interpX, interpY, brushSize);
+ }
+ }
+ lastScratchX = x;
+ lastScratchY = y;
+}
+game.down = function (x, y, obj) {
+ isScratching = true;
+ lastScratchX = x;
+ lastScratchY = y;
+ scratchSurface.scratch(x, y, brushSize);
+};
+game.move = function (x, y, obj) {
+ if (isScratching) {
+ handleScratch(x, y);
+ }
+};
+game.up = function (x, y, obj) {
+ isScratching = false;
+};
+// Brush size cycling (tap bottom area to change)
+LK.gui.bottom.down = function (x, y, obj) {
+ if (brushSize === 30) {
+ brushSize = 60;
+ brushSizeText.setText('Brush Size: Medium');
+ } else if (brushSize === 60) {
+ brushSize = 90;
+ brushSizeText.setText('Brush Size: Large');
+ } else {
+ brushSize = 30;
+ brushSizeText.setText('Brush Size: Small');
+ }
+ // Visual feedback
+ tween(brushSizeText, {
+ scaleX: 1.2,
+ scaleY: 1.2
+ }, {
+ duration: 200,
+ onFinish: function onFinish() {
+ tween(brushSizeText, {
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 200
+ });
+ }
+ });
+};
+// Update progress
+var progressUpdateTimer = 0;
+game.update = function () {
+ progressUpdateTimer++;
+ // Update progress every 30 frames (0.5 seconds)
+ if (progressUpdateTimer >= 30) {
+ var scratchPercentage = scratchSurface.getScratchPercentage();
+ progressDisplay.updateProgress(scratchPercentage);
+ progressUpdateTimer = 0;
+ }
+};
\ No newline at end of file