/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Cookie = Container.expand(function (type) {
var self = Container.call(this);
self.cookieType = type || 'regular';
self.fallSpeed = 3;
self.points = 10;
var cookieGraphics;
if (self.cookieType === 'golden') {
cookieGraphics = self.attachAsset('goldenCookie', {
anchorX: 0.5,
anchorY: 0.5
});
self.points = 50;
self.fallSpeed = 2;
} else if (self.cookieType === 'rotten') {
cookieGraphics = self.attachAsset('rottenCookie', {
anchorX: 0.5,
anchorY: 0.5
});
self.points = -20;
self.fallSpeed = 4;
} else {
cookieGraphics = self.attachAsset('regularCookie', {
anchorX: 0.5,
anchorY: 0.5
});
}
self.update = function () {
self.y += self.fallSpeed;
};
return self;
});
var Hammer = Container.expand(function () {
var self = Container.call(this);
var hammerGraphics = self.attachAsset('hammer', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
var hammer = game.addChild(new Hammer());
hammer.x = 2048 / 2;
hammer.y = 2732 - 200;
var cookies = [];
var lives = 3;
var cookieSpawnTimer = 0;
var spawnDelay = 90; // frames between cookie spawns
var difficultyTimer = 0;
// Score display
var scoreTxt = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Lives display
var livesTxt = new Text2('Lives: 3', {
size: 50,
fill: 0xFF0000
});
livesTxt.anchor.set(0, 0);
livesTxt.x = 20;
livesTxt.y = 20;
LK.gui.topLeft.addChild(livesTxt);
function spawnCookie() {
var cookieType = 'regular';
var rand = Math.random();
if (rand < 0.1) {
cookieType = 'golden';
} else if (rand < 0.2) {
cookieType = 'rotten';
}
var cookie = new Cookie(cookieType);
cookie.x = Math.random() * (2048 - 240) + 120;
cookie.y = -120;
cookie.lastY = cookie.y;
cookie.lastIntersecting = false;
cookies.push(cookie);
game.addChild(cookie);
}
function createSmashEffect(x, y) {
LK.effects.flashObject(hammer, 0xFFFFFF, 200);
// Simple particle effect using multiple small cookies
for (var i = 0; i < 5; i++) {
var particle = LK.getAsset('regularCookie', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.3,
scaleY: 0.3,
x: x + (Math.random() - 0.5) * 40,
y: y + (Math.random() - 0.5) * 40
});
game.addChild(particle);
tween(particle, {
alpha: 0,
scaleX: 0.1,
scaleY: 0.1,
y: particle.y + Math.random() * 100 + 50
}, {
duration: 800,
onFinish: function onFinish() {
particle.destroy();
}
});
}
}
game.move = function (x, y, obj) {
hammer.x = x;
hammer.y = y;
};
game.down = function (x, y, obj) {
hammer.x = x;
hammer.y = y;
};
game.update = function () {
// Spawn cookies
cookieSpawnTimer++;
if (cookieSpawnTimer >= spawnDelay) {
spawnCookie();
cookieSpawnTimer = 0;
}
// Increase difficulty over time
difficultyTimer++;
if (difficultyTimer >= 600) {
// Every 10 seconds at 60fps
if (spawnDelay > 30) {
spawnDelay -= 5;
}
difficultyTimer = 0;
}
// Update cookies
for (var i = cookies.length - 1; i >= 0; i--) {
var cookie = cookies[i];
// Check if cookie hit the ground
if (cookie.lastY < 2732 + 60 && cookie.y >= 2732 + 60) {
if (cookie.cookieType !== 'rotten') {
lives--;
livesTxt.setText('Lives: ' + lives);
LK.effects.flashScreen(0xff0000, 300);
if (lives <= 0) {
LK.showGameOver();
return;
}
}
cookie.destroy();
cookies.splice(i, 1);
continue;
}
// Check hammer collision
var currentIntersecting = cookie.intersects(hammer);
if (!cookie.lastIntersecting && currentIntersecting) {
// Cookie was smashed
var newScore = LK.getScore() + cookie.points;
LK.setScore(Math.max(0, newScore)); // Ensure score doesn't go negative
scoreTxt.setText('Score: ' + LK.getScore());
createSmashEffect(cookie.x, cookie.y);
if (cookie.cookieType === 'golden') {
LK.getSound('bonus').play();
LK.effects.flashScreen(0xFFD700, 200);
} else if (cookie.cookieType === 'rotten') {
LK.getSound('rotten').play();
LK.effects.flashScreen(0x8B4513, 200);
} else {
LK.getSound('smash').play();
}
cookie.destroy();
cookies.splice(i, 1);
continue;
}
cookie.lastY = cookie.y;
cookie.lastIntersecting = currentIntersecting;
}
}; ===================================================================
--- original.js
+++ change.js
@@ -88,10 +88,10 @@
} else if (rand < 0.2) {
cookieType = 'rotten';
}
var cookie = new Cookie(cookieType);
- cookie.x = Math.random() * (2048 - 160) + 80;
- cookie.y = -80;
+ cookie.x = Math.random() * (2048 - 240) + 120;
+ cookie.y = -120;
cookie.lastY = cookie.y;
cookie.lastIntersecting = false;
cookies.push(cookie);
game.addChild(cookie);
@@ -149,9 +149,9 @@
// Update cookies
for (var i = cookies.length - 1; i >= 0; i--) {
var cookie = cookies[i];
// Check if cookie hit the ground
- if (cookie.lastY < 2732 && cookie.y >= 2732) {
+ if (cookie.lastY < 2732 + 60 && cookie.y >= 2732 + 60) {
if (cookie.cookieType !== 'rotten') {
lives--;
livesTxt.setText('Lives: ' + lives);
LK.effects.flashScreen(0xff0000, 300);