/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Frog = Container.expand(function () {
var self = Container.call(this);
var frogGraphics = self.attachAsset('frog', {
anchorX: 0.5,
anchorY: 0.5
});
self.collected = false;
self.hopTimer = 0;
self.down = function (x, y, obj) {
if (!self.collected) {
self.collect();
}
};
self.collect = function () {
if (self.collected) return;
self.collected = true;
LK.getSound('collect').play();
// Bounce animation
tween(self, {
scaleX: 1.5,
scaleY: 1.5,
alpha: 0.8
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self, {
y: self.y - 100,
alpha: 0
}, {
duration: 300,
easing: tween.easeIn,
onFinish: function onFinish() {
self.destroy();
}
});
}
});
frogsCollected++;
checkLevelComplete();
};
self.hop = function () {
if (self.collected) return;
var hopHeight = 20 + Math.random() * 20;
tween(self, {
y: self.y - hopHeight
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self, {
y: self.y + hopHeight
}, {
duration: 300,
easing: tween.easeIn
});
}
});
};
self.update = function () {
if (self.collected) return;
self.hopTimer++;
if (self.hopTimer > 120 + Math.random() * 180) {
self.hop();
self.hopTimer = 0;
}
};
return self;
});
var Girl = Container.expand(function () {
var self = Container.call(this);
var girlGraphics = self.attachAsset('girl', {
anchorX: 0.5,
anchorY: 1.0
});
return self;
});
var Puppy = Container.expand(function () {
var self = Container.call(this);
var puppyGraphics = self.attachAsset('puppy', {
anchorX: 0.5,
anchorY: 1.0
});
self.lookAt = function (targetX, targetY) {
var angle = Math.atan2(targetY - self.y, targetX - self.x);
tween(puppyGraphics, {
rotation: angle
}, {
duration: 500,
easing: tween.easeOut
});
};
self.wag = function () {
tween(puppyGraphics, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(puppyGraphics, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 200,
easing: tween.easeOut
});
}
});
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb
});
/****
* Game Code
****/
var currentLevel = 1;
var totalLevels = 5;
var frogsInLevel = 0;
var frogsCollected = 0;
var frogs = [];
var girl;
var puppy;
var ground;
var levelText;
var instructionText;
// Initialize ground
ground = game.addChild(LK.getAsset('ground', {
anchorX: 0,
anchorY: 1.0,
x: 0,
y: 2732
}));
// Initialize characters
girl = game.addChild(new Girl());
girl.x = 300;
girl.y = 2532;
puppy = game.addChild(new Puppy());
puppy.x = 200;
puppy.y = 2532;
// Initialize UI
levelText = new Text2('Level 1', {
size: 80,
fill: 0xFFFFFF
});
levelText.anchor.set(0.5, 0);
LK.gui.top.addChild(levelText);
levelText.y = 100;
instructionText = new Text2('Tap the frogs to collect them!', {
size: 60,
fill: 0xFFFFFF
});
instructionText.anchor.set(0.5, 0);
LK.gui.top.addChild(instructionText);
instructionText.y = 200;
function generateFrogPositions(numFrogs) {
var positions = [];
var attempts = 0;
var maxAttempts = 100;
while (positions.length < numFrogs && attempts < maxAttempts) {
var x = 150 + Math.random() * (2048 - 300);
var y = 300 + Math.random() * (2200 - 300);
var validPosition = true;
for (var i = 0; i < positions.length; i++) {
var distance = Math.sqrt(Math.pow(x - positions[i].x, 2) + Math.pow(y - positions[i].y, 2));
if (distance < 120) {
validPosition = false;
break;
}
}
if (validPosition) {
positions.push({
x: x,
y: y
});
}
attempts++;
}
return positions;
}
function startLevel(level) {
// Clear existing frogs
for (var i = frogs.length - 1; i >= 0; i--) {
frogs[i].destroy();
}
frogs = [];
frogsCollected = 0;
frogsInLevel = Math.min(3 + level, 6);
levelText.setText('Level ' + level);
var positions = generateFrogPositions(frogsInLevel);
for (var i = 0; i < positions.length; i++) {
var frog = game.addChild(new Frog());
frog.x = positions[i].x;
frog.y = positions[i].y;
frogs.push(frog);
// Add entrance animation
frog.alpha = 0;
frog.scaleX = 0;
frog.scaleY = 0;
tween(frog, {
alpha: 1,
scaleX: 1,
scaleY: 1
}, {
duration: 500 + i * 100,
easing: tween.bounceOut
});
}
}
function checkLevelComplete() {
if (frogsCollected >= frogsInLevel) {
LK.getSound('levelComplete').play();
puppy.wag();
LK.setTimeout(function () {
currentLevel++;
if (currentLevel > totalLevels) {
instructionText.setText('All levels complete! Great job!');
LK.showYouWin();
} else {
startLevel(currentLevel);
}
}, 1500);
}
}
var puppyHintTimer = 0;
game.update = function () {
puppyHintTimer++;
// Puppy looks at nearest uncollected frog every 3 seconds
if (puppyHintTimer > 180) {
var nearestFrog = null;
var nearestDistance = Infinity;
for (var i = 0; i < frogs.length; i++) {
if (!frogs[i].collected) {
var distance = Math.sqrt(Math.pow(frogs[i].x - puppy.x, 2) + Math.pow(frogs[i].y - puppy.y, 2));
if (distance < nearestDistance) {
nearestDistance = distance;
nearestFrog = frogs[i];
}
}
}
if (nearestFrog) {
puppy.lookAt(nearestFrog.x, nearestFrog.y);
}
puppyHintTimer = 0;
}
};
// Start the first level
startLevel(currentLevel); ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,263 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Frog = Container.expand(function () {
+ var self = Container.call(this);
+ var frogGraphics = self.attachAsset('frog', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.collected = false;
+ self.hopTimer = 0;
+ self.down = function (x, y, obj) {
+ if (!self.collected) {
+ self.collect();
+ }
+ };
+ self.collect = function () {
+ if (self.collected) return;
+ self.collected = true;
+ LK.getSound('collect').play();
+ // Bounce animation
+ tween(self, {
+ scaleX: 1.5,
+ scaleY: 1.5,
+ alpha: 0.8
+ }, {
+ duration: 200,
+ easing: tween.easeOut,
+ onFinish: function onFinish() {
+ tween(self, {
+ y: self.y - 100,
+ alpha: 0
+ }, {
+ duration: 300,
+ easing: tween.easeIn,
+ onFinish: function onFinish() {
+ self.destroy();
+ }
+ });
+ }
+ });
+ frogsCollected++;
+ checkLevelComplete();
+ };
+ self.hop = function () {
+ if (self.collected) return;
+ var hopHeight = 20 + Math.random() * 20;
+ tween(self, {
+ y: self.y - hopHeight
+ }, {
+ duration: 300,
+ easing: tween.easeOut,
+ onFinish: function onFinish() {
+ tween(self, {
+ y: self.y + hopHeight
+ }, {
+ duration: 300,
+ easing: tween.easeIn
+ });
+ }
+ });
+ };
+ self.update = function () {
+ if (self.collected) return;
+ self.hopTimer++;
+ if (self.hopTimer > 120 + Math.random() * 180) {
+ self.hop();
+ self.hopTimer = 0;
+ }
+ };
+ return self;
+});
+var Girl = Container.expand(function () {
+ var self = Container.call(this);
+ var girlGraphics = self.attachAsset('girl', {
+ anchorX: 0.5,
+ anchorY: 1.0
+ });
+ return self;
+});
+var Puppy = Container.expand(function () {
+ var self = Container.call(this);
+ var puppyGraphics = self.attachAsset('puppy', {
+ anchorX: 0.5,
+ anchorY: 1.0
+ });
+ self.lookAt = function (targetX, targetY) {
+ var angle = Math.atan2(targetY - self.y, targetX - self.x);
+ tween(puppyGraphics, {
+ rotation: angle
+ }, {
+ duration: 500,
+ easing: tween.easeOut
+ });
+ };
+ self.wag = function () {
+ tween(puppyGraphics, {
+ scaleX: 1.2,
+ scaleY: 1.2
+ }, {
+ duration: 200,
+ easing: tween.easeOut,
+ onFinish: function onFinish() {
+ tween(puppyGraphics, {
+ scaleX: 1.0,
+ scaleY: 1.0
+ }, {
+ duration: 200,
+ easing: tween.easeOut
+ });
+ }
+ });
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x87ceeb
+});
+
+/****
+* Game Code
+****/
+var currentLevel = 1;
+var totalLevels = 5;
+var frogsInLevel = 0;
+var frogsCollected = 0;
+var frogs = [];
+var girl;
+var puppy;
+var ground;
+var levelText;
+var instructionText;
+// Initialize ground
+ground = game.addChild(LK.getAsset('ground', {
+ anchorX: 0,
+ anchorY: 1.0,
+ x: 0,
+ y: 2732
+}));
+// Initialize characters
+girl = game.addChild(new Girl());
+girl.x = 300;
+girl.y = 2532;
+puppy = game.addChild(new Puppy());
+puppy.x = 200;
+puppy.y = 2532;
+// Initialize UI
+levelText = new Text2('Level 1', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+levelText.anchor.set(0.5, 0);
+LK.gui.top.addChild(levelText);
+levelText.y = 100;
+instructionText = new Text2('Tap the frogs to collect them!', {
+ size: 60,
+ fill: 0xFFFFFF
+});
+instructionText.anchor.set(0.5, 0);
+LK.gui.top.addChild(instructionText);
+instructionText.y = 200;
+function generateFrogPositions(numFrogs) {
+ var positions = [];
+ var attempts = 0;
+ var maxAttempts = 100;
+ while (positions.length < numFrogs && attempts < maxAttempts) {
+ var x = 150 + Math.random() * (2048 - 300);
+ var y = 300 + Math.random() * (2200 - 300);
+ var validPosition = true;
+ for (var i = 0; i < positions.length; i++) {
+ var distance = Math.sqrt(Math.pow(x - positions[i].x, 2) + Math.pow(y - positions[i].y, 2));
+ if (distance < 120) {
+ validPosition = false;
+ break;
+ }
+ }
+ if (validPosition) {
+ positions.push({
+ x: x,
+ y: y
+ });
+ }
+ attempts++;
+ }
+ return positions;
+}
+function startLevel(level) {
+ // Clear existing frogs
+ for (var i = frogs.length - 1; i >= 0; i--) {
+ frogs[i].destroy();
+ }
+ frogs = [];
+ frogsCollected = 0;
+ frogsInLevel = Math.min(3 + level, 6);
+ levelText.setText('Level ' + level);
+ var positions = generateFrogPositions(frogsInLevel);
+ for (var i = 0; i < positions.length; i++) {
+ var frog = game.addChild(new Frog());
+ frog.x = positions[i].x;
+ frog.y = positions[i].y;
+ frogs.push(frog);
+ // Add entrance animation
+ frog.alpha = 0;
+ frog.scaleX = 0;
+ frog.scaleY = 0;
+ tween(frog, {
+ alpha: 1,
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 500 + i * 100,
+ easing: tween.bounceOut
+ });
+ }
+}
+function checkLevelComplete() {
+ if (frogsCollected >= frogsInLevel) {
+ LK.getSound('levelComplete').play();
+ puppy.wag();
+ LK.setTimeout(function () {
+ currentLevel++;
+ if (currentLevel > totalLevels) {
+ instructionText.setText('All levels complete! Great job!');
+ LK.showYouWin();
+ } else {
+ startLevel(currentLevel);
+ }
+ }, 1500);
+ }
+}
+var puppyHintTimer = 0;
+game.update = function () {
+ puppyHintTimer++;
+ // Puppy looks at nearest uncollected frog every 3 seconds
+ if (puppyHintTimer > 180) {
+ var nearestFrog = null;
+ var nearestDistance = Infinity;
+ for (var i = 0; i < frogs.length; i++) {
+ if (!frogs[i].collected) {
+ var distance = Math.sqrt(Math.pow(frogs[i].x - puppy.x, 2) + Math.pow(frogs[i].y - puppy.y, 2));
+ if (distance < nearestDistance) {
+ nearestDistance = distance;
+ nearestFrog = frogs[i];
+ }
+ }
+ }
+ if (nearestFrog) {
+ puppy.lookAt(nearestFrog.x, nearestFrog.y);
+ }
+ puppyHintTimer = 0;
+ }
+};
+// Start the first level
+startLevel(currentLevel);
\ No newline at end of file