/****
* Classes
****/
var BlueberryButton = Container.expand(function () {
var self = Container.call(this);
var buttonGraphic = self.attachAsset('blueberryButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.on('down', function (x, y, obj) {
handleButtons(self);
});
});
// CakeLayer class
var CakeLayer = Container.expand(function () {
var self = Container.call(this);
var layerGraphic = self.attachAsset('cakeLayer', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.startY = self.y;
self.targetY = 0;
self.tweenStartTime = LK.ticks;
self.tweening = false;
self.inPlace = false;
self._move_migrated = function () {
if (!self.tweening && !self.inPlace) {
self.tweening = true;
self.startY = self.y;
self.targetY = game.height - 300 - currentCakeHeight - self.height / 2;
self.tweenStartTime = LK.ticks;
}
var tweenDuration = 60; // Duration of the tween in ticks
var timeElapsed = LK.ticks - self.tweenStartTime;
if (timeElapsed < tweenDuration) {
//self.y = easeOutElastic(timeElapsed, self.startY, self.targetY - self.startY, tweenDuration);
self.y = easeInExpo(timeElapsed, self.startY, self.targetY - self.startY, tweenDuration);
//self.y = easeOutElastic(timeElapsed, self.startY, self.targetY - self.startY, tweenDuration);
} else {
self.y = self.targetY;
self.tweening = false;
self.inPlace = true;
if (!self.shaken && typeof shakeScreen === 'function') {
shakeScreen(300);
self.shaken = true;
showOptions();
LK.getSound('cakelayerDrop').play();
}
//currentCakeHeight = currentCakeHeight + self.height;
//console.log('currentCakeHeight is now:' + currentCakeHeight);
}
};
});
// Candle class
var Candle = Container.expand(function () {
var self = Container.call(this);
var candleGraphic = self.attachAsset('candle', {
anchorX: 0.5,
anchorY: 0.5
});
self.targetY = 0;
self.speed = 60;
self.delay = 0;
self.waited = 0;
self._move_migrated = function () {
if (self.waited < self.delay) {
self.waited++;
} else {
if (self.y < self.targetY) {
self.y += self.speed;
} else {
self.y = self.targetY;
}
}
};
});
// Filling class
var Filling = Container.expand(function (type) {
var self = Container.call(this);
var fillingGraphic = self.attachAsset(type === 'good' ? 'goodFilling' : 'badFilling', {
anchorX: 0.5,
anchorY: 0.5
});
self.type = type;
self.speed = 5;
self._move_migrated = function () {
self.y += self.speed;
};
});
var FishButton = Container.expand(function () {
var self = Container.call(this);
var buttonGraphic = self.attachAsset('fishButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.on('down', function (x, y, obj) {
handleButtons(self);
LK.getSound('fishBlub').play();
});
});
var FrogButton = Container.expand(function () {
var self = Container.call(this);
var buttonGraphic = self.attachAsset('frogButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.on('down', function (x, y, obj) {
handleButtons(self);
LK.getSound('frogCroak').play();
});
});
var MangoButton = Container.expand(function () {
var self = Container.call(this);
var buttonGraphic = self.attachAsset('mangoButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.on('down', function (x, y, obj) {
handleButtons(self);
});
});
var MouseButton = Container.expand(function () {
var self = Container.call(this);
var buttonGraphic = self.attachAsset('mouseButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.on('down', function (x, y, obj) {
handleButtons(self);
LK.getSound('mouseSqueek').play();
});
});
var NutellaButton = Container.expand(function () {
var self = Container.call(this);
var buttonGraphic = self.attachAsset('nutellaButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.on('down', function (x, y, obj) {
handleButtons(self);
});
});
var PineappleButton = Container.expand(function () {
var self = Container.call(this);
var buttonGraphic = self.attachAsset('pineappleButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.on('down', function (x, y, obj) {
handleButtons(self);
});
});
var RaspberryButton = Container.expand(function () {
var self = Container.call(this);
var buttonGraphic = self.attachAsset('raspberryButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.on('down', function (x, y, obj) {
handleButtons(self);
});
});
var StrawberryButton = Container.expand(function () {
var self = Container.call(this);
var buttonGraphic = self.attachAsset('strawberryButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.on('down', function (x, y, obj) {
handleButtons(self);
});
});
// Table class
var Table = Container.expand(function () {
var self = Container.call(this);
var tableGraphic = self.attachAsset('table', {
anchorX: 0.5,
anchorY: 0.5
});
});
// TopDecoration class
var TopDecoration = Container.expand(function () {
var self = Container.call(this);
var decorationGraphic = self.attachAsset('topDecoration', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.startY = self.y;
self.targetY = 0;
self.tweenStartTime = LK.ticks;
self.tweening = false;
self.inPlace = false;
self._move_migrated = function () {
if (!self.tweening && !self.inPlace) {
self.tweening = true;
self.startY = self.y;
self.targetY = game.height - 300 - currentCakeHeight - self.height / 2;
self.tweenStartTime = LK.ticks;
}
var tweenDuration = 60; // Duration of the tween in ticks
var timeElapsed = LK.ticks - self.tweenStartTime;
if (timeElapsed < tweenDuration) {
//self.y = easeOutElastic(timeElapsed, self.startY, self.targetY - self.startY, tweenDuration);
self.y = easeInExpo(timeElapsed, self.startY, self.targetY - self.startY, tweenDuration);
//self.y = easeOutElastic(timeElapsed, self.startY, self.targetY - self.startY, tweenDuration);
} else {
self.y = self.targetY;
self.tweening = false;
self.inPlace = true;
if (!self.shaken && typeof shakeScreen === 'function') {
shakeScreen(300);
self.shaken = true;
//showOptions();
}
//currentCakeHeight = currentCakeHeight + self.height;
//console.log('currentCakeHeight is now:' + currentCakeHeight);
}
};
});
var WhippedCreamButton = Container.expand(function () {
var self = Container.call(this);
var buttonGraphic = self.attachAsset('whippedCreamButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.on('down', function (x, y, obj) {
handleButtons(self);
});
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb // Init game with sky blue background
});
/****
* Game Code
****/
// TODO:
// add instructions text at start, and require click/tap beofre beginnning.
function shuffleArray(array) {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array[i];
array[i] = array[j];
array[j] = temp;
}
return array;
}
function showOptions() {
goodFill.forEach(function (i) {
i.y = 4000;
});
badFill.forEach(function (i) {
i.y = 4000;
});
var t = [];
for (i = 0; i < 10; i++) {
var g = goodFill[Math.floor(Math.random() * goodFill.length)];
if (!t.includes(g) && t.length < 2) {
t.push(g);
}
}
console.log(t);
var b = badFill[Math.floor(Math.random() * badFill.length)];
t.push(b);
shuffleArray(t);
t[0].x = game.width / 2 - 400;
t[1].x = game.width / 2;
t[2].x = game.width / 2 + 400;
for (var j = 0; j < t.length; j++) {
t[j].y = 2550;
}
}
;
// Add background image
function shakeScreen(intensity, shakes) {
var shakeCount = 0;
var maxShakes = shakes || 10;
var shakeAmount = 10;
var shakeInterval = LK.setInterval(function () {
game.x += Math.random() * shakeAmount / 2 - shakeAmount / 4;
game.y += Math.random() * shakeAmount - shakeAmount / 2;
shakeCount++;
if (shakeCount >= maxShakes) {
LK.clearInterval(shakeInterval);
game.x = 0;
game.y = 0;
}
}, 5);
}
var background = game.addChild(LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5
}));
background.x = game.width / 2;
background.y = game.height / 2;
// Initialize important asset arrays
// Define the assets for the cake layers and fillings
function easeInExpo(t, b, c, d) {
//d *= 15;
return t == 0 ? b : c * Math.pow(2, 10 * (t / d - 1)) + b;
}
function easeOutElastic(t, b, c, d) {
//d *= 15;
var s = 1.70158;
var p = 0;
var a = c;
if (t == 0) {
return b;
}
if ((t /= d) == 1) {
return b + c;
}
if (!p) {
p = d * .3;
}
if (a < Math.abs(c)) {
a = c;
var s = p / 4;
} else {
var s = p / (2 * Math.PI) * Math.asin(c / a);
}
return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b;
}
var cakeLayers = [];
var fillings = [];
var candles = [];
var currentCakeHeight = 0;
var score = 0;
var stars = []; // Define stars array to track star particles
// Create a draggable cake base
var cakeBase = game.addChild(new CakeLayer());
cakeBase.x = game.width / 2;
cakeBase.y = game.height - cakeBase.height / 2;
// Handle dragging the cake base
var dragNode = null;
game.on('down', function (x, y, obj) {
dragNode = cakeBase;
});
game.on('move', function (x, y, obj) {
if (dragNode) {
var pos = game.toLocal(obj.global);
dragNode.x = pos.x;
}
});
game.on('up', function (x, y, obj) {
dragNode = null;
}); // Create and position the table at the bottom of the screen
var table = game.addChild(new Table());
table.x = game.width / 2 - 35;
table.y = game.height - table.height / 2 + 1320;
table.scale.x = 3;
table.scale.y = 2;
// Add Mango button to the game
var mangoButton = game.addChild(new MangoButton());
mangoButton.x = game.width / 2 + 800;
mangoButton.y = game.height - 800;
var frogButton = game.addChild(new FrogButton());
frogButton.x = game.width / 2 + 400;
frogButton.y = game.height - 150;
var fishButton = game.addChild(new FishButton());
fishButton.x = game.width / 2 + 800;
fishButton.y = game.height - 1000;
var mouseButton = game.addChild(new MouseButton());
mouseButton.x = game.width / 2 - 800;
mouseButton.y = game.height - 800;
var pineappleButton = game.addChild(new PineappleButton());
pineappleButton.x = game.width / 2;
pineappleButton.y = game.height - 150;
var whippedCreamButton = game.addChild(new WhippedCreamButton());
whippedCreamButton.x = game.width / 2 - 400;
whippedCreamButton.y = game.height - 150;
var nutellaButton = game.addChild(new NutellaButton());
nutellaButton.x = game.width / 2 - 800;
nutellaButton.y = game.height - 150;
var blueberryButton = game.addChild(new BlueberryButton());
blueberryButton.x = game.width / 2 + 800;
blueberryButton.y = game.height - 150;
var raspberryButton = game.addChild(new RaspberryButton());
raspberryButton.x = game.width / 2 - 800;
raspberryButton.y = game.height - 150 - 400;
var strawberryButton = game.addChild(new StrawberryButton());
strawberryButton.x = game.width / 2 + 800;
strawberryButton.y = game.height - 150 - 400;
var goodFill = [mangoButton, raspberryButton, nutellaButton, whippedCreamButton, pineappleButton, blueberryButton, strawberryButton];
var badFill = [mouseButton, fishButton, frogButton];
goodFill.forEach(function (i) {
i.bonus = 1;
i.y = 4000;
});
badFill.forEach(function (i) {
i.bonus = -1;
i.y = 4000;
});
function handleButtons(button) {
//button.interactive = false;
//button.zIndex = 1000; //game.children.length - 1;
//button.y = game.height - currentCakeHeight - button.height / 2 - 400;
//button.visible = false;
button.y = 4000;
//LK.setScore(LK.getScore() + button.bonus);
score += button.bonus;
scoreLabel.setText('' + score);
if (button.bonus > 0) {
var w = Math.random() < 0.33 ? 1 : Math.random() < 0.5 ? 2 : 3;
LK.getSound('yumSound' + w).play();
for (var i = 0; i < 20; i++) {
var star = LK.getAsset('star', {
anchorX: 0.5,
anchorY: 0.5,
x: scoreLabel.x,
y: scoreLabel.y + 300
});
game.addChild(star);
// Adjust initial velocities to make stars explode upwards
star.vx = Math.random() * 32 - 16; // Horizontal velocity
star.vy = -(Math.random() * 8 + 4); // Vertical velocity, initially upwards
star.life = 240; // Extend life to allow for upward movement and fall
star.gravity = 0.2; // Gravity effect on star
star.alpha = 0.75; // Initial alpha for fade out effect
stars.push(star); // Add star to stars array for tracking
}
} else {
LK.effects.flashObject(scoreLabel, 0xff0000, 500);
}
// Add a copy of the clicked button to the latest cake layer
if (cakeLayers.length > 0) {
var latestCakeLayer = cakeLayers[cakeLayers.length - 1];
if (latestCakeLayer.inPlace) {
var buttonCopy = new button.constructor();
buttonCopy.interactive = false;
if (button.bonus > 0) {
buttonCopy.x = latestCakeLayer.x + button.x - 1000;
buttonCopy.y = latestCakeLayer.y - 150;
} else {
buttonCopy.x = button.x;
buttonCopy.y = 2550;
buttonCopy.vx = Math.random() < 0.5 ? 30 : -30;
buttonCopy.vy = -40;
buttonCopy.life = 240;
buttonCopy.gravity = 1;
stars.push(buttonCopy);
}
game.addChild(buttonCopy);
}
}
}
;
function showGameOverMessage() {
console.log('showgameovermessage');
LK.getSound('bgMusic').play();
var msgLabel = new Text2('Congratulations!\nYou added ' + score + ' fillings to your cake\nAnd got ' + score + ' candles', {
size: 100,
fill: "#ffffff",
align: "center",
weight: 800,
dropShadow: true,
dropShadowColor: '#000000',
dropShadowAngle: Math.PI / 6,
dropShadowDistance: 5
});
msgLabel.x = game.width / 2;
msgLabel.y = 1200;
msgLabel.anchor.set(0.5, 0);
game.addChild(msgLabel);
}
;
function showNoCandlesMessage() {
console.log('shownocandlesmessage');
LK.getSound('music2').play();
var msgLabel = new Text2('You added the wrong fillings to your cake.\nPlease try again for a better result.', {
size: 100,
fill: "#ffffff",
align: "center",
weight: 800,
dropShadow: true,
dropShadowColor: '#000000',
dropShadowAngle: Math.PI / 6,
dropShadowDistance: 5
});
msgLabel.x = game.width / 2;
msgLabel.y = 1200;
msgLabel.anchor.set(0.5, 0);
game.addChild(msgLabel);
}
;
var scoreLabel = new Text2('0', {
size: 200,
weight: 500,
fill: "#ffffff",
align: "center",
strokeColor: "#000000",
strokeThickness: 25
});
scoreLabel.x = game.width / 2;
scoreLabel.y = 50;
scoreLabel.anchor.set(0.5, 0);
game.addChild(scoreLabel);
var instLabel = new Text2('Add fillings to each layer of your cake.\nTap to start', {
size: 100,
weight: 500,
fill: "#bbddff",
align: "center",
strokeColor: "#222222",
strokeThickness: 25
});
instLabel.x = game.width / 2;
instLabel.y = 2200;
instLabel.anchor.set(0.5, 0);
game.addChild(instLabel);
LK.getSound('bgMusic').play();
var gameStarted = false;
game.on('down', function () {
if (!gameStarted) {
gameStarted = true;
instLabel.destroy();
}
});
// Game tick event
LK.on('tick', function () {
if (gameStarted) {
// Update stars in the game tick function
for (var i = stars.length - 1; i >= 0; i--) {
var star = stars[i];
star.vx *= 0.99; // Apply slight horizontal drag
star.vy += star.gravity; // Apply gravity effect
star.x += star.vx;
star.y += star.vy;
star.alpha -= 1 / star.life; // Fade out effect
star.life--;
if (star.life <= 0) {
star.destroy();
stars.splice(i, 1); // Remove star from array once it's life ends
}
}
// Move cake layers
for (var i = cakeLayers.length - 1; i >= 0; i--) {
cakeLayers[i]._move_migrated();
// Remove off-screen cake layers
/*if (cakeLayers[i].y > game.height + cakeLayers[i].height) {
cakeLayers[i].destroy();
cakeLayers.splice(i, 1);
}*/
}
for (var i = candles.length - 1; i >= 0; i--) {
candles[i]._move_migrated();
}
// Spawn cake layers and fillings
if (LK.ticks % 180 === 0 && currentCakeHeight < 1200) {
var newLayer = new CakeLayer(currentCakeHeight);
newLayer.x = game.width / 2;
newLayer.y = -newLayer.height / 2;
cakeLayers.push(newLayer);
game.addChild(newLayer);
currentCakeHeight += currentCakeHeight == 0 ? 1 : 150;
} else if (LK.ticks % 180 === 0 && currentCakeHeight > 1200 && currentCakeHeight < 1300) {
//remove buttons for fillings
goodFill.forEach(function (i) {
i.y = 4000;
});
badFill.forEach(function (i) {
i.y = 4000;
});
//create the final top layer of the cake
var newLayer = new TopDecoration(currentCakeHeight);
newLayer.x = game.width / 2;
newLayer.y = -newLayer.height / 2;
cakeLayers.push(newLayer);
game.addChild(newLayer);
currentCakeHeight += 150;
if (score > 0) {
// Drop candles in an elliptical pattern on the top decoration layer, after a delay.
var ellipseCenterX = game.width / 2;
var ellipseCenterY = newLayer.y + 1000;
var ellipseRadiusX = newLayer.width / 2.5; // Ellipse width
var ellipseRadiusY = 50; // Ellipse height, smaller for a flatter ellipse
for (var i = 0; i < score; i++) {
var angle = i / score * 2 * Math.PI; // Distribute candles evenly in a circle
var angle = i / score * 2 * Math.PI - 0.1; // Distribute candles evenly in a circle
//var angle = i / score * 2 * Math.PI % Math.PI / 0.2783; // Distribute candles evenly in a circle
var candle = new Candle();
candle.x = ellipseCenterX + ellipseRadiusX * Math.cos(angle);
candle.targetY = ellipseCenterY + ellipseRadiusY * Math.sin(angle) - candle.height / 2; // Adjust for candle height
candle.y = -1000;
candle.delay = 60 + 15 * i;
game.addChild(candle);
candles.push(candle);
}
LK.setTimeout(showGameOverMessage, 60 + 15 * score + 10);
LK.setTimeout(LK.showGameOver, 7060 + 15 * score + 10);
} else {
//no candles
LK.setTimeout(showNoCandlesMessage, 60);
LK.setTimeout(LK.showGameOver, 9560);
}
}
}
});
a dark wooden kitchen table with a serving plate.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A bakery wall with shelves full of cakes, toppings, berries. Rich game illustration style.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A swirl of delicious whipped cream. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A small pile of delicious blueberries. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A few delicious red raspberries, cleaned.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Lush, mature strawberries, cleaned and slices and ready for use in bakery or for decoration.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A little green frog. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A cute little goldfish. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A golden star.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A pile of pieces of milk chocolate. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.