/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Egg = Container.expand(function (type) {
var self = Container.call(this);
self.type = type || 'pabby';
self.speed = 4 + Math.random() * 3;
self.caught = false;
self.lastY = 0;
var eggGraphics = self.attachAsset(self.type, {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
if (!self.caught) {
self.y += self.speed;
}
};
return self;
});
var Pablo = Container.expand(function () {
var self = Container.call(this);
var pabloGraphics = self.attachAsset('pablo', {
anchorX: 0.5,
anchorY: 0.5
});
self.catchRadius = 100;
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
var pablo = game.addChild(new Pablo());
pablo.x = 1024;
pablo.y = 2600;
var eggs = [];
var eggTypes = ['pabby', 'yoyo', 'oscar'];
var missedEggs = 0;
var maxMissedEggs = 5;
var eggSpawnTimer = 0;
var eggSpawnInterval = 90;
var minSpawnInterval = 30;
var gameSpeed = 1;
var scoreTxt = new Text2('Score: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var livesTxt = new Text2('Lives: ' + (maxMissedEggs - missedEggs), {
size: 60,
fill: 0xFFFFFF
});
livesTxt.anchor.set(0, 0);
livesTxt.x = 100;
livesTxt.y = 100;
LK.gui.topLeft.addChild(livesTxt);
var dragNode = null;
function handleMove(x, y, obj) {
if (dragNode) {
dragNode.x = Math.max(80, Math.min(1968, x));
}
}
game.move = handleMove;
game.down = function (x, y, obj) {
var pabloPos = pablo.parent.toGlobal(pablo.position);
var distance = Math.sqrt(Math.pow(x - pabloPos.x, 2) + Math.pow(y - pabloPos.y, 2));
if (distance < pablo.catchRadius) {
dragNode = pablo;
handleMove(x, y, obj);
}
};
game.up = function (x, y, obj) {
dragNode = null;
};
function spawnEgg() {
var eggType = eggTypes[Math.floor(Math.random() * eggTypes.length)];
var newEgg = new Egg(eggType);
newEgg.x = 100 + Math.random() * 1848;
newEgg.y = -100;
newEgg.lastY = newEgg.y;
eggs.push(newEgg);
game.addChild(newEgg);
}
function checkCatch(egg) {
var distance = Math.sqrt(Math.pow(egg.x - pablo.x, 2) + Math.pow(egg.y - pablo.y, 2));
return distance < pablo.catchRadius;
}
game.update = function () {
eggSpawnTimer++;
if (eggSpawnTimer >= eggSpawnInterval) {
spawnEgg();
eggSpawnTimer = 0;
if (eggSpawnInterval > minSpawnInterval) {
eggSpawnInterval = Math.max(minSpawnInterval, eggSpawnInterval - 1);
}
}
for (var i = eggs.length - 1; i >= 0; i--) {
var egg = eggs[i];
if (!egg.caught && checkCatch(egg)) {
egg.caught = true;
LK.setScore(LK.getScore() + 10);
scoreTxt.setText('Score: ' + LK.getScore());
tween(egg, {
alpha: 0,
scaleX: 1.5,
scaleY: 1.5
}, {
duration: 300,
onFinish: function onFinish() {
egg.destroy();
}
});
eggs.splice(i, 1);
LK.getSound('catch').play();
LK.effects.flashObject(pablo, 0x00FF00, 200);
continue;
}
if (egg.lastY < 2732 && egg.y >= 2732 && !egg.caught) {
missedEggs++;
livesTxt.setText('Lives: ' + (maxMissedEggs - missedEggs));
var crackedEgg = LK.getAsset('crackedEgg', {
anchorX: 0.5,
anchorY: 0.5
});
crackedEgg.x = egg.x;
crackedEgg.y = 2732;
game.addChild(crackedEgg);
tween(crackedEgg, {
alpha: 0
}, {
duration: 1000,
onFinish: function onFinish() {
crackedEgg.destroy();
}
});
LK.getSound('miss').play();
LK.effects.flashScreen(0xFF0000, 300);
if (missedEggs >= maxMissedEggs) {
LK.showGameOver();
return;
}
}
if (egg.y > 2800) {
egg.destroy();
eggs.splice(i, 1);
}
egg.lastY = egg.y;
}
if (LK.getScore() >= 500) {
LK.showYouWin();
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,166 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Egg = Container.expand(function (type) {
+ var self = Container.call(this);
+ self.type = type || 'pabby';
+ self.speed = 4 + Math.random() * 3;
+ self.caught = false;
+ self.lastY = 0;
+ var eggGraphics = self.attachAsset(self.type, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.update = function () {
+ if (!self.caught) {
+ self.y += self.speed;
+ }
+ };
+ return self;
+});
+var Pablo = Container.expand(function () {
+ var self = Container.call(this);
+ var pabloGraphics = self.attachAsset('pablo', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.catchRadius = 100;
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x87CEEB
+});
+
+/****
+* Game Code
+****/
+var pablo = game.addChild(new Pablo());
+pablo.x = 1024;
+pablo.y = 2600;
+var eggs = [];
+var eggTypes = ['pabby', 'yoyo', 'oscar'];
+var missedEggs = 0;
+var maxMissedEggs = 5;
+var eggSpawnTimer = 0;
+var eggSpawnInterval = 90;
+var minSpawnInterval = 30;
+var gameSpeed = 1;
+var scoreTxt = new Text2('Score: 0', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+var livesTxt = new Text2('Lives: ' + (maxMissedEggs - missedEggs), {
+ size: 60,
+ fill: 0xFFFFFF
+});
+livesTxt.anchor.set(0, 0);
+livesTxt.x = 100;
+livesTxt.y = 100;
+LK.gui.topLeft.addChild(livesTxt);
+var dragNode = null;
+function handleMove(x, y, obj) {
+ if (dragNode) {
+ dragNode.x = Math.max(80, Math.min(1968, x));
+ }
+}
+game.move = handleMove;
+game.down = function (x, y, obj) {
+ var pabloPos = pablo.parent.toGlobal(pablo.position);
+ var distance = Math.sqrt(Math.pow(x - pabloPos.x, 2) + Math.pow(y - pabloPos.y, 2));
+ if (distance < pablo.catchRadius) {
+ dragNode = pablo;
+ handleMove(x, y, obj);
+ }
+};
+game.up = function (x, y, obj) {
+ dragNode = null;
+};
+function spawnEgg() {
+ var eggType = eggTypes[Math.floor(Math.random() * eggTypes.length)];
+ var newEgg = new Egg(eggType);
+ newEgg.x = 100 + Math.random() * 1848;
+ newEgg.y = -100;
+ newEgg.lastY = newEgg.y;
+ eggs.push(newEgg);
+ game.addChild(newEgg);
+}
+function checkCatch(egg) {
+ var distance = Math.sqrt(Math.pow(egg.x - pablo.x, 2) + Math.pow(egg.y - pablo.y, 2));
+ return distance < pablo.catchRadius;
+}
+game.update = function () {
+ eggSpawnTimer++;
+ if (eggSpawnTimer >= eggSpawnInterval) {
+ spawnEgg();
+ eggSpawnTimer = 0;
+ if (eggSpawnInterval > minSpawnInterval) {
+ eggSpawnInterval = Math.max(minSpawnInterval, eggSpawnInterval - 1);
+ }
+ }
+ for (var i = eggs.length - 1; i >= 0; i--) {
+ var egg = eggs[i];
+ if (!egg.caught && checkCatch(egg)) {
+ egg.caught = true;
+ LK.setScore(LK.getScore() + 10);
+ scoreTxt.setText('Score: ' + LK.getScore());
+ tween(egg, {
+ alpha: 0,
+ scaleX: 1.5,
+ scaleY: 1.5
+ }, {
+ duration: 300,
+ onFinish: function onFinish() {
+ egg.destroy();
+ }
+ });
+ eggs.splice(i, 1);
+ LK.getSound('catch').play();
+ LK.effects.flashObject(pablo, 0x00FF00, 200);
+ continue;
+ }
+ if (egg.lastY < 2732 && egg.y >= 2732 && !egg.caught) {
+ missedEggs++;
+ livesTxt.setText('Lives: ' + (maxMissedEggs - missedEggs));
+ var crackedEgg = LK.getAsset('crackedEgg', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ crackedEgg.x = egg.x;
+ crackedEgg.y = 2732;
+ game.addChild(crackedEgg);
+ tween(crackedEgg, {
+ alpha: 0
+ }, {
+ duration: 1000,
+ onFinish: function onFinish() {
+ crackedEgg.destroy();
+ }
+ });
+ LK.getSound('miss').play();
+ LK.effects.flashScreen(0xFF0000, 300);
+ if (missedEggs >= maxMissedEggs) {
+ LK.showGameOver();
+ return;
+ }
+ }
+ if (egg.y > 2800) {
+ egg.destroy();
+ eggs.splice(i, 1);
+ }
+ egg.lastY = egg.y;
+ }
+ if (LK.getScore() >= 500) {
+ LK.showYouWin();
+ }
+};
\ No newline at end of file