User prompt
haz los dialogos del golem mas grandes y que aparezcan en un globo de texto ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
haz que el golem pueda decir mensajes dependiendo de como esta, por ejemplo si tiene un sombrero diria: ¡que buen gusto tienes! y tambien si tiene hambre diria: que hambre tengo, ¡dame de comer! ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
haz que se pueda quitar el moño y el sombrero con un boton en la tienda ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
añade moños a la tienda para el golem ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
haz mas grandes las barras de hambre y felicidad y tambien haz un nuevo boton que diga miniGame 2 que sea un nuevo miniGame que sea de conectar colores con sus nombres por tiempo ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
haz mas separados los botones de Feed, Clean, Play, Shop y Mini game y tambien haz que entre mas cara sea la comida, rellene mas la barra de comida ↪💡 Consider importing and using the following plugins: @upit/storage.v1, @upit/tween.v1
User prompt
haz que cuando estes en el menu de comida al tocar una comida se le de la comida que elejiste al golem ↪💡 Consider importing and using the following plugins: @upit/storage.v1, @upit/tween.v1
User prompt
haz que cuando toques el boton Feed aparezca un menu de la comida que compraste para elegir que darle de comer al golem ↪💡 Consider importing and using the following plugins: @upit/storage.v1, @upit/tween.v1
User prompt
haz todo el texto del juego mas grande
User prompt
haz todos los botones del juego mas grandes y que en la tienda haiga diferentes tipos comida para comprar y que ahora tengas que comprar la comida para que no sea infinita ↪💡 Consider importing and using the following plugins: @upit/storage.v1, @upit/tween.v1
User prompt
haz que el minijuego de flappy bird tenga que empezar cuando toques primero el boton Mini Game y luego el boto Jump ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
agrega una tienda que sirva paraa comprar sombreros con las monedas ↪💡 Consider importing and using the following plugins: @upit/storage.v1, @upit/tween.v1
User prompt
haz que cada que pases por un tubo en el minijuego recivas una moneda ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
haz que las monedas aparezcan mas veces en el minijuego ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
haz un boton para el minijuego de flappy bird para saltar con el pajaro y que el pajaro sea mas grande ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
haz que haya un boton que diga: Mini Game que cuando lo toques haga que jueges un mini juego estilo flappy bird y que entre mas cuides a tu golem resiva monedas que hagan que le puedas comprar ropa a el golem ↪💡 Consider importing and using the following plugins: @upit/tween.v1, @upit/storage.v1
User prompt
haz que cuando toques el boton Clean aparezca una gota de agua que caiga sobre la suciedad y que los botones para hacer una accion sean mas grandes ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
crea una barra de hambre, que cuando presionas el boton Play aparezca una pelota que tengas que hacer revotar para subir la barra de felicidad ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
User prompt
Stone Golem Pet
Initial prompt
un juego de cuidar a un golem de piedra mascota estilo talking tom
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Ball = Container.expand(function () {
var self = Container.call(this);
var ballGraphics = self.attachAsset('ball', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityX = 3 + Math.random() * 4;
self.velocityY = 3 + Math.random() * 4;
self.isActive = true;
self.update = function () {
if (!self.isActive) return;
// Move ball
self.x += self.velocityX;
self.y += self.velocityY;
// Bounce off walls
if (self.x <= 30 || self.x >= 2018) {
self.velocityX *= -1;
}
if (self.y <= 200 || self.y >= 2200) {
self.velocityY *= -1;
}
// Keep ball in bounds
self.x = Math.max(30, Math.min(2018, self.x));
self.y = Math.max(200, Math.min(2200, self.y));
};
self.down = function (x, y, obj) {
if (!self.isActive) return;
// Ball was touched - increase happiness
golem.happiness = Math.min(100, golem.happiness + 3);
// Bounce effect
tween(self, {
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 100
});
tween(self, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 100
});
// Change velocity randomly
self.velocityX = (Math.random() - 0.5) * 8;
self.velocityY = (Math.random() - 0.5) * 8;
LK.getSound('happy').play();
};
return self;
});
var BowItem = Container.expand(function (bowType, price, bowColor) {
var self = Container.call(this);
// Create item background
var itemBg = self.attachAsset('shopBg', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.2,
scaleY: 0.15,
alpha: 0.8
});
// Create bow preview
var bowPreview = self.attachAsset(bowType, {
anchorX: 0.5,
anchorY: 0.5,
y: -30
});
// Create price text
var priceText = new Text2(price + ' coins', {
size: 36,
fill: 0xFFFFFF
});
priceText.anchor.set(0.5, 0.5);
priceText.y = 20;
self.addChild(priceText);
// Create buy status text
var statusText = new Text2('', {
size: 32,
fill: 0x2ecc71
});
statusText.anchor.set(0.5, 0.5);
statusText.y = 45;
self.addChild(statusText);
self.bowType = bowType;
self.price = price;
self.bowColor = bowColor;
self.updateStatus = function () {
var ownedBows = storage.ownedBows || [];
if (ownedBows.indexOf(self.bowType) !== -1) {
statusText.setText('OWNED');
statusText.tint = 0x2ecc71;
} else if (golem.coins >= self.price) {
statusText.setText('BUY');
statusText.tint = 0xf39c12;
} else {
statusText.setText('NOT ENOUGH COINS');
statusText.tint = 0xe74c3c;
}
};
self.down = function (x, y, obj) {
var ownedBows = storage.ownedBows || [];
if (ownedBows.indexOf(self.bowType) !== -1) {
// Already owned - equip it
storage.equippedBow = self.bowType;
if (golem.currentBow) {
golem.removeChild(golem.currentBow);
}
golem.currentBow = golem.attachAsset(self.bowType, {
anchorX: 0.5,
anchorY: 0.5,
x: -120,
y: -100
});
} else if (golem.coins >= self.price) {
// Buy the bow
golem.coins -= self.price;
ownedBows.push(self.bowType);
storage.ownedBows = ownedBows;
storage.golemCoins = golem.coins;
// Equip immediately
storage.equippedBow = self.bowType;
if (golem.currentBow) {
golem.removeChild(golem.currentBow);
}
golem.currentBow = golem.attachAsset(self.bowType, {
anchorX: 0.5,
anchorY: 0.5,
x: -120,
y: -100
});
// Show immediate message about new bow
currentMessage = golem.generateMessage();
golemMessageText.setText(currentMessage);
messageTimer = messageDuration;
speechBubbleContainer.visible = true;
speechBubbleContainer.alpha = 0;
speechBubbleContainer.scaleX = 0.3;
speechBubbleContainer.scaleY = 0.3;
tween(speechBubbleContainer, {
alpha: 1,
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 400,
easing: tween.easeOut
});
// Purchase animation
tween(self, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 200
});
tween(self, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 200
});
}
// Update all shop items
if (shopContainer && shopContainer.visible) {
for (var i = 0; i < shopItems.length; i++) {
shopItems[i].updateStatus();
}
}
};
return self;
});
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.collected = false;
self.floatOffset = Math.random() * Math.PI * 2;
self.update = function () {
// Floating animation
self.y += Math.sin(LK.ticks * 0.1 + self.floatOffset) * 0.3;
self.rotation += 0.05;
};
return self;
});
var ColorMatchGame = Container.expand(function () {
var self = Container.call(this);
// Game variables
self.gameActive = false;
self.timeLeft = 30; // 30 seconds
self.score = 0;
self.currentTarget = null;
self.colors = ['red', 'blue', 'green', 'yellow'];
self.colorNames = {
'red': 'RED',
'blue': 'BLUE',
'green': 'GREEN',
'yellow': 'YELLOW'
};
self.colorValues = {
'red': 0xff0000,
'blue': 0x0000ff,
'green': 0x00ff00,
'yellow': 0xffff00
};
// Create game background
var gameBg = self.attachAsset('shopBg', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.95
});
// Create timer display
var timerBg = self.attachAsset('gameTimer', {
anchorX: 0.5,
anchorY: 0.5,
y: -1000
});
var timerText = new Text2('Time: 30', {
size: 48,
fill: 0xFFFFFF
});
timerText.anchor.set(0.5, 0.5);
timerBg.addChild(timerText);
// Create score display
var scoreText = new Text2('Score: 0', {
size: 48,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0.5);
scoreText.y = -900;
self.addChild(scoreText);
// Create target color name display
var targetText = new Text2('Match the color:', {
size: 56,
fill: 0xFFFFFF
});
targetText.anchor.set(0.5, 0.5);
targetText.y = -750;
self.addChild(targetText);
var colorNameText = new Text2('RED', {
size: 72,
fill: 0xFFFFFF
});
colorNameText.anchor.set(0.5, 0.5);
colorNameText.y = -650;
self.addChild(colorNameText);
// Create color buttons
self.colorButtons = [];
for (var i = 0; i < 4; i++) {
var colorButton = self.addChild(new Container());
var colorShape = colorButton.attachAsset('color' + self.colors[i].charAt(0).toUpperCase() + self.colors[i].slice(1), {
anchorX: 0.5,
anchorY: 0.5
});
colorButton.x = -300 + i % 2 * 600;
colorButton.y = -400 + Math.floor(i / 2) * 300;
colorButton.colorType = self.colors[i];
colorButton.down = function (x, y, obj) {
if (!self.gameActive) return;
if (this.colorType === self.currentTarget) {
// Correct match
self.score += 10;
scoreText.setText('Score: ' + self.score);
// Success animation
tween(this, {
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 150
});
tween(this, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 150
});
// Generate new target
self.generateNewTarget();
} else {
// Wrong match - penalty
self.score = Math.max(0, self.score - 5);
scoreText.setText('Score: ' + self.score);
// Error animation
tween(this, {
tint: 0xff0000
}, {
duration: 200
});
tween(this, {
tint: 0xffffff
}, {
duration: 200
});
}
};
self.colorButtons.push(colorButton);
}
// Create close button
var closeBtn = self.attachAsset('closeButton', {
anchorX: 0.5,
anchorY: 0.5,
x: 800,
y: -1000
});
var closeText = new Text2('X', {
size: 48,
fill: 0xFFFFFF
});
closeText.anchor.set(0.5, 0.5);
closeBtn.addChild(closeText);
// Generate new target color
self.generateNewTarget = function () {
self.currentTarget = self.colors[Math.floor(Math.random() * self.colors.length)];
colorNameText.setText(self.colorNames[self.currentTarget]);
colorNameText.tint = self.colorValues[self.currentTarget];
};
// Start the game
self.startGame = function () {
self.gameActive = true;
self.timeLeft = 30;
self.score = 0;
scoreText.setText('Score: 0');
self.generateNewTarget();
};
// Update timer
self.update = function () {
if (self.gameActive) {
if (LK.ticks % 60 === 0) {
// Every second
self.timeLeft--;
timerText.setText('Time: ' + self.timeLeft);
if (self.timeLeft <= 0) {
self.endGame();
}
}
}
};
// End the game
self.endGame = function () {
self.gameActive = false;
// Award coins based on score
var coinsEarned = Math.floor(self.score / 5);
golem.coins += coinsEarned;
// Show final score
targetText.setText('Game Over!');
colorNameText.setText('Coins Earned: ' + coinsEarned);
colorNameText.tint = 0xffd700;
};
return self;
});
var Crystal = Container.expand(function () {
var self = Container.call(this);
var crystalGraphics = self.attachAsset('crystal', {
anchorX: 0.5,
anchorY: 0.5
});
// Floating animation
self.floatOffset = Math.random() * Math.PI * 2;
self.update = function () {
self.y += Math.sin(LK.ticks * 0.05 + self.floatOffset) * 0.5;
self.rotation += 0.01;
};
return self;
});
var FlappyBird = Container.expand(function () {
var self = Container.call(this);
var birdGraphics = self.attachAsset('flappyBird', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityY = 0;
self.gravity = 0.8;
self.jumpPower = -12;
self.isAlive = true;
self.update = function () {
if (!self.isAlive) return;
// Apply gravity
self.velocityY += self.gravity;
self.y += self.velocityY;
// Rotate bird based on velocity
self.rotation = Math.min(Math.max(self.velocityY * 0.1, -0.5), 0.5);
// Check bounds
if (self.y < 300 || self.y > 2400) {
self.isAlive = false;
}
};
self.jump = function () {
if (self.isAlive) {
self.velocityY = self.jumpPower;
// Jump animation
tween(self, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 100
});
tween(self, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 100
});
}
};
self.down = function (x, y, obj) {
self.jump();
};
return self;
});
var FoodItem = Container.expand(function (foodType, price, foodName) {
var self = Container.call(this);
// Create item background
var itemBg = self.attachAsset('shopBg', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.2,
scaleY: 0.15,
alpha: 0.8
});
// Create food preview
var foodPreview = self.attachAsset(foodType, {
anchorX: 0.5,
anchorY: 0.5,
y: -30
});
// Create food name text
var nameText = new Text2(foodName, {
size: 32,
fill: 0xFFFFFF
});
nameText.anchor.set(0.5, 0.5);
nameText.y = -10;
self.addChild(nameText);
// Create price text
var priceText = new Text2(price + ' coins', {
size: 36,
fill: 0xFFFFFF
});
priceText.anchor.set(0.5, 0.5);
priceText.y = 20;
self.addChild(priceText);
// Create buy status text
var statusText = new Text2('', {
size: 32,
fill: 0x2ecc71
});
statusText.anchor.set(0.5, 0.5);
statusText.y = 45;
self.addChild(statusText);
self.foodType = foodType;
self.price = price;
self.foodName = foodName;
self.updateStatus = function () {
if (golem.coins >= self.price) {
statusText.setText('BUY');
statusText.tint = 0xf39c12;
} else {
statusText.setText('NOT ENOUGH COINS');
statusText.tint = 0xe74c3c;
}
};
self.down = function (x, y, obj) {
if (golem.coins >= self.price) {
// Buy the food
golem.coins -= self.price;
storage.golemCoins = golem.coins;
// Add food to inventory
var ownedFood = storage.ownedFood || [];
ownedFood.push(self.foodType);
storage.ownedFood = ownedFood;
// Purchase animation
tween(self, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 200
});
tween(self, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 200
});
// Update all shop items
if (shopContainer && shopContainer.visible) {
for (var i = 0; i < shopItems.length; i++) {
shopItems[i].updateStatus();
}
}
}
};
return self;
});
var GameButton = Container.expand(function (text, color) {
var self = Container.call(this);
var buttonBg = self.attachAsset(color === 0x9B59B6 ? 'feedButton' : color === 0x3498DB ? 'cleanButton' : 'playButton', {
anchorX: 0.5,
anchorY: 0.5
});
var buttonText = new Text2(text, {
size: 48,
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.callback = null;
self.down = function (x, y, obj) {
// Button press animation
tween(self, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100
});
tween(self, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 100
});
if (self.callback) {
self.callback();
}
};
return self;
});
var Pipe = Container.expand(function (isTop) {
var self = Container.call(this);
var pipeGraphics = self.attachAsset('pipe', {
anchorX: 0.5,
anchorY: isTop ? 1.0 : 0.0
});
self.speed = -4;
self.passed = false;
self.update = function () {
self.x += self.speed;
};
return self;
});
var ShopItem = Container.expand(function (hatType, price, hatColor) {
var self = Container.call(this);
// Create item background
var itemBg = self.attachAsset('shopBg', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.2,
scaleY: 0.15,
alpha: 0.8
});
// Create hat preview
var hatPreview = self.attachAsset(hatType, {
anchorX: 0.5,
anchorY: 0.5,
y: -30
});
// Create price text
var priceText = new Text2(price + ' coins', {
size: 36,
fill: 0xFFFFFF
});
priceText.anchor.set(0.5, 0.5);
priceText.y = 20;
self.addChild(priceText);
// Create buy status text
var statusText = new Text2('', {
size: 32,
fill: 0x2ecc71
});
statusText.anchor.set(0.5, 0.5);
statusText.y = 45;
self.addChild(statusText);
self.hatType = hatType;
self.price = price;
self.hatColor = hatColor;
self.updateStatus = function () {
var ownedHats = storage.ownedHats || [];
if (ownedHats.indexOf(self.hatType) !== -1) {
statusText.setText('OWNED');
statusText.tint = 0x2ecc71;
} else if (golem.coins >= self.price) {
statusText.setText('BUY');
statusText.tint = 0xf39c12;
} else {
statusText.setText('NOT ENOUGH COINS');
statusText.tint = 0xe74c3c;
}
};
self.down = function (x, y, obj) {
var ownedHats = storage.ownedHats || [];
if (ownedHats.indexOf(self.hatType) !== -1) {
// Already owned - equip it
storage.equippedHat = self.hatType;
if (golem.currentHat) {
golem.removeChild(golem.currentHat);
}
golem.currentHat = golem.attachAsset(self.hatType, {
anchorX: 0.5,
anchorY: 1.0,
x: 0,
y: -180
});
} else if (golem.coins >= self.price) {
// Buy the hat
golem.coins -= self.price;
ownedHats.push(self.hatType);
storage.ownedHats = ownedHats;
storage.golemCoins = golem.coins;
// Equip immediately
storage.equippedHat = self.hatType;
if (golem.currentHat) {
golem.removeChild(golem.currentHat);
}
golem.currentHat = golem.attachAsset(self.hatType, {
anchorX: 0.5,
anchorY: 1.0,
x: 0,
y: -180
});
// Show immediate message about new hat
speechBubbleContainer.visible = true;
speechBubbleContainer.alpha = 0;
speechBubbleContainer.scaleX = 0.3;
speechBubbleContainer.scaleY = 0.3;
tween(speechBubbleContainer, {
alpha: 1,
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 400,
easing: tween.easeOut
});
currentMessage = golem.generateMessage();
golemMessageText.setText(currentMessage);
messageTimer = messageDuration;
// Purchase animation
tween(self, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 200
});
tween(self, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 200
});
}
// Update all shop items
if (shopContainer && shopContainer.visible) {
for (var i = 0; i < shopItems.length; i++) {
shopItems[i].updateStatus();
}
}
};
return self;
});
var StoneGolem = Container.expand(function () {
var self = Container.call(this);
// Create golem body
var body = self.attachAsset('golem', {
anchorX: 0.5,
anchorY: 0.5
});
// Create eyes
var leftEye = self.attachAsset('golemEyes', {
anchorX: 0.5,
anchorY: 0.5,
x: -60,
y: -80
});
var rightEye = self.attachAsset('golemEyes', {
anchorX: 0.5,
anchorY: 0.5,
x: 60,
y: -80
});
// Create mouth
var mouth = self.attachAsset('golemMouth', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 0
});
// Golem properties
self.happiness = storage.golemHappiness || 100;
self.hunger = storage.golemHunger || 100;
self.lastFeedTime = storage.lastFeedTime || Date.now();
self.lastCleanTime = storage.lastCleanTime || Date.now();
self.coins = storage.golemCoins || 0;
self.mood = 'happy'; // happy, sad, sleepy, excited
self.mossSpots = [];
self.currentHat = null;
self.currentBow = null;
// Load equipped hat if any
if (storage.equippedHat) {
self.currentHat = self.attachAsset(storage.equippedHat, {
anchorX: 0.5,
anchorY: 1.0,
x: 0,
y: -180
});
}
// Load equipped bow if any
if (storage.equippedBow) {
self.currentBow = self.attachAsset(storage.equippedBow, {
anchorX: 0.5,
anchorY: 0.5,
x: -120,
y: -100
});
}
// Create initial moss spots
self.createMossSpots = function () {
for (var i = 0; i < 3; i++) {
var mossSpot = self.attachAsset('moss', {
anchorX: 0.5,
anchorY: 0.5,
x: (Math.random() - 0.5) * 300,
y: (Math.random() - 0.5) * 400,
alpha: 0.7
});
self.mossSpots.push(mossSpot);
}
};
self.createMossSpots();
// React to petting
self.pet = function () {
// Happy animation
tween(self, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 200,
easing: tween.easeOut
});
tween(self, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 200,
easing: tween.easeIn
});
// Eyes blink
tween(leftEye, {
scaleY: 0.1
}, {
duration: 100
});
tween(leftEye, {
scaleY: 1.0
}, {
duration: 100
});
tween(rightEye, {
scaleY: 0.1
}, {
duration: 100
});
tween(rightEye, {
scaleY: 1.0
}, {
duration: 100
});
LK.getSound('happy').play();
self.happiness = Math.min(100, self.happiness + 2);
};
// Feed the golem
self.feed = function () {
// Check if player has food in inventory
var ownedFood = storage.ownedFood || [];
if (ownedFood.length === 0) {
return false; // No food available
}
if (Date.now() - self.lastFeedTime > 5000) {
// Can feed every 5 seconds
// Consume one food item
ownedFood.pop();
storage.ownedFood = ownedFood;
mouth.scaleX = 1.5;
mouth.scaleY = 1.5;
tween(mouth, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 500
});
// Bounce animation
tween(self, {
y: self.y - 20
}, {
duration: 200,
easing: tween.easeOut
});
tween(self, {
y: self.y
}, {
duration: 200,
easing: tween.bounceOut
});
LK.getSound('eat').play();
self.happiness = Math.min(100, self.happiness + 15);
self.hunger = Math.min(100, self.hunger + 20);
self.lastFeedTime = Date.now();
return true;
}
return false;
};
// Clean moss from golem
self.clean = function () {
if (self.mossSpots.length > 0) {
var mossToRemove = self.mossSpots.pop();
tween(mossToRemove, {
alpha: 0,
scaleX: 2,
scaleY: 2
}, {
duration: 300,
onFinish: function onFinish() {
self.removeChild(mossToRemove);
}
});
LK.getSound('clean').play();
self.happiness = Math.min(100, self.happiness + 10);
return true;
}
return false;
};
// Update mood based on happiness
self.updateMood = function () {
if (self.happiness > 80) {
self.mood = 'happy';
body.tint = 0x8B7355; // Normal stone color
} else if (self.happiness > 50) {
self.mood = 'neutral';
body.tint = 0x7A6B4F; // Slightly darker
} else if (self.happiness > 20) {
self.mood = 'sad';
body.tint = 0x695C42; // Darker
} else {
self.mood = 'very_sad';
body.tint = 0x5A4D35; // Very dark
}
};
// Generate contextual messages based on golem's state
self.generateMessage = function () {
var messages = [];
// Messages about accessories
if (self.currentHat && self.currentBow) {
messages.push('¡Qué elegante me veo con mi sombrero y moño!');
messages.push('¡Me encanta mi estilo!');
} else if (self.currentHat) {
messages.push('¡Qué buen gusto tienes!');
messages.push('¡Mi sombrero me queda perfecto!');
messages.push('¡Me siento muy elegante!');
} else if (self.currentBow) {
messages.push('¡Mi moño es hermoso!');
messages.push('¡Gracias por este lindo accesorio!');
}
// Messages about hunger
if (self.hunger < 30) {
messages.push('¡Qué hambre tengo, dame de comer!');
messages.push('¡Necesito comida urgente!');
messages.push('¡Mi estómago está rugiendo!');
} else if (self.hunger > 80) {
messages.push('¡Qué rico estuvo eso!');
messages.push('¡Estoy muy satisfecho!');
}
// Messages about happiness
if (self.happiness < 25) {
messages.push('¡Me siento muy triste!');
messages.push('¡Necesito más cariño!');
messages.push('¡Por favor, juega conmigo!');
} else if (self.happiness > 90) {
messages.push('¡Soy el golem más feliz del mundo!');
messages.push('¡Me encanta pasar tiempo contigo!');
messages.push('¡Qué día tan maravilloso!');
}
// Messages about cleanliness
if (self.mossSpots.length > 3) {
messages.push('¡Ayúdame a limpiarme!');
messages.push('¡Estoy muy sucio!');
messages.push('¡Necesito un baño!');
} else if (self.mossSpots.length === 0) {
messages.push('¡Qué limpio estoy!');
messages.push('¡Gracias por cuidarme tan bien!');
}
// Default happy messages
if (messages.length === 0) {
messages.push('¡Hola, amigo!');
messages.push('¡Qué lindo día!');
messages.push('¡Me gusta estar contigo!');
messages.push('¡Soy tu fiel compañero!');
}
return messages[Math.floor(Math.random() * messages.length)];
};
// Decrease happiness over time
self.update = function () {
// Decrease happiness slowly over time
if (LK.ticks % 300 == 0) {
// Every 5 seconds at 60fps
self.happiness = Math.max(0, self.happiness - 1);
self.updateMood();
}
// Decrease hunger over time
if (LK.ticks % 240 == 0) {
// Every 4 seconds at 60fps
self.hunger = Math.max(0, self.hunger - 1);
}
// Add moss spots occasionally
if (LK.ticks % 1800 == 0 && self.mossSpots.length < 5) {
// Every 30 seconds
var mossSpot = self.attachAsset('moss', {
anchorX: 0.5,
anchorY: 0.5,
x: (Math.random() - 0.5) * 300,
y: (Math.random() - 0.5) * 400,
alpha: 0.7
});
self.mossSpots.push(mossSpot);
}
// Save state
if (LK.ticks % 60 == 0) {
// Every second
storage.golemHappiness = self.happiness;
storage.golemHunger = self.hunger;
storage.lastFeedTime = self.lastFeedTime;
storage.lastCleanTime = self.lastCleanTime;
storage.golemCoins = self.coins;
}
};
// Touch response
self.down = function (x, y, obj) {
self.pet();
};
return self;
});
var WaterDrop = Container.expand(function () {
var self = Container.call(this);
var dropGraphics = self.attachAsset('waterDrop', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityY = 8;
self.isActive = true;
self.update = function () {
if (!self.isActive) return;
// Move water drop down
self.y += self.velocityY;
// Check if drop hit any moss spots
for (var i = 0; i < golem.mossSpots.length; i++) {
var mossSpot = golem.mossSpots[i];
var mossGlobalPos = golem.toGlobal(mossSpot.position);
var dropGlobalPos = game.toGlobal(self.position);
var distance = Math.sqrt(Math.pow(mossGlobalPos.x - dropGlobalPos.x, 2) + Math.pow(mossGlobalPos.y - dropGlobalPos.y, 2));
if (distance < 50) {
// Hit moss - clean it
golem.mossSpots.splice(i, 1);
tween(mossSpot, {
alpha: 0,
scaleX: 2,
scaleY: 2
}, {
duration: 300,
onFinish: function onFinish() {
golem.removeChild(mossSpot);
}
});
golem.happiness = Math.min(100, golem.happiness + 10);
LK.getSound('clean').play();
// Remove water drop
self.isActive = false;
game.removeChild(self);
return;
}
}
// Remove drop if it goes off screen
if (self.y > 2732) {
self.isActive = false;
game.removeChild(self);
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2C3E50
});
/****
* Game Code
****/
// Create UI elements
var happinessBg = LK.getAsset('happinessBg', {
anchorX: 0.5,
anchorY: 0.5
});
LK.gui.top.addChild(happinessBg);
happinessBg.y = 100;
var happinessBar = LK.getAsset('happinessBar', {
anchorX: 0.0,
anchorY: 0.5
});
happinessBg.addChild(happinessBar);
happinessBar.x = -200;
var happinessText = new Text2('Happiness: 100%', {
size: 48,
fill: 0xFFFFFF
});
happinessText.anchor.set(0.5, 0);
LK.gui.top.addChild(happinessText);
happinessText.y = 50;
// Create hunger bar UI
var hungerBg = LK.getAsset('hungerBg', {
anchorX: 0.5,
anchorY: 0.5
});
LK.gui.top.addChild(hungerBg);
hungerBg.y = 160;
var hungerBar = LK.getAsset('hungerBar', {
anchorX: 0.0,
anchorY: 0.5
});
hungerBg.addChild(hungerBar);
hungerBar.x = -200;
var hungerText = new Text2('Hunger: 100%', {
size: 48,
fill: 0xFFFFFF
});
hungerText.anchor.set(0.5, 0);
LK.gui.top.addChild(hungerText);
hungerText.y = 140;
// Create coins display
var coinsText = new Text2('Coins: 0', {
size: 48,
fill: 0xFFFFFF
});
coinsText.anchor.set(0.5, 0);
LK.gui.top.addChild(coinsText);
coinsText.y = 200;
// Create food inventory display
var foodText = new Text2('Food: 0', {
size: 48,
fill: 0xFFFFFF
});
foodText.anchor.set(0.5, 0);
LK.gui.top.addChild(foodText);
foodText.y = 240;
// Create golem message speech bubble container
var speechBubbleContainer = new Container();
speechBubbleContainer.x = 1024;
speechBubbleContainer.y = 600;
game.addChild(speechBubbleContainer);
// Create speech bubble background
var speechBubbleBg = speechBubbleContainer.attachAsset('speechBubble', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.95
});
// Create speech bubble tail (pointing to golem)
var speechTail = speechBubbleContainer.attachAsset('speechTail', {
anchorX: 0.5,
anchorY: 0,
y: 100,
rotation: Math.PI / 4
});
// Create golem message display with larger text
var golemMessageText = new Text2('', {
size: 48,
fill: 0x333333
});
golemMessageText.anchor.set(0.5, 0.5);
speechBubbleContainer.addChild(golemMessageText);
// Initially hide the speech bubble
speechBubbleContainer.alpha = 0;
speechBubbleContainer.visible = false;
// Message system variables
var currentMessage = '';
var messageTimer = 0;
var messageDuration = 180; // 3 seconds at 60fps
var lastMessageCheck = 0;
// Create main golem
var golem = game.addChild(new StoneGolem());
golem.x = 1024;
golem.y = 1200;
// Create control buttons with increased spacing
var feedButton = new GameButton('Feed', 0x9B59B6);
feedButton.x = 1024 - 400;
feedButton.y = 2500;
// Food menu variables
var isFoodMenuOpen = false;
var foodMenuContainer = null;
feedButton.callback = function () {
var ownedFood = storage.ownedFood || [];
if (ownedFood.length === 0) {
// No food available - show message
return;
}
// Open food selection menu
if (!isFoodMenuOpen) {
isFoodMenuOpen = true;
// Create food menu container
foodMenuContainer = game.addChild(new Container());
// Create menu background
var menuBg = foodMenuContainer.attachAsset('shopBg', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.8,
scaleY: 0.6,
alpha: 0.9
});
foodMenuContainer.x = 1024;
foodMenuContainer.y = 1366;
// Create menu title
var menuTitle = new Text2('SELECT FOOD', {
size: 48,
fill: 0xFFFFFF
});
menuTitle.anchor.set(0.5, 0.5);
menuTitle.y = -400;
foodMenuContainer.addChild(menuTitle);
// Create close button
var closeBtn = foodMenuContainer.attachAsset('closeButton', {
anchorX: 0.5,
anchorY: 0.5,
x: 600,
y: -400
});
var closeText = new Text2('X', {
size: 48,
fill: 0xFFFFFF
});
closeText.anchor.set(0.5, 0.5);
closeBtn.addChild(closeText);
// Group food items by type and show counts
var foodCounts = {};
for (var i = 0; i < ownedFood.length; i++) {
var foodType = ownedFood[i];
foodCounts[foodType] = (foodCounts[foodType] || 0) + 1;
}
// Create food selection items
var foodTypes = Object.keys(foodCounts);
var foodNames = {
'food1': 'Apple',
'food2': 'Bread',
'food3': 'Cheese',
'food4': 'Cake'
};
for (var i = 0; i < foodTypes.length; i++) {
var foodType = foodTypes[i];
var count = foodCounts[foodType];
// Create food item container
var foodItem = foodMenuContainer.addChild(new Container());
foodItem.x = -300 + i % 2 * 600;
foodItem.y = -200 + Math.floor(i / 2) * 200;
// Create food background
var itemBg = foodItem.attachAsset('shopBg', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.15,
scaleY: 0.1,
alpha: 0.6
});
// Create food image
var foodImage = foodItem.attachAsset(foodType, {
anchorX: 0.5,
anchorY: 0.5,
y: -20,
scaleX: 0.5,
scaleY: 0.5
});
// Create food name and count text
var foodText = new Text2(foodNames[foodType] + ' (' + count + ')', {
size: 32,
fill: 0xFFFFFF
});
foodText.anchor.set(0.5, 0.5);
foodText.y = 30;
foodItem.addChild(foodText);
// Add click handler for feeding
foodItem.foodType = foodType;
foodItem.down = function (x, y, obj) {
// Feed the golem with selected food
var selectedFood = this.foodType;
// Remove one of this food type from inventory
var ownedFood = storage.ownedFood || [];
var foodIndex = ownedFood.indexOf(selectedFood);
if (foodIndex !== -1) {
ownedFood.splice(foodIndex, 1);
storage.ownedFood = ownedFood;
// Determine hunger restoration based on food type and price
var foodPrices = {
'food1': 5,
'food2': 10,
'food3': 20,
'food4': 30
};
var foodPrice = foodPrices[selectedFood] || 5;
var hungerRestoration = Math.floor(foodPrice * 1.5); // More expensive food restores more hunger
// Feed animation and effects
var mouth = golem.children[2]; // mouth is third child
mouth.scaleX = 1.5;
mouth.scaleY = 1.5;
tween(mouth, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 500
});
// Bounce animation
tween(golem, {
y: golem.y - 20
}, {
duration: 200,
easing: tween.easeOut
});
tween(golem, {
y: golem.y
}, {
duration: 200,
easing: tween.bounceOut
});
// Create crystal animation
var crystal = game.addChild(new Crystal());
crystal.x = golem.x;
crystal.y = golem.y - 200;
tween(crystal, {
x: golem.x,
y: golem.y
}, {
duration: 800,
easing: tween.easeIn,
onFinish: function onFinish() {
game.removeChild(crystal);
}
});
LK.getSound('eat').play();
golem.happiness = Math.min(100, golem.happiness + 15);
golem.hunger = Math.min(100, golem.hunger + hungerRestoration);
golem.lastFeedTime = Date.now();
// Close food menu after feeding
closeFoodMenu();
}
};
}
// Menu entrance animation
foodMenuContainer.alpha = 0;
foodMenuContainer.scaleX = 0.5;
foodMenuContainer.scaleY = 0.5;
tween(foodMenuContainer, {
alpha: 1,
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 300,
easing: tween.easeOut
});
}
};
function closeFoodMenu() {
if (foodMenuContainer) {
tween(foodMenuContainer, {
alpha: 0,
scaleX: 0.5,
scaleY: 0.5
}, {
duration: 300,
easing: tween.easeIn,
onFinish: function onFinish() {
game.removeChild(foodMenuContainer);
foodMenuContainer = null;
}
});
}
isFoodMenuOpen = false;
}
game.addChild(feedButton);
var cleanButton = new GameButton('Clean', 0x3498DB);
cleanButton.x = 1024 - 200;
cleanButton.y = 2500;
cleanButton.callback = function () {
// Create water drop that falls on moss
var waterDrop = game.addChild(new WaterDrop());
waterDrop.x = golem.x + (Math.random() - 0.5) * 200;
waterDrop.y = 300;
// Add some animation to the water drop creation
tween(waterDrop, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 100
});
tween(waterDrop, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 100
});
};
game.addChild(cleanButton);
var playButton = new GameButton('Play', 0xE74C3C);
playButton.x = 1024;
playButton.y = 2500;
// Game state variables
var isPlayingMiniGame = false;
var miniGameBall = null;
var miniGameTimer = 0;
var miniGameDuration = 600; // 10 seconds at 60fps
// Shop variables
var isShopOpen = false;
var shopContainer = null;
var shopItems = [];
// Flappy bird mini game variables
var isPlayingFlappyBird = false;
var isFlappyBirdReady = false;
var flappyBird = null;
var jumpButton = null;
var pipes = [];
var gameCoins = [];
var flappyScore = 0;
var pipeSpawnTimer = 0;
var coinSpawnTimer = 0;
playButton.callback = function () {
if (!isPlayingMiniGame) {
// Start mini-game
isPlayingMiniGame = true;
miniGameTimer = 0;
miniGameBall = game.addChild(new Ball());
miniGameBall.x = 1024;
miniGameBall.y = 1000;
} else {
// Stop mini-game early
if (miniGameBall) {
miniGameBall.isActive = false;
game.removeChild(miniGameBall);
miniGameBall = null;
}
isPlayingMiniGame = false;
}
};
game.addChild(playButton);
var miniGameButton = new GameButton('Mini Game', 0xF39C12);
miniGameButton.x = 1024 + 200;
miniGameButton.y = 2500;
miniGameButton.callback = function () {
if (!isFlappyBirdReady && !isPlayingFlappyBird) {
// Prepare flappy bird mini game (don't start yet)
isFlappyBirdReady = true;
flappyScore = 0;
pipeSpawnTimer = 0;
coinSpawnTimer = 0;
// Create bird
flappyBird = game.addChild(new FlappyBird());
flappyBird.x = 400;
flappyBird.y = 1200;
// Clear any existing pipes and coins
// Create jump button for flappy bird
jumpButton = game.addChild(new GameButton('JUMP', 0x27AE60));
jumpButton.x = 1024;
jumpButton.y = 2200;
jumpButton.callback = function () {
if (flappyBird && flappyBird.isAlive) {
if (!isPlayingFlappyBird && isFlappyBirdReady) {
// Start the game on first jump
isPlayingFlappyBird = true;
}
flappyBird.jump();
}
};
pipes = [];
gameCoins = [];
} else {
// Stop flappy bird game
if (flappyBird) {
game.removeChild(flappyBird);
flappyBird = null;
}
if (jumpButton) {
game.removeChild(jumpButton);
jumpButton = null;
}
// Clean up pipes
for (var i = 0; i < pipes.length; i++) {
game.removeChild(pipes[i]);
}
pipes = [];
// Clean up coins
for (var i = 0; i < gameCoins.length; i++) {
game.removeChild(gameCoins[i]);
}
gameCoins = [];
isPlayingFlappyBird = false;
isFlappyBirdReady = false;
}
};
game.addChild(miniGameButton);
var miniGame2Button = new GameButton('Mini Game 2', 0x9B59B6);
miniGame2Button.x = 1024 - 400;
miniGame2Button.y = 2380;
// Color match game variables
var isColorGameActive = false;
var colorMatchGame = null;
miniGame2Button.callback = function () {
if (!isColorGameActive) {
// Start color match game
isColorGameActive = true;
// Create color match game
colorMatchGame = game.addChild(new ColorMatchGame());
colorMatchGame.x = 1024;
colorMatchGame.y = 1366;
// Game entrance animation
colorMatchGame.alpha = 0;
colorMatchGame.scaleX = 0.5;
colorMatchGame.scaleY = 0.5;
tween(colorMatchGame, {
alpha: 1,
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
colorMatchGame.startGame();
}
});
} else {
// Close color match game
if (colorMatchGame) {
tween(colorMatchGame, {
alpha: 0,
scaleX: 0.5,
scaleY: 0.5
}, {
duration: 300,
easing: tween.easeIn,
onFinish: function onFinish() {
game.removeChild(colorMatchGame);
colorMatchGame = null;
}
});
}
isColorGameActive = false;
}
};
game.addChild(miniGame2Button);
var shopButton = new GameButton('Shop', 0x8E44AD);
shopButton.x = 1024 + 400;
shopButton.y = 2500;
shopButton.callback = function () {
if (!isShopOpen) {
// Open shop
isShopOpen = true;
// Create shop container
shopContainer = game.addChild(new Container());
// Create shop background
var shopBg = shopContainer.attachAsset('shopBg', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.9
});
shopContainer.x = 1024;
shopContainer.y = 1366;
// Create shop title
var shopTitle = new Text2('HAT SHOP', {
size: 64,
fill: 0xFFFFFF
});
shopTitle.anchor.set(0.5, 0.5);
shopTitle.y = -1000;
shopContainer.addChild(shopTitle);
// Create close button
var closeBtn = shopContainer.attachAsset('closeButton', {
anchorX: 0.5,
anchorY: 0.5,
x: 800,
y: -1000
});
// Add close button text
var closeText = new Text2('X', {
size: 48,
fill: 0xFFFFFF
});
closeText.anchor.set(0.5, 0.5);
closeBtn.addChild(closeText);
// Create shop items
shopItems = [];
// Add hat section
var hatTypes = ['hat1', 'hat2', 'hat3', 'hat4'];
var hatPrices = [10, 25, 50, 100];
var hatColors = [0xe74c3c, 0x3498db, 0xf39c12, 0x2ecc71];
for (var i = 0; i < hatTypes.length; i++) {
var shopItem = shopContainer.addChild(new ShopItem(hatTypes[i], hatPrices[i], hatColors[i]));
shopItem.x = -600 + i % 2 * 600;
shopItem.y = -700 + Math.floor(i / 2) * 300;
shopItem.updateStatus();
shopItems.push(shopItem);
}
// Add food section title
var foodTitle = new Text2('FOOD', {
size: 48,
fill: 0xFFFFFF
});
foodTitle.anchor.set(0.5, 0.5);
foodTitle.y = -200;
shopContainer.addChild(foodTitle);
// Add food items
var foodTypes = ['food1', 'food2', 'food3', 'food4'];
var foodPrices = [5, 10, 20, 30];
var foodNames = ['Apple', 'Bread', 'Cheese', 'Cake'];
for (var i = 0; i < foodTypes.length; i++) {
var foodItem = shopContainer.addChild(new FoodItem(foodTypes[i], foodPrices[i], foodNames[i]));
foodItem.x = -600 + i % 2 * 600;
foodItem.y = -100 + Math.floor(i / 2) * 300;
foodItem.updateStatus();
shopItems.push(foodItem);
}
// Add bow section title
var bowTitle = new Text2('BOWS', {
size: 48,
fill: 0xFFFFFF
});
bowTitle.anchor.set(0.5, 0.5);
bowTitle.y = 400;
shopContainer.addChild(bowTitle);
// Add bow items
var bowTypes = ['bow1', 'bow2', 'bow3'];
var bowPrices = [15, 35, 75];
var bowColors = [0xe91e63, 0x9c27b0, 0x673ab7];
for (var i = 0; i < bowTypes.length; i++) {
var bowItem = shopContainer.addChild(new BowItem(bowTypes[i], bowPrices[i], bowColors[i]));
bowItem.x = -300 + i % 3 * 300;
bowItem.y = 500 + Math.floor(i / 3) * 200;
bowItem.updateStatus();
shopItems.push(bowItem);
}
// Add remove accessories section title
var removeTitle = new Text2('REMOVE ACCESSORIES', {
size: 48,
fill: 0xFFFFFF
});
removeTitle.anchor.set(0.5, 0.5);
removeTitle.y = 700;
shopContainer.addChild(removeTitle);
// Add remove hat button
var removeHatButton = shopContainer.addChild(new Container());
var removeHatBg = removeHatButton.attachAsset('shopBg', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.2,
scaleY: 0.15,
alpha: 0.8
});
removeHatButton.x = -200;
removeHatButton.y = 800;
var removeHatText = new Text2('REMOVE HAT', {
size: 32,
fill: 0xFFFFFF
});
removeHatText.anchor.set(0.5, 0.5);
removeHatButton.addChild(removeHatText);
removeHatButton.down = function (x, y, obj) {
if (golem.currentHat) {
golem.removeChild(golem.currentHat);
golem.currentHat = null;
storage.equippedHat = null;
// Success animation
tween(this, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 150
});
tween(this, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 150
});
}
};
// Add remove bow button
var removeBowButton = shopContainer.addChild(new Container());
var removeBowBg = removeBowButton.attachAsset('shopBg', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.2,
scaleY: 0.15,
alpha: 0.8
});
removeBowButton.x = 200;
removeBowButton.y = 800;
var removeBowText = new Text2('REMOVE BOW', {
size: 32,
fill: 0xFFFFFF
});
removeBowText.anchor.set(0.5, 0.5);
removeBowButton.addChild(removeBowText);
removeBowButton.down = function (x, y, obj) {
if (golem.currentBow) {
golem.removeChild(golem.currentBow);
golem.currentBow = null;
storage.equippedBow = null;
// Success animation
tween(this, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 150
});
tween(this, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 150
});
}
};
// Shop entrance animation
shopContainer.alpha = 0;
shopContainer.scaleX = 0.5;
shopContainer.scaleY = 0.5;
tween(shopContainer, {
alpha: 1,
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 300,
easing: tween.easeOut
});
} else {
// Close shop
if (shopContainer) {
tween(shopContainer, {
alpha: 0,
scaleX: 0.5,
scaleY: 0.5
}, {
duration: 300,
easing: tween.easeIn,
onFinish: function onFinish() {
game.removeChild(shopContainer);
shopContainer = null;
shopItems = [];
}
});
}
isShopOpen = false;
}
};
game.addChild(shopButton);
// Add close shop functionality
game.down = function (x, y, obj) {
if (isShopOpen && shopContainer) {
// Check if clicked close button or outside shop
var localPos = shopContainer.toLocal({
x: x,
y: y
});
if (localPos.x > 750 && localPos.x < 850 && localPos.y > -1050 && localPos.y < -950) {
// Clicked close button
shopButton.callback();
} else if (Math.abs(localPos.x) > 900 || Math.abs(localPos.y) > 1100) {
// Clicked outside shop
shopButton.callback();
}
}
// Handle food menu close
if (isFoodMenuOpen && foodMenuContainer) {
var localPos = foodMenuContainer.toLocal({
x: x,
y: y
});
if (localPos.x > 550 && localPos.x < 650 && localPos.y > -450 && localPos.y < -350) {
// Clicked close button
closeFoodMenu();
} else if (Math.abs(localPos.x) > 700 || Math.abs(localPos.y) > 500) {
// Clicked outside menu
closeFoodMenu();
}
}
// Handle color match game close
if (isColorGameActive && colorMatchGame) {
var localPos = colorMatchGame.toLocal({
x: x,
y: y
});
if (localPos.x > 750 && localPos.x < 850 && localPos.y > -1050 && localPos.y < -950) {
// Clicked close button
miniGame2Button.callback();
} else if (Math.abs(localPos.x) > 900 || Math.abs(localPos.y) > 1100) {
// Clicked outside game
miniGame2Button.callback();
}
}
};
// Floating crystals for ambiance
var floatingCrystals = [];
for (var i = 0; i < 3; i++) {
var floatingCrystal = game.addChild(new Crystal());
floatingCrystal.x = 200 + i * 800;
floatingCrystal.y = 300 + Math.random() * 200;
floatingCrystal.alpha = 0.3;
floatingCrystal.scaleX = 0.5;
floatingCrystal.scaleY = 0.5;
floatingCrystals.push(floatingCrystal);
}
// Game update loop
game.update = function () {
// Update happiness display
var happinessPercent = Math.max(0, golem.happiness);
happinessText.setText('Happiness: ' + Math.round(happinessPercent) + '%');
// Update happiness bar visual
var barWidth = happinessPercent / 100 * 400;
happinessBar.width = barWidth;
// Change bar color based on happiness
if (happinessPercent > 60) {
happinessBar.tint = 0x2ECC71; // Green
} else if (happinessPercent > 30) {
happinessBar.tint = 0xF39C12; // Orange
} else {
happinessBar.tint = 0xE74C3C; // Red
}
// Update hunger display
var hungerPercent = Math.max(0, golem.hunger);
hungerText.setText('Hunger: ' + Math.round(hungerPercent) + '%');
// Update hunger bar visual
var hungerBarWidth = hungerPercent / 100 * 400;
hungerBar.width = hungerBarWidth;
// Change hunger bar color based on hunger level
if (hungerPercent > 60) {
hungerBar.tint = 0xE67E22; // Orange
} else if (hungerPercent > 30) {
hungerBar.tint = 0xD35400; // Darker orange
} else {
hungerBar.tint = 0xE74C3C; // Red
}
// Update coins display
coinsText.setText('Coins: ' + golem.coins);
// Update food inventory display
var ownedFood = storage.ownedFood || [];
foodText.setText('Food: ' + ownedFood.length);
// Handle flappy bird mini game
if ((isPlayingFlappyBird || isFlappyBirdReady) && flappyBird) {
// Spawn pipes (only when actually playing)
if (isPlayingFlappyBird) {
pipeSpawnTimer++;
if (pipeSpawnTimer >= 120) {
// Every 2 seconds
pipeSpawnTimer = 0;
var gapY = 800 + Math.random() * 800; // Random gap position
var gapSize = 300; // Gap between pipes
// Top pipe
var topPipe = game.addChild(new Pipe(true));
topPipe.x = 2200;
topPipe.y = gapY - gapSize / 2;
pipes.push(topPipe);
// Bottom pipe
var bottomPipe = game.addChild(new Pipe(false));
bottomPipe.x = 2200;
bottomPipe.y = gapY + gapSize / 2;
pipes.push(bottomPipe);
}
// Spawn coins
coinSpawnTimer++;
if (coinSpawnTimer >= 90) {
// Every 1.5 seconds
coinSpawnTimer = 0;
var gameCoin = game.addChild(new Coin());
gameCoin.x = 2200;
gameCoin.y = 600 + Math.random() * 1200;
gameCoins.push(gameCoin);
}
}
// Update and check pipes
for (var i = pipes.length - 1; i >= 0; i--) {
var pipe = pipes[i];
// Check collision with bird
if (flappyBird.intersects(pipe)) {
flappyBird.isAlive = false;
}
// Mark pipe as passed and award coins when bird passes through
if (!pipe.passed && pipe.x < flappyBird.x) {
pipe.passed = true;
// Award coins based on care level when passing through pipe
var careBonus = Math.floor((golem.happiness + golem.hunger) / 20);
golem.coins += 1 + careBonus;
flappyScore++;
}
// Remove off-screen pipes
if (pipe.x < -100) {
game.removeChild(pipe);
pipes.splice(i, 1);
}
}
// Update and check coins
for (var i = gameCoins.length - 1; i >= 0; i--) {
var gameCoin = gameCoins[i];
// Check collision with bird
if (!gameCoin.collected && flappyBird.intersects(gameCoin)) {
gameCoin.collected = true;
var careBonus = Math.floor((golem.happiness + golem.hunger) / 25);
golem.coins += 2 + careBonus;
// Coin collection animation
tween(gameCoin, {
alpha: 0,
scaleX: 2,
scaleY: 2
}, {
duration: 200,
onFinish: function onFinish() {
game.removeChild(gameCoin);
}
});
gameCoins.splice(i, 1);
continue;
}
// Remove off-screen coins
if (gameCoin.x < -50) {
game.removeChild(gameCoin);
gameCoins.splice(i, 1);
}
}
// Check if bird died
if (!flappyBird.isAlive) {
// End game
game.removeChild(flappyBird);
flappyBird = null;
if (jumpButton) {
game.removeChild(jumpButton);
jumpButton = null;
}
// Clean up pipes
for (var i = 0; i < pipes.length; i++) {
game.removeChild(pipes[i]);
}
pipes = [];
// Clean up coins
for (var i = 0; i < gameCoins.length; i++) {
game.removeChild(gameCoins[i]);
}
gameCoins = [];
isPlayingFlappyBird = false;
isFlappyBirdReady = false;
}
}
// Handle mini-game
if (isPlayingMiniGame) {
miniGameTimer++;
// End mini-game after duration
if (miniGameTimer >= miniGameDuration) {
if (miniGameBall) {
miniGameBall.isActive = false;
game.removeChild(miniGameBall);
miniGameBall = null;
}
isPlayingMiniGame = false;
}
}
// Handle golem message system
if (LK.ticks % 300 === 0) {
// Check every 5 seconds
lastMessageCheck++;
if (lastMessageCheck >= 6) {
// Show message every 30 seconds
lastMessageCheck = 0;
currentMessage = golem.generateMessage();
golemMessageText.setText(currentMessage);
messageTimer = messageDuration;
speechBubbleContainer.visible = true;
speechBubbleContainer.alpha = 0;
speechBubbleContainer.scaleX = 0.3;
speechBubbleContainer.scaleY = 0.3;
tween(speechBubbleContainer, {
alpha: 1,
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 400,
easing: tween.easeOut
});
// Message appearance animation
}
}
// Update message timer
if (messageTimer > 0) {
messageTimer--;
if (messageTimer <= 0) {
// Fade out message
tween(speechBubbleContainer, {
alpha: 0,
scaleX: 0.3,
scaleY: 0.3
}, {
duration: 400,
easing: tween.easeIn,
onFinish: function onFinish() {
golemMessageText.setText('');
speechBubbleContainer.visible = false;
}
});
}
}
// Game over condition
if (golem.happiness <= 0 || golem.hunger <= 0) {
LK.showGameOver();
}
// Idle animations for golem
if (LK.ticks % 600 == 0) {
// Every 10 seconds
// Random idle animation
if (Math.random() < 0.5) {
tween(golem, {
rotation: 0.1
}, {
duration: 1000,
easing: tween.easeInOut
});
tween(golem, {
rotation: 0
}, {
duration: 1000,
easing: tween.easeInOut
});
}
}
}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Ball = Container.expand(function () {
var self = Container.call(this);
var ballGraphics = self.attachAsset('ball', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityX = 3 + Math.random() * 4;
self.velocityY = 3 + Math.random() * 4;
self.isActive = true;
self.update = function () {
if (!self.isActive) return;
// Move ball
self.x += self.velocityX;
self.y += self.velocityY;
// Bounce off walls
if (self.x <= 30 || self.x >= 2018) {
self.velocityX *= -1;
}
if (self.y <= 200 || self.y >= 2200) {
self.velocityY *= -1;
}
// Keep ball in bounds
self.x = Math.max(30, Math.min(2018, self.x));
self.y = Math.max(200, Math.min(2200, self.y));
};
self.down = function (x, y, obj) {
if (!self.isActive) return;
// Ball was touched - increase happiness
golem.happiness = Math.min(100, golem.happiness + 3);
// Bounce effect
tween(self, {
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 100
});
tween(self, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 100
});
// Change velocity randomly
self.velocityX = (Math.random() - 0.5) * 8;
self.velocityY = (Math.random() - 0.5) * 8;
LK.getSound('happy').play();
};
return self;
});
var BowItem = Container.expand(function (bowType, price, bowColor) {
var self = Container.call(this);
// Create item background
var itemBg = self.attachAsset('shopBg', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.2,
scaleY: 0.15,
alpha: 0.8
});
// Create bow preview
var bowPreview = self.attachAsset(bowType, {
anchorX: 0.5,
anchorY: 0.5,
y: -30
});
// Create price text
var priceText = new Text2(price + ' coins', {
size: 36,
fill: 0xFFFFFF
});
priceText.anchor.set(0.5, 0.5);
priceText.y = 20;
self.addChild(priceText);
// Create buy status text
var statusText = new Text2('', {
size: 32,
fill: 0x2ecc71
});
statusText.anchor.set(0.5, 0.5);
statusText.y = 45;
self.addChild(statusText);
self.bowType = bowType;
self.price = price;
self.bowColor = bowColor;
self.updateStatus = function () {
var ownedBows = storage.ownedBows || [];
if (ownedBows.indexOf(self.bowType) !== -1) {
statusText.setText('OWNED');
statusText.tint = 0x2ecc71;
} else if (golem.coins >= self.price) {
statusText.setText('BUY');
statusText.tint = 0xf39c12;
} else {
statusText.setText('NOT ENOUGH COINS');
statusText.tint = 0xe74c3c;
}
};
self.down = function (x, y, obj) {
var ownedBows = storage.ownedBows || [];
if (ownedBows.indexOf(self.bowType) !== -1) {
// Already owned - equip it
storage.equippedBow = self.bowType;
if (golem.currentBow) {
golem.removeChild(golem.currentBow);
}
golem.currentBow = golem.attachAsset(self.bowType, {
anchorX: 0.5,
anchorY: 0.5,
x: -120,
y: -100
});
} else if (golem.coins >= self.price) {
// Buy the bow
golem.coins -= self.price;
ownedBows.push(self.bowType);
storage.ownedBows = ownedBows;
storage.golemCoins = golem.coins;
// Equip immediately
storage.equippedBow = self.bowType;
if (golem.currentBow) {
golem.removeChild(golem.currentBow);
}
golem.currentBow = golem.attachAsset(self.bowType, {
anchorX: 0.5,
anchorY: 0.5,
x: -120,
y: -100
});
// Show immediate message about new bow
currentMessage = golem.generateMessage();
golemMessageText.setText(currentMessage);
messageTimer = messageDuration;
speechBubbleContainer.visible = true;
speechBubbleContainer.alpha = 0;
speechBubbleContainer.scaleX = 0.3;
speechBubbleContainer.scaleY = 0.3;
tween(speechBubbleContainer, {
alpha: 1,
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 400,
easing: tween.easeOut
});
// Purchase animation
tween(self, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 200
});
tween(self, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 200
});
}
// Update all shop items
if (shopContainer && shopContainer.visible) {
for (var i = 0; i < shopItems.length; i++) {
shopItems[i].updateStatus();
}
}
};
return self;
});
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.collected = false;
self.floatOffset = Math.random() * Math.PI * 2;
self.update = function () {
// Floating animation
self.y += Math.sin(LK.ticks * 0.1 + self.floatOffset) * 0.3;
self.rotation += 0.05;
};
return self;
});
var ColorMatchGame = Container.expand(function () {
var self = Container.call(this);
// Game variables
self.gameActive = false;
self.timeLeft = 30; // 30 seconds
self.score = 0;
self.currentTarget = null;
self.colors = ['red', 'blue', 'green', 'yellow'];
self.colorNames = {
'red': 'RED',
'blue': 'BLUE',
'green': 'GREEN',
'yellow': 'YELLOW'
};
self.colorValues = {
'red': 0xff0000,
'blue': 0x0000ff,
'green': 0x00ff00,
'yellow': 0xffff00
};
// Create game background
var gameBg = self.attachAsset('shopBg', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.95
});
// Create timer display
var timerBg = self.attachAsset('gameTimer', {
anchorX: 0.5,
anchorY: 0.5,
y: -1000
});
var timerText = new Text2('Time: 30', {
size: 48,
fill: 0xFFFFFF
});
timerText.anchor.set(0.5, 0.5);
timerBg.addChild(timerText);
// Create score display
var scoreText = new Text2('Score: 0', {
size: 48,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0.5);
scoreText.y = -900;
self.addChild(scoreText);
// Create target color name display
var targetText = new Text2('Match the color:', {
size: 56,
fill: 0xFFFFFF
});
targetText.anchor.set(0.5, 0.5);
targetText.y = -750;
self.addChild(targetText);
var colorNameText = new Text2('RED', {
size: 72,
fill: 0xFFFFFF
});
colorNameText.anchor.set(0.5, 0.5);
colorNameText.y = -650;
self.addChild(colorNameText);
// Create color buttons
self.colorButtons = [];
for (var i = 0; i < 4; i++) {
var colorButton = self.addChild(new Container());
var colorShape = colorButton.attachAsset('color' + self.colors[i].charAt(0).toUpperCase() + self.colors[i].slice(1), {
anchorX: 0.5,
anchorY: 0.5
});
colorButton.x = -300 + i % 2 * 600;
colorButton.y = -400 + Math.floor(i / 2) * 300;
colorButton.colorType = self.colors[i];
colorButton.down = function (x, y, obj) {
if (!self.gameActive) return;
if (this.colorType === self.currentTarget) {
// Correct match
self.score += 10;
scoreText.setText('Score: ' + self.score);
// Success animation
tween(this, {
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 150
});
tween(this, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 150
});
// Generate new target
self.generateNewTarget();
} else {
// Wrong match - penalty
self.score = Math.max(0, self.score - 5);
scoreText.setText('Score: ' + self.score);
// Error animation
tween(this, {
tint: 0xff0000
}, {
duration: 200
});
tween(this, {
tint: 0xffffff
}, {
duration: 200
});
}
};
self.colorButtons.push(colorButton);
}
// Create close button
var closeBtn = self.attachAsset('closeButton', {
anchorX: 0.5,
anchorY: 0.5,
x: 800,
y: -1000
});
var closeText = new Text2('X', {
size: 48,
fill: 0xFFFFFF
});
closeText.anchor.set(0.5, 0.5);
closeBtn.addChild(closeText);
// Generate new target color
self.generateNewTarget = function () {
self.currentTarget = self.colors[Math.floor(Math.random() * self.colors.length)];
colorNameText.setText(self.colorNames[self.currentTarget]);
colorNameText.tint = self.colorValues[self.currentTarget];
};
// Start the game
self.startGame = function () {
self.gameActive = true;
self.timeLeft = 30;
self.score = 0;
scoreText.setText('Score: 0');
self.generateNewTarget();
};
// Update timer
self.update = function () {
if (self.gameActive) {
if (LK.ticks % 60 === 0) {
// Every second
self.timeLeft--;
timerText.setText('Time: ' + self.timeLeft);
if (self.timeLeft <= 0) {
self.endGame();
}
}
}
};
// End the game
self.endGame = function () {
self.gameActive = false;
// Award coins based on score
var coinsEarned = Math.floor(self.score / 5);
golem.coins += coinsEarned;
// Show final score
targetText.setText('Game Over!');
colorNameText.setText('Coins Earned: ' + coinsEarned);
colorNameText.tint = 0xffd700;
};
return self;
});
var Crystal = Container.expand(function () {
var self = Container.call(this);
var crystalGraphics = self.attachAsset('crystal', {
anchorX: 0.5,
anchorY: 0.5
});
// Floating animation
self.floatOffset = Math.random() * Math.PI * 2;
self.update = function () {
self.y += Math.sin(LK.ticks * 0.05 + self.floatOffset) * 0.5;
self.rotation += 0.01;
};
return self;
});
var FlappyBird = Container.expand(function () {
var self = Container.call(this);
var birdGraphics = self.attachAsset('flappyBird', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityY = 0;
self.gravity = 0.8;
self.jumpPower = -12;
self.isAlive = true;
self.update = function () {
if (!self.isAlive) return;
// Apply gravity
self.velocityY += self.gravity;
self.y += self.velocityY;
// Rotate bird based on velocity
self.rotation = Math.min(Math.max(self.velocityY * 0.1, -0.5), 0.5);
// Check bounds
if (self.y < 300 || self.y > 2400) {
self.isAlive = false;
}
};
self.jump = function () {
if (self.isAlive) {
self.velocityY = self.jumpPower;
// Jump animation
tween(self, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 100
});
tween(self, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 100
});
}
};
self.down = function (x, y, obj) {
self.jump();
};
return self;
});
var FoodItem = Container.expand(function (foodType, price, foodName) {
var self = Container.call(this);
// Create item background
var itemBg = self.attachAsset('shopBg', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.2,
scaleY: 0.15,
alpha: 0.8
});
// Create food preview
var foodPreview = self.attachAsset(foodType, {
anchorX: 0.5,
anchorY: 0.5,
y: -30
});
// Create food name text
var nameText = new Text2(foodName, {
size: 32,
fill: 0xFFFFFF
});
nameText.anchor.set(0.5, 0.5);
nameText.y = -10;
self.addChild(nameText);
// Create price text
var priceText = new Text2(price + ' coins', {
size: 36,
fill: 0xFFFFFF
});
priceText.anchor.set(0.5, 0.5);
priceText.y = 20;
self.addChild(priceText);
// Create buy status text
var statusText = new Text2('', {
size: 32,
fill: 0x2ecc71
});
statusText.anchor.set(0.5, 0.5);
statusText.y = 45;
self.addChild(statusText);
self.foodType = foodType;
self.price = price;
self.foodName = foodName;
self.updateStatus = function () {
if (golem.coins >= self.price) {
statusText.setText('BUY');
statusText.tint = 0xf39c12;
} else {
statusText.setText('NOT ENOUGH COINS');
statusText.tint = 0xe74c3c;
}
};
self.down = function (x, y, obj) {
if (golem.coins >= self.price) {
// Buy the food
golem.coins -= self.price;
storage.golemCoins = golem.coins;
// Add food to inventory
var ownedFood = storage.ownedFood || [];
ownedFood.push(self.foodType);
storage.ownedFood = ownedFood;
// Purchase animation
tween(self, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 200
});
tween(self, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 200
});
// Update all shop items
if (shopContainer && shopContainer.visible) {
for (var i = 0; i < shopItems.length; i++) {
shopItems[i].updateStatus();
}
}
}
};
return self;
});
var GameButton = Container.expand(function (text, color) {
var self = Container.call(this);
var buttonBg = self.attachAsset(color === 0x9B59B6 ? 'feedButton' : color === 0x3498DB ? 'cleanButton' : 'playButton', {
anchorX: 0.5,
anchorY: 0.5
});
var buttonText = new Text2(text, {
size: 48,
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.callback = null;
self.down = function (x, y, obj) {
// Button press animation
tween(self, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100
});
tween(self, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 100
});
if (self.callback) {
self.callback();
}
};
return self;
});
var Pipe = Container.expand(function (isTop) {
var self = Container.call(this);
var pipeGraphics = self.attachAsset('pipe', {
anchorX: 0.5,
anchorY: isTop ? 1.0 : 0.0
});
self.speed = -4;
self.passed = false;
self.update = function () {
self.x += self.speed;
};
return self;
});
var ShopItem = Container.expand(function (hatType, price, hatColor) {
var self = Container.call(this);
// Create item background
var itemBg = self.attachAsset('shopBg', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.2,
scaleY: 0.15,
alpha: 0.8
});
// Create hat preview
var hatPreview = self.attachAsset(hatType, {
anchorX: 0.5,
anchorY: 0.5,
y: -30
});
// Create price text
var priceText = new Text2(price + ' coins', {
size: 36,
fill: 0xFFFFFF
});
priceText.anchor.set(0.5, 0.5);
priceText.y = 20;
self.addChild(priceText);
// Create buy status text
var statusText = new Text2('', {
size: 32,
fill: 0x2ecc71
});
statusText.anchor.set(0.5, 0.5);
statusText.y = 45;
self.addChild(statusText);
self.hatType = hatType;
self.price = price;
self.hatColor = hatColor;
self.updateStatus = function () {
var ownedHats = storage.ownedHats || [];
if (ownedHats.indexOf(self.hatType) !== -1) {
statusText.setText('OWNED');
statusText.tint = 0x2ecc71;
} else if (golem.coins >= self.price) {
statusText.setText('BUY');
statusText.tint = 0xf39c12;
} else {
statusText.setText('NOT ENOUGH COINS');
statusText.tint = 0xe74c3c;
}
};
self.down = function (x, y, obj) {
var ownedHats = storage.ownedHats || [];
if (ownedHats.indexOf(self.hatType) !== -1) {
// Already owned - equip it
storage.equippedHat = self.hatType;
if (golem.currentHat) {
golem.removeChild(golem.currentHat);
}
golem.currentHat = golem.attachAsset(self.hatType, {
anchorX: 0.5,
anchorY: 1.0,
x: 0,
y: -180
});
} else if (golem.coins >= self.price) {
// Buy the hat
golem.coins -= self.price;
ownedHats.push(self.hatType);
storage.ownedHats = ownedHats;
storage.golemCoins = golem.coins;
// Equip immediately
storage.equippedHat = self.hatType;
if (golem.currentHat) {
golem.removeChild(golem.currentHat);
}
golem.currentHat = golem.attachAsset(self.hatType, {
anchorX: 0.5,
anchorY: 1.0,
x: 0,
y: -180
});
// Show immediate message about new hat
speechBubbleContainer.visible = true;
speechBubbleContainer.alpha = 0;
speechBubbleContainer.scaleX = 0.3;
speechBubbleContainer.scaleY = 0.3;
tween(speechBubbleContainer, {
alpha: 1,
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 400,
easing: tween.easeOut
});
currentMessage = golem.generateMessage();
golemMessageText.setText(currentMessage);
messageTimer = messageDuration;
// Purchase animation
tween(self, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 200
});
tween(self, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 200
});
}
// Update all shop items
if (shopContainer && shopContainer.visible) {
for (var i = 0; i < shopItems.length; i++) {
shopItems[i].updateStatus();
}
}
};
return self;
});
var StoneGolem = Container.expand(function () {
var self = Container.call(this);
// Create golem body
var body = self.attachAsset('golem', {
anchorX: 0.5,
anchorY: 0.5
});
// Create eyes
var leftEye = self.attachAsset('golemEyes', {
anchorX: 0.5,
anchorY: 0.5,
x: -60,
y: -80
});
var rightEye = self.attachAsset('golemEyes', {
anchorX: 0.5,
anchorY: 0.5,
x: 60,
y: -80
});
// Create mouth
var mouth = self.attachAsset('golemMouth', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 0
});
// Golem properties
self.happiness = storage.golemHappiness || 100;
self.hunger = storage.golemHunger || 100;
self.lastFeedTime = storage.lastFeedTime || Date.now();
self.lastCleanTime = storage.lastCleanTime || Date.now();
self.coins = storage.golemCoins || 0;
self.mood = 'happy'; // happy, sad, sleepy, excited
self.mossSpots = [];
self.currentHat = null;
self.currentBow = null;
// Load equipped hat if any
if (storage.equippedHat) {
self.currentHat = self.attachAsset(storage.equippedHat, {
anchorX: 0.5,
anchorY: 1.0,
x: 0,
y: -180
});
}
// Load equipped bow if any
if (storage.equippedBow) {
self.currentBow = self.attachAsset(storage.equippedBow, {
anchorX: 0.5,
anchorY: 0.5,
x: -120,
y: -100
});
}
// Create initial moss spots
self.createMossSpots = function () {
for (var i = 0; i < 3; i++) {
var mossSpot = self.attachAsset('moss', {
anchorX: 0.5,
anchorY: 0.5,
x: (Math.random() - 0.5) * 300,
y: (Math.random() - 0.5) * 400,
alpha: 0.7
});
self.mossSpots.push(mossSpot);
}
};
self.createMossSpots();
// React to petting
self.pet = function () {
// Happy animation
tween(self, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 200,
easing: tween.easeOut
});
tween(self, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 200,
easing: tween.easeIn
});
// Eyes blink
tween(leftEye, {
scaleY: 0.1
}, {
duration: 100
});
tween(leftEye, {
scaleY: 1.0
}, {
duration: 100
});
tween(rightEye, {
scaleY: 0.1
}, {
duration: 100
});
tween(rightEye, {
scaleY: 1.0
}, {
duration: 100
});
LK.getSound('happy').play();
self.happiness = Math.min(100, self.happiness + 2);
};
// Feed the golem
self.feed = function () {
// Check if player has food in inventory
var ownedFood = storage.ownedFood || [];
if (ownedFood.length === 0) {
return false; // No food available
}
if (Date.now() - self.lastFeedTime > 5000) {
// Can feed every 5 seconds
// Consume one food item
ownedFood.pop();
storage.ownedFood = ownedFood;
mouth.scaleX = 1.5;
mouth.scaleY = 1.5;
tween(mouth, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 500
});
// Bounce animation
tween(self, {
y: self.y - 20
}, {
duration: 200,
easing: tween.easeOut
});
tween(self, {
y: self.y
}, {
duration: 200,
easing: tween.bounceOut
});
LK.getSound('eat').play();
self.happiness = Math.min(100, self.happiness + 15);
self.hunger = Math.min(100, self.hunger + 20);
self.lastFeedTime = Date.now();
return true;
}
return false;
};
// Clean moss from golem
self.clean = function () {
if (self.mossSpots.length > 0) {
var mossToRemove = self.mossSpots.pop();
tween(mossToRemove, {
alpha: 0,
scaleX: 2,
scaleY: 2
}, {
duration: 300,
onFinish: function onFinish() {
self.removeChild(mossToRemove);
}
});
LK.getSound('clean').play();
self.happiness = Math.min(100, self.happiness + 10);
return true;
}
return false;
};
// Update mood based on happiness
self.updateMood = function () {
if (self.happiness > 80) {
self.mood = 'happy';
body.tint = 0x8B7355; // Normal stone color
} else if (self.happiness > 50) {
self.mood = 'neutral';
body.tint = 0x7A6B4F; // Slightly darker
} else if (self.happiness > 20) {
self.mood = 'sad';
body.tint = 0x695C42; // Darker
} else {
self.mood = 'very_sad';
body.tint = 0x5A4D35; // Very dark
}
};
// Generate contextual messages based on golem's state
self.generateMessage = function () {
var messages = [];
// Messages about accessories
if (self.currentHat && self.currentBow) {
messages.push('¡Qué elegante me veo con mi sombrero y moño!');
messages.push('¡Me encanta mi estilo!');
} else if (self.currentHat) {
messages.push('¡Qué buen gusto tienes!');
messages.push('¡Mi sombrero me queda perfecto!');
messages.push('¡Me siento muy elegante!');
} else if (self.currentBow) {
messages.push('¡Mi moño es hermoso!');
messages.push('¡Gracias por este lindo accesorio!');
}
// Messages about hunger
if (self.hunger < 30) {
messages.push('¡Qué hambre tengo, dame de comer!');
messages.push('¡Necesito comida urgente!');
messages.push('¡Mi estómago está rugiendo!');
} else if (self.hunger > 80) {
messages.push('¡Qué rico estuvo eso!');
messages.push('¡Estoy muy satisfecho!');
}
// Messages about happiness
if (self.happiness < 25) {
messages.push('¡Me siento muy triste!');
messages.push('¡Necesito más cariño!');
messages.push('¡Por favor, juega conmigo!');
} else if (self.happiness > 90) {
messages.push('¡Soy el golem más feliz del mundo!');
messages.push('¡Me encanta pasar tiempo contigo!');
messages.push('¡Qué día tan maravilloso!');
}
// Messages about cleanliness
if (self.mossSpots.length > 3) {
messages.push('¡Ayúdame a limpiarme!');
messages.push('¡Estoy muy sucio!');
messages.push('¡Necesito un baño!');
} else if (self.mossSpots.length === 0) {
messages.push('¡Qué limpio estoy!');
messages.push('¡Gracias por cuidarme tan bien!');
}
// Default happy messages
if (messages.length === 0) {
messages.push('¡Hola, amigo!');
messages.push('¡Qué lindo día!');
messages.push('¡Me gusta estar contigo!');
messages.push('¡Soy tu fiel compañero!');
}
return messages[Math.floor(Math.random() * messages.length)];
};
// Decrease happiness over time
self.update = function () {
// Decrease happiness slowly over time
if (LK.ticks % 300 == 0) {
// Every 5 seconds at 60fps
self.happiness = Math.max(0, self.happiness - 1);
self.updateMood();
}
// Decrease hunger over time
if (LK.ticks % 240 == 0) {
// Every 4 seconds at 60fps
self.hunger = Math.max(0, self.hunger - 1);
}
// Add moss spots occasionally
if (LK.ticks % 1800 == 0 && self.mossSpots.length < 5) {
// Every 30 seconds
var mossSpot = self.attachAsset('moss', {
anchorX: 0.5,
anchorY: 0.5,
x: (Math.random() - 0.5) * 300,
y: (Math.random() - 0.5) * 400,
alpha: 0.7
});
self.mossSpots.push(mossSpot);
}
// Save state
if (LK.ticks % 60 == 0) {
// Every second
storage.golemHappiness = self.happiness;
storage.golemHunger = self.hunger;
storage.lastFeedTime = self.lastFeedTime;
storage.lastCleanTime = self.lastCleanTime;
storage.golemCoins = self.coins;
}
};
// Touch response
self.down = function (x, y, obj) {
self.pet();
};
return self;
});
var WaterDrop = Container.expand(function () {
var self = Container.call(this);
var dropGraphics = self.attachAsset('waterDrop', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityY = 8;
self.isActive = true;
self.update = function () {
if (!self.isActive) return;
// Move water drop down
self.y += self.velocityY;
// Check if drop hit any moss spots
for (var i = 0; i < golem.mossSpots.length; i++) {
var mossSpot = golem.mossSpots[i];
var mossGlobalPos = golem.toGlobal(mossSpot.position);
var dropGlobalPos = game.toGlobal(self.position);
var distance = Math.sqrt(Math.pow(mossGlobalPos.x - dropGlobalPos.x, 2) + Math.pow(mossGlobalPos.y - dropGlobalPos.y, 2));
if (distance < 50) {
// Hit moss - clean it
golem.mossSpots.splice(i, 1);
tween(mossSpot, {
alpha: 0,
scaleX: 2,
scaleY: 2
}, {
duration: 300,
onFinish: function onFinish() {
golem.removeChild(mossSpot);
}
});
golem.happiness = Math.min(100, golem.happiness + 10);
LK.getSound('clean').play();
// Remove water drop
self.isActive = false;
game.removeChild(self);
return;
}
}
// Remove drop if it goes off screen
if (self.y > 2732) {
self.isActive = false;
game.removeChild(self);
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2C3E50
});
/****
* Game Code
****/
// Create UI elements
var happinessBg = LK.getAsset('happinessBg', {
anchorX: 0.5,
anchorY: 0.5
});
LK.gui.top.addChild(happinessBg);
happinessBg.y = 100;
var happinessBar = LK.getAsset('happinessBar', {
anchorX: 0.0,
anchorY: 0.5
});
happinessBg.addChild(happinessBar);
happinessBar.x = -200;
var happinessText = new Text2('Happiness: 100%', {
size: 48,
fill: 0xFFFFFF
});
happinessText.anchor.set(0.5, 0);
LK.gui.top.addChild(happinessText);
happinessText.y = 50;
// Create hunger bar UI
var hungerBg = LK.getAsset('hungerBg', {
anchorX: 0.5,
anchorY: 0.5
});
LK.gui.top.addChild(hungerBg);
hungerBg.y = 160;
var hungerBar = LK.getAsset('hungerBar', {
anchorX: 0.0,
anchorY: 0.5
});
hungerBg.addChild(hungerBar);
hungerBar.x = -200;
var hungerText = new Text2('Hunger: 100%', {
size: 48,
fill: 0xFFFFFF
});
hungerText.anchor.set(0.5, 0);
LK.gui.top.addChild(hungerText);
hungerText.y = 140;
// Create coins display
var coinsText = new Text2('Coins: 0', {
size: 48,
fill: 0xFFFFFF
});
coinsText.anchor.set(0.5, 0);
LK.gui.top.addChild(coinsText);
coinsText.y = 200;
// Create food inventory display
var foodText = new Text2('Food: 0', {
size: 48,
fill: 0xFFFFFF
});
foodText.anchor.set(0.5, 0);
LK.gui.top.addChild(foodText);
foodText.y = 240;
// Create golem message speech bubble container
var speechBubbleContainer = new Container();
speechBubbleContainer.x = 1024;
speechBubbleContainer.y = 600;
game.addChild(speechBubbleContainer);
// Create speech bubble background
var speechBubbleBg = speechBubbleContainer.attachAsset('speechBubble', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.95
});
// Create speech bubble tail (pointing to golem)
var speechTail = speechBubbleContainer.attachAsset('speechTail', {
anchorX: 0.5,
anchorY: 0,
y: 100,
rotation: Math.PI / 4
});
// Create golem message display with larger text
var golemMessageText = new Text2('', {
size: 48,
fill: 0x333333
});
golemMessageText.anchor.set(0.5, 0.5);
speechBubbleContainer.addChild(golemMessageText);
// Initially hide the speech bubble
speechBubbleContainer.alpha = 0;
speechBubbleContainer.visible = false;
// Message system variables
var currentMessage = '';
var messageTimer = 0;
var messageDuration = 180; // 3 seconds at 60fps
var lastMessageCheck = 0;
// Create main golem
var golem = game.addChild(new StoneGolem());
golem.x = 1024;
golem.y = 1200;
// Create control buttons with increased spacing
var feedButton = new GameButton('Feed', 0x9B59B6);
feedButton.x = 1024 - 400;
feedButton.y = 2500;
// Food menu variables
var isFoodMenuOpen = false;
var foodMenuContainer = null;
feedButton.callback = function () {
var ownedFood = storage.ownedFood || [];
if (ownedFood.length === 0) {
// No food available - show message
return;
}
// Open food selection menu
if (!isFoodMenuOpen) {
isFoodMenuOpen = true;
// Create food menu container
foodMenuContainer = game.addChild(new Container());
// Create menu background
var menuBg = foodMenuContainer.attachAsset('shopBg', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.8,
scaleY: 0.6,
alpha: 0.9
});
foodMenuContainer.x = 1024;
foodMenuContainer.y = 1366;
// Create menu title
var menuTitle = new Text2('SELECT FOOD', {
size: 48,
fill: 0xFFFFFF
});
menuTitle.anchor.set(0.5, 0.5);
menuTitle.y = -400;
foodMenuContainer.addChild(menuTitle);
// Create close button
var closeBtn = foodMenuContainer.attachAsset('closeButton', {
anchorX: 0.5,
anchorY: 0.5,
x: 600,
y: -400
});
var closeText = new Text2('X', {
size: 48,
fill: 0xFFFFFF
});
closeText.anchor.set(0.5, 0.5);
closeBtn.addChild(closeText);
// Group food items by type and show counts
var foodCounts = {};
for (var i = 0; i < ownedFood.length; i++) {
var foodType = ownedFood[i];
foodCounts[foodType] = (foodCounts[foodType] || 0) + 1;
}
// Create food selection items
var foodTypes = Object.keys(foodCounts);
var foodNames = {
'food1': 'Apple',
'food2': 'Bread',
'food3': 'Cheese',
'food4': 'Cake'
};
for (var i = 0; i < foodTypes.length; i++) {
var foodType = foodTypes[i];
var count = foodCounts[foodType];
// Create food item container
var foodItem = foodMenuContainer.addChild(new Container());
foodItem.x = -300 + i % 2 * 600;
foodItem.y = -200 + Math.floor(i / 2) * 200;
// Create food background
var itemBg = foodItem.attachAsset('shopBg', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.15,
scaleY: 0.1,
alpha: 0.6
});
// Create food image
var foodImage = foodItem.attachAsset(foodType, {
anchorX: 0.5,
anchorY: 0.5,
y: -20,
scaleX: 0.5,
scaleY: 0.5
});
// Create food name and count text
var foodText = new Text2(foodNames[foodType] + ' (' + count + ')', {
size: 32,
fill: 0xFFFFFF
});
foodText.anchor.set(0.5, 0.5);
foodText.y = 30;
foodItem.addChild(foodText);
// Add click handler for feeding
foodItem.foodType = foodType;
foodItem.down = function (x, y, obj) {
// Feed the golem with selected food
var selectedFood = this.foodType;
// Remove one of this food type from inventory
var ownedFood = storage.ownedFood || [];
var foodIndex = ownedFood.indexOf(selectedFood);
if (foodIndex !== -1) {
ownedFood.splice(foodIndex, 1);
storage.ownedFood = ownedFood;
// Determine hunger restoration based on food type and price
var foodPrices = {
'food1': 5,
'food2': 10,
'food3': 20,
'food4': 30
};
var foodPrice = foodPrices[selectedFood] || 5;
var hungerRestoration = Math.floor(foodPrice * 1.5); // More expensive food restores more hunger
// Feed animation and effects
var mouth = golem.children[2]; // mouth is third child
mouth.scaleX = 1.5;
mouth.scaleY = 1.5;
tween(mouth, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 500
});
// Bounce animation
tween(golem, {
y: golem.y - 20
}, {
duration: 200,
easing: tween.easeOut
});
tween(golem, {
y: golem.y
}, {
duration: 200,
easing: tween.bounceOut
});
// Create crystal animation
var crystal = game.addChild(new Crystal());
crystal.x = golem.x;
crystal.y = golem.y - 200;
tween(crystal, {
x: golem.x,
y: golem.y
}, {
duration: 800,
easing: tween.easeIn,
onFinish: function onFinish() {
game.removeChild(crystal);
}
});
LK.getSound('eat').play();
golem.happiness = Math.min(100, golem.happiness + 15);
golem.hunger = Math.min(100, golem.hunger + hungerRestoration);
golem.lastFeedTime = Date.now();
// Close food menu after feeding
closeFoodMenu();
}
};
}
// Menu entrance animation
foodMenuContainer.alpha = 0;
foodMenuContainer.scaleX = 0.5;
foodMenuContainer.scaleY = 0.5;
tween(foodMenuContainer, {
alpha: 1,
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 300,
easing: tween.easeOut
});
}
};
function closeFoodMenu() {
if (foodMenuContainer) {
tween(foodMenuContainer, {
alpha: 0,
scaleX: 0.5,
scaleY: 0.5
}, {
duration: 300,
easing: tween.easeIn,
onFinish: function onFinish() {
game.removeChild(foodMenuContainer);
foodMenuContainer = null;
}
});
}
isFoodMenuOpen = false;
}
game.addChild(feedButton);
var cleanButton = new GameButton('Clean', 0x3498DB);
cleanButton.x = 1024 - 200;
cleanButton.y = 2500;
cleanButton.callback = function () {
// Create water drop that falls on moss
var waterDrop = game.addChild(new WaterDrop());
waterDrop.x = golem.x + (Math.random() - 0.5) * 200;
waterDrop.y = 300;
// Add some animation to the water drop creation
tween(waterDrop, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 100
});
tween(waterDrop, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 100
});
};
game.addChild(cleanButton);
var playButton = new GameButton('Play', 0xE74C3C);
playButton.x = 1024;
playButton.y = 2500;
// Game state variables
var isPlayingMiniGame = false;
var miniGameBall = null;
var miniGameTimer = 0;
var miniGameDuration = 600; // 10 seconds at 60fps
// Shop variables
var isShopOpen = false;
var shopContainer = null;
var shopItems = [];
// Flappy bird mini game variables
var isPlayingFlappyBird = false;
var isFlappyBirdReady = false;
var flappyBird = null;
var jumpButton = null;
var pipes = [];
var gameCoins = [];
var flappyScore = 0;
var pipeSpawnTimer = 0;
var coinSpawnTimer = 0;
playButton.callback = function () {
if (!isPlayingMiniGame) {
// Start mini-game
isPlayingMiniGame = true;
miniGameTimer = 0;
miniGameBall = game.addChild(new Ball());
miniGameBall.x = 1024;
miniGameBall.y = 1000;
} else {
// Stop mini-game early
if (miniGameBall) {
miniGameBall.isActive = false;
game.removeChild(miniGameBall);
miniGameBall = null;
}
isPlayingMiniGame = false;
}
};
game.addChild(playButton);
var miniGameButton = new GameButton('Mini Game', 0xF39C12);
miniGameButton.x = 1024 + 200;
miniGameButton.y = 2500;
miniGameButton.callback = function () {
if (!isFlappyBirdReady && !isPlayingFlappyBird) {
// Prepare flappy bird mini game (don't start yet)
isFlappyBirdReady = true;
flappyScore = 0;
pipeSpawnTimer = 0;
coinSpawnTimer = 0;
// Create bird
flappyBird = game.addChild(new FlappyBird());
flappyBird.x = 400;
flappyBird.y = 1200;
// Clear any existing pipes and coins
// Create jump button for flappy bird
jumpButton = game.addChild(new GameButton('JUMP', 0x27AE60));
jumpButton.x = 1024;
jumpButton.y = 2200;
jumpButton.callback = function () {
if (flappyBird && flappyBird.isAlive) {
if (!isPlayingFlappyBird && isFlappyBirdReady) {
// Start the game on first jump
isPlayingFlappyBird = true;
}
flappyBird.jump();
}
};
pipes = [];
gameCoins = [];
} else {
// Stop flappy bird game
if (flappyBird) {
game.removeChild(flappyBird);
flappyBird = null;
}
if (jumpButton) {
game.removeChild(jumpButton);
jumpButton = null;
}
// Clean up pipes
for (var i = 0; i < pipes.length; i++) {
game.removeChild(pipes[i]);
}
pipes = [];
// Clean up coins
for (var i = 0; i < gameCoins.length; i++) {
game.removeChild(gameCoins[i]);
}
gameCoins = [];
isPlayingFlappyBird = false;
isFlappyBirdReady = false;
}
};
game.addChild(miniGameButton);
var miniGame2Button = new GameButton('Mini Game 2', 0x9B59B6);
miniGame2Button.x = 1024 - 400;
miniGame2Button.y = 2380;
// Color match game variables
var isColorGameActive = false;
var colorMatchGame = null;
miniGame2Button.callback = function () {
if (!isColorGameActive) {
// Start color match game
isColorGameActive = true;
// Create color match game
colorMatchGame = game.addChild(new ColorMatchGame());
colorMatchGame.x = 1024;
colorMatchGame.y = 1366;
// Game entrance animation
colorMatchGame.alpha = 0;
colorMatchGame.scaleX = 0.5;
colorMatchGame.scaleY = 0.5;
tween(colorMatchGame, {
alpha: 1,
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
colorMatchGame.startGame();
}
});
} else {
// Close color match game
if (colorMatchGame) {
tween(colorMatchGame, {
alpha: 0,
scaleX: 0.5,
scaleY: 0.5
}, {
duration: 300,
easing: tween.easeIn,
onFinish: function onFinish() {
game.removeChild(colorMatchGame);
colorMatchGame = null;
}
});
}
isColorGameActive = false;
}
};
game.addChild(miniGame2Button);
var shopButton = new GameButton('Shop', 0x8E44AD);
shopButton.x = 1024 + 400;
shopButton.y = 2500;
shopButton.callback = function () {
if (!isShopOpen) {
// Open shop
isShopOpen = true;
// Create shop container
shopContainer = game.addChild(new Container());
// Create shop background
var shopBg = shopContainer.attachAsset('shopBg', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.9
});
shopContainer.x = 1024;
shopContainer.y = 1366;
// Create shop title
var shopTitle = new Text2('HAT SHOP', {
size: 64,
fill: 0xFFFFFF
});
shopTitle.anchor.set(0.5, 0.5);
shopTitle.y = -1000;
shopContainer.addChild(shopTitle);
// Create close button
var closeBtn = shopContainer.attachAsset('closeButton', {
anchorX: 0.5,
anchorY: 0.5,
x: 800,
y: -1000
});
// Add close button text
var closeText = new Text2('X', {
size: 48,
fill: 0xFFFFFF
});
closeText.anchor.set(0.5, 0.5);
closeBtn.addChild(closeText);
// Create shop items
shopItems = [];
// Add hat section
var hatTypes = ['hat1', 'hat2', 'hat3', 'hat4'];
var hatPrices = [10, 25, 50, 100];
var hatColors = [0xe74c3c, 0x3498db, 0xf39c12, 0x2ecc71];
for (var i = 0; i < hatTypes.length; i++) {
var shopItem = shopContainer.addChild(new ShopItem(hatTypes[i], hatPrices[i], hatColors[i]));
shopItem.x = -600 + i % 2 * 600;
shopItem.y = -700 + Math.floor(i / 2) * 300;
shopItem.updateStatus();
shopItems.push(shopItem);
}
// Add food section title
var foodTitle = new Text2('FOOD', {
size: 48,
fill: 0xFFFFFF
});
foodTitle.anchor.set(0.5, 0.5);
foodTitle.y = -200;
shopContainer.addChild(foodTitle);
// Add food items
var foodTypes = ['food1', 'food2', 'food3', 'food4'];
var foodPrices = [5, 10, 20, 30];
var foodNames = ['Apple', 'Bread', 'Cheese', 'Cake'];
for (var i = 0; i < foodTypes.length; i++) {
var foodItem = shopContainer.addChild(new FoodItem(foodTypes[i], foodPrices[i], foodNames[i]));
foodItem.x = -600 + i % 2 * 600;
foodItem.y = -100 + Math.floor(i / 2) * 300;
foodItem.updateStatus();
shopItems.push(foodItem);
}
// Add bow section title
var bowTitle = new Text2('BOWS', {
size: 48,
fill: 0xFFFFFF
});
bowTitle.anchor.set(0.5, 0.5);
bowTitle.y = 400;
shopContainer.addChild(bowTitle);
// Add bow items
var bowTypes = ['bow1', 'bow2', 'bow3'];
var bowPrices = [15, 35, 75];
var bowColors = [0xe91e63, 0x9c27b0, 0x673ab7];
for (var i = 0; i < bowTypes.length; i++) {
var bowItem = shopContainer.addChild(new BowItem(bowTypes[i], bowPrices[i], bowColors[i]));
bowItem.x = -300 + i % 3 * 300;
bowItem.y = 500 + Math.floor(i / 3) * 200;
bowItem.updateStatus();
shopItems.push(bowItem);
}
// Add remove accessories section title
var removeTitle = new Text2('REMOVE ACCESSORIES', {
size: 48,
fill: 0xFFFFFF
});
removeTitle.anchor.set(0.5, 0.5);
removeTitle.y = 700;
shopContainer.addChild(removeTitle);
// Add remove hat button
var removeHatButton = shopContainer.addChild(new Container());
var removeHatBg = removeHatButton.attachAsset('shopBg', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.2,
scaleY: 0.15,
alpha: 0.8
});
removeHatButton.x = -200;
removeHatButton.y = 800;
var removeHatText = new Text2('REMOVE HAT', {
size: 32,
fill: 0xFFFFFF
});
removeHatText.anchor.set(0.5, 0.5);
removeHatButton.addChild(removeHatText);
removeHatButton.down = function (x, y, obj) {
if (golem.currentHat) {
golem.removeChild(golem.currentHat);
golem.currentHat = null;
storage.equippedHat = null;
// Success animation
tween(this, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 150
});
tween(this, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 150
});
}
};
// Add remove bow button
var removeBowButton = shopContainer.addChild(new Container());
var removeBowBg = removeBowButton.attachAsset('shopBg', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.2,
scaleY: 0.15,
alpha: 0.8
});
removeBowButton.x = 200;
removeBowButton.y = 800;
var removeBowText = new Text2('REMOVE BOW', {
size: 32,
fill: 0xFFFFFF
});
removeBowText.anchor.set(0.5, 0.5);
removeBowButton.addChild(removeBowText);
removeBowButton.down = function (x, y, obj) {
if (golem.currentBow) {
golem.removeChild(golem.currentBow);
golem.currentBow = null;
storage.equippedBow = null;
// Success animation
tween(this, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 150
});
tween(this, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 150
});
}
};
// Shop entrance animation
shopContainer.alpha = 0;
shopContainer.scaleX = 0.5;
shopContainer.scaleY = 0.5;
tween(shopContainer, {
alpha: 1,
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 300,
easing: tween.easeOut
});
} else {
// Close shop
if (shopContainer) {
tween(shopContainer, {
alpha: 0,
scaleX: 0.5,
scaleY: 0.5
}, {
duration: 300,
easing: tween.easeIn,
onFinish: function onFinish() {
game.removeChild(shopContainer);
shopContainer = null;
shopItems = [];
}
});
}
isShopOpen = false;
}
};
game.addChild(shopButton);
// Add close shop functionality
game.down = function (x, y, obj) {
if (isShopOpen && shopContainer) {
// Check if clicked close button or outside shop
var localPos = shopContainer.toLocal({
x: x,
y: y
});
if (localPos.x > 750 && localPos.x < 850 && localPos.y > -1050 && localPos.y < -950) {
// Clicked close button
shopButton.callback();
} else if (Math.abs(localPos.x) > 900 || Math.abs(localPos.y) > 1100) {
// Clicked outside shop
shopButton.callback();
}
}
// Handle food menu close
if (isFoodMenuOpen && foodMenuContainer) {
var localPos = foodMenuContainer.toLocal({
x: x,
y: y
});
if (localPos.x > 550 && localPos.x < 650 && localPos.y > -450 && localPos.y < -350) {
// Clicked close button
closeFoodMenu();
} else if (Math.abs(localPos.x) > 700 || Math.abs(localPos.y) > 500) {
// Clicked outside menu
closeFoodMenu();
}
}
// Handle color match game close
if (isColorGameActive && colorMatchGame) {
var localPos = colorMatchGame.toLocal({
x: x,
y: y
});
if (localPos.x > 750 && localPos.x < 850 && localPos.y > -1050 && localPos.y < -950) {
// Clicked close button
miniGame2Button.callback();
} else if (Math.abs(localPos.x) > 900 || Math.abs(localPos.y) > 1100) {
// Clicked outside game
miniGame2Button.callback();
}
}
};
// Floating crystals for ambiance
var floatingCrystals = [];
for (var i = 0; i < 3; i++) {
var floatingCrystal = game.addChild(new Crystal());
floatingCrystal.x = 200 + i * 800;
floatingCrystal.y = 300 + Math.random() * 200;
floatingCrystal.alpha = 0.3;
floatingCrystal.scaleX = 0.5;
floatingCrystal.scaleY = 0.5;
floatingCrystals.push(floatingCrystal);
}
// Game update loop
game.update = function () {
// Update happiness display
var happinessPercent = Math.max(0, golem.happiness);
happinessText.setText('Happiness: ' + Math.round(happinessPercent) + '%');
// Update happiness bar visual
var barWidth = happinessPercent / 100 * 400;
happinessBar.width = barWidth;
// Change bar color based on happiness
if (happinessPercent > 60) {
happinessBar.tint = 0x2ECC71; // Green
} else if (happinessPercent > 30) {
happinessBar.tint = 0xF39C12; // Orange
} else {
happinessBar.tint = 0xE74C3C; // Red
}
// Update hunger display
var hungerPercent = Math.max(0, golem.hunger);
hungerText.setText('Hunger: ' + Math.round(hungerPercent) + '%');
// Update hunger bar visual
var hungerBarWidth = hungerPercent / 100 * 400;
hungerBar.width = hungerBarWidth;
// Change hunger bar color based on hunger level
if (hungerPercent > 60) {
hungerBar.tint = 0xE67E22; // Orange
} else if (hungerPercent > 30) {
hungerBar.tint = 0xD35400; // Darker orange
} else {
hungerBar.tint = 0xE74C3C; // Red
}
// Update coins display
coinsText.setText('Coins: ' + golem.coins);
// Update food inventory display
var ownedFood = storage.ownedFood || [];
foodText.setText('Food: ' + ownedFood.length);
// Handle flappy bird mini game
if ((isPlayingFlappyBird || isFlappyBirdReady) && flappyBird) {
// Spawn pipes (only when actually playing)
if (isPlayingFlappyBird) {
pipeSpawnTimer++;
if (pipeSpawnTimer >= 120) {
// Every 2 seconds
pipeSpawnTimer = 0;
var gapY = 800 + Math.random() * 800; // Random gap position
var gapSize = 300; // Gap between pipes
// Top pipe
var topPipe = game.addChild(new Pipe(true));
topPipe.x = 2200;
topPipe.y = gapY - gapSize / 2;
pipes.push(topPipe);
// Bottom pipe
var bottomPipe = game.addChild(new Pipe(false));
bottomPipe.x = 2200;
bottomPipe.y = gapY + gapSize / 2;
pipes.push(bottomPipe);
}
// Spawn coins
coinSpawnTimer++;
if (coinSpawnTimer >= 90) {
// Every 1.5 seconds
coinSpawnTimer = 0;
var gameCoin = game.addChild(new Coin());
gameCoin.x = 2200;
gameCoin.y = 600 + Math.random() * 1200;
gameCoins.push(gameCoin);
}
}
// Update and check pipes
for (var i = pipes.length - 1; i >= 0; i--) {
var pipe = pipes[i];
// Check collision with bird
if (flappyBird.intersects(pipe)) {
flappyBird.isAlive = false;
}
// Mark pipe as passed and award coins when bird passes through
if (!pipe.passed && pipe.x < flappyBird.x) {
pipe.passed = true;
// Award coins based on care level when passing through pipe
var careBonus = Math.floor((golem.happiness + golem.hunger) / 20);
golem.coins += 1 + careBonus;
flappyScore++;
}
// Remove off-screen pipes
if (pipe.x < -100) {
game.removeChild(pipe);
pipes.splice(i, 1);
}
}
// Update and check coins
for (var i = gameCoins.length - 1; i >= 0; i--) {
var gameCoin = gameCoins[i];
// Check collision with bird
if (!gameCoin.collected && flappyBird.intersects(gameCoin)) {
gameCoin.collected = true;
var careBonus = Math.floor((golem.happiness + golem.hunger) / 25);
golem.coins += 2 + careBonus;
// Coin collection animation
tween(gameCoin, {
alpha: 0,
scaleX: 2,
scaleY: 2
}, {
duration: 200,
onFinish: function onFinish() {
game.removeChild(gameCoin);
}
});
gameCoins.splice(i, 1);
continue;
}
// Remove off-screen coins
if (gameCoin.x < -50) {
game.removeChild(gameCoin);
gameCoins.splice(i, 1);
}
}
// Check if bird died
if (!flappyBird.isAlive) {
// End game
game.removeChild(flappyBird);
flappyBird = null;
if (jumpButton) {
game.removeChild(jumpButton);
jumpButton = null;
}
// Clean up pipes
for (var i = 0; i < pipes.length; i++) {
game.removeChild(pipes[i]);
}
pipes = [];
// Clean up coins
for (var i = 0; i < gameCoins.length; i++) {
game.removeChild(gameCoins[i]);
}
gameCoins = [];
isPlayingFlappyBird = false;
isFlappyBirdReady = false;
}
}
// Handle mini-game
if (isPlayingMiniGame) {
miniGameTimer++;
// End mini-game after duration
if (miniGameTimer >= miniGameDuration) {
if (miniGameBall) {
miniGameBall.isActive = false;
game.removeChild(miniGameBall);
miniGameBall = null;
}
isPlayingMiniGame = false;
}
}
// Handle golem message system
if (LK.ticks % 300 === 0) {
// Check every 5 seconds
lastMessageCheck++;
if (lastMessageCheck >= 6) {
// Show message every 30 seconds
lastMessageCheck = 0;
currentMessage = golem.generateMessage();
golemMessageText.setText(currentMessage);
messageTimer = messageDuration;
speechBubbleContainer.visible = true;
speechBubbleContainer.alpha = 0;
speechBubbleContainer.scaleX = 0.3;
speechBubbleContainer.scaleY = 0.3;
tween(speechBubbleContainer, {
alpha: 1,
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 400,
easing: tween.easeOut
});
// Message appearance animation
}
}
// Update message timer
if (messageTimer > 0) {
messageTimer--;
if (messageTimer <= 0) {
// Fade out message
tween(speechBubbleContainer, {
alpha: 0,
scaleX: 0.3,
scaleY: 0.3
}, {
duration: 400,
easing: tween.easeIn,
onFinish: function onFinish() {
golemMessageText.setText('');
speechBubbleContainer.visible = false;
}
});
}
}
// Game over condition
if (golem.happiness <= 0 || golem.hunger <= 0) {
LK.showGameOver();
}
// Idle animations for golem
if (LK.ticks % 600 == 0) {
// Every 10 seconds
// Random idle animation
if (Math.random() < 0.5) {
tween(golem, {
rotation: 0.1
}, {
duration: 1000,
easing: tween.easeInOut
});
tween(golem, {
rotation: 0
}, {
duration: 1000,
easing: tween.easeInOut
});
}
}
};
una roca regtangular en 2d de color gris claro. In-Game asset. 2d. High contrast. No shadows
una pelota de tenis naranja. In-Game asset. 2d. High contrast. No shadows
gota de agua en 2d. In-Game asset. 2d. High contrast. No shadows
cristal morado cubico 2d. In-Game asset. 2d. High contrast. No shadows
pajaro de flappy bird 2d. In-Game asset. 2d. High contrast. No shadows
tubo de flappy bird. In-Game asset. 2d. High contrast. No shadows
moneda de flappy bird. In-Game asset. 2d. High contrast. No shadows
sombrero de mago de color azul 2d. In-Game asset. 2d. High contrast. No shadows
sombrero de mafioso de color rojo. In-Game asset. 2d. High contrast. No shadows
sombrero de vaquero de color naranja. In-Game asset. 2d. High contrast. No shadows
sombrero de hojas de color verde 2d. In-Game asset. 2d. High contrast. No shadows
bread 2d. In-Game asset. 2d. High contrast. No shadows
apple 2d. In-Game asset. 2d. High contrast. No shadows
chesse 2d. In-Game asset. 2d. High contrast. No shadows
red X. In-Game asset. 2d. High contrast. No shadows
green mold stain 2d. In-Game asset. 2d. High contrast. No shadows
moño. In-Game asset. 2d. High contrast. No shadows
moño negro elegante 2d. In-Game asset. 2d. High contrast. No shadows
moño azul 2d. In-Game asset. 2d. High contrast. No shadows
speechbubble. In-Game asset. 2d. High contrast. No shadows