/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Character = Container.expand(function (name) { var self = Container.call(this); var characterBody = self.attachAsset('character', { anchorX: 0.5, anchorY: 0.5 }); self.name = name; self.isTransformed = false; self.hair = null; self.leftTooth = null; self.rightTooth = null; self.leftArm = null; self.rightArm = null; self.transform = function () { if (self.isTransformed) return; self.isTransformed = true; // Turn character purple tween(characterBody, { tint: 0x8A2BE2 }, { duration: 500 }); // Add long purple hair self.hair = self.addChild(LK.getAsset('hair', { anchorX: 0.5, anchorY: 1, scaleX: 0, scaleY: 0 })); self.hair.x = 0; self.hair.y = -125; // Add long teeth self.leftTooth = self.addChild(LK.getAsset('tooth', { anchorX: 0.5, anchorY: 0, scaleX: 0, scaleY: 0 })); self.leftTooth.x = -30; self.leftTooth.y = 50; self.rightTooth = self.addChild(LK.getAsset('tooth', { anchorX: 0.5, anchorY: 0, scaleX: 0, scaleY: 0 })); self.rightTooth.x = 30; self.rightTooth.y = 50; // Add extended arms self.leftArm = self.addChild(LK.getAsset('arm', { anchorX: 1, anchorY: 0.5, scaleX: 0, scaleY: 0 })); self.leftArm.x = -100; self.leftArm.y = 0; self.rightArm = self.addChild(LK.getAsset('arm', { anchorX: 0, anchorY: 0.5, scaleX: 0, scaleY: 0 })); self.rightArm.x = 100; self.rightArm.y = 0; // Animate transformations tween(self.hair, { scaleX: 1, scaleY: 1 }, { duration: 800, easing: tween.bounceOut }); tween(self.leftTooth, { scaleX: 1, scaleY: 1 }, { duration: 600, easing: tween.elasticOut }); tween(self.rightTooth, { scaleX: 1, scaleY: 1 }, { duration: 600, easing: tween.elasticOut }); tween(self.leftArm, { scaleX: 1, scaleY: 1 }, { duration: 1000, easing: tween.easeOut }); tween(self.rightArm, { scaleX: 1, scaleY: 1 }, { duration: 1000, easing: tween.easeOut }); // Play transformation sound LK.getSound('transform').play(); // Flash effect LK.effects.flashObject(self, 0x8A2BE2, 800); }; return self; }); var PurplePotion = Container.expand(function () { var self = Container.call(this); var potionGraphics = self.attachAsset('potion', { anchorX: 0.5, anchorY: 0.5 }); self.originalX = 41; self.originalY = 200; self.isDragging = false; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB }); /**** * Game Code ****/ var potion = null; var characters = []; var dragTarget = null; // Create purple potion at starting position potion = game.addChild(new PurplePotion()); potion.x = 41; potion.y = 200; // Create four PBS Kids characters var characterNames = ['Dash', 'Dot', 'Dee', 'Del']; var characterPositions = [{ x: 400, y: 400 }, { x: 800, y: 400 }, { x: 1200, y: 400 }, { x: 1600, y: 400 }]; for (var i = 0; i < characterNames.length; i++) { var character = game.addChild(new Character(characterNames[i])); character.x = characterPositions[i].x; character.y = characterPositions[i].y; characters.push(character); } // Add title text var titleText = new Text2('Purple Villain Transformation Lab', { size: 80, fill: 0x4B0082 }); titleText.anchor.set(0.5, 0); LK.gui.top.addChild(titleText); titleText.y = 100; // Add instruction text var instructionText = new Text2('Drag the purple potion to transform characters!', { size: 50, fill: 0x000080 }); instructionText.anchor.set(0.5, 0); LK.gui.top.addChild(instructionText); instructionText.y = 200; function handleMove(x, y, obj) { if (dragTarget === potion) { potion.x = x; potion.y = y; } } game.move = handleMove; game.down = function (x, y, obj) { // Check if clicking on potion if (potion.intersects({ x: x, y: y, width: 1, height: 1 })) { dragTarget = potion; potion.isDragging = true; handleMove(x, y, obj); } }; game.up = function (x, y, obj) { if (dragTarget === potion) { // Check if potion intersects with any character for (var i = 0; i < characters.length; i++) { var character = characters[i]; if (potion.intersects(character)) { character.transform(); break; } } // Return potion to original position tween(potion, { x: potion.originalX, y: potion.originalY }, { duration: 500, easing: tween.easeOut }); potion.isDragging = false; dragTarget = null; } }; game.update = function () { // Game runs at 60 FPS, update logic here if needed };
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,227 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Character = Container.expand(function (name) {
+ var self = Container.call(this);
+ var characterBody = self.attachAsset('character', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.name = name;
+ self.isTransformed = false;
+ self.hair = null;
+ self.leftTooth = null;
+ self.rightTooth = null;
+ self.leftArm = null;
+ self.rightArm = null;
+ self.transform = function () {
+ if (self.isTransformed) return;
+ self.isTransformed = true;
+ // Turn character purple
+ tween(characterBody, {
+ tint: 0x8A2BE2
+ }, {
+ duration: 500
+ });
+ // Add long purple hair
+ self.hair = self.addChild(LK.getAsset('hair', {
+ anchorX: 0.5,
+ anchorY: 1,
+ scaleX: 0,
+ scaleY: 0
+ }));
+ self.hair.x = 0;
+ self.hair.y = -125;
+ // Add long teeth
+ self.leftTooth = self.addChild(LK.getAsset('tooth', {
+ anchorX: 0.5,
+ anchorY: 0,
+ scaleX: 0,
+ scaleY: 0
+ }));
+ self.leftTooth.x = -30;
+ self.leftTooth.y = 50;
+ self.rightTooth = self.addChild(LK.getAsset('tooth', {
+ anchorX: 0.5,
+ anchorY: 0,
+ scaleX: 0,
+ scaleY: 0
+ }));
+ self.rightTooth.x = 30;
+ self.rightTooth.y = 50;
+ // Add extended arms
+ self.leftArm = self.addChild(LK.getAsset('arm', {
+ anchorX: 1,
+ anchorY: 0.5,
+ scaleX: 0,
+ scaleY: 0
+ }));
+ self.leftArm.x = -100;
+ self.leftArm.y = 0;
+ self.rightArm = self.addChild(LK.getAsset('arm', {
+ anchorX: 0,
+ anchorY: 0.5,
+ scaleX: 0,
+ scaleY: 0
+ }));
+ self.rightArm.x = 100;
+ self.rightArm.y = 0;
+ // Animate transformations
+ tween(self.hair, {
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 800,
+ easing: tween.bounceOut
+ });
+ tween(self.leftTooth, {
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 600,
+ easing: tween.elasticOut
+ });
+ tween(self.rightTooth, {
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 600,
+ easing: tween.elasticOut
+ });
+ tween(self.leftArm, {
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 1000,
+ easing: tween.easeOut
+ });
+ tween(self.rightArm, {
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 1000,
+ easing: tween.easeOut
+ });
+ // Play transformation sound
+ LK.getSound('transform').play();
+ // Flash effect
+ LK.effects.flashObject(self, 0x8A2BE2, 800);
+ };
+ return self;
+});
+var PurplePotion = Container.expand(function () {
+ var self = Container.call(this);
+ var potionGraphics = self.attachAsset('potion', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.originalX = 41;
+ self.originalY = 200;
+ self.isDragging = false;
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x87CEEB
+});
+
+/****
+* Game Code
+****/
+var potion = null;
+var characters = [];
+var dragTarget = null;
+// Create purple potion at starting position
+potion = game.addChild(new PurplePotion());
+potion.x = 41;
+potion.y = 200;
+// Create four PBS Kids characters
+var characterNames = ['Dash', 'Dot', 'Dee', 'Del'];
+var characterPositions = [{
+ x: 400,
+ y: 400
+}, {
+ x: 800,
+ y: 400
+}, {
+ x: 1200,
+ y: 400
+}, {
+ x: 1600,
+ y: 400
+}];
+for (var i = 0; i < characterNames.length; i++) {
+ var character = game.addChild(new Character(characterNames[i]));
+ character.x = characterPositions[i].x;
+ character.y = characterPositions[i].y;
+ characters.push(character);
+}
+// Add title text
+var titleText = new Text2('Purple Villain Transformation Lab', {
+ size: 80,
+ fill: 0x4B0082
+});
+titleText.anchor.set(0.5, 0);
+LK.gui.top.addChild(titleText);
+titleText.y = 100;
+// Add instruction text
+var instructionText = new Text2('Drag the purple potion to transform characters!', {
+ size: 50,
+ fill: 0x000080
+});
+instructionText.anchor.set(0.5, 0);
+LK.gui.top.addChild(instructionText);
+instructionText.y = 200;
+function handleMove(x, y, obj) {
+ if (dragTarget === potion) {
+ potion.x = x;
+ potion.y = y;
+ }
+}
+game.move = handleMove;
+game.down = function (x, y, obj) {
+ // Check if clicking on potion
+ if (potion.intersects({
+ x: x,
+ y: y,
+ width: 1,
+ height: 1
+ })) {
+ dragTarget = potion;
+ potion.isDragging = true;
+ handleMove(x, y, obj);
+ }
+};
+game.up = function (x, y, obj) {
+ if (dragTarget === potion) {
+ // Check if potion intersects with any character
+ for (var i = 0; i < characters.length; i++) {
+ var character = characters[i];
+ if (potion.intersects(character)) {
+ character.transform();
+ break;
+ }
+ }
+ // Return potion to original position
+ tween(potion, {
+ x: potion.originalX,
+ y: potion.originalY
+ }, {
+ duration: 500,
+ easing: tween.easeOut
+ });
+ potion.isDragging = false;
+ dragTarget = null;
+ }
+};
+game.update = function () {
+ // Game runs at 60 FPS, update logic here if needed
+};
\ No newline at end of file