Code edit (1 edits merged)
Please save this source code
User prompt
Pango's Magic Wand Mayhem
Initial prompt
Pango the blue raccoon 💙: rabbit 🤍 and skunk 🖤 are doing some magic with their wands. Tap on rabbit’s wand or skunk’s wand to make it bang, turn into frogs, turn into birds, turn into pigs, and make it a jelly flood.
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Bang = Container.expand(function () {
var self = Container.call(this);
var bangGraphics = self.attachAsset('bang', {
anchorX: 0.5,
anchorY: 0.5
});
self.lifetime = 0;
self.maxLifetime = 30; // 0.5 seconds at 60fps
self.update = function () {
self.lifetime++;
var scale = 1 + self.lifetime / self.maxLifetime * 2;
bangGraphics.scaleX = scale;
bangGraphics.scaleY = scale;
bangGraphics.alpha = 1 - self.lifetime / self.maxLifetime;
if (self.lifetime > self.maxLifetime) {
self.destroy();
var index = bangs.indexOf(self);
if (index > -1) {
bangs.splice(index, 1);
}
}
};
return self;
});
var JellyDrop = Container.expand(function () {
var self = Container.call(this);
var jellyGraphics = self.attachAsset('jelly', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedX = (Math.random() - 0.5) * 4;
self.speedY = Math.random() * 2 + 1;
self.lifetime = 0;
self.maxLifetime = 300; // 5 seconds at 60fps
self.update = function () {
self.x += self.speedX;
self.y += self.speedY;
self.lifetime++;
if (self.lifetime > self.maxLifetime || self.y > 2732 + 50) {
self.destroy();
var index = jellyDrops.indexOf(self);
if (index > -1) {
jellyDrops.splice(index, 1);
}
}
};
return self;
});
var MagicCreature = Container.expand(function (creatureType) {
var self = Container.call(this);
var creatureGraphics = self.attachAsset(creatureType, {
anchorX: 0.5,
anchorY: 0.5
});
self.creatureType = creatureType;
self.lifetime = 0;
self.maxLifetime = 180; // 3 seconds at 60fps
self.update = function () {
self.lifetime++;
if (self.lifetime > self.maxLifetime) {
self.destroy();
var index = magicCreatures.indexOf(self);
if (index > -1) {
magicCreatures.splice(index, 1);
}
}
};
return self;
});
var MagicWand = Container.expand(function (wandType) {
var self = Container.call(this);
var wandGraphics = self.attachAsset(wandType === 'rabbit' ? 'rabbitWand' : 'skunkWand', {
anchorX: 0.5,
anchorY: 0.5
});
self.wandType = wandType;
self.isGlowing = false;
self.startGlow = function () {
if (!self.isGlowing) {
self.isGlowing = true;
tween(wandGraphics, {
scaleX: 1.2,
scaleY: 1.2,
alpha: 0.8
}, {
duration: 500
});
tween(wandGraphics, {
scaleX: 1.0,
scaleY: 1.0,
alpha: 1.0
}, {
duration: 500,
onFinish: function onFinish() {
self.isGlowing = false;
}
});
}
};
self.down = function (x, y, obj) {
self.startGlow();
if (self.wandType === 'rabbit') {
triggerRabbitMagic();
} else {
triggerSkunkMagic();
}
LK.getSound('magic').play();
};
return self;
});
var Sparkle = Container.expand(function () {
var self = Container.call(this);
var sparkleGraphics = self.attachAsset('sparkle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedX = (Math.random() - 0.5) * 8;
self.speedY = (Math.random() - 0.5) * 8;
self.lifetime = 0;
self.maxLifetime = 60; // 1 second at 60fps
self.update = function () {
self.x += self.speedX;
self.y += self.speedY;
self.lifetime++;
sparkleGraphics.alpha = 1 - self.lifetime / self.maxLifetime;
if (self.lifetime > self.maxLifetime) {
self.destroy();
var index = sparkles.indexOf(self);
if (index > -1) {
sparkles.splice(index, 1);
}
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
var magicCreatures = [];
var jellyDrops = [];
var sparkles = [];
var bangs = [];
// Create Pango the blue raccoon in center
var pango = game.addChild(LK.getAsset('pango', {
anchorX: 0.5,
anchorY: 1.0
}));
pango.x = 1024;
pango.y = 2200;
// Create rabbit wizard on left side
var rabbit = game.addChild(LK.getAsset('rabbit', {
anchorX: 0.5,
anchorY: 1.0
}));
rabbit.x = 400;
rabbit.y = 2100;
// Create skunk wizard on right side
var skunk = game.addChild(LK.getAsset('skunk', {
anchorX: 0.5,
anchorY: 1.0
}));
skunk.x = 1648;
skunk.y = 2100;
// Create rabbit's magic wand
var rabbitWand = game.addChild(new MagicWand('rabbit'));
rabbitWand.x = 320;
rabbitWand.y = 1950;
rabbitWand.rotation = Math.PI / 4;
// Create skunk's magic wand
var skunkWand = game.addChild(new MagicWand('skunk'));
skunkWand.x = 1728;
skunkWand.y = 1950;
skunkWand.rotation = -Math.PI / 4;
// Score display
var scoreTxt = new Text2('Score: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
function updateScore() {
scoreTxt.setText('Score: ' + LK.getScore());
}
function createSparkles(x, y, count) {
for (var i = 0; i < count; i++) {
var sparkle = new Sparkle();
sparkle.x = x + (Math.random() - 0.5) * 100;
sparkle.y = y + (Math.random() - 0.5) * 100;
sparkles.push(sparkle);
game.addChild(sparkle);
}
}
function createBang(x, y) {
var bang = new Bang();
bang.x = x;
bang.y = y;
bangs.push(bang);
game.addChild(bang);
LK.getSound('bang').play();
}
function triggerRabbitMagic() {
var magicType = Math.floor(Math.random() * 4);
LK.setScore(LK.getScore() + 10);
updateScore();
switch (magicType) {
case 0:
// Transform to frog
var frog = new MagicCreature('frog');
frog.x = 200 + Math.random() * 400;
frog.y = 1200 + Math.random() * 400;
magicCreatures.push(frog);
game.addChild(frog);
createSparkles(frog.x, frog.y, 5);
LK.getSound('transform').play();
break;
case 1:
// Transform to bird
var bird = new MagicCreature('bird');
bird.x = 200 + Math.random() * 400;
bird.y = 800 + Math.random() * 400;
magicCreatures.push(bird);
game.addChild(bird);
createSparkles(bird.x, bird.y, 5);
LK.getSound('transform').play();
break;
case 2:
// Explosive bang
createBang(300 + Math.random() * 200, 1000 + Math.random() * 400);
createSparkles(400, 1200, 8);
break;
case 3:
// Jelly flood
for (var i = 0; i < 15; i++) {
var jelly = new JellyDrop();
jelly.x = 100 + Math.random() * 600;
jelly.y = 800 + Math.random() * 200;
jellyDrops.push(jelly);
game.addChild(jelly);
}
LK.getSound('jelly').play();
break;
}
}
function triggerSkunkMagic() {
var magicType = Math.floor(Math.random() * 4);
LK.setScore(LK.getScore() + 10);
updateScore();
switch (magicType) {
case 0:
// Transform to pig
var pig = new MagicCreature('pig');
pig.x = 1400 + Math.random() * 400;
pig.y = 1200 + Math.random() * 400;
magicCreatures.push(pig);
game.addChild(pig);
createSparkles(pig.x, pig.y, 5);
LK.getSound('transform').play();
break;
case 1:
// Transform to bird
var bird = new MagicCreature('bird');
bird.x = 1400 + Math.random() * 400;
bird.y = 800 + Math.random() * 400;
magicCreatures.push(bird);
game.addChild(bird);
createSparkles(bird.x, bird.y, 5);
LK.getSound('transform').play();
break;
case 2:
// Explosive bang
createBang(1500 + Math.random() * 200, 1000 + Math.random() * 400);
createSparkles(1600, 1200, 8);
break;
case 3:
// Jelly flood
for (var i = 0; i < 15; i++) {
var jelly = new JellyDrop();
jelly.x = 1300 + Math.random() * 600;
jelly.y = 800 + Math.random() * 200;
jellyDrops.push(jelly);
game.addChild(jelly);
}
LK.getSound('jelly').play();
break;
}
}
// Add some idle animations to characters
var idleTimer = 0;
game.update = function () {
idleTimer++;
// Idle animations for characters
if (idleTimer % 120 === 0) {
tween(pango, {
scaleX: 1.1,
scaleY: 0.9
}, {
duration: 200
});
tween(pango, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 200
});
}
if (idleTimer % 180 === 0) {
tween(rabbit, {
rotation: 0.1
}, {
duration: 300
});
tween(rabbit, {
rotation: 0
}, {
duration: 300
});
}
if (idleTimer % 200 === 0) {
tween(skunk, {
rotation: -0.1
}, {
duration: 300
});
tween(skunk, {
rotation: 0
}, {
duration: 300
});
}
// Update all magic creatures
for (var i = magicCreatures.length - 1; i >= 0; i--) {
if (magicCreatures[i] && magicCreatures[i].update) {
magicCreatures[i].update();
}
}
// Update all jelly drops
for (var j = jellyDrops.length - 1; j >= 0; j--) {
if (jellyDrops[j] && jellyDrops[j].update) {
jellyDrops[j].update();
}
}
// Update all sparkles
for (var k = sparkles.length - 1; k >= 0; k--) {
if (sparkles[k] && sparkles[k].update) {
sparkles[k].update();
}
}
// Update all bangs
for (var l = bangs.length - 1; l >= 0; l--) {
if (bangs[l] && bangs[l].update) {
bangs[l].update();
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,370 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Bang = Container.expand(function () {
+ var self = Container.call(this);
+ var bangGraphics = self.attachAsset('bang', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.lifetime = 0;
+ self.maxLifetime = 30; // 0.5 seconds at 60fps
+ self.update = function () {
+ self.lifetime++;
+ var scale = 1 + self.lifetime / self.maxLifetime * 2;
+ bangGraphics.scaleX = scale;
+ bangGraphics.scaleY = scale;
+ bangGraphics.alpha = 1 - self.lifetime / self.maxLifetime;
+ if (self.lifetime > self.maxLifetime) {
+ self.destroy();
+ var index = bangs.indexOf(self);
+ if (index > -1) {
+ bangs.splice(index, 1);
+ }
+ }
+ };
+ return self;
+});
+var JellyDrop = Container.expand(function () {
+ var self = Container.call(this);
+ var jellyGraphics = self.attachAsset('jelly', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speedX = (Math.random() - 0.5) * 4;
+ self.speedY = Math.random() * 2 + 1;
+ self.lifetime = 0;
+ self.maxLifetime = 300; // 5 seconds at 60fps
+ self.update = function () {
+ self.x += self.speedX;
+ self.y += self.speedY;
+ self.lifetime++;
+ if (self.lifetime > self.maxLifetime || self.y > 2732 + 50) {
+ self.destroy();
+ var index = jellyDrops.indexOf(self);
+ if (index > -1) {
+ jellyDrops.splice(index, 1);
+ }
+ }
+ };
+ return self;
+});
+var MagicCreature = Container.expand(function (creatureType) {
+ var self = Container.call(this);
+ var creatureGraphics = self.attachAsset(creatureType, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.creatureType = creatureType;
+ self.lifetime = 0;
+ self.maxLifetime = 180; // 3 seconds at 60fps
+ self.update = function () {
+ self.lifetime++;
+ if (self.lifetime > self.maxLifetime) {
+ self.destroy();
+ var index = magicCreatures.indexOf(self);
+ if (index > -1) {
+ magicCreatures.splice(index, 1);
+ }
+ }
+ };
+ return self;
+});
+var MagicWand = Container.expand(function (wandType) {
+ var self = Container.call(this);
+ var wandGraphics = self.attachAsset(wandType === 'rabbit' ? 'rabbitWand' : 'skunkWand', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.wandType = wandType;
+ self.isGlowing = false;
+ self.startGlow = function () {
+ if (!self.isGlowing) {
+ self.isGlowing = true;
+ tween(wandGraphics, {
+ scaleX: 1.2,
+ scaleY: 1.2,
+ alpha: 0.8
+ }, {
+ duration: 500
+ });
+ tween(wandGraphics, {
+ scaleX: 1.0,
+ scaleY: 1.0,
+ alpha: 1.0
+ }, {
+ duration: 500,
+ onFinish: function onFinish() {
+ self.isGlowing = false;
+ }
+ });
+ }
+ };
+ self.down = function (x, y, obj) {
+ self.startGlow();
+ if (self.wandType === 'rabbit') {
+ triggerRabbitMagic();
+ } else {
+ triggerSkunkMagic();
+ }
+ LK.getSound('magic').play();
+ };
+ return self;
+});
+var Sparkle = Container.expand(function () {
+ var self = Container.call(this);
+ var sparkleGraphics = self.attachAsset('sparkle', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speedX = (Math.random() - 0.5) * 8;
+ self.speedY = (Math.random() - 0.5) * 8;
+ self.lifetime = 0;
+ self.maxLifetime = 60; // 1 second at 60fps
+ self.update = function () {
+ self.x += self.speedX;
+ self.y += self.speedY;
+ self.lifetime++;
+ sparkleGraphics.alpha = 1 - self.lifetime / self.maxLifetime;
+ if (self.lifetime > self.maxLifetime) {
+ self.destroy();
+ var index = sparkles.indexOf(self);
+ if (index > -1) {
+ sparkles.splice(index, 1);
+ }
+ }
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x87CEEB
+});
+
+/****
+* Game Code
+****/
+var magicCreatures = [];
+var jellyDrops = [];
+var sparkles = [];
+var bangs = [];
+// Create Pango the blue raccoon in center
+var pango = game.addChild(LK.getAsset('pango', {
+ anchorX: 0.5,
+ anchorY: 1.0
+}));
+pango.x = 1024;
+pango.y = 2200;
+// Create rabbit wizard on left side
+var rabbit = game.addChild(LK.getAsset('rabbit', {
+ anchorX: 0.5,
+ anchorY: 1.0
+}));
+rabbit.x = 400;
+rabbit.y = 2100;
+// Create skunk wizard on right side
+var skunk = game.addChild(LK.getAsset('skunk', {
+ anchorX: 0.5,
+ anchorY: 1.0
+}));
+skunk.x = 1648;
+skunk.y = 2100;
+// Create rabbit's magic wand
+var rabbitWand = game.addChild(new MagicWand('rabbit'));
+rabbitWand.x = 320;
+rabbitWand.y = 1950;
+rabbitWand.rotation = Math.PI / 4;
+// Create skunk's magic wand
+var skunkWand = game.addChild(new MagicWand('skunk'));
+skunkWand.x = 1728;
+skunkWand.y = 1950;
+skunkWand.rotation = -Math.PI / 4;
+// Score display
+var scoreTxt = new Text2('Score: 0', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+function updateScore() {
+ scoreTxt.setText('Score: ' + LK.getScore());
+}
+function createSparkles(x, y, count) {
+ for (var i = 0; i < count; i++) {
+ var sparkle = new Sparkle();
+ sparkle.x = x + (Math.random() - 0.5) * 100;
+ sparkle.y = y + (Math.random() - 0.5) * 100;
+ sparkles.push(sparkle);
+ game.addChild(sparkle);
+ }
+}
+function createBang(x, y) {
+ var bang = new Bang();
+ bang.x = x;
+ bang.y = y;
+ bangs.push(bang);
+ game.addChild(bang);
+ LK.getSound('bang').play();
+}
+function triggerRabbitMagic() {
+ var magicType = Math.floor(Math.random() * 4);
+ LK.setScore(LK.getScore() + 10);
+ updateScore();
+ switch (magicType) {
+ case 0:
+ // Transform to frog
+ var frog = new MagicCreature('frog');
+ frog.x = 200 + Math.random() * 400;
+ frog.y = 1200 + Math.random() * 400;
+ magicCreatures.push(frog);
+ game.addChild(frog);
+ createSparkles(frog.x, frog.y, 5);
+ LK.getSound('transform').play();
+ break;
+ case 1:
+ // Transform to bird
+ var bird = new MagicCreature('bird');
+ bird.x = 200 + Math.random() * 400;
+ bird.y = 800 + Math.random() * 400;
+ magicCreatures.push(bird);
+ game.addChild(bird);
+ createSparkles(bird.x, bird.y, 5);
+ LK.getSound('transform').play();
+ break;
+ case 2:
+ // Explosive bang
+ createBang(300 + Math.random() * 200, 1000 + Math.random() * 400);
+ createSparkles(400, 1200, 8);
+ break;
+ case 3:
+ // Jelly flood
+ for (var i = 0; i < 15; i++) {
+ var jelly = new JellyDrop();
+ jelly.x = 100 + Math.random() * 600;
+ jelly.y = 800 + Math.random() * 200;
+ jellyDrops.push(jelly);
+ game.addChild(jelly);
+ }
+ LK.getSound('jelly').play();
+ break;
+ }
+}
+function triggerSkunkMagic() {
+ var magicType = Math.floor(Math.random() * 4);
+ LK.setScore(LK.getScore() + 10);
+ updateScore();
+ switch (magicType) {
+ case 0:
+ // Transform to pig
+ var pig = new MagicCreature('pig');
+ pig.x = 1400 + Math.random() * 400;
+ pig.y = 1200 + Math.random() * 400;
+ magicCreatures.push(pig);
+ game.addChild(pig);
+ createSparkles(pig.x, pig.y, 5);
+ LK.getSound('transform').play();
+ break;
+ case 1:
+ // Transform to bird
+ var bird = new MagicCreature('bird');
+ bird.x = 1400 + Math.random() * 400;
+ bird.y = 800 + Math.random() * 400;
+ magicCreatures.push(bird);
+ game.addChild(bird);
+ createSparkles(bird.x, bird.y, 5);
+ LK.getSound('transform').play();
+ break;
+ case 2:
+ // Explosive bang
+ createBang(1500 + Math.random() * 200, 1000 + Math.random() * 400);
+ createSparkles(1600, 1200, 8);
+ break;
+ case 3:
+ // Jelly flood
+ for (var i = 0; i < 15; i++) {
+ var jelly = new JellyDrop();
+ jelly.x = 1300 + Math.random() * 600;
+ jelly.y = 800 + Math.random() * 200;
+ jellyDrops.push(jelly);
+ game.addChild(jelly);
+ }
+ LK.getSound('jelly').play();
+ break;
+ }
+}
+// Add some idle animations to characters
+var idleTimer = 0;
+game.update = function () {
+ idleTimer++;
+ // Idle animations for characters
+ if (idleTimer % 120 === 0) {
+ tween(pango, {
+ scaleX: 1.1,
+ scaleY: 0.9
+ }, {
+ duration: 200
+ });
+ tween(pango, {
+ scaleX: 1.0,
+ scaleY: 1.0
+ }, {
+ duration: 200
+ });
+ }
+ if (idleTimer % 180 === 0) {
+ tween(rabbit, {
+ rotation: 0.1
+ }, {
+ duration: 300
+ });
+ tween(rabbit, {
+ rotation: 0
+ }, {
+ duration: 300
+ });
+ }
+ if (idleTimer % 200 === 0) {
+ tween(skunk, {
+ rotation: -0.1
+ }, {
+ duration: 300
+ });
+ tween(skunk, {
+ rotation: 0
+ }, {
+ duration: 300
+ });
+ }
+ // Update all magic creatures
+ for (var i = magicCreatures.length - 1; i >= 0; i--) {
+ if (magicCreatures[i] && magicCreatures[i].update) {
+ magicCreatures[i].update();
+ }
+ }
+ // Update all jelly drops
+ for (var j = jellyDrops.length - 1; j >= 0; j--) {
+ if (jellyDrops[j] && jellyDrops[j].update) {
+ jellyDrops[j].update();
+ }
+ }
+ // Update all sparkles
+ for (var k = sparkles.length - 1; k >= 0; k--) {
+ if (sparkles[k] && sparkles[k].update) {
+ sparkles[k].update();
+ }
+ }
+ // Update all bangs
+ for (var l = bangs.length - 1; l >= 0; l--) {
+ if (bangs[l] && bangs[l].update) {
+ bangs[l].update();
+ }
+ }
+};
\ No newline at end of file