/**** * Classes ****/ // Class for the cat image var Cat = Container.expand(function () { var self = Container.call(this); var catGraphics = self.attachAsset('cat1', { anchorX: 0.5, anchorY: 0.5 }); }); // Class for the level counter var LevelCounter = Container.expand(function () { var self = Container.call(this); var levelText = new Text2('Level: 1', { size: 150, fill: 0xFFFFFF, align: 'center' }); self.addChild(levelText); self.updateLevel = function (level) { levelText.setText('Level: ' + level); }; }); //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Class for a single square var Square = Container.expand(function () { var self = Container.call(this); var squareGraphics = self.attachAsset('square', { anchorX: 0.5, anchorY: 0.5, scaleX: 2, scaleY: 2 }); self.highlight = function () { squareGraphics.tint = 0xff0000; // Change color to red }; self.reset = function () { squareGraphics.tint = 0xffffff; // Reset color to white }; self.clicked = function () { squareGraphics.tint = 0x00ff00; // Change color to green when clicked }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ var background = game.attachAsset('background', { anchorX: 0.0, anchorY: 0.0 }); // Add the cat image to the game var cat = game.addChild(new Cat()); cat.x = 500; // Move the cat to the right cat.y = 2732 - cat.height * 3; // Increase the cat's size cat.scaleX = 4.5; // Increase the cat's size by 1.5 times cat.scaleY = 4.5; // Increase the cat's size by 1.5 times // Initialize the level counter and add it to the game var levelCounter = new LevelCounter(); levelCounter.x = 2048 / 2 - 260; // Move the level counter a bit more to the right levelCounter.y = 100; game.addChild(levelCounter); var grid = []; var sequence = []; var currentLevel = 1; var currentStep = 0; var gridSize = { rows: 4, cols: 5 }; var squareSize = { width: 350, height: 350 }; var gridOffset = { x: (2048 - gridSize.cols * squareSize.width) / 2 + 180, y: (2732 - gridSize.rows * squareSize.height) / 2 + 50 }; // Initialize grid for (var row = 0; row < gridSize.rows; row++) { grid[row] = []; for (var col = 0; col < gridSize.cols; col++) { var square = new Square(); square.x = gridOffset.x + col * squareSize.width; square.y = gridOffset.y + row * squareSize.height; grid[row][col] = square; game.addChild(square); } } // Function to start a new level function startLevel() { sequence.push({ row: Math.floor(Math.random() * gridSize.rows), col: Math.floor(Math.random() * gridSize.cols) }); // Change the cat image every 3 levels if (currentLevel % 3 === 0) { var catNumber = Math.floor(Math.random() * 6) + 1; cat.removeChildren(); // Remove the old cat image cat.attachAsset('cat' + catNumber, { anchorX: 0.5, anchorY: 0.5 }); } currentStep = 0; levelCounter.updateLevel(currentLevel); // Update the level counter showSequence(); } // Function to show the sequence to the player function showSequence() { if (currentStep < sequence.length) { var pos = sequence[currentStep]; grid[pos.row][pos.col].highlight(); LK.setTimeout(function () { grid[pos.row][pos.col].reset(); currentStep++; showSequence(); }, 500); } else { currentStep = 0; } } // Function to handle player's input function handleInput(row, col) { if (sequence[currentStep].row === row && sequence[currentStep].col === col) { if (currentStep > 0) { var prevPos = sequence[currentStep - 1]; grid[prevPos.row][prevPos.col].reset(); } grid[row][col].clicked(); currentStep++; if (currentStep === sequence.length) { currentLevel++; startLevel(); } } else { LK.showGameOver(); } } // Attach event listeners to each square for (var row = 0; row < gridSize.rows; row++) { for (var col = 0; col < gridSize.cols; col++) { (function (r, c) { grid[r][c].down = function () { handleInput(r, c); LK.getSound('click').play(); }; })(row, col); } } // Start the first level startLevel(); // Play 'nature' music in the background on a loop LK.playMusic('nature', { loop: true });
/****
* Classes
****/
// Class for the cat image
var Cat = Container.expand(function () {
var self = Container.call(this);
var catGraphics = self.attachAsset('cat1', {
anchorX: 0.5,
anchorY: 0.5
});
});
// Class for the level counter
var LevelCounter = Container.expand(function () {
var self = Container.call(this);
var levelText = new Text2('Level: 1', {
size: 150,
fill: 0xFFFFFF,
align: 'center'
});
self.addChild(levelText);
self.updateLevel = function (level) {
levelText.setText('Level: ' + level);
};
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Class for a single square
var Square = Container.expand(function () {
var self = Container.call(this);
var squareGraphics = self.attachAsset('square', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2,
scaleY: 2
});
self.highlight = function () {
squareGraphics.tint = 0xff0000; // Change color to red
};
self.reset = function () {
squareGraphics.tint = 0xffffff; // Reset color to white
};
self.clicked = function () {
squareGraphics.tint = 0x00ff00; // Change color to green when clicked
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
var background = game.attachAsset('background', {
anchorX: 0.0,
anchorY: 0.0
});
// Add the cat image to the game
var cat = game.addChild(new Cat());
cat.x = 500; // Move the cat to the right
cat.y = 2732 - cat.height * 3; // Increase the cat's size
cat.scaleX = 4.5; // Increase the cat's size by 1.5 times
cat.scaleY = 4.5; // Increase the cat's size by 1.5 times
// Initialize the level counter and add it to the game
var levelCounter = new LevelCounter();
levelCounter.x = 2048 / 2 - 260; // Move the level counter a bit more to the right
levelCounter.y = 100;
game.addChild(levelCounter);
var grid = [];
var sequence = [];
var currentLevel = 1;
var currentStep = 0;
var gridSize = {
rows: 4,
cols: 5
};
var squareSize = {
width: 350,
height: 350
};
var gridOffset = {
x: (2048 - gridSize.cols * squareSize.width) / 2 + 180,
y: (2732 - gridSize.rows * squareSize.height) / 2 + 50
};
// Initialize grid
for (var row = 0; row < gridSize.rows; row++) {
grid[row] = [];
for (var col = 0; col < gridSize.cols; col++) {
var square = new Square();
square.x = gridOffset.x + col * squareSize.width;
square.y = gridOffset.y + row * squareSize.height;
grid[row][col] = square;
game.addChild(square);
}
}
// Function to start a new level
function startLevel() {
sequence.push({
row: Math.floor(Math.random() * gridSize.rows),
col: Math.floor(Math.random() * gridSize.cols)
});
// Change the cat image every 3 levels
if (currentLevel % 3 === 0) {
var catNumber = Math.floor(Math.random() * 6) + 1;
cat.removeChildren(); // Remove the old cat image
cat.attachAsset('cat' + catNumber, {
anchorX: 0.5,
anchorY: 0.5
});
}
currentStep = 0;
levelCounter.updateLevel(currentLevel); // Update the level counter
showSequence();
}
// Function to show the sequence to the player
function showSequence() {
if (currentStep < sequence.length) {
var pos = sequence[currentStep];
grid[pos.row][pos.col].highlight();
LK.setTimeout(function () {
grid[pos.row][pos.col].reset();
currentStep++;
showSequence();
}, 500);
} else {
currentStep = 0;
}
}
// Function to handle player's input
function handleInput(row, col) {
if (sequence[currentStep].row === row && sequence[currentStep].col === col) {
if (currentStep > 0) {
var prevPos = sequence[currentStep - 1];
grid[prevPos.row][prevPos.col].reset();
}
grid[row][col].clicked();
currentStep++;
if (currentStep === sequence.length) {
currentLevel++;
startLevel();
}
} else {
LK.showGameOver();
}
}
// Attach event listeners to each square
for (var row = 0; row < gridSize.rows; row++) {
for (var col = 0; col < gridSize.cols; col++) {
(function (r, c) {
grid[r][c].down = function () {
handleInput(r, c);
LK.getSound('click').play();
};
})(row, col);
}
}
// Start the first level
startLevel();
// Play 'nature' music in the background on a loop
LK.playMusic('nature', {
loop: true
});