Code edit (1 edits merged)
Please save this source code
User prompt
My Birthday Party
Initial prompt
Toca birthday party (2011). Type your first name here, tap on number 1 or number 7 that shows how old you are, tap on any balloon from 4 balloons to choose, tap on any cake from 4 cakes to choose, tap on any colored icing to ice your cake, tap on the doorbell to see what it is, tap o choose a bubble wand, and then wave it across the screen to make bubbles, tap on 1 or 7 candles to blow out.
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var AgeSelector = Container.expand(function () {
var self = Container.call(this);
self.selectedAge = 1;
var age1Button = new Text2('1', {
size: 120,
fill: 0xFF6B6B
});
age1Button.anchor.set(0.5, 0.5);
age1Button.x = -100;
self.addChild(age1Button);
var age7Button = new Text2('7', {
size: 120,
fill: 0x4ECDC4
});
age7Button.anchor.set(0.5, 0.5);
age7Button.x = 100;
self.addChild(age7Button);
self.down = function (x, y, obj) {
if (x < 0) {
self.selectedAge = 1;
age1Button.fill = "#ff0000";
age7Button.fill = "#4ecdc4";
} else {
self.selectedAge = 7;
age7Button.fill = "#00ff00";
age1Button.fill = "#ff6b6b";
}
};
return self;
});
var BalloonSelector = Container.expand(function () {
var self = Container.call(this);
self.selectedBalloon = 'balloons1';
self.balloonOptions = [];
for (var i = 0; i < 4; i++) {
var balloon = self.attachAsset('balloons' + (i + 1), {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.3,
scaleY: 0.3,
x: (i - 1.5) * 200
});
self.balloonOptions.push(balloon);
}
self.down = function (x, y, obj) {
var index = Math.floor((x + 300) / 200);
if (index >= 0 && index < 4) {
self.selectedBalloon = 'balloons' + (index + 1);
// Visual feedback
for (var i = 0; i < self.balloonOptions.length; i++) {
self.balloonOptions[i].alpha = i === index ? 1.0 : 0.5;
}
}
};
return self;
});
var BubbleWand = Container.expand(function () {
var self = Container.call(this);
var wandGraphic = self.attachAsset('wand', {
anchorX: 0.5,
anchorY: 1.0
});
self.bubbles = [];
self.isWaving = false;
self.down = function (x, y, obj) {
self.isWaving = true;
};
self.up = function (x, y, obj) {
self.isWaving = false;
};
self.move = function (x, y, obj) {
if (self.isWaving) {
self.x = x;
self.y = y;
// Create bubble
if (Math.random() < 0.3) {
self.createBubble(x, y);
}
}
};
self.createBubble = function (x, y) {
var bubble = LK.getAsset('bubble', {
anchorX: 0.5,
anchorY: 0.5,
x: x,
y: y,
alpha: 0.7
});
game.addChild(bubble);
self.bubbles.push(bubble);
// Animate bubble
tween(bubble, {
y: y - 300,
alpha: 0
}, {
duration: 2000,
onFinish: function onFinish() {
bubble.destroy();
var index = self.bubbles.indexOf(bubble);
if (index > -1) {
self.bubbles.splice(index, 1);
}
}
});
LK.getSound('pop').play();
};
return self;
});
var CakeSelector = Container.expand(function () {
var self = Container.call(this);
self.selectedCake = 'cake1';
self.cakeOptions = [];
for (var i = 0; i < 4; i++) {
var cake = self.attachAsset('cake' + (i + 1), {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.4,
scaleY: 0.4,
x: (i - 1.5) * 250
});
self.cakeOptions.push(cake);
}
self.down = function (x, y, obj) {
var index = Math.floor((x + 375) / 250);
if (index >= 0 && index < 4) {
self.selectedCake = 'cake' + (index + 1);
// Visual feedback
for (var i = 0; i < self.cakeOptions.length; i++) {
self.cakeOptions[i].alpha = i === index ? 1.0 : 0.5;
}
}
};
return self;
});
var CandleCeremony = Container.expand(function () {
var self = Container.call(this);
self.cake = null;
self.candles = [];
self.candleCount = 1;
self.candlesPlaced = false;
self.setupCake = function (cakeType, icingColor, age) {
self.cake = self.attachAsset(cakeType, {
anchorX: 0.5,
anchorY: 0.5
});
// Add icing decoration
var icingAsset = 'icing_' + icingColor;
for (var i = 0; i < 5; i++) {
var icing = LK.getAsset(icingAsset, {
anchorX: 0.5,
anchorY: 0.5,
x: (i - 2) * 60,
y: -120
});
self.addChild(icing);
}
self.candleCount = age;
};
self.down = function (x, y, obj) {
if (!self.candlesPlaced) {
self.placeCandles();
} else {
self.blowOutCandles();
}
};
self.placeCandles = function () {
for (var i = 0; i < self.candleCount; i++) {
var candle = LK.getAsset('candle', {
anchorX: 0.5,
anchorY: 1.0,
x: (i - (self.candleCount - 1) / 2) * 50,
y: -100
});
self.addChild(candle);
var flame = LK.getAsset('flame', {
anchorX: 0.5,
anchorY: 1.0,
x: (i - (self.candleCount - 1) / 2) * 50,
y: -180
});
self.addChild(flame);
self.candles.push({
candle: candle,
flame: flame,
lit: true
});
}
self.candlesPlaced = true;
};
self.blowOutCandles = function () {
for (var i = 0; i < self.candles.length; i++) {
if (self.candles[i].lit) {
self.candles[i].flame.alpha = 0;
self.candles[i].lit = false;
}
}
LK.getSound('blow_candles').play();
// Show wish message
var wishText = new Text2('Make a wish! π', {
size: 80,
fill: 0xFF6B6B
});
wishText.anchor.set(0.5, 0.5);
wishText.y = 200;
self.addChild(wishText);
tween(wishText, {
alpha: 0
}, {
duration: 3000
});
};
return self;
});
var Doorbell = Container.expand(function () {
var self = Container.call(this);
var doorbellGraphic = self.attachAsset('doorbell', {
anchorX: 0.5,
anchorY: 0.5
});
self.surpriseText = new Text2('', {
size: 60,
fill: 0xFF6B6B
});
self.surpriseText.anchor.set(0.5, 0.5);
self.surpriseText.y = 150;
self.addChild(self.surpriseText);
self.down = function (x, y, obj) {
var surprises = ['π Party guests arrived!', 'π Gift delivered!', 'π΅ Music started!', 'π° More cake!'];
var randomSurprise = surprises[Math.floor(Math.random() * surprises.length)];
self.surpriseText.setText(randomSurprise);
LK.getSound('doorbell_ring').play();
tween(doorbellGraphic, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 100
});
tween(doorbellGraphic, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 100
});
};
return self;
});
var IcingSelector = Container.expand(function () {
var self = Container.call(this);
self.selectedIcing = 'red';
var icingColors = ['red', 'blue', 'green', 'yellow'];
self.icingOptions = [];
for (var i = 0; i < 4; i++) {
var icing = self.attachAsset('icing_' + icingColors[i], {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2,
scaleY: 2,
x: (i - 1.5) * 150
});
self.icingOptions.push(icing);
}
self.down = function (x, y, obj) {
var index = Math.floor((x + 225) / 150);
if (index >= 0 && index < 4) {
self.selectedIcing = icingColors[index];
// Visual feedback
for (var i = 0; i < self.icingOptions.length; i++) {
self.icingOptions[i].alpha = i === index ? 1.0 : 0.5;
}
}
};
return self;
});
var NameInput = Container.expand(function () {
var self = Container.call(this);
self.inputText = new Text2('Enter your name...', {
size: 80,
fill: 0x333333
});
self.inputText.anchor.set(0.5, 0.5);
self.addChild(self.inputText);
self.playerName = '';
self.down = function (x, y, obj) {
// Simple name input simulation - cycle through common names
var names = ['Alex', 'Sam', 'Jordan', 'Casey', 'Taylor'];
var currentIndex = names.indexOf(self.playerName);
var nextIndex = (currentIndex + 1) % names.length;
self.playerName = names[nextIndex];
self.inputText.setText(self.playerName);
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xfff5f5
});
/****
* Game Code
****/
// Party elements
var gameState = 'nameEntry';
var playerName = '';
var playerAge = 1;
var selectedBalloon = 'balloons1';
var selectedCake = 'cake1';
var selectedIcing = 'red';
// UI Elements
var titleText = new Text2('My Birthday Party! π', {
size: 100,
fill: 0xFF6B6B
});
titleText.anchor.set(0.5, 0);
LK.gui.top.addChild(titleText);
var instructionText = new Text2('Tap to enter your name', {
size: 60,
fill: 0x333333
});
instructionText.anchor.set(0.5, 0.5);
instructionText.x = 1024;
instructionText.y = 400;
game.addChild(instructionText);
// Game elements
var nameInput = null;
var ageSelector = null;
var balloonSelector = null;
var cakeSelector = null;
var icingSelector = null;
var doorbell = null;
var bubbleWand = null;
var candleCeremony = null;
function initializeNameEntry() {
nameInput = new NameInput();
nameInput.x = 1024;
nameInput.y = 600;
game.addChild(nameInput);
}
function initializeAgeSelection() {
if (nameInput) {
playerName = nameInput.playerName;
nameInput.destroy();
nameInput = null;
}
instructionText.setText('Choose your age: 1 or 7');
ageSelector = new AgeSelector();
ageSelector.x = 1024;
ageSelector.y = 800;
game.addChild(ageSelector);
}
function initializeBalloonSelection() {
if (ageSelector) {
playerAge = ageSelector.selectedAge;
ageSelector.destroy();
ageSelector = null;
}
instructionText.setText('Pick your favorite balloons!');
balloonSelector = new BalloonSelector();
balloonSelector.x = 1024;
balloonSelector.y = 800;
game.addChild(balloonSelector);
}
function initializeCakeSelection() {
if (balloonSelector) {
selectedBalloon = balloonSelector.selectedBalloon;
balloonSelector.destroy();
balloonSelector = null;
}
instructionText.setText('Choose your birthday cake!');
cakeSelector = new CakeSelector();
cakeSelector.x = 1024;
cakeSelector.y = 1000;
game.addChild(cakeSelector);
}
function initializeIcingSelection() {
if (cakeSelector) {
selectedCake = cakeSelector.selectedCake;
cakeSelector.destroy();
cakeSelector = null;
}
instructionText.setText('Pick icing color for decoration!');
icingSelector = new IcingSelector();
icingSelector.x = 1024;
icingSelector.y = 1200;
game.addChild(icingSelector);
}
function initializePartyTime() {
if (icingSelector) {
selectedIcing = icingSelector.selectedIcing;
icingSelector.destroy();
icingSelector = null;
}
instructionText.setText('Ring the doorbell for surprises!');
// Add chosen balloons as decoration
var balloonDecor = LK.getAsset(selectedBalloon, {
anchorX: 0.5,
anchorY: 0.5,
x: 300,
y: 400,
scaleX: 0.6,
scaleY: 0.6
});
game.addChild(balloonDecor);
var balloonDecor2 = LK.getAsset(selectedBalloon, {
anchorX: 0.5,
anchorY: 0.5,
x: 1700,
y: 400,
scaleX: 0.6,
scaleY: 0.6
});
game.addChild(balloonDecor2);
doorbell = new Doorbell();
doorbell.x = 1024;
doorbell.y = 600;
game.addChild(doorbell);
}
function initializeBubbleTime() {
instructionText.setText('Wave the magic wand to make bubbles!');
if (doorbell) {
doorbell.destroy();
doorbell = null;
}
bubbleWand = new BubbleWand();
bubbleWand.x = 1024;
bubbleWand.y = 1000;
game.addChild(bubbleWand);
}
function initializeCandleTime() {
instructionText.setText('Place candles and blow them out!');
if (bubbleWand) {
bubbleWand.destroy();
bubbleWand = null;
}
candleCeremony = new CandleCeremony();
candleCeremony.x = 1024;
candleCeremony.y = 1400;
candleCeremony.setupCake(selectedCake, selectedIcing, playerAge);
game.addChild(candleCeremony);
}
function initializeComplete() {
instructionText.setText('Happy Birthday ' + playerName + '! ππ');
// Show final celebration
var celebrationText = new Text2('π Party Complete! π', {
size: 80,
fill: 0xFF6B6B
});
celebrationText.anchor.set(0.5, 0.5);
celebrationText.x = 1024;
celebrationText.y = 2200;
game.addChild(celebrationText);
}
// Initialize first state
initializeNameEntry();
var stateTimer = 0;
game.down = function (x, y, obj) {
stateTimer = 0; // Reset timer on interaction
};
game.update = function () {
stateTimer++;
// Auto-advance states for demo purposes (can be removed for manual progression)
if (stateTimer > 300) {
// 5 seconds at 60fps
stateTimer = 0;
switch (gameState) {
case 'nameEntry':
gameState = 'ageSelection';
initializeAgeSelection();
break;
case 'ageSelection':
gameState = 'balloonSelection';
initializeBalloonSelection();
break;
case 'balloonSelection':
gameState = 'cakeSelection';
initializeCakeSelection();
break;
case 'cakeSelection':
gameState = 'icingSelection';
initializeIcingSelection();
break;
case 'icingSelection':
gameState = 'partyTime';
initializePartyTime();
break;
case 'partyTime':
gameState = 'bubbleTime';
initializeBubbleTime();
break;
case 'bubbleTime':
gameState = 'candleTime';
initializeCandleTime();
break;
case 'candleTime':
gameState = 'complete';
initializeComplete();
break;
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,510 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var AgeSelector = Container.expand(function () {
+ var self = Container.call(this);
+ self.selectedAge = 1;
+ var age1Button = new Text2('1', {
+ size: 120,
+ fill: 0xFF6B6B
+ });
+ age1Button.anchor.set(0.5, 0.5);
+ age1Button.x = -100;
+ self.addChild(age1Button);
+ var age7Button = new Text2('7', {
+ size: 120,
+ fill: 0x4ECDC4
+ });
+ age7Button.anchor.set(0.5, 0.5);
+ age7Button.x = 100;
+ self.addChild(age7Button);
+ self.down = function (x, y, obj) {
+ if (x < 0) {
+ self.selectedAge = 1;
+ age1Button.fill = "#ff0000";
+ age7Button.fill = "#4ecdc4";
+ } else {
+ self.selectedAge = 7;
+ age7Button.fill = "#00ff00";
+ age1Button.fill = "#ff6b6b";
+ }
+ };
+ return self;
+});
+var BalloonSelector = Container.expand(function () {
+ var self = Container.call(this);
+ self.selectedBalloon = 'balloons1';
+ self.balloonOptions = [];
+ for (var i = 0; i < 4; i++) {
+ var balloon = self.attachAsset('balloons' + (i + 1), {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: 0.3,
+ scaleY: 0.3,
+ x: (i - 1.5) * 200
+ });
+ self.balloonOptions.push(balloon);
+ }
+ self.down = function (x, y, obj) {
+ var index = Math.floor((x + 300) / 200);
+ if (index >= 0 && index < 4) {
+ self.selectedBalloon = 'balloons' + (index + 1);
+ // Visual feedback
+ for (var i = 0; i < self.balloonOptions.length; i++) {
+ self.balloonOptions[i].alpha = i === index ? 1.0 : 0.5;
+ }
+ }
+ };
+ return self;
+});
+var BubbleWand = Container.expand(function () {
+ var self = Container.call(this);
+ var wandGraphic = self.attachAsset('wand', {
+ anchorX: 0.5,
+ anchorY: 1.0
+ });
+ self.bubbles = [];
+ self.isWaving = false;
+ self.down = function (x, y, obj) {
+ self.isWaving = true;
+ };
+ self.up = function (x, y, obj) {
+ self.isWaving = false;
+ };
+ self.move = function (x, y, obj) {
+ if (self.isWaving) {
+ self.x = x;
+ self.y = y;
+ // Create bubble
+ if (Math.random() < 0.3) {
+ self.createBubble(x, y);
+ }
+ }
+ };
+ self.createBubble = function (x, y) {
+ var bubble = LK.getAsset('bubble', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: x,
+ y: y,
+ alpha: 0.7
+ });
+ game.addChild(bubble);
+ self.bubbles.push(bubble);
+ // Animate bubble
+ tween(bubble, {
+ y: y - 300,
+ alpha: 0
+ }, {
+ duration: 2000,
+ onFinish: function onFinish() {
+ bubble.destroy();
+ var index = self.bubbles.indexOf(bubble);
+ if (index > -1) {
+ self.bubbles.splice(index, 1);
+ }
+ }
+ });
+ LK.getSound('pop').play();
+ };
+ return self;
+});
+var CakeSelector = Container.expand(function () {
+ var self = Container.call(this);
+ self.selectedCake = 'cake1';
+ self.cakeOptions = [];
+ for (var i = 0; i < 4; i++) {
+ var cake = self.attachAsset('cake' + (i + 1), {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: 0.4,
+ scaleY: 0.4,
+ x: (i - 1.5) * 250
+ });
+ self.cakeOptions.push(cake);
+ }
+ self.down = function (x, y, obj) {
+ var index = Math.floor((x + 375) / 250);
+ if (index >= 0 && index < 4) {
+ self.selectedCake = 'cake' + (index + 1);
+ // Visual feedback
+ for (var i = 0; i < self.cakeOptions.length; i++) {
+ self.cakeOptions[i].alpha = i === index ? 1.0 : 0.5;
+ }
+ }
+ };
+ return self;
+});
+var CandleCeremony = Container.expand(function () {
+ var self = Container.call(this);
+ self.cake = null;
+ self.candles = [];
+ self.candleCount = 1;
+ self.candlesPlaced = false;
+ self.setupCake = function (cakeType, icingColor, age) {
+ self.cake = self.attachAsset(cakeType, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Add icing decoration
+ var icingAsset = 'icing_' + icingColor;
+ for (var i = 0; i < 5; i++) {
+ var icing = LK.getAsset(icingAsset, {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: (i - 2) * 60,
+ y: -120
+ });
+ self.addChild(icing);
+ }
+ self.candleCount = age;
+ };
+ self.down = function (x, y, obj) {
+ if (!self.candlesPlaced) {
+ self.placeCandles();
+ } else {
+ self.blowOutCandles();
+ }
+ };
+ self.placeCandles = function () {
+ for (var i = 0; i < self.candleCount; i++) {
+ var candle = LK.getAsset('candle', {
+ anchorX: 0.5,
+ anchorY: 1.0,
+ x: (i - (self.candleCount - 1) / 2) * 50,
+ y: -100
+ });
+ self.addChild(candle);
+ var flame = LK.getAsset('flame', {
+ anchorX: 0.5,
+ anchorY: 1.0,
+ x: (i - (self.candleCount - 1) / 2) * 50,
+ y: -180
+ });
+ self.addChild(flame);
+ self.candles.push({
+ candle: candle,
+ flame: flame,
+ lit: true
+ });
+ }
+ self.candlesPlaced = true;
+ };
+ self.blowOutCandles = function () {
+ for (var i = 0; i < self.candles.length; i++) {
+ if (self.candles[i].lit) {
+ self.candles[i].flame.alpha = 0;
+ self.candles[i].lit = false;
+ }
+ }
+ LK.getSound('blow_candles').play();
+ // Show wish message
+ var wishText = new Text2('Make a wish! π', {
+ size: 80,
+ fill: 0xFF6B6B
+ });
+ wishText.anchor.set(0.5, 0.5);
+ wishText.y = 200;
+ self.addChild(wishText);
+ tween(wishText, {
+ alpha: 0
+ }, {
+ duration: 3000
+ });
+ };
+ return self;
+});
+var Doorbell = Container.expand(function () {
+ var self = Container.call(this);
+ var doorbellGraphic = self.attachAsset('doorbell', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.surpriseText = new Text2('', {
+ size: 60,
+ fill: 0xFF6B6B
+ });
+ self.surpriseText.anchor.set(0.5, 0.5);
+ self.surpriseText.y = 150;
+ self.addChild(self.surpriseText);
+ self.down = function (x, y, obj) {
+ var surprises = ['π Party guests arrived!', 'π Gift delivered!', 'π΅ Music started!', 'π° More cake!'];
+ var randomSurprise = surprises[Math.floor(Math.random() * surprises.length)];
+ self.surpriseText.setText(randomSurprise);
+ LK.getSound('doorbell_ring').play();
+ tween(doorbellGraphic, {
+ scaleX: 1.2,
+ scaleY: 1.2
+ }, {
+ duration: 100
+ });
+ tween(doorbellGraphic, {
+ scaleX: 1.0,
+ scaleY: 1.0
+ }, {
+ duration: 100
+ });
+ };
+ return self;
+});
+var IcingSelector = Container.expand(function () {
+ var self = Container.call(this);
+ self.selectedIcing = 'red';
+ var icingColors = ['red', 'blue', 'green', 'yellow'];
+ self.icingOptions = [];
+ for (var i = 0; i < 4; i++) {
+ var icing = self.attachAsset('icing_' + icingColors[i], {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: 2,
+ scaleY: 2,
+ x: (i - 1.5) * 150
+ });
+ self.icingOptions.push(icing);
+ }
+ self.down = function (x, y, obj) {
+ var index = Math.floor((x + 225) / 150);
+ if (index >= 0 && index < 4) {
+ self.selectedIcing = icingColors[index];
+ // Visual feedback
+ for (var i = 0; i < self.icingOptions.length; i++) {
+ self.icingOptions[i].alpha = i === index ? 1.0 : 0.5;
+ }
+ }
+ };
+ return self;
+});
+var NameInput = Container.expand(function () {
+ var self = Container.call(this);
+ self.inputText = new Text2('Enter your name...', {
+ size: 80,
+ fill: 0x333333
+ });
+ self.inputText.anchor.set(0.5, 0.5);
+ self.addChild(self.inputText);
+ self.playerName = '';
+ self.down = function (x, y, obj) {
+ // Simple name input simulation - cycle through common names
+ var names = ['Alex', 'Sam', 'Jordan', 'Casey', 'Taylor'];
+ var currentIndex = names.indexOf(self.playerName);
+ var nextIndex = (currentIndex + 1) % names.length;
+ self.playerName = names[nextIndex];
+ self.inputText.setText(self.playerName);
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0xfff5f5
+});
+
+/****
+* Game Code
+****/
+// Party elements
+var gameState = 'nameEntry';
+var playerName = '';
+var playerAge = 1;
+var selectedBalloon = 'balloons1';
+var selectedCake = 'cake1';
+var selectedIcing = 'red';
+// UI Elements
+var titleText = new Text2('My Birthday Party! π', {
+ size: 100,
+ fill: 0xFF6B6B
+});
+titleText.anchor.set(0.5, 0);
+LK.gui.top.addChild(titleText);
+var instructionText = new Text2('Tap to enter your name', {
+ size: 60,
+ fill: 0x333333
+});
+instructionText.anchor.set(0.5, 0.5);
+instructionText.x = 1024;
+instructionText.y = 400;
+game.addChild(instructionText);
+// Game elements
+var nameInput = null;
+var ageSelector = null;
+var balloonSelector = null;
+var cakeSelector = null;
+var icingSelector = null;
+var doorbell = null;
+var bubbleWand = null;
+var candleCeremony = null;
+function initializeNameEntry() {
+ nameInput = new NameInput();
+ nameInput.x = 1024;
+ nameInput.y = 600;
+ game.addChild(nameInput);
+}
+function initializeAgeSelection() {
+ if (nameInput) {
+ playerName = nameInput.playerName;
+ nameInput.destroy();
+ nameInput = null;
+ }
+ instructionText.setText('Choose your age: 1 or 7');
+ ageSelector = new AgeSelector();
+ ageSelector.x = 1024;
+ ageSelector.y = 800;
+ game.addChild(ageSelector);
+}
+function initializeBalloonSelection() {
+ if (ageSelector) {
+ playerAge = ageSelector.selectedAge;
+ ageSelector.destroy();
+ ageSelector = null;
+ }
+ instructionText.setText('Pick your favorite balloons!');
+ balloonSelector = new BalloonSelector();
+ balloonSelector.x = 1024;
+ balloonSelector.y = 800;
+ game.addChild(balloonSelector);
+}
+function initializeCakeSelection() {
+ if (balloonSelector) {
+ selectedBalloon = balloonSelector.selectedBalloon;
+ balloonSelector.destroy();
+ balloonSelector = null;
+ }
+ instructionText.setText('Choose your birthday cake!');
+ cakeSelector = new CakeSelector();
+ cakeSelector.x = 1024;
+ cakeSelector.y = 1000;
+ game.addChild(cakeSelector);
+}
+function initializeIcingSelection() {
+ if (cakeSelector) {
+ selectedCake = cakeSelector.selectedCake;
+ cakeSelector.destroy();
+ cakeSelector = null;
+ }
+ instructionText.setText('Pick icing color for decoration!');
+ icingSelector = new IcingSelector();
+ icingSelector.x = 1024;
+ icingSelector.y = 1200;
+ game.addChild(icingSelector);
+}
+function initializePartyTime() {
+ if (icingSelector) {
+ selectedIcing = icingSelector.selectedIcing;
+ icingSelector.destroy();
+ icingSelector = null;
+ }
+ instructionText.setText('Ring the doorbell for surprises!');
+ // Add chosen balloons as decoration
+ var balloonDecor = LK.getAsset(selectedBalloon, {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 300,
+ y: 400,
+ scaleX: 0.6,
+ scaleY: 0.6
+ });
+ game.addChild(balloonDecor);
+ var balloonDecor2 = LK.getAsset(selectedBalloon, {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 1700,
+ y: 400,
+ scaleX: 0.6,
+ scaleY: 0.6
+ });
+ game.addChild(balloonDecor2);
+ doorbell = new Doorbell();
+ doorbell.x = 1024;
+ doorbell.y = 600;
+ game.addChild(doorbell);
+}
+function initializeBubbleTime() {
+ instructionText.setText('Wave the magic wand to make bubbles!');
+ if (doorbell) {
+ doorbell.destroy();
+ doorbell = null;
+ }
+ bubbleWand = new BubbleWand();
+ bubbleWand.x = 1024;
+ bubbleWand.y = 1000;
+ game.addChild(bubbleWand);
+}
+function initializeCandleTime() {
+ instructionText.setText('Place candles and blow them out!');
+ if (bubbleWand) {
+ bubbleWand.destroy();
+ bubbleWand = null;
+ }
+ candleCeremony = new CandleCeremony();
+ candleCeremony.x = 1024;
+ candleCeremony.y = 1400;
+ candleCeremony.setupCake(selectedCake, selectedIcing, playerAge);
+ game.addChild(candleCeremony);
+}
+function initializeComplete() {
+ instructionText.setText('Happy Birthday ' + playerName + '! ππ');
+ // Show final celebration
+ var celebrationText = new Text2('π Party Complete! π', {
+ size: 80,
+ fill: 0xFF6B6B
+ });
+ celebrationText.anchor.set(0.5, 0.5);
+ celebrationText.x = 1024;
+ celebrationText.y = 2200;
+ game.addChild(celebrationText);
+}
+// Initialize first state
+initializeNameEntry();
+var stateTimer = 0;
+game.down = function (x, y, obj) {
+ stateTimer = 0; // Reset timer on interaction
+};
+game.update = function () {
+ stateTimer++;
+ // Auto-advance states for demo purposes (can be removed for manual progression)
+ if (stateTimer > 300) {
+ // 5 seconds at 60fps
+ stateTimer = 0;
+ switch (gameState) {
+ case 'nameEntry':
+ gameState = 'ageSelection';
+ initializeAgeSelection();
+ break;
+ case 'ageSelection':
+ gameState = 'balloonSelection';
+ initializeBalloonSelection();
+ break;
+ case 'balloonSelection':
+ gameState = 'cakeSelection';
+ initializeCakeSelection();
+ break;
+ case 'cakeSelection':
+ gameState = 'icingSelection';
+ initializeIcingSelection();
+ break;
+ case 'icingSelection':
+ gameState = 'partyTime';
+ initializePartyTime();
+ break;
+ case 'partyTime':
+ gameState = 'bubbleTime';
+ initializeBubbleTime();
+ break;
+ case 'bubbleTime':
+ gameState = 'candleTime';
+ initializeCandleTime();
+ break;
+ case 'candleTime':
+ gameState = 'complete';
+ initializeComplete();
+ break;
+ }
+ }
+};
\ No newline at end of file