/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var ColorButton = Container.expand(function (buttonId, assetId, soundId, x, y) {
var self = Container.call(this);
self.buttonId = buttonId;
self.soundId = soundId;
self.isActive = false;
self.originalAlpha = 0.7;
self.activeAlpha = 1.0;
var buttonGraphics = self.attachAsset(assetId, {
anchorX: 0.5,
anchorY: 0.5,
alpha: self.originalAlpha
});
self.x = x;
self.y = y;
self.activate = function () {
self.isActive = true;
buttonGraphics.alpha = self.activeAlpha;
LK.getSound(self.soundId).play();
LK.setTimeout(function () {
self.deactivate();
}, 400);
};
self.deactivate = function () {
self.isActive = false;
buttonGraphics.alpha = self.originalAlpha;
};
self.flash = function () {
tween(buttonGraphics, {
alpha: 1.0,
tint: 0xFFFFFF
}, {
duration: 200,
onFinish: function onFinish() {
tween(buttonGraphics, {
alpha: self.originalAlpha,
tint: 0xFFFFFF
}, {
duration: 200
});
}
});
};
self.down = function (x, y, obj) {
if (gameState === 'input' && !inputLocked) {
self.activate();
handlePlayerInput(self.buttonId);
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2c3e50
});
/****
* Game Code
****/
var gameState = 'ready'; // 'ready', 'showing', 'input', 'gameover'
var sequence = [];
var playerInput = [];
var currentLevel = 1;
var showingIndex = 0;
var inputLocked = false;
// Create buttons
var buttons = [];
var buttonPositions = [{
x: 2048 / 2 - 160,
y: 2732 / 2 - 160
}, {
x: 2048 / 2 + 160,
y: 2732 / 2 - 160
}, {
x: 2048 / 2 - 160,
y: 2732 / 2 + 160
}, {
x: 2048 / 2 + 160,
y: 2732 / 2 + 160
}];
for (var i = 0; i < 4; i++) {
var button = new ColorButton(i, 'button' + (i + 1), 'tone' + (i + 1), buttonPositions[i].x, buttonPositions[i].y);
buttons.push(button);
game.addChild(button);
}
// Add rounded square board behind buttons
var roundBoard = game.attachAsset('roundBoard', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.8
});
roundBoard.x = 2048 / 2;
roundBoard.y = 2732 / 2;
// Move board to back so buttons appear on top
game.setChildIndex(roundBoard, 0);
// UI Elements
var titleText = new Text2('What Is The Code', {
size: 120,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 2048 / 2;
titleText.y = 300;
game.addChild(titleText);
var instructionText = new Text2('Watch the pattern, then repeat it!', {
size: 60,
fill: 0xBDC3C7
});
instructionText.anchor.set(0.5, 0.5);
instructionText.x = 2048 / 2;
instructionText.y = 400;
game.addChild(instructionText);
var levelText = new Text2('Level: 1', {
size: 80,
fill: 0xE74C3C
});
levelText.anchor.set(0.5, 0.5);
levelText.x = 2048 / 2;
levelText.y = 2200;
game.addChild(levelText);
var scoreText = new Text2('Score: 0', {
size: 80,
fill: 0xF39C12
});
scoreText.anchor.set(0.5, 0);
scoreText.x = 2048 / 2;
scoreText.y = 100;
LK.gui.top.addChild(scoreText);
// Game Logic Functions
function startNewLevel() {
gameState = 'ready';
playerInput = [];
// Add new random button to sequence
var randomButton = Math.floor(Math.random() * 4);
sequence.push(randomButton);
levelText.setText('Level: ' + currentLevel);
instructionText.setText('Watch carefully...');
LK.setTimeout(function () {
showSequence();
}, 1000);
}
function showSequence() {
gameState = 'showing';
showingIndex = 0;
inputLocked = true;
showNextInSequence();
}
function showNextInSequence() {
if (showingIndex < sequence.length) {
var buttonIndex = sequence[showingIndex];
buttons[buttonIndex].activate();
showingIndex++;
LK.setTimeout(function () {
showNextInSequence();
}, 800);
} else {
// Sequence shown, wait for player input
gameState = 'input';
inputLocked = false;
instructionText.setText('Your turn!');
}
}
function handlePlayerInput(buttonId) {
playerInput.push(buttonId);
// Check if input matches sequence so far
var currentIndex = playerInput.length - 1;
if (playerInput[currentIndex] !== sequence[currentIndex]) {
// Wrong input
gameWrong();
return;
}
// Check if sequence is complete
if (playerInput.length === sequence.length) {
// Correct sequence completed
gameCorrect();
}
}
function gameCorrect() {
inputLocked = true;
LK.getSound('success').play();
LK.setScore(LK.getScore() + currentLevel * 10);
scoreText.setText('Score: ' + LK.getScore());
instructionText.setText('Correct! Next level...');
// Flash all buttons green
for (var i = 0; i < buttons.length; i++) {
buttons[i].flash();
}
currentLevel++;
LK.setTimeout(function () {
startNewLevel();
}, 1500);
}
function gameWrong() {
inputLocked = true;
gameState = 'gameover';
LK.getSound('error').play();
instructionText.setText('Wrong! Game Over');
// Flash screen red
LK.effects.flashScreen(0xff0000, 1000);
LK.setTimeout(function () {
LK.showGameOver();
}, 2000);
}
// Start the game
LK.setTimeout(function () {
instructionText.setText('Get ready...');
LK.setTimeout(function () {
startNewLevel();
}, 1000);
}, 2000);
game.update = function () {
// Update score display
scoreText.setText('Score: ' + LK.getScore());
}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var ColorButton = Container.expand(function (buttonId, assetId, soundId, x, y) {
var self = Container.call(this);
self.buttonId = buttonId;
self.soundId = soundId;
self.isActive = false;
self.originalAlpha = 0.7;
self.activeAlpha = 1.0;
var buttonGraphics = self.attachAsset(assetId, {
anchorX: 0.5,
anchorY: 0.5,
alpha: self.originalAlpha
});
self.x = x;
self.y = y;
self.activate = function () {
self.isActive = true;
buttonGraphics.alpha = self.activeAlpha;
LK.getSound(self.soundId).play();
LK.setTimeout(function () {
self.deactivate();
}, 400);
};
self.deactivate = function () {
self.isActive = false;
buttonGraphics.alpha = self.originalAlpha;
};
self.flash = function () {
tween(buttonGraphics, {
alpha: 1.0,
tint: 0xFFFFFF
}, {
duration: 200,
onFinish: function onFinish() {
tween(buttonGraphics, {
alpha: self.originalAlpha,
tint: 0xFFFFFF
}, {
duration: 200
});
}
});
};
self.down = function (x, y, obj) {
if (gameState === 'input' && !inputLocked) {
self.activate();
handlePlayerInput(self.buttonId);
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2c3e50
});
/****
* Game Code
****/
var gameState = 'ready'; // 'ready', 'showing', 'input', 'gameover'
var sequence = [];
var playerInput = [];
var currentLevel = 1;
var showingIndex = 0;
var inputLocked = false;
// Create buttons
var buttons = [];
var buttonPositions = [{
x: 2048 / 2 - 160,
y: 2732 / 2 - 160
}, {
x: 2048 / 2 + 160,
y: 2732 / 2 - 160
}, {
x: 2048 / 2 - 160,
y: 2732 / 2 + 160
}, {
x: 2048 / 2 + 160,
y: 2732 / 2 + 160
}];
for (var i = 0; i < 4; i++) {
var button = new ColorButton(i, 'button' + (i + 1), 'tone' + (i + 1), buttonPositions[i].x, buttonPositions[i].y);
buttons.push(button);
game.addChild(button);
}
// Add rounded square board behind buttons
var roundBoard = game.attachAsset('roundBoard', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.8
});
roundBoard.x = 2048 / 2;
roundBoard.y = 2732 / 2;
// Move board to back so buttons appear on top
game.setChildIndex(roundBoard, 0);
// UI Elements
var titleText = new Text2('What Is The Code', {
size: 120,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 2048 / 2;
titleText.y = 300;
game.addChild(titleText);
var instructionText = new Text2('Watch the pattern, then repeat it!', {
size: 60,
fill: 0xBDC3C7
});
instructionText.anchor.set(0.5, 0.5);
instructionText.x = 2048 / 2;
instructionText.y = 400;
game.addChild(instructionText);
var levelText = new Text2('Level: 1', {
size: 80,
fill: 0xE74C3C
});
levelText.anchor.set(0.5, 0.5);
levelText.x = 2048 / 2;
levelText.y = 2200;
game.addChild(levelText);
var scoreText = new Text2('Score: 0', {
size: 80,
fill: 0xF39C12
});
scoreText.anchor.set(0.5, 0);
scoreText.x = 2048 / 2;
scoreText.y = 100;
LK.gui.top.addChild(scoreText);
// Game Logic Functions
function startNewLevel() {
gameState = 'ready';
playerInput = [];
// Add new random button to sequence
var randomButton = Math.floor(Math.random() * 4);
sequence.push(randomButton);
levelText.setText('Level: ' + currentLevel);
instructionText.setText('Watch carefully...');
LK.setTimeout(function () {
showSequence();
}, 1000);
}
function showSequence() {
gameState = 'showing';
showingIndex = 0;
inputLocked = true;
showNextInSequence();
}
function showNextInSequence() {
if (showingIndex < sequence.length) {
var buttonIndex = sequence[showingIndex];
buttons[buttonIndex].activate();
showingIndex++;
LK.setTimeout(function () {
showNextInSequence();
}, 800);
} else {
// Sequence shown, wait for player input
gameState = 'input';
inputLocked = false;
instructionText.setText('Your turn!');
}
}
function handlePlayerInput(buttonId) {
playerInput.push(buttonId);
// Check if input matches sequence so far
var currentIndex = playerInput.length - 1;
if (playerInput[currentIndex] !== sequence[currentIndex]) {
// Wrong input
gameWrong();
return;
}
// Check if sequence is complete
if (playerInput.length === sequence.length) {
// Correct sequence completed
gameCorrect();
}
}
function gameCorrect() {
inputLocked = true;
LK.getSound('success').play();
LK.setScore(LK.getScore() + currentLevel * 10);
scoreText.setText('Score: ' + LK.getScore());
instructionText.setText('Correct! Next level...');
// Flash all buttons green
for (var i = 0; i < buttons.length; i++) {
buttons[i].flash();
}
currentLevel++;
LK.setTimeout(function () {
startNewLevel();
}, 1500);
}
function gameWrong() {
inputLocked = true;
gameState = 'gameover';
LK.getSound('error').play();
instructionText.setText('Wrong! Game Over');
// Flash screen red
LK.effects.flashScreen(0xff0000, 1000);
LK.setTimeout(function () {
LK.showGameOver();
}, 2000);
}
// Start the game
LK.setTimeout(function () {
instructionText.setText('Get ready...');
LK.setTimeout(function () {
startNewLevel();
}, 1000);
}, 2000);
game.update = function () {
// Update score display
scoreText.setText('Score: ' + LK.getScore());
};
red circle button. In-Game asset. 2d. High contrast. No shadows
green circle button. In-Game asset. 2d. High contrast. No shadows
yellow circle button. In-Game asset. 2d. High contrast. No shadows
blue circle button. In-Game asset. 2d. High contrast. No shadows
make round square back. In-Game asset. 2d. High contrast. No shadows