/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
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.rotation = 0;
self.update = function () {
self.rotation += 0.05;
};
self.down = function (x, y, obj) {
if (!self.collected) {
self.collected = true;
playerCoins += 10;
LK.getSound('coinCollect').play();
updateCoinUI();
self.destroy();
}
};
return self;
});
var CompanionGirl = Container.expand(function () {
var self = Container.call(this);
var bodyContainer = self.addChild(new Container());
var girlBody = bodyContainer.attachAsset('girlBody', {
anchorX: 0.5,
anchorY: 0.5
});
var girlHead = bodyContainer.addChild(LK.getAsset('girlHead', {
anchorX: 0.5,
anchorY: 0.5
}));
girlHead.y = -120;
var leftEye = bodyContainer.addChild(LK.getAsset('girlEye', {
anchorX: 0.5,
anchorY: 0.5
}));
leftEye.x = -35;
leftEye.y = -140;
var rightEye = bodyContainer.addChild(LK.getAsset('girlEye', {
anchorX: 0.5,
anchorY: 0.5
}));
rightEye.x = 35;
rightEye.y = -140;
var mouth = bodyContainer.addChild(LK.getAsset('girlMouth', {
anchorX: 0.5,
anchorY: 0.5
}));
mouth.y = -100;
self.happiness = 50;
self.stress = 30;
self.lastHappiness = 50;
self.lastStress = 30;
self.setHappiness = function (value) {
self.lastHappiness = self.happiness;
self.happiness = Math.max(0, Math.min(100, value));
};
self.setStress = function (value) {
self.lastStress = self.stress;
self.stress = Math.max(0, Math.min(100, value));
};
self.pet = function () {
self.setHappiness(self.happiness + 15);
self.setStress(Math.max(0, self.stress - 10));
LK.getSound('petSound').play();
tween(bodyContainer, {
scaleX: 1.15,
scaleY: 1.15
}, {
duration: 200,
easing: tween.easeOut
});
tween(bodyContainer, {
scaleX: 1,
scaleY: 1
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {}
});
};
self.feed = function () {
self.setHappiness(self.happiness + 20);
self.setStress(Math.max(0, self.stress - 5));
LK.getSound('feedSound').play();
mouth.tint = 0x00FF00;
LK.setTimeout(function () {
mouth.tint = 0xFF0000;
}, 300);
};
self.showAffection = function () {
var heart = new Container();
heart.x = self.x;
heart.y = self.y - 150;
var heartGraphics = heart.attachAsset('heart', {
anchorX: 0.5,
anchorY: 0.5
});
heart.alpha = 0.8;
gameContainer.addChild(heart);
tween(heart, {
y: heart.y - 100,
alpha: 0
}, {
duration: 1000,
easing: tween.easeOut,
onFinish: function onFinish() {
heart.destroy();
}
});
};
self.update = function () {
if (self.lastHappiness !== self.happiness || self.lastStress !== self.stress) {
updateMeterUI();
self.lastHappiness = self.happiness;
self.lastStress = self.stress;
}
};
return self;
});
var DecorItem = Container.expand(function () {
var self = Container.call(this);
self.assetId = 'coin';
self.itemName = 'Decoration';
self.price = 50;
var graphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
graphics.tint = 0x9370DB;
self.down = function (x, y, obj) {
if (playerCoins >= self.price) {
playerCoins -= self.price;
updateCoinUI();
self.destroy();
companion.showAffection();
companion.setHappiness(companion.happiness + 10);
LK.getSound('coinCollect').play();
}
};
return self;
});
var Food = Container.expand(function () {
var self = Container.call(this);
var foodGraphics = self.attachAsset('food', {
anchorX: 0.5,
anchorY: 0.5
});
self.collected = false;
self.down = function (x, y, obj) {
if (!self.collected) {
self.collected = true;
companion.feed();
companion.showAffection();
self.destroy();
}
};
return self;
});
var MiniGameDropper = Container.expand(function () {
var self = Container.call(this);
var gameBg = self.attachAsset('miniGameArea', {
anchorX: 0.5,
anchorY: 0.5
});
self.score = 0;
self.timeLeft = 30;
self.gameActive = true;
self.targets = [];
var scoreText = self.addChild(new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
}));
scoreText.anchor.set(0.5, 0.5);
scoreText.x = 0;
scoreText.y = -500;
var timerText = self.addChild(new Text2('Time: 30', {
size: 60,
fill: 0xFFFFFF
}));
timerText.anchor.set(0.5, 0.5);
timerText.x = 0;
timerText.y = -450;
self.spawnTarget = function () {
if (self.gameActive) {
var target = self.addChild(new Container());
var targetGraphics = target.attachAsset('targetObject', {
anchorX: 0.5,
anchorY: 0.5
});
target.x = (Math.random() - 0.5) * 1200;
target.y = (Math.random() - 0.5) * 900;
target.collected = false;
target.down = function (x, y, obj) {
if (!target.collected && self.gameActive) {
target.collected = true;
self.score += 1;
scoreText.setText('Score: ' + self.score);
target.destroy();
}
};
self.targets.push(target);
}
};
self.update = function () {
if (self.gameActive) {
if (LK.ticks % 30 === 0) {
self.timeLeft -= 1;
timerText.setText('Time: ' + self.timeLeft);
if (self.timeLeft <= 0) {
self.gameActive = false;
endMiniGame(self.score);
}
}
if (LK.ticks % 20 === 0) {
self.spawnTarget();
}
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xFFEFDB
});
/****
* Game Code
****/
var gameContainer = game;
var companion;
var playerCoins = storage.coins || 100;
var playerHappiness = storage.happiness || 50;
var playerStress = storage.stress || 30;
var gameState = 'playing';
var miniGameActive = false;
function createCompanion() {
companion = gameContainer.addChild(new CompanionGirl());
companion.x = 1024;
companion.y = 800;
companion.setHappiness(playerHappiness);
companion.setStress(playerStress);
}
function createUI() {
var homeContainer = gameContainer.addChild(new Container());
homeContainer.x = 1024;
homeContainer.y = 1100;
var floor = homeContainer.attachAsset('floor', {
anchorX: 0.5,
anchorY: 0.5
});
var coinUIBg = gameContainer.addChild(LK.getAsset('stressMeterBg', {
anchorX: 0.5,
anchorY: 0.5
}));
coinUIBg.x = 1024;
coinUIBg.y = 80;
coinUIBg.tint = 0xFFD700;
var coinText = gameContainer.addChild(new Text2('Coins: ' + playerCoins, {
size: 50,
fill: 0x000000
}));
coinText.anchor.set(0.5, 0.5);
coinText.x = 1024;
coinText.y = 80;
var stressBg = gameContainer.addChild(LK.getAsset('stressMeterBg', {
anchorX: 0.5,
anchorY: 0.5
}));
stressBg.x = 200;
stressBg.y = 100;
var stressFill = gameContainer.addChild(LK.getAsset('stressMeterFill', {
anchorX: 0,
anchorY: 0.5
}));
stressFill.x = 0;
stressFill.y = 100;
stressFill.scaleX = playerStress / 100;
var stressLabel = gameContainer.addChild(new Text2('Stress', {
size: 35,
fill: 0xFFFFFF
}));
stressLabel.anchor.set(0.5, 0.5);
stressLabel.x = 200;
stressLabel.y = 30;
var happinessBg = gameContainer.addChild(LK.getAsset('happinessMeterBg', {
anchorX: 0.5,
anchorY: 0.5
}));
happinessBg.x = 200;
happinessBg.y = 180;
var happinessFill = gameContainer.addChild(LK.getAsset('happinessMeterFill', {
anchorX: 0,
anchorY: 0.5
}));
happinessFill.x = 0;
happinessFill.y = 180;
happinessFill.scaleX = playerHappiness / 100;
var happinessLabel = gameContainer.addChild(new Text2('Happiness', {
size: 35,
fill: 0xFFFFFF
}));
happinessLabel.anchor.set(0.5, 0.5);
happinessLabel.x = 200;
happinessLabel.y = 110;
var petButton = gameContainer.addChild(new Container());
petButton.x = 300;
petButton.y = 2600;
petButton.interactive = true;
var petButtonGraphics = petButton.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
petButtonGraphics.tint = 0xFF1493;
var petButtonText = petButton.addChild(new Text2('Pet', {
size: 45,
fill: 0xFFFFFF
}));
petButtonText.anchor.set(0.5, 0.5);
var feedButton = gameContainer.addChild(new Container());
feedButton.x = 1024;
feedButton.y = 2600;
feedButton.interactive = true;
var feedButtonGraphics = feedButton.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
feedButtonGraphics.tint = 0xFF6347;
var feedButtonText = feedButton.addChild(new Text2('Feed', {
size: 45,
fill: 0xFFFFFF
}));
feedButtonText.anchor.set(0.5, 0.5);
var gameButton = gameContainer.addChild(new Container());
gameButton.x = 1748;
gameButton.y = 2600;
gameButton.interactive = true;
var gameButtonGraphics = gameButton.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
gameButtonGraphics.tint = 0x4169E1;
var gameButtonText = gameButton.addChild(new Text2('Game', {
size: 45,
fill: 0xFFFFFF
}));
gameButtonText.anchor.set(0.5, 0.5);
var leemeButton = gameContainer.addChild(new Container());
leemeButton.x = 1820;
leemeButton.y = 300;
leemeButton.interactive = true;
var leemeButtonGraphics = leemeButton.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
leemeButtonGraphics.tint = 0x9370DB;
leemeButtonGraphics.scaleX = 1.5;
leemeButtonGraphics.scaleY = 1.5;
var leemeButtonText = leemeButton.addChild(new Text2('Leeme', {
size: 45,
fill: 0xFFFFFF
}));
leemeButtonText.anchor.set(0.5, 0.5);
gameContainer.petButton = petButton;
gameContainer.feedButton = feedButton;
gameContainer.gameButton = gameButton;
gameContainer.leemeButton = leemeButton;
gameContainer.coinText = coinText;
gameContainer.stressFill = stressFill;
gameContainer.happinessFill = happinessFill;
}
function updateMeterUI() {
if (gameContainer.stressFill) {
gameContainer.stressFill.scaleX = companion.stress / 100;
}
if (gameContainer.happinessFill) {
gameContainer.happinessFill.scaleX = companion.happiness / 100;
}
}
function updateCoinUI() {
if (gameContainer.coinText) {
gameContainer.coinText.setText('Coins: ' + playerCoins);
}
}
function spawnFood() {
if (gameState === 'playing' && Math.random() < 0.15) {
var food = gameContainer.addChild(new Food());
food.x = 600 + Math.random() * 850;
food.y = 400 + Math.random() * 600;
}
}
function spawnDecoration() {
if (gameState === 'playing' && Math.random() < 0.08) {
var decor = gameContainer.addChild(new DecorItem());
decor.x = 600 + Math.random() * 850;
decor.y = 400 + Math.random() * 600;
}
}
function startMiniGame() {
if (miniGameActive || gameState !== 'playing') return;
miniGameActive = true;
gameState = 'miniGame';
gameContainer.petButton.visible = false;
gameContainer.feedButton.visible = false;
gameContainer.gameButton.visible = false;
companion.visible = false;
var miniGame = gameContainer.addChild(new MiniGameDropper());
miniGame.x = 1024;
miniGame.y = 1366;
gameContainer.miniGame = miniGame;
}
function endMiniGame(score) {
miniGameActive = false;
gameState = 'playing';
gameContainer.petButton.visible = true;
gameContainer.feedButton.visible = true;
gameContainer.gameButton.visible = true;
companion.visible = true;
var coinsEarned = score * 5;
playerCoins += coinsEarned;
updateCoinUI();
if (gameContainer.miniGame) {
gameContainer.miniGame.destroy();
gameContainer.miniGame = null;
}
}
function saveGame() {
storage.coins = playerCoins;
storage.happiness = companion.happiness;
storage.stress = companion.stress;
}
game.down = function (x, y, obj) {
if (gameState !== 'playing') return;
if (gameContainer.petButton && gameContainer.petButton.visible) {
if (Math.abs(x - gameContainer.petButton.x) < 100 && Math.abs(y - gameContainer.petButton.y) < 40) {
companion.pet();
companion.showAffection();
}
}
if (gameContainer.feedButton && gameContainer.feedButton.visible) {
if (Math.abs(x - gameContainer.feedButton.x) < 100 && Math.abs(y - gameContainer.feedButton.y) < 40) {
var food = gameContainer.addChild(new Food());
food.x = companion.x + (Math.random() - 0.5) * 200;
food.y = companion.y + 100;
}
}
if (gameContainer.gameButton && gameContainer.gameButton.visible) {
if (Math.abs(x - gameContainer.gameButton.x) < 100 && Math.abs(y - gameContainer.gameButton.y) < 40) {
startMiniGame();
}
}
if (gameContainer.leemeButton) {
if (Math.abs(x - gameContainer.leemeButton.x) < 150 && Math.abs(y - gameContainer.leemeButton.y) < 60) {
var messageBox = gameContainer.addChild(new Container());
messageBox.x = 1024;
messageBox.y = 1366;
var messageBg = messageBox.attachAsset('home', {
anchorX: 0.5,
anchorY: 0.5
});
messageBg.scaleX = 0.6;
messageBg.scaleY = 0.6;
messageBg.tint = 0x333333;
messageBg.alpha = 0.95;
var messageText = messageBox.addChild(new Text2('Este es una prueba para ver si se puede actualizar un juego estando publicado ya que mi verdadero juego recibirá actualizaciones y necesitaba hacer, gracias, aqui estare avisando cuando lo publique', {
size: 40,
fill: 0xFFFFFF
}));
messageText.anchor.set(0.5, 0.5);
messageText.x = 0;
messageText.y = -100;
var closeButton = messageBox.addChild(new Container());
closeButton.x = 0;
closeButton.y = 150;
closeButton.interactive = true;
var closeButtonGraphics = closeButton.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
closeButtonGraphics.tint = 0xFF1493;
closeButtonGraphics.scaleX = 0.8;
closeButtonGraphics.scaleY = 0.8;
var closeButtonText = closeButton.addChild(new Text2('Cerrar', {
size: 35,
fill: 0xFFFFFF
}));
closeButtonText.anchor.set(0.5, 0.5);
closeButton.down = function () {
messageBox.destroy();
};
} //{3g_new}
}
};
createCompanion();
createUI();
game.update = function () {
if (gameState === 'playing') {
companion.update();
if (LK.ticks % 300 === 0) {
companion.setStress(Math.min(100, companion.stress + 5));
spawnFood();
spawnDecoration();
}
if (companion.stress >= 100 || companion.happiness <= 0) {
gameState = 'gameOver';
saveGame();
LK.getSound('gameOver').play();
LK.showGameOver();
}
if (LK.ticks % 600 === 0) {
saveGame();
}
} else if (gameState === 'miniGame' && gameContainer.miniGame) {
gameContainer.miniGame.update();
}
};
LK.playMusic('bgmusic'); /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
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.rotation = 0;
self.update = function () {
self.rotation += 0.05;
};
self.down = function (x, y, obj) {
if (!self.collected) {
self.collected = true;
playerCoins += 10;
LK.getSound('coinCollect').play();
updateCoinUI();
self.destroy();
}
};
return self;
});
var CompanionGirl = Container.expand(function () {
var self = Container.call(this);
var bodyContainer = self.addChild(new Container());
var girlBody = bodyContainer.attachAsset('girlBody', {
anchorX: 0.5,
anchorY: 0.5
});
var girlHead = bodyContainer.addChild(LK.getAsset('girlHead', {
anchorX: 0.5,
anchorY: 0.5
}));
girlHead.y = -120;
var leftEye = bodyContainer.addChild(LK.getAsset('girlEye', {
anchorX: 0.5,
anchorY: 0.5
}));
leftEye.x = -35;
leftEye.y = -140;
var rightEye = bodyContainer.addChild(LK.getAsset('girlEye', {
anchorX: 0.5,
anchorY: 0.5
}));
rightEye.x = 35;
rightEye.y = -140;
var mouth = bodyContainer.addChild(LK.getAsset('girlMouth', {
anchorX: 0.5,
anchorY: 0.5
}));
mouth.y = -100;
self.happiness = 50;
self.stress = 30;
self.lastHappiness = 50;
self.lastStress = 30;
self.setHappiness = function (value) {
self.lastHappiness = self.happiness;
self.happiness = Math.max(0, Math.min(100, value));
};
self.setStress = function (value) {
self.lastStress = self.stress;
self.stress = Math.max(0, Math.min(100, value));
};
self.pet = function () {
self.setHappiness(self.happiness + 15);
self.setStress(Math.max(0, self.stress - 10));
LK.getSound('petSound').play();
tween(bodyContainer, {
scaleX: 1.15,
scaleY: 1.15
}, {
duration: 200,
easing: tween.easeOut
});
tween(bodyContainer, {
scaleX: 1,
scaleY: 1
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {}
});
};
self.feed = function () {
self.setHappiness(self.happiness + 20);
self.setStress(Math.max(0, self.stress - 5));
LK.getSound('feedSound').play();
mouth.tint = 0x00FF00;
LK.setTimeout(function () {
mouth.tint = 0xFF0000;
}, 300);
};
self.showAffection = function () {
var heart = new Container();
heart.x = self.x;
heart.y = self.y - 150;
var heartGraphics = heart.attachAsset('heart', {
anchorX: 0.5,
anchorY: 0.5
});
heart.alpha = 0.8;
gameContainer.addChild(heart);
tween(heart, {
y: heart.y - 100,
alpha: 0
}, {
duration: 1000,
easing: tween.easeOut,
onFinish: function onFinish() {
heart.destroy();
}
});
};
self.update = function () {
if (self.lastHappiness !== self.happiness || self.lastStress !== self.stress) {
updateMeterUI();
self.lastHappiness = self.happiness;
self.lastStress = self.stress;
}
};
return self;
});
var DecorItem = Container.expand(function () {
var self = Container.call(this);
self.assetId = 'coin';
self.itemName = 'Decoration';
self.price = 50;
var graphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
graphics.tint = 0x9370DB;
self.down = function (x, y, obj) {
if (playerCoins >= self.price) {
playerCoins -= self.price;
updateCoinUI();
self.destroy();
companion.showAffection();
companion.setHappiness(companion.happiness + 10);
LK.getSound('coinCollect').play();
}
};
return self;
});
var Food = Container.expand(function () {
var self = Container.call(this);
var foodGraphics = self.attachAsset('food', {
anchorX: 0.5,
anchorY: 0.5
});
self.collected = false;
self.down = function (x, y, obj) {
if (!self.collected) {
self.collected = true;
companion.feed();
companion.showAffection();
self.destroy();
}
};
return self;
});
var MiniGameDropper = Container.expand(function () {
var self = Container.call(this);
var gameBg = self.attachAsset('miniGameArea', {
anchorX: 0.5,
anchorY: 0.5
});
self.score = 0;
self.timeLeft = 30;
self.gameActive = true;
self.targets = [];
var scoreText = self.addChild(new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
}));
scoreText.anchor.set(0.5, 0.5);
scoreText.x = 0;
scoreText.y = -500;
var timerText = self.addChild(new Text2('Time: 30', {
size: 60,
fill: 0xFFFFFF
}));
timerText.anchor.set(0.5, 0.5);
timerText.x = 0;
timerText.y = -450;
self.spawnTarget = function () {
if (self.gameActive) {
var target = self.addChild(new Container());
var targetGraphics = target.attachAsset('targetObject', {
anchorX: 0.5,
anchorY: 0.5
});
target.x = (Math.random() - 0.5) * 1200;
target.y = (Math.random() - 0.5) * 900;
target.collected = false;
target.down = function (x, y, obj) {
if (!target.collected && self.gameActive) {
target.collected = true;
self.score += 1;
scoreText.setText('Score: ' + self.score);
target.destroy();
}
};
self.targets.push(target);
}
};
self.update = function () {
if (self.gameActive) {
if (LK.ticks % 30 === 0) {
self.timeLeft -= 1;
timerText.setText('Time: ' + self.timeLeft);
if (self.timeLeft <= 0) {
self.gameActive = false;
endMiniGame(self.score);
}
}
if (LK.ticks % 20 === 0) {
self.spawnTarget();
}
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xFFEFDB
});
/****
* Game Code
****/
var gameContainer = game;
var companion;
var playerCoins = storage.coins || 100;
var playerHappiness = storage.happiness || 50;
var playerStress = storage.stress || 30;
var gameState = 'playing';
var miniGameActive = false;
function createCompanion() {
companion = gameContainer.addChild(new CompanionGirl());
companion.x = 1024;
companion.y = 800;
companion.setHappiness(playerHappiness);
companion.setStress(playerStress);
}
function createUI() {
var homeContainer = gameContainer.addChild(new Container());
homeContainer.x = 1024;
homeContainer.y = 1100;
var floor = homeContainer.attachAsset('floor', {
anchorX: 0.5,
anchorY: 0.5
});
var coinUIBg = gameContainer.addChild(LK.getAsset('stressMeterBg', {
anchorX: 0.5,
anchorY: 0.5
}));
coinUIBg.x = 1024;
coinUIBg.y = 80;
coinUIBg.tint = 0xFFD700;
var coinText = gameContainer.addChild(new Text2('Coins: ' + playerCoins, {
size: 50,
fill: 0x000000
}));
coinText.anchor.set(0.5, 0.5);
coinText.x = 1024;
coinText.y = 80;
var stressBg = gameContainer.addChild(LK.getAsset('stressMeterBg', {
anchorX: 0.5,
anchorY: 0.5
}));
stressBg.x = 200;
stressBg.y = 100;
var stressFill = gameContainer.addChild(LK.getAsset('stressMeterFill', {
anchorX: 0,
anchorY: 0.5
}));
stressFill.x = 0;
stressFill.y = 100;
stressFill.scaleX = playerStress / 100;
var stressLabel = gameContainer.addChild(new Text2('Stress', {
size: 35,
fill: 0xFFFFFF
}));
stressLabel.anchor.set(0.5, 0.5);
stressLabel.x = 200;
stressLabel.y = 30;
var happinessBg = gameContainer.addChild(LK.getAsset('happinessMeterBg', {
anchorX: 0.5,
anchorY: 0.5
}));
happinessBg.x = 200;
happinessBg.y = 180;
var happinessFill = gameContainer.addChild(LK.getAsset('happinessMeterFill', {
anchorX: 0,
anchorY: 0.5
}));
happinessFill.x = 0;
happinessFill.y = 180;
happinessFill.scaleX = playerHappiness / 100;
var happinessLabel = gameContainer.addChild(new Text2('Happiness', {
size: 35,
fill: 0xFFFFFF
}));
happinessLabel.anchor.set(0.5, 0.5);
happinessLabel.x = 200;
happinessLabel.y = 110;
var petButton = gameContainer.addChild(new Container());
petButton.x = 300;
petButton.y = 2600;
petButton.interactive = true;
var petButtonGraphics = petButton.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
petButtonGraphics.tint = 0xFF1493;
var petButtonText = petButton.addChild(new Text2('Pet', {
size: 45,
fill: 0xFFFFFF
}));
petButtonText.anchor.set(0.5, 0.5);
var feedButton = gameContainer.addChild(new Container());
feedButton.x = 1024;
feedButton.y = 2600;
feedButton.interactive = true;
var feedButtonGraphics = feedButton.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
feedButtonGraphics.tint = 0xFF6347;
var feedButtonText = feedButton.addChild(new Text2('Feed', {
size: 45,
fill: 0xFFFFFF
}));
feedButtonText.anchor.set(0.5, 0.5);
var gameButton = gameContainer.addChild(new Container());
gameButton.x = 1748;
gameButton.y = 2600;
gameButton.interactive = true;
var gameButtonGraphics = gameButton.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
gameButtonGraphics.tint = 0x4169E1;
var gameButtonText = gameButton.addChild(new Text2('Game', {
size: 45,
fill: 0xFFFFFF
}));
gameButtonText.anchor.set(0.5, 0.5);
var leemeButton = gameContainer.addChild(new Container());
leemeButton.x = 1820;
leemeButton.y = 300;
leemeButton.interactive = true;
var leemeButtonGraphics = leemeButton.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
leemeButtonGraphics.tint = 0x9370DB;
leemeButtonGraphics.scaleX = 1.5;
leemeButtonGraphics.scaleY = 1.5;
var leemeButtonText = leemeButton.addChild(new Text2('Leeme', {
size: 45,
fill: 0xFFFFFF
}));
leemeButtonText.anchor.set(0.5, 0.5);
gameContainer.petButton = petButton;
gameContainer.feedButton = feedButton;
gameContainer.gameButton = gameButton;
gameContainer.leemeButton = leemeButton;
gameContainer.coinText = coinText;
gameContainer.stressFill = stressFill;
gameContainer.happinessFill = happinessFill;
}
function updateMeterUI() {
if (gameContainer.stressFill) {
gameContainer.stressFill.scaleX = companion.stress / 100;
}
if (gameContainer.happinessFill) {
gameContainer.happinessFill.scaleX = companion.happiness / 100;
}
}
function updateCoinUI() {
if (gameContainer.coinText) {
gameContainer.coinText.setText('Coins: ' + playerCoins);
}
}
function spawnFood() {
if (gameState === 'playing' && Math.random() < 0.15) {
var food = gameContainer.addChild(new Food());
food.x = 600 + Math.random() * 850;
food.y = 400 + Math.random() * 600;
}
}
function spawnDecoration() {
if (gameState === 'playing' && Math.random() < 0.08) {
var decor = gameContainer.addChild(new DecorItem());
decor.x = 600 + Math.random() * 850;
decor.y = 400 + Math.random() * 600;
}
}
function startMiniGame() {
if (miniGameActive || gameState !== 'playing') return;
miniGameActive = true;
gameState = 'miniGame';
gameContainer.petButton.visible = false;
gameContainer.feedButton.visible = false;
gameContainer.gameButton.visible = false;
companion.visible = false;
var miniGame = gameContainer.addChild(new MiniGameDropper());
miniGame.x = 1024;
miniGame.y = 1366;
gameContainer.miniGame = miniGame;
}
function endMiniGame(score) {
miniGameActive = false;
gameState = 'playing';
gameContainer.petButton.visible = true;
gameContainer.feedButton.visible = true;
gameContainer.gameButton.visible = true;
companion.visible = true;
var coinsEarned = score * 5;
playerCoins += coinsEarned;
updateCoinUI();
if (gameContainer.miniGame) {
gameContainer.miniGame.destroy();
gameContainer.miniGame = null;
}
}
function saveGame() {
storage.coins = playerCoins;
storage.happiness = companion.happiness;
storage.stress = companion.stress;
}
game.down = function (x, y, obj) {
if (gameState !== 'playing') return;
if (gameContainer.petButton && gameContainer.petButton.visible) {
if (Math.abs(x - gameContainer.petButton.x) < 100 && Math.abs(y - gameContainer.petButton.y) < 40) {
companion.pet();
companion.showAffection();
}
}
if (gameContainer.feedButton && gameContainer.feedButton.visible) {
if (Math.abs(x - gameContainer.feedButton.x) < 100 && Math.abs(y - gameContainer.feedButton.y) < 40) {
var food = gameContainer.addChild(new Food());
food.x = companion.x + (Math.random() - 0.5) * 200;
food.y = companion.y + 100;
}
}
if (gameContainer.gameButton && gameContainer.gameButton.visible) {
if (Math.abs(x - gameContainer.gameButton.x) < 100 && Math.abs(y - gameContainer.gameButton.y) < 40) {
startMiniGame();
}
}
if (gameContainer.leemeButton) {
if (Math.abs(x - gameContainer.leemeButton.x) < 150 && Math.abs(y - gameContainer.leemeButton.y) < 60) {
var messageBox = gameContainer.addChild(new Container());
messageBox.x = 1024;
messageBox.y = 1366;
var messageBg = messageBox.attachAsset('home', {
anchorX: 0.5,
anchorY: 0.5
});
messageBg.scaleX = 0.6;
messageBg.scaleY = 0.6;
messageBg.tint = 0x333333;
messageBg.alpha = 0.95;
var messageText = messageBox.addChild(new Text2('Este es una prueba para ver si se puede actualizar un juego estando publicado ya que mi verdadero juego recibirá actualizaciones y necesitaba hacer, gracias, aqui estare avisando cuando lo publique', {
size: 40,
fill: 0xFFFFFF
}));
messageText.anchor.set(0.5, 0.5);
messageText.x = 0;
messageText.y = -100;
var closeButton = messageBox.addChild(new Container());
closeButton.x = 0;
closeButton.y = 150;
closeButton.interactive = true;
var closeButtonGraphics = closeButton.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
closeButtonGraphics.tint = 0xFF1493;
closeButtonGraphics.scaleX = 0.8;
closeButtonGraphics.scaleY = 0.8;
var closeButtonText = closeButton.addChild(new Text2('Cerrar', {
size: 35,
fill: 0xFFFFFF
}));
closeButtonText.anchor.set(0.5, 0.5);
closeButton.down = function () {
messageBox.destroy();
};
} //{3g_new}
}
};
createCompanion();
createUI();
game.update = function () {
if (gameState === 'playing') {
companion.update();
if (LK.ticks % 300 === 0) {
companion.setStress(Math.min(100, companion.stress + 5));
spawnFood();
spawnDecoration();
}
if (companion.stress >= 100 || companion.happiness <= 0) {
gameState = 'gameOver';
saveGame();
LK.getSound('gameOver').play();
LK.showGameOver();
}
if (LK.ticks % 600 === 0) {
saveGame();
}
} else if (gameState === 'miniGame' && gameContainer.miniGame) {
gameContainer.miniGame.update();
}
};
LK.playMusic('bgmusic');