/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var PetTile = Container.expand(function (type, gridX, gridY) {
var self = Container.call(this);
self.type = type;
self.gridX = gridX;
self.gridY = gridY;
self.isSelected = false;
self.isMatched = false;
var tileColors = {
'dog': 0xF4A460,
'cat': 0xFF69B4,
'bird': 0x87CEEB,
'fish': 0x40E0D0,
'hamster': 0xFFDAB9
};
var tileAssets = {
'dog': 'dogTile',
'cat': 'catTile',
'bird': 'birdTile',
'fish': 'fishTile',
'hamster': 'hamsterTile'
};
var tileGraphics = self.attachAsset(tileAssets[type], {
anchorX: 0.5,
anchorY: 0.5
});
self.select = function () {
self.isSelected = true;
tween(tileGraphics, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 200
});
};
self.deselect = function () {
self.isSelected = false;
tween(tileGraphics, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 200
});
};
self.markMatched = function () {
self.isMatched = true;
tween(tileGraphics, {
alpha: 0,
scaleX: 0.1,
scaleY: 0.1
}, {
duration: 300,
onFinish: function onFinish() {
self.destroy();
}
});
};
self.down = function (x, y, obj) {
if (!gameStarted || gameOver) return;
if (selectedTile === null) {
selectedTile = self;
self.select();
} else if (selectedTile === self) {
selectedTile.deselect();
selectedTile = null;
} else {
if (areAdjacent(selectedTile, self)) {
swapTiles(selectedTile, self);
}
selectedTile.deselect();
selectedTile = null;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x90EE90
});
/****
* Game Code
****/
var gridWidth = 6;
var gridHeight = 8;
var tileSize = 220;
var grid = [];
var selectedTile = null;
var gameStarted = false;
var gameOver = false;
var timeLeft = 300;
var difficulty = 'easy';
var targetScore = 250000;
var petTypes = ['dog', 'cat', 'bird', 'fish', 'hamster'];
// Pet store background for menu with gradient effect
var menuBackground = LK.getAsset('petStoreBackground', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.9,
tint: 0xE1BEE7
});
menuBackground.x = 2048 / 2;
menuBackground.y = 2732 / 2;
game.addChild(menuBackground);
// Add overlay for better text contrast
var menuOverlay = LK.getAsset('petStoreBackground', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.3,
tint: 0x1A1A2E
});
menuOverlay.x = 2048 / 2;
menuOverlay.y = 2732 / 2;
game.addChild(menuOverlay);
// Menu title with improved styling
var titleText = new Text2('PET STORE MATCH', {
size: 140,
fill: 0xFFD700
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 2048 / 2;
titleText.y = 2732 / 2 - 450;
game.addChild(titleText);
// Add shadow effect to title
var titleShadow = new Text2('PET STORE MATCH', {
size: 140,
fill: 0x333333
});
titleShadow.anchor.set(0.5, 0.5);
titleShadow.x = 2048 / 2 + 5;
titleShadow.y = 2732 / 2 - 445;
titleShadow.alpha = 0.8;
game.addChildAt(titleShadow, game.children.length - 1);
// Enhanced Food Bag Progress Tracker
var foodBagContainer = new Container();
foodBagContainer.x = 280;
foodBagContainer.y = 180;
foodBagContainer.visible = false;
LK.gui.topLeft.addChild(foodBagContainer);
// Score text for food bag display
var scoreText = new Text2('0 / 250k', {
size: 36,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0.5);
scoreText.x = 0;
scoreText.y = -120;
foodBagContainer.addChild(scoreText);
// Progress text for food bag display
var progressText = new Text2('NEED MORE FOOD!', {
size: 32,
fill: 0xFF6B6B
});
progressText.anchor.set(0.5, 0.5);
progressText.x = 0;
progressText.y = -80;
foodBagContainer.addChild(progressText);
// Food bag background with border
var foodBagBorder = LK.getAsset('gridBackground', {
anchorX: 0.5,
anchorY: 1,
scaleX: 2.2,
scaleY: 2.5,
tint: 0x654321
});
foodBagBorder.alpha = 0.9;
foodBagContainer.addChild(foodBagBorder);
var foodBagBg = LK.getAsset('hamsterTile', {
anchorX: 0.5,
anchorY: 1,
scaleX: 1.8,
scaleY: 2.2,
tint: 0x8B4513
});
foodBagBg.alpha = 0.85;
foodBagContainer.addChild(foodBagBg);
var foodBagFill = LK.getAsset('hamsterTile', {
anchorX: 0.5,
anchorY: 1,
scaleX: 1.6,
scaleY: 0,
tint: 0xFFD700
});
foodBagFill.alpha = 0.9;
foodBagContainer.addChild(foodBagFill);
// Enhanced circular back button with arrow
var backToMenuBg = LK.getAsset('gridBackground', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5,
scaleY: 1.5,
tint: 0x607D8B
});
backToMenuBg.x = -120;
backToMenuBg.y = 100;
backToMenuBg.visible = false;
LK.gui.topRight.addChild(backToMenuBg);
var backToMenuButton = new Text2('↶', {
size: 80,
fill: 0xFFFFFF
});
backToMenuButton.anchor.set(0.5, 0.5);
backToMenuButton.x = -120;
backToMenuButton.y = 100;
backToMenuButton.visible = false;
LK.gui.topRight.addChild(backToMenuButton);
// Music toggle button
var musicButtonBg = LK.getAsset('gridBackground', {
anchorX: 0,
anchorY: 1,
scaleX: 1.8,
scaleY: 1,
tint: 0x9C27B0
});
musicButtonBg.x = 20;
musicButtonBg.y = -100;
LK.gui.bottomLeft.addChild(musicButtonBg);
var musicToggleButton = new Text2('MUSIC ON', {
size: 48,
fill: 0xFFFFFF
});
musicToggleButton.anchor.set(0, 1);
musicToggleButton.x = 20;
musicToggleButton.y = -110;
LK.gui.bottomLeft.addChild(musicToggleButton);
var musicEnabled = true;
// Enhanced start button with background and shadow
var startButtonBg = LK.getAsset('gridBackground', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 5,
scaleY: 1.5,
tint: 0x2196F3
});
startButtonBg.x = 2048 / 2;
startButtonBg.y = 2732 / 2 + 180;
game.addChild(startButtonBg);
var startButtonShadow = LK.getAsset('gridBackground', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 5,
scaleY: 1.5,
tint: 0x0D47A1,
alpha: 0.6
});
startButtonShadow.x = 2048 / 2 + 8;
startButtonShadow.y = 2732 / 2 + 188;
game.addChild(startButtonShadow);
var startButton = new Text2('START GAME', {
size: 120,
fill: 0xFFFFFF
});
startButton.anchor.set(0.5, 0.5);
startButton.x = 2048 / 2;
startButton.y = 2732 / 2 + 180;
game.addChild(startButton);
// Enhanced difficulty buttons with better styling
var easyButtonBg = LK.getAsset('gridBackground', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 4,
scaleY: 1.2,
tint: 0x4CAF50
});
easyButtonBg.x = 2048 / 2;
easyButtonBg.y = 2732 / 2 - 250;
game.addChild(easyButtonBg);
var easyButtonShadow = LK.getAsset('gridBackground', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 4,
scaleY: 1.2,
tint: 0x2E7D32,
alpha: 0.6
});
easyButtonShadow.x = 2048 / 2 + 8;
easyButtonShadow.y = 2732 / 2 - 242;
game.addChild(easyButtonShadow);
var easyButton = new Text2('EASY - Goal: 250k (5min)', {
size: 58,
fill: 0xFFFFFF
});
easyButton.anchor.set(0.5, 0.5);
easyButton.x = 2048 / 2;
easyButton.y = 2732 / 2 - 250;
game.addChild(easyButton);
var mediumButtonBg = LK.getAsset('gridBackground', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 4,
scaleY: 1.2,
tint: 0xFF9800
});
mediumButtonBg.x = 2048 / 2;
mediumButtonBg.y = 2732 / 2 - 120;
game.addChild(mediumButtonBg);
var mediumButtonShadow = LK.getAsset('gridBackground', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 4,
scaleY: 1.2,
tint: 0xE65100,
alpha: 0.6
});
mediumButtonShadow.x = 2048 / 2 + 8;
mediumButtonShadow.y = 2732 / 2 - 112;
game.addChild(mediumButtonShadow);
var mediumButton = new Text2('MEDIUM - Goal: 150k (3min)', {
size: 58,
fill: 0xFFFFFF
});
mediumButton.anchor.set(0.5, 0.5);
mediumButton.x = 2048 / 2;
mediumButton.y = 2732 / 2 - 120;
game.addChild(mediumButton);
var hardButtonBg = LK.getAsset('gridBackground', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 4,
scaleY: 1.2,
tint: 0xF44336
});
hardButtonBg.x = 2048 / 2;
hardButtonBg.y = 2732 / 2 + 10;
game.addChild(hardButtonBg);
var hardButtonShadow = LK.getAsset('gridBackground', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 4,
scaleY: 1.2,
tint: 0xC62828,
alpha: 0.6
});
hardButtonShadow.x = 2048 / 2 + 8;
hardButtonShadow.y = 2732 / 2 + 18;
game.addChild(hardButtonShadow);
var hardButton = new Text2('HARD - Goal: 100k (2min)', {
size: 58,
fill: 0xFFFFFF
});
hardButton.anchor.set(0.5, 0.5);
hardButton.x = 2048 / 2;
hardButton.y = 2732 / 2 + 10;
game.addChild(hardButton);
// Game timer
var gameTimer = null;
var gridBackgroundTiles = [];
function clearGrid() {
// Clear existing grid tiles
for (var i = 0; i < grid.length; i++) {
for (var j = 0; j < grid[i].length; j++) {
if (grid[i][j]) {
grid[i][j].destroy();
}
}
}
grid = [];
// Clear grid background tiles
for (var i = 0; i < gridBackgroundTiles.length; i++) {
if (gridBackgroundTiles[i]) {
gridBackgroundTiles[i].destroy();
}
}
gridBackgroundTiles = [];
}
function initializeGrid() {
clearGrid();
// Random grid layout
var layouts = [{
width: 6,
height: 8
}, {
width: 7,
height: 7
}, {
width: 8,
height: 6
}];
var layout = layouts[Math.floor(Math.random() * layouts.length)];
gridWidth = layout.width;
gridHeight = layout.height;
// Initialize grid array
for (var i = 0; i < gridWidth; i++) {
grid[i] = [];
for (var j = 0; j < gridHeight; j++) {
grid[i][j] = null;
}
}
// Calculate grid position to center it
var gridPixelWidth = gridWidth * tileSize;
var gridPixelHeight = gridHeight * tileSize;
var startX = (2048 - gridPixelWidth) / 2 + tileSize / 2;
var startY = (2732 - gridPixelHeight) / 2 + tileSize / 2;
// Create background tiles only when game starts
for (var i = 0; i < gridWidth; i++) {
for (var j = 0; j < gridHeight; j++) {
var bg = LK.getAsset('gridBackground', {
anchorX: 0.5,
anchorY: 0.5
});
bg.x = startX + i * tileSize;
bg.y = startY + j * tileSize;
bg.alpha = 0.8;
gridBackgroundTiles.push(bg);
game.addChild(bg);
}
}
// Fill grid with random tiles
fillGrid();
}
function fillGrid() {
var gridPixelWidth = gridWidth * tileSize;
var gridPixelHeight = gridHeight * tileSize;
var startX = (2048 - gridPixelWidth) / 2 + tileSize / 2;
var startY = (2732 - gridPixelHeight) / 2 + tileSize / 2;
for (var i = 0; i < gridWidth; i++) {
for (var j = 0; j < gridHeight; j++) {
if (grid[i][j] === null) {
var type = getRandomPetType(i, j);
var tile = new PetTile(type, i, j);
tile.x = startX + i * tileSize;
tile.y = startY + j * tileSize;
grid[i][j] = tile;
game.addChild(tile);
}
}
}
}
function getRandomPetType(x, y) {
var attempts = 0;
var type;
do {
type = petTypes[Math.floor(Math.random() * petTypes.length)];
attempts++;
} while (attempts < 10 && wouldCreateMatch(x, y, type));
return type;
}
function wouldCreateMatch(x, y, type) {
// Check horizontal
var horizontalCount = 1;
// Check left
for (var i = x - 1; i >= 0 && grid[i][y] && grid[i][y].type === type; i--) {
horizontalCount++;
}
// Check right
for (var i = x + 1; i < gridWidth && grid[i][y] && grid[i][y].type === type; i++) {
horizontalCount++;
}
// Check vertical
var verticalCount = 1;
// Check up
for (var j = y - 1; j >= 0 && grid[x][j] && grid[x][j].type === type; j--) {
verticalCount++;
}
// Check down
for (var j = y + 1; j < gridHeight && grid[x][j] && grid[x][j].type === type; j++) {
verticalCount++;
}
return horizontalCount >= 3 || verticalCount >= 3;
}
function areAdjacent(tile1, tile2) {
var dx = Math.abs(tile1.gridX - tile2.gridX);
var dy = Math.abs(tile1.gridY - tile2.gridY);
return dx === 1 && dy === 0 || dx === 0 && dy === 1;
}
function swapTiles(tile1, tile2) {
LK.getSound('swap').play();
// Swap grid positions
var tempX = tile1.gridX;
var tempY = tile1.gridY;
tile1.gridX = tile2.gridX;
tile1.gridY = tile2.gridY;
tile2.gridX = tempX;
tile2.gridY = tempY;
// Swap in grid array
grid[tile1.gridX][tile1.gridY] = tile1;
grid[tile2.gridX][tile2.gridY] = tile2;
// Animate swap
var tile1TargetX = tile1.x;
var tile1TargetY = tile1.y;
var tile2TargetX = tile2.x;
var tile2TargetY = tile2.y;
tween(tile1, {
x: tile2TargetX,
y: tile2TargetY
}, {
duration: 300
});
tween(tile2, {
x: tile1TargetX,
y: tile1TargetY
}, {
duration: 300,
onFinish: function onFinish() {
checkForMatches();
}
});
}
function checkForMatches() {
var matches = findMatches();
if (matches.length > 0) {
LK.getSound('match').play();
// Calculate score and create effects based on match size
var matchScore = 0;
for (var i = 0; i < matches.length; i++) {
var matchSize = matches[i].length;
var match = matches[i];
// Calculate center position of match for effects
var centerX = 0;
var centerY = 0;
for (var k = 0; k < match.length; k++) {
centerX += match[k].x;
centerY += match[k].y;
}
centerX /= match.length;
centerY /= match.length;
if (matchSize === 3) {
matchScore += 1000;
LK.getSound('match3').play();
createStarEffect(centerX, centerY);
} else if (matchSize === 4) {
matchScore += 3000;
LK.getSound('match4').play();
createConfettiEffect(centerX, centerY);
} else if (matchSize >= 5) {
matchScore += 5000;
LK.getSound('match5').play();
createFireworkEffect(centerX, centerY);
}
}
LK.setScore(LK.getScore() + matchScore);
updateFoodBagDisplay();
// Mark matched tiles
for (var i = 0; i < matches.length; i++) {
for (var j = 0; j < matches[i].length; j++) {
var tile = matches[i][j];
tile.markMatched();
grid[tile.gridX][tile.gridY] = null;
}
}
// Wait for animation then refill
LK.setTimeout(function () {
dropTiles();
fillGrid();
LK.setTimeout(function () {
checkForMatches();
}, 300);
}, 300);
}
}
function findMatches() {
var matches = [];
var checked = [];
// Initialize checked array
for (var i = 0; i < gridWidth; i++) {
checked[i] = [];
for (var j = 0; j < gridHeight; j++) {
checked[i][j] = false;
}
}
// Find horizontal matches
for (var j = 0; j < gridHeight; j++) {
for (var i = 0; i < gridWidth - 2; i++) {
if (grid[i][j] && grid[i + 1][j] && grid[i + 2][j] && grid[i][j].type === grid[i + 1][j].type && grid[i][j].type === grid[i + 2][j].type) {
var match = [];
var k = i;
while (k < gridWidth && grid[k][j] && grid[k][j].type === grid[i][j].type) {
if (!checked[k][j]) {
match.push(grid[k][j]);
checked[k][j] = true;
}
k++;
}
if (match.length >= 3) {
matches.push(match);
}
}
}
}
// Find vertical matches
for (var i = 0; i < gridWidth; i++) {
for (var j = 0; j < gridHeight - 2; j++) {
if (grid[i][j] && grid[i][j + 1] && grid[i][j + 2] && grid[i][j].type === grid[i][j + 1].type && grid[i][j].type === grid[i][j + 2].type) {
var match = [];
var k = j;
while (k < gridHeight && grid[i][k] && grid[i][k].type === grid[i][j].type) {
if (!checked[i][k]) {
match.push(grid[i][k]);
checked[i][k] = true;
}
k++;
}
if (match.length >= 3) {
matches.push(match);
}
}
}
}
return matches;
}
function dropTiles() {
for (var i = 0; i < gridWidth; i++) {
var writeIndex = gridHeight - 1;
for (var j = gridHeight - 1; j >= 0; j--) {
if (grid[i][j] !== null) {
if (j !== writeIndex) {
grid[i][writeIndex] = grid[i][j];
grid[i][j] = null;
grid[i][writeIndex].gridY = writeIndex;
var gridPixelWidth = gridWidth * tileSize;
var gridPixelHeight = gridHeight * tileSize;
var startX = (2048 - gridPixelWidth) / 2 + tileSize / 2;
var startY = (2732 - gridPixelHeight) / 2 + tileSize / 2;
var targetY = startY + writeIndex * tileSize;
tween(grid[i][writeIndex], {
y: targetY
}, {
duration: 200
});
}
writeIndex--;
}
}
}
}
function formatTime(seconds) {
var minutes = Math.floor(seconds / 60);
var remainingSeconds = seconds % 60;
return minutes + ':' + (remainingSeconds < 10 ? '0' : '') + remainingSeconds;
}
function updateFoodBagDisplay() {
var currentScore = LK.getScore();
var progress = Math.min(currentScore / targetScore, 1);
// Update food bag fill with smooth animation
tween(foodBagFill, {
scaleY: progress * 2.0
}, {
duration: 500,
easing: tween.easeOut
});
// Update score text with better formatting
var targetText = targetScore >= 1000000 ? (targetScore / 1000000).toFixed(1) + 'M' : targetScore >= 1000 ? targetScore / 1000 + 'k' : targetScore;
var currentText = currentScore >= 1000000 ? (currentScore / 1000000).toFixed(1) + 'M' : currentScore >= 1000 ? Math.floor(currentScore / 1000) + 'k' : currentScore;
scoreText.setText(currentText + ' / ' + targetText);
// Enhanced progress indicator with color transitions
if (progress < 0.3) {
foodBagFill.tint = 0xFF4444;
progressText.setText('NEED MORE FOOD!');
progressText.tint = 0xFF6B6B;
} else if (progress < 0.7) {
foodBagFill.tint = 0xFFAA00;
progressText.setText('GETTING THERE!');
progressText.tint = 0xFFD93D;
} else if (progress < 0.95) {
foodBagFill.tint = 0x44FF44;
progressText.setText('ALMOST FULL!');
progressText.tint = 0x6BCF7F;
} else {
foodBagFill.tint = 0x00FF00;
progressText.setText('GOAL ACHIEVED!');
progressText.tint = 0x4ECDC4;
}
// Pulse effect when close to goal
if (progress > 0.9) {
tween(foodBagContainer, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 200,
onFinish: function onFinish() {
tween(foodBagContainer, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 200
});
}
});
}
}
function createStarEffect(x, y) {
for (var i = 0; i < 6; i++) {
var star = LK.getAsset('star', {
anchorX: 0.5,
anchorY: 0.5
});
star.x = x + (Math.random() - 0.5) * 200;
star.y = y + (Math.random() - 0.5) * 200;
star.alpha = 0.8;
game.addChild(star);
tween(star, {
scaleX: 2,
scaleY: 2,
alpha: 0,
rotation: Math.PI * 2
}, {
duration: 1000,
easing: tween.easeOut,
onFinish: function onFinish() {
star.destroy();
}
});
}
}
function createConfettiEffect(x, y) {
for (var i = 0; i < 12; i++) {
var confetti = LK.getAsset('confetti', {
anchorX: 0.5,
anchorY: 0.5
});
confetti.x = x + (Math.random() - 0.5) * 300;
confetti.y = y + (Math.random() - 0.5) * 300;
confetti.tint = Math.random() * 0xFFFFFF;
confetti.rotation = Math.random() * Math.PI * 2;
game.addChild(confetti);
tween(confetti, {
scaleX: 1.5,
scaleY: 1.5,
alpha: 0,
y: confetti.y + 400,
rotation: confetti.rotation + Math.PI * 4
}, {
duration: 1500,
easing: tween.easeOut,
onFinish: function onFinish() {
confetti.destroy();
}
});
}
}
function createFireworkEffect(x, y) {
for (var i = 0; i < 20; i++) {
var firework = LK.getAsset('firework', {
anchorX: 0.5,
anchorY: 0.5
});
var angle = i / 20 * Math.PI * 2;
var distance = 300;
firework.x = x;
firework.y = y;
firework.tint = Math.random() * 0xFFFFFF;
firework.scaleX = 0.3;
firework.scaleY = 0.3;
game.addChild(firework);
tween(firework, {
x: x + Math.cos(angle) * distance,
y: y + Math.sin(angle) * distance,
scaleX: 1.2,
scaleY: 1.2,
alpha: 0
}, {
duration: 2000,
easing: tween.easeOut,
onFinish: function onFinish() {
firework.destroy();
}
});
}
}
function startGame() {
gameStarted = true;
gameOver = false;
LK.setScore(0);
// Start background music if enabled
if (musicEnabled) {
LK.playMusic('mascotas');
}
// Animate menu elements disappearing
tween(menuBackground, {
alpha: 0
}, {
duration: 500
});
tween(titleText, {
alpha: 0,
y: 2732 / 2 - 500
}, {
duration: 500
});
// Hide menu elements
startButton.visible = false;
startButtonBg.visible = false;
startButtonShadow.visible = false;
easyButton.visible = false;
mediumButton.visible = false;
hardButton.visible = false;
easyButtonBg.visible = false;
easyButtonShadow.visible = false;
mediumButtonBg.visible = false;
mediumButtonShadow.visible = false;
hardButtonBg.visible = false;
hardButtonShadow.visible = false;
titleText.visible = false;
titleShadow.visible = false;
menuBackground.visible = false;
menuOverlay.visible = false;
// Show game elements with animation
backToMenuButton.visible = true;
backToMenuBg.visible = true;
foodBagContainer.visible = true;
tween(backToMenuButton, {
alpha: 1
}, {
duration: 500
});
tween(backToMenuBg, {
alpha: 1
}, {
duration: 500
});
// Animate in UI containers
tween(foodBagContainer, {
alpha: 1,
scaleX: 1,
scaleY: 1
}, {
duration: 600,
easing: tween.easeOut
});
// Add enhanced game background
var gameBackground = LK.getAsset('gridBackground', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 12,
scaleY: 18,
alpha: 0.15,
tint: 0x2E7D32
});
gameBackground.x = 2048 / 2;
gameBackground.y = 2732 / 2;
game.addChildAt(gameBackground, 0);
initializeGrid();
updateFoodBagDisplay();
}
// Enhanced back to menu functionality with animations
backToMenuButton.down = function (x, y, obj) {
if (!gameStarted || gameOver) return;
tween(backToMenuBg, {
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 150,
onFinish: function onFinish() {
tween(backToMenuBg, {
scaleX: 1.5,
scaleY: 1.5
}, {
duration: 150
});
}
});
tween(backToMenuButton, {
rotation: -0.5
}, {
duration: 150,
onFinish: function onFinish() {
tween(backToMenuButton, {
rotation: 0
}, {
duration: 150
});
}
});
LK.setTimeout(function () {
gameOver = true;
gameStarted = false;
if (gameTimer) LK.clearInterval(gameTimer);
// Clear the entire game grid and backgrounds
clearGrid();
// Animate menu elements appearing
tween(menuBackground, {
alpha: 0.9
}, {
duration: 500
});
tween(menuOverlay, {
alpha: 0.3
}, {
duration: 500
});
tween(titleText, {
alpha: 1,
y: 2732 / 2 - 450
}, {
duration: 500
});
tween(titleShadow, {
alpha: 0.8,
y: 2732 / 2 - 445
}, {
duration: 500
});
// Show menu elements
startButton.visible = true;
startButtonBg.visible = true;
startButtonShadow.visible = true;
easyButton.visible = true;
mediumButton.visible = true;
hardButton.visible = true;
easyButtonBg.visible = true;
easyButtonShadow.visible = true;
mediumButtonBg.visible = true;
mediumButtonShadow.visible = true;
hardButtonBg.visible = true;
hardButtonShadow.visible = true;
titleText.visible = true;
titleShadow.visible = true;
menuBackground.visible = true;
menuOverlay.visible = true;
// Hide game elements
backToMenuButton.visible = false;
backToMenuBg.visible = false;
// Hide UI containers with animation
tween(foodBagContainer, {
alpha: 0,
scaleX: 0.5,
scaleY: 0.5
}, {
duration: 400,
easing: tween.easeIn,
onFinish: function onFinish() {
foodBagContainer.visible = false;
}
});
// Reset game state
LK.setScore(0);
updateFoodBagDisplay();
}, 150);
};
function endGame() {
gameOver = true;
LK.clearInterval(gameTimer);
if (LK.getScore() >= targetScore) {
LK.showYouWin();
} else {
LK.showGameOver();
}
}
// Enhanced difficulty button handlers with animations
easyButton.down = function (x, y, obj) {
// Immediate visual feedback
tween(easyButtonBg, {
scaleX: 3.6,
scaleY: 1.0,
tint: 0x66BB6A
}, {
duration: 100
});
tween(easyButton, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100,
onFinish: function onFinish() {
tween(easyButton, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
tween(easyButtonBg, {
scaleX: 4,
scaleY: 1.2,
tint: 0x4CAF50
}, {
duration: 100
});
}
});
// Faster response time
LK.setTimeout(function () {
difficulty = 'easy';
targetScore = 250000;
updateFoodBagDisplay();
startGame();
}, 120);
};
mediumButton.down = function (x, y, obj) {
// Immediate visual feedback
tween(mediumButtonBg, {
scaleX: 3.6,
scaleY: 1.0,
tint: 0xFFB74D
}, {
duration: 100
});
tween(mediumButton, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100,
onFinish: function onFinish() {
tween(mediumButton, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
tween(mediumButtonBg, {
scaleX: 4,
scaleY: 1.2,
tint: 0xFF9800
}, {
duration: 100
});
}
});
// Faster response time
LK.setTimeout(function () {
difficulty = 'medium';
targetScore = 150000;
updateFoodBagDisplay();
startGame();
}, 120);
};
hardButton.down = function (x, y, obj) {
// Immediate visual feedback
tween(hardButtonBg, {
scaleX: 3.6,
scaleY: 1.0,
tint: 0xEF5350
}, {
duration: 100
});
tween(hardButton, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100,
onFinish: function onFinish() {
tween(hardButton, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
tween(hardButtonBg, {
scaleX: 4,
scaleY: 1.2,
tint: 0xF44336
}, {
duration: 100
});
}
});
// Faster response time
LK.setTimeout(function () {
difficulty = 'hard';
targetScore = 100000;
updateFoodBagDisplay();
startGame();
}, 120);
};
startButton.down = function (x, y, obj) {
// Immediate visual feedback
tween(startButtonBg, {
scaleX: 4.6,
scaleY: 1.3,
tint: 0x1976D2
}, {
duration: 100
});
tween(startButton, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100,
onFinish: function onFinish() {
tween(startButton, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
tween(startButtonBg, {
scaleX: 5,
scaleY: 1.5,
tint: 0x2196F3
}, {
duration: 100
});
}
});
// Faster response time
LK.setTimeout(function () {
startGame();
}, 120);
};
// Music toggle functionality
musicToggleButton.down = function (x, y, obj) {
tween(musicButtonBg, {
scaleX: 1.6,
scaleY: 0.9
}, {
duration: 150,
onFinish: function onFinish() {
tween(musicButtonBg, {
scaleX: 1.8,
scaleY: 1
}, {
duration: 150
});
}
});
if (musicEnabled) {
LK.stopMusic();
musicToggleButton.setText('MUSIC OFF');
musicEnabled = false;
} else {
LK.playMusic('mascotas');
musicToggleButton.setText('MUSIC ON');
musicEnabled = true;
}
};
// Add subtle pulse animations to menu buttons
var pulseTimer = 0;
game.update = function () {
// Game loop runs here
if (!gameStarted && !gameOver) {
pulseTimer += 0.02;
// Pulse effect for buttons
var pulseScale = 1 + Math.sin(pulseTimer) * 0.03;
if (startButton.visible) {
startButton.scaleX = pulseScale;
startButton.scaleY = pulseScale;
}
}
}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var PetTile = Container.expand(function (type, gridX, gridY) {
var self = Container.call(this);
self.type = type;
self.gridX = gridX;
self.gridY = gridY;
self.isSelected = false;
self.isMatched = false;
var tileColors = {
'dog': 0xF4A460,
'cat': 0xFF69B4,
'bird': 0x87CEEB,
'fish': 0x40E0D0,
'hamster': 0xFFDAB9
};
var tileAssets = {
'dog': 'dogTile',
'cat': 'catTile',
'bird': 'birdTile',
'fish': 'fishTile',
'hamster': 'hamsterTile'
};
var tileGraphics = self.attachAsset(tileAssets[type], {
anchorX: 0.5,
anchorY: 0.5
});
self.select = function () {
self.isSelected = true;
tween(tileGraphics, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 200
});
};
self.deselect = function () {
self.isSelected = false;
tween(tileGraphics, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 200
});
};
self.markMatched = function () {
self.isMatched = true;
tween(tileGraphics, {
alpha: 0,
scaleX: 0.1,
scaleY: 0.1
}, {
duration: 300,
onFinish: function onFinish() {
self.destroy();
}
});
};
self.down = function (x, y, obj) {
if (!gameStarted || gameOver) return;
if (selectedTile === null) {
selectedTile = self;
self.select();
} else if (selectedTile === self) {
selectedTile.deselect();
selectedTile = null;
} else {
if (areAdjacent(selectedTile, self)) {
swapTiles(selectedTile, self);
}
selectedTile.deselect();
selectedTile = null;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x90EE90
});
/****
* Game Code
****/
var gridWidth = 6;
var gridHeight = 8;
var tileSize = 220;
var grid = [];
var selectedTile = null;
var gameStarted = false;
var gameOver = false;
var timeLeft = 300;
var difficulty = 'easy';
var targetScore = 250000;
var petTypes = ['dog', 'cat', 'bird', 'fish', 'hamster'];
// Pet store background for menu with gradient effect
var menuBackground = LK.getAsset('petStoreBackground', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.9,
tint: 0xE1BEE7
});
menuBackground.x = 2048 / 2;
menuBackground.y = 2732 / 2;
game.addChild(menuBackground);
// Add overlay for better text contrast
var menuOverlay = LK.getAsset('petStoreBackground', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.3,
tint: 0x1A1A2E
});
menuOverlay.x = 2048 / 2;
menuOverlay.y = 2732 / 2;
game.addChild(menuOverlay);
// Menu title with improved styling
var titleText = new Text2('PET STORE MATCH', {
size: 140,
fill: 0xFFD700
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 2048 / 2;
titleText.y = 2732 / 2 - 450;
game.addChild(titleText);
// Add shadow effect to title
var titleShadow = new Text2('PET STORE MATCH', {
size: 140,
fill: 0x333333
});
titleShadow.anchor.set(0.5, 0.5);
titleShadow.x = 2048 / 2 + 5;
titleShadow.y = 2732 / 2 - 445;
titleShadow.alpha = 0.8;
game.addChildAt(titleShadow, game.children.length - 1);
// Enhanced Food Bag Progress Tracker
var foodBagContainer = new Container();
foodBagContainer.x = 280;
foodBagContainer.y = 180;
foodBagContainer.visible = false;
LK.gui.topLeft.addChild(foodBagContainer);
// Score text for food bag display
var scoreText = new Text2('0 / 250k', {
size: 36,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0.5);
scoreText.x = 0;
scoreText.y = -120;
foodBagContainer.addChild(scoreText);
// Progress text for food bag display
var progressText = new Text2('NEED MORE FOOD!', {
size: 32,
fill: 0xFF6B6B
});
progressText.anchor.set(0.5, 0.5);
progressText.x = 0;
progressText.y = -80;
foodBagContainer.addChild(progressText);
// Food bag background with border
var foodBagBorder = LK.getAsset('gridBackground', {
anchorX: 0.5,
anchorY: 1,
scaleX: 2.2,
scaleY: 2.5,
tint: 0x654321
});
foodBagBorder.alpha = 0.9;
foodBagContainer.addChild(foodBagBorder);
var foodBagBg = LK.getAsset('hamsterTile', {
anchorX: 0.5,
anchorY: 1,
scaleX: 1.8,
scaleY: 2.2,
tint: 0x8B4513
});
foodBagBg.alpha = 0.85;
foodBagContainer.addChild(foodBagBg);
var foodBagFill = LK.getAsset('hamsterTile', {
anchorX: 0.5,
anchorY: 1,
scaleX: 1.6,
scaleY: 0,
tint: 0xFFD700
});
foodBagFill.alpha = 0.9;
foodBagContainer.addChild(foodBagFill);
// Enhanced circular back button with arrow
var backToMenuBg = LK.getAsset('gridBackground', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5,
scaleY: 1.5,
tint: 0x607D8B
});
backToMenuBg.x = -120;
backToMenuBg.y = 100;
backToMenuBg.visible = false;
LK.gui.topRight.addChild(backToMenuBg);
var backToMenuButton = new Text2('↶', {
size: 80,
fill: 0xFFFFFF
});
backToMenuButton.anchor.set(0.5, 0.5);
backToMenuButton.x = -120;
backToMenuButton.y = 100;
backToMenuButton.visible = false;
LK.gui.topRight.addChild(backToMenuButton);
// Music toggle button
var musicButtonBg = LK.getAsset('gridBackground', {
anchorX: 0,
anchorY: 1,
scaleX: 1.8,
scaleY: 1,
tint: 0x9C27B0
});
musicButtonBg.x = 20;
musicButtonBg.y = -100;
LK.gui.bottomLeft.addChild(musicButtonBg);
var musicToggleButton = new Text2('MUSIC ON', {
size: 48,
fill: 0xFFFFFF
});
musicToggleButton.anchor.set(0, 1);
musicToggleButton.x = 20;
musicToggleButton.y = -110;
LK.gui.bottomLeft.addChild(musicToggleButton);
var musicEnabled = true;
// Enhanced start button with background and shadow
var startButtonBg = LK.getAsset('gridBackground', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 5,
scaleY: 1.5,
tint: 0x2196F3
});
startButtonBg.x = 2048 / 2;
startButtonBg.y = 2732 / 2 + 180;
game.addChild(startButtonBg);
var startButtonShadow = LK.getAsset('gridBackground', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 5,
scaleY: 1.5,
tint: 0x0D47A1,
alpha: 0.6
});
startButtonShadow.x = 2048 / 2 + 8;
startButtonShadow.y = 2732 / 2 + 188;
game.addChild(startButtonShadow);
var startButton = new Text2('START GAME', {
size: 120,
fill: 0xFFFFFF
});
startButton.anchor.set(0.5, 0.5);
startButton.x = 2048 / 2;
startButton.y = 2732 / 2 + 180;
game.addChild(startButton);
// Enhanced difficulty buttons with better styling
var easyButtonBg = LK.getAsset('gridBackground', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 4,
scaleY: 1.2,
tint: 0x4CAF50
});
easyButtonBg.x = 2048 / 2;
easyButtonBg.y = 2732 / 2 - 250;
game.addChild(easyButtonBg);
var easyButtonShadow = LK.getAsset('gridBackground', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 4,
scaleY: 1.2,
tint: 0x2E7D32,
alpha: 0.6
});
easyButtonShadow.x = 2048 / 2 + 8;
easyButtonShadow.y = 2732 / 2 - 242;
game.addChild(easyButtonShadow);
var easyButton = new Text2('EASY - Goal: 250k (5min)', {
size: 58,
fill: 0xFFFFFF
});
easyButton.anchor.set(0.5, 0.5);
easyButton.x = 2048 / 2;
easyButton.y = 2732 / 2 - 250;
game.addChild(easyButton);
var mediumButtonBg = LK.getAsset('gridBackground', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 4,
scaleY: 1.2,
tint: 0xFF9800
});
mediumButtonBg.x = 2048 / 2;
mediumButtonBg.y = 2732 / 2 - 120;
game.addChild(mediumButtonBg);
var mediumButtonShadow = LK.getAsset('gridBackground', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 4,
scaleY: 1.2,
tint: 0xE65100,
alpha: 0.6
});
mediumButtonShadow.x = 2048 / 2 + 8;
mediumButtonShadow.y = 2732 / 2 - 112;
game.addChild(mediumButtonShadow);
var mediumButton = new Text2('MEDIUM - Goal: 150k (3min)', {
size: 58,
fill: 0xFFFFFF
});
mediumButton.anchor.set(0.5, 0.5);
mediumButton.x = 2048 / 2;
mediumButton.y = 2732 / 2 - 120;
game.addChild(mediumButton);
var hardButtonBg = LK.getAsset('gridBackground', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 4,
scaleY: 1.2,
tint: 0xF44336
});
hardButtonBg.x = 2048 / 2;
hardButtonBg.y = 2732 / 2 + 10;
game.addChild(hardButtonBg);
var hardButtonShadow = LK.getAsset('gridBackground', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 4,
scaleY: 1.2,
tint: 0xC62828,
alpha: 0.6
});
hardButtonShadow.x = 2048 / 2 + 8;
hardButtonShadow.y = 2732 / 2 + 18;
game.addChild(hardButtonShadow);
var hardButton = new Text2('HARD - Goal: 100k (2min)', {
size: 58,
fill: 0xFFFFFF
});
hardButton.anchor.set(0.5, 0.5);
hardButton.x = 2048 / 2;
hardButton.y = 2732 / 2 + 10;
game.addChild(hardButton);
// Game timer
var gameTimer = null;
var gridBackgroundTiles = [];
function clearGrid() {
// Clear existing grid tiles
for (var i = 0; i < grid.length; i++) {
for (var j = 0; j < grid[i].length; j++) {
if (grid[i][j]) {
grid[i][j].destroy();
}
}
}
grid = [];
// Clear grid background tiles
for (var i = 0; i < gridBackgroundTiles.length; i++) {
if (gridBackgroundTiles[i]) {
gridBackgroundTiles[i].destroy();
}
}
gridBackgroundTiles = [];
}
function initializeGrid() {
clearGrid();
// Random grid layout
var layouts = [{
width: 6,
height: 8
}, {
width: 7,
height: 7
}, {
width: 8,
height: 6
}];
var layout = layouts[Math.floor(Math.random() * layouts.length)];
gridWidth = layout.width;
gridHeight = layout.height;
// Initialize grid array
for (var i = 0; i < gridWidth; i++) {
grid[i] = [];
for (var j = 0; j < gridHeight; j++) {
grid[i][j] = null;
}
}
// Calculate grid position to center it
var gridPixelWidth = gridWidth * tileSize;
var gridPixelHeight = gridHeight * tileSize;
var startX = (2048 - gridPixelWidth) / 2 + tileSize / 2;
var startY = (2732 - gridPixelHeight) / 2 + tileSize / 2;
// Create background tiles only when game starts
for (var i = 0; i < gridWidth; i++) {
for (var j = 0; j < gridHeight; j++) {
var bg = LK.getAsset('gridBackground', {
anchorX: 0.5,
anchorY: 0.5
});
bg.x = startX + i * tileSize;
bg.y = startY + j * tileSize;
bg.alpha = 0.8;
gridBackgroundTiles.push(bg);
game.addChild(bg);
}
}
// Fill grid with random tiles
fillGrid();
}
function fillGrid() {
var gridPixelWidth = gridWidth * tileSize;
var gridPixelHeight = gridHeight * tileSize;
var startX = (2048 - gridPixelWidth) / 2 + tileSize / 2;
var startY = (2732 - gridPixelHeight) / 2 + tileSize / 2;
for (var i = 0; i < gridWidth; i++) {
for (var j = 0; j < gridHeight; j++) {
if (grid[i][j] === null) {
var type = getRandomPetType(i, j);
var tile = new PetTile(type, i, j);
tile.x = startX + i * tileSize;
tile.y = startY + j * tileSize;
grid[i][j] = tile;
game.addChild(tile);
}
}
}
}
function getRandomPetType(x, y) {
var attempts = 0;
var type;
do {
type = petTypes[Math.floor(Math.random() * petTypes.length)];
attempts++;
} while (attempts < 10 && wouldCreateMatch(x, y, type));
return type;
}
function wouldCreateMatch(x, y, type) {
// Check horizontal
var horizontalCount = 1;
// Check left
for (var i = x - 1; i >= 0 && grid[i][y] && grid[i][y].type === type; i--) {
horizontalCount++;
}
// Check right
for (var i = x + 1; i < gridWidth && grid[i][y] && grid[i][y].type === type; i++) {
horizontalCount++;
}
// Check vertical
var verticalCount = 1;
// Check up
for (var j = y - 1; j >= 0 && grid[x][j] && grid[x][j].type === type; j--) {
verticalCount++;
}
// Check down
for (var j = y + 1; j < gridHeight && grid[x][j] && grid[x][j].type === type; j++) {
verticalCount++;
}
return horizontalCount >= 3 || verticalCount >= 3;
}
function areAdjacent(tile1, tile2) {
var dx = Math.abs(tile1.gridX - tile2.gridX);
var dy = Math.abs(tile1.gridY - tile2.gridY);
return dx === 1 && dy === 0 || dx === 0 && dy === 1;
}
function swapTiles(tile1, tile2) {
LK.getSound('swap').play();
// Swap grid positions
var tempX = tile1.gridX;
var tempY = tile1.gridY;
tile1.gridX = tile2.gridX;
tile1.gridY = tile2.gridY;
tile2.gridX = tempX;
tile2.gridY = tempY;
// Swap in grid array
grid[tile1.gridX][tile1.gridY] = tile1;
grid[tile2.gridX][tile2.gridY] = tile2;
// Animate swap
var tile1TargetX = tile1.x;
var tile1TargetY = tile1.y;
var tile2TargetX = tile2.x;
var tile2TargetY = tile2.y;
tween(tile1, {
x: tile2TargetX,
y: tile2TargetY
}, {
duration: 300
});
tween(tile2, {
x: tile1TargetX,
y: tile1TargetY
}, {
duration: 300,
onFinish: function onFinish() {
checkForMatches();
}
});
}
function checkForMatches() {
var matches = findMatches();
if (matches.length > 0) {
LK.getSound('match').play();
// Calculate score and create effects based on match size
var matchScore = 0;
for (var i = 0; i < matches.length; i++) {
var matchSize = matches[i].length;
var match = matches[i];
// Calculate center position of match for effects
var centerX = 0;
var centerY = 0;
for (var k = 0; k < match.length; k++) {
centerX += match[k].x;
centerY += match[k].y;
}
centerX /= match.length;
centerY /= match.length;
if (matchSize === 3) {
matchScore += 1000;
LK.getSound('match3').play();
createStarEffect(centerX, centerY);
} else if (matchSize === 4) {
matchScore += 3000;
LK.getSound('match4').play();
createConfettiEffect(centerX, centerY);
} else if (matchSize >= 5) {
matchScore += 5000;
LK.getSound('match5').play();
createFireworkEffect(centerX, centerY);
}
}
LK.setScore(LK.getScore() + matchScore);
updateFoodBagDisplay();
// Mark matched tiles
for (var i = 0; i < matches.length; i++) {
for (var j = 0; j < matches[i].length; j++) {
var tile = matches[i][j];
tile.markMatched();
grid[tile.gridX][tile.gridY] = null;
}
}
// Wait for animation then refill
LK.setTimeout(function () {
dropTiles();
fillGrid();
LK.setTimeout(function () {
checkForMatches();
}, 300);
}, 300);
}
}
function findMatches() {
var matches = [];
var checked = [];
// Initialize checked array
for (var i = 0; i < gridWidth; i++) {
checked[i] = [];
for (var j = 0; j < gridHeight; j++) {
checked[i][j] = false;
}
}
// Find horizontal matches
for (var j = 0; j < gridHeight; j++) {
for (var i = 0; i < gridWidth - 2; i++) {
if (grid[i][j] && grid[i + 1][j] && grid[i + 2][j] && grid[i][j].type === grid[i + 1][j].type && grid[i][j].type === grid[i + 2][j].type) {
var match = [];
var k = i;
while (k < gridWidth && grid[k][j] && grid[k][j].type === grid[i][j].type) {
if (!checked[k][j]) {
match.push(grid[k][j]);
checked[k][j] = true;
}
k++;
}
if (match.length >= 3) {
matches.push(match);
}
}
}
}
// Find vertical matches
for (var i = 0; i < gridWidth; i++) {
for (var j = 0; j < gridHeight - 2; j++) {
if (grid[i][j] && grid[i][j + 1] && grid[i][j + 2] && grid[i][j].type === grid[i][j + 1].type && grid[i][j].type === grid[i][j + 2].type) {
var match = [];
var k = j;
while (k < gridHeight && grid[i][k] && grid[i][k].type === grid[i][j].type) {
if (!checked[i][k]) {
match.push(grid[i][k]);
checked[i][k] = true;
}
k++;
}
if (match.length >= 3) {
matches.push(match);
}
}
}
}
return matches;
}
function dropTiles() {
for (var i = 0; i < gridWidth; i++) {
var writeIndex = gridHeight - 1;
for (var j = gridHeight - 1; j >= 0; j--) {
if (grid[i][j] !== null) {
if (j !== writeIndex) {
grid[i][writeIndex] = grid[i][j];
grid[i][j] = null;
grid[i][writeIndex].gridY = writeIndex;
var gridPixelWidth = gridWidth * tileSize;
var gridPixelHeight = gridHeight * tileSize;
var startX = (2048 - gridPixelWidth) / 2 + tileSize / 2;
var startY = (2732 - gridPixelHeight) / 2 + tileSize / 2;
var targetY = startY + writeIndex * tileSize;
tween(grid[i][writeIndex], {
y: targetY
}, {
duration: 200
});
}
writeIndex--;
}
}
}
}
function formatTime(seconds) {
var minutes = Math.floor(seconds / 60);
var remainingSeconds = seconds % 60;
return minutes + ':' + (remainingSeconds < 10 ? '0' : '') + remainingSeconds;
}
function updateFoodBagDisplay() {
var currentScore = LK.getScore();
var progress = Math.min(currentScore / targetScore, 1);
// Update food bag fill with smooth animation
tween(foodBagFill, {
scaleY: progress * 2.0
}, {
duration: 500,
easing: tween.easeOut
});
// Update score text with better formatting
var targetText = targetScore >= 1000000 ? (targetScore / 1000000).toFixed(1) + 'M' : targetScore >= 1000 ? targetScore / 1000 + 'k' : targetScore;
var currentText = currentScore >= 1000000 ? (currentScore / 1000000).toFixed(1) + 'M' : currentScore >= 1000 ? Math.floor(currentScore / 1000) + 'k' : currentScore;
scoreText.setText(currentText + ' / ' + targetText);
// Enhanced progress indicator with color transitions
if (progress < 0.3) {
foodBagFill.tint = 0xFF4444;
progressText.setText('NEED MORE FOOD!');
progressText.tint = 0xFF6B6B;
} else if (progress < 0.7) {
foodBagFill.tint = 0xFFAA00;
progressText.setText('GETTING THERE!');
progressText.tint = 0xFFD93D;
} else if (progress < 0.95) {
foodBagFill.tint = 0x44FF44;
progressText.setText('ALMOST FULL!');
progressText.tint = 0x6BCF7F;
} else {
foodBagFill.tint = 0x00FF00;
progressText.setText('GOAL ACHIEVED!');
progressText.tint = 0x4ECDC4;
}
// Pulse effect when close to goal
if (progress > 0.9) {
tween(foodBagContainer, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 200,
onFinish: function onFinish() {
tween(foodBagContainer, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 200
});
}
});
}
}
function createStarEffect(x, y) {
for (var i = 0; i < 6; i++) {
var star = LK.getAsset('star', {
anchorX: 0.5,
anchorY: 0.5
});
star.x = x + (Math.random() - 0.5) * 200;
star.y = y + (Math.random() - 0.5) * 200;
star.alpha = 0.8;
game.addChild(star);
tween(star, {
scaleX: 2,
scaleY: 2,
alpha: 0,
rotation: Math.PI * 2
}, {
duration: 1000,
easing: tween.easeOut,
onFinish: function onFinish() {
star.destroy();
}
});
}
}
function createConfettiEffect(x, y) {
for (var i = 0; i < 12; i++) {
var confetti = LK.getAsset('confetti', {
anchorX: 0.5,
anchorY: 0.5
});
confetti.x = x + (Math.random() - 0.5) * 300;
confetti.y = y + (Math.random() - 0.5) * 300;
confetti.tint = Math.random() * 0xFFFFFF;
confetti.rotation = Math.random() * Math.PI * 2;
game.addChild(confetti);
tween(confetti, {
scaleX: 1.5,
scaleY: 1.5,
alpha: 0,
y: confetti.y + 400,
rotation: confetti.rotation + Math.PI * 4
}, {
duration: 1500,
easing: tween.easeOut,
onFinish: function onFinish() {
confetti.destroy();
}
});
}
}
function createFireworkEffect(x, y) {
for (var i = 0; i < 20; i++) {
var firework = LK.getAsset('firework', {
anchorX: 0.5,
anchorY: 0.5
});
var angle = i / 20 * Math.PI * 2;
var distance = 300;
firework.x = x;
firework.y = y;
firework.tint = Math.random() * 0xFFFFFF;
firework.scaleX = 0.3;
firework.scaleY = 0.3;
game.addChild(firework);
tween(firework, {
x: x + Math.cos(angle) * distance,
y: y + Math.sin(angle) * distance,
scaleX: 1.2,
scaleY: 1.2,
alpha: 0
}, {
duration: 2000,
easing: tween.easeOut,
onFinish: function onFinish() {
firework.destroy();
}
});
}
}
function startGame() {
gameStarted = true;
gameOver = false;
LK.setScore(0);
// Start background music if enabled
if (musicEnabled) {
LK.playMusic('mascotas');
}
// Animate menu elements disappearing
tween(menuBackground, {
alpha: 0
}, {
duration: 500
});
tween(titleText, {
alpha: 0,
y: 2732 / 2 - 500
}, {
duration: 500
});
// Hide menu elements
startButton.visible = false;
startButtonBg.visible = false;
startButtonShadow.visible = false;
easyButton.visible = false;
mediumButton.visible = false;
hardButton.visible = false;
easyButtonBg.visible = false;
easyButtonShadow.visible = false;
mediumButtonBg.visible = false;
mediumButtonShadow.visible = false;
hardButtonBg.visible = false;
hardButtonShadow.visible = false;
titleText.visible = false;
titleShadow.visible = false;
menuBackground.visible = false;
menuOverlay.visible = false;
// Show game elements with animation
backToMenuButton.visible = true;
backToMenuBg.visible = true;
foodBagContainer.visible = true;
tween(backToMenuButton, {
alpha: 1
}, {
duration: 500
});
tween(backToMenuBg, {
alpha: 1
}, {
duration: 500
});
// Animate in UI containers
tween(foodBagContainer, {
alpha: 1,
scaleX: 1,
scaleY: 1
}, {
duration: 600,
easing: tween.easeOut
});
// Add enhanced game background
var gameBackground = LK.getAsset('gridBackground', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 12,
scaleY: 18,
alpha: 0.15,
tint: 0x2E7D32
});
gameBackground.x = 2048 / 2;
gameBackground.y = 2732 / 2;
game.addChildAt(gameBackground, 0);
initializeGrid();
updateFoodBagDisplay();
}
// Enhanced back to menu functionality with animations
backToMenuButton.down = function (x, y, obj) {
if (!gameStarted || gameOver) return;
tween(backToMenuBg, {
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 150,
onFinish: function onFinish() {
tween(backToMenuBg, {
scaleX: 1.5,
scaleY: 1.5
}, {
duration: 150
});
}
});
tween(backToMenuButton, {
rotation: -0.5
}, {
duration: 150,
onFinish: function onFinish() {
tween(backToMenuButton, {
rotation: 0
}, {
duration: 150
});
}
});
LK.setTimeout(function () {
gameOver = true;
gameStarted = false;
if (gameTimer) LK.clearInterval(gameTimer);
// Clear the entire game grid and backgrounds
clearGrid();
// Animate menu elements appearing
tween(menuBackground, {
alpha: 0.9
}, {
duration: 500
});
tween(menuOverlay, {
alpha: 0.3
}, {
duration: 500
});
tween(titleText, {
alpha: 1,
y: 2732 / 2 - 450
}, {
duration: 500
});
tween(titleShadow, {
alpha: 0.8,
y: 2732 / 2 - 445
}, {
duration: 500
});
// Show menu elements
startButton.visible = true;
startButtonBg.visible = true;
startButtonShadow.visible = true;
easyButton.visible = true;
mediumButton.visible = true;
hardButton.visible = true;
easyButtonBg.visible = true;
easyButtonShadow.visible = true;
mediumButtonBg.visible = true;
mediumButtonShadow.visible = true;
hardButtonBg.visible = true;
hardButtonShadow.visible = true;
titleText.visible = true;
titleShadow.visible = true;
menuBackground.visible = true;
menuOverlay.visible = true;
// Hide game elements
backToMenuButton.visible = false;
backToMenuBg.visible = false;
// Hide UI containers with animation
tween(foodBagContainer, {
alpha: 0,
scaleX: 0.5,
scaleY: 0.5
}, {
duration: 400,
easing: tween.easeIn,
onFinish: function onFinish() {
foodBagContainer.visible = false;
}
});
// Reset game state
LK.setScore(0);
updateFoodBagDisplay();
}, 150);
};
function endGame() {
gameOver = true;
LK.clearInterval(gameTimer);
if (LK.getScore() >= targetScore) {
LK.showYouWin();
} else {
LK.showGameOver();
}
}
// Enhanced difficulty button handlers with animations
easyButton.down = function (x, y, obj) {
// Immediate visual feedback
tween(easyButtonBg, {
scaleX: 3.6,
scaleY: 1.0,
tint: 0x66BB6A
}, {
duration: 100
});
tween(easyButton, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100,
onFinish: function onFinish() {
tween(easyButton, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
tween(easyButtonBg, {
scaleX: 4,
scaleY: 1.2,
tint: 0x4CAF50
}, {
duration: 100
});
}
});
// Faster response time
LK.setTimeout(function () {
difficulty = 'easy';
targetScore = 250000;
updateFoodBagDisplay();
startGame();
}, 120);
};
mediumButton.down = function (x, y, obj) {
// Immediate visual feedback
tween(mediumButtonBg, {
scaleX: 3.6,
scaleY: 1.0,
tint: 0xFFB74D
}, {
duration: 100
});
tween(mediumButton, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100,
onFinish: function onFinish() {
tween(mediumButton, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
tween(mediumButtonBg, {
scaleX: 4,
scaleY: 1.2,
tint: 0xFF9800
}, {
duration: 100
});
}
});
// Faster response time
LK.setTimeout(function () {
difficulty = 'medium';
targetScore = 150000;
updateFoodBagDisplay();
startGame();
}, 120);
};
hardButton.down = function (x, y, obj) {
// Immediate visual feedback
tween(hardButtonBg, {
scaleX: 3.6,
scaleY: 1.0,
tint: 0xEF5350
}, {
duration: 100
});
tween(hardButton, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100,
onFinish: function onFinish() {
tween(hardButton, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
tween(hardButtonBg, {
scaleX: 4,
scaleY: 1.2,
tint: 0xF44336
}, {
duration: 100
});
}
});
// Faster response time
LK.setTimeout(function () {
difficulty = 'hard';
targetScore = 100000;
updateFoodBagDisplay();
startGame();
}, 120);
};
startButton.down = function (x, y, obj) {
// Immediate visual feedback
tween(startButtonBg, {
scaleX: 4.6,
scaleY: 1.3,
tint: 0x1976D2
}, {
duration: 100
});
tween(startButton, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100,
onFinish: function onFinish() {
tween(startButton, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
tween(startButtonBg, {
scaleX: 5,
scaleY: 1.5,
tint: 0x2196F3
}, {
duration: 100
});
}
});
// Faster response time
LK.setTimeout(function () {
startGame();
}, 120);
};
// Music toggle functionality
musicToggleButton.down = function (x, y, obj) {
tween(musicButtonBg, {
scaleX: 1.6,
scaleY: 0.9
}, {
duration: 150,
onFinish: function onFinish() {
tween(musicButtonBg, {
scaleX: 1.8,
scaleY: 1
}, {
duration: 150
});
}
});
if (musicEnabled) {
LK.stopMusic();
musicToggleButton.setText('MUSIC OFF');
musicEnabled = false;
} else {
LK.playMusic('mascotas');
musicToggleButton.setText('MUSIC ON');
musicEnabled = true;
}
};
// Add subtle pulse animations to menu buttons
var pulseTimer = 0;
game.update = function () {
// Game loop runs here
if (!gameStarted && !gameOver) {
pulseTimer += 0.02;
// Pulse effect for buttons
var pulseScale = 1 + Math.sin(pulseTimer) * 0.03;
if (startButton.visible) {
startButton.scaleX = pulseScale;
startButton.scaleY = pulseScale;
}
}
};
Mantén este estilo de diseño, pero en lugar de ser el rostro de un gato, que sea el de un perico verde de pico amarillo.
Mantén este mismo estilo, pero has que el perro sea de color azul con manchas blancas.
Mejora este diseño de hámster
Crea un patrón de estampado de comida de anímale, como pescado, huesos, semillas, con un color rojo y blanco