Code edit (1 edits merged)
Please save this source code
User prompt
Color Command Rush
Initial prompt
Make a bop it knock off that says colors red green and blue and you have to tap it within 5 seconds if you get it wrong then you lose and you have to restart. You can also put it on practice mode where it has a streak and if you lose you lose the streak but not the game
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var ColorButton = Container.expand(function (color, colorHex) {
var self = Container.call(this);
self.color = color;
self.colorHex = colorHex;
var buttonGraphics = self.attachAsset(color + 'Button', {
anchorX: 0.5,
anchorY: 0.5
});
self.originalScale = 1.0;
self.pressedScale = 0.9;
self.press = function () {
tween(buttonGraphics, {
scaleX: self.pressedScale,
scaleY: self.pressedScale
}, {
duration: 100
});
tween(buttonGraphics, {
scaleX: self.originalScale,
scaleY: self.originalScale
}, {
duration: 100
});
};
self.down = function (x, y, obj) {
self.press();
if (gameState === 'playing') {
checkAnswer(self.color);
}
};
return self;
});
var ModeButton = Container.expand(function (mode, text) {
var self = Container.call(this);
self.mode = mode;
var buttonBg = self.attachAsset('modeButton', {
anchorX: 0.5,
anchorY: 0.5
});
var buttonText = new Text2(text, {
size: 60,
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.down = function (x, y, obj) {
selectMode(self.mode);
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x111111
});
/****
* Game Code
****/
var gameState = 'modeSelect'; // 'modeSelect', 'playing', 'gameOver'
var gameMode = ''; // 'classic' or 'practice'
var currentColor = '';
var score = 0;
var streak = 0;
var timeRemaining = 5.0;
var commandTimer = null;
var countdownTimer = null;
var colors = ['red', 'green', 'blue'];
var colorHexes = {
red: 0xFF0000,
green: 0x00FF00,
blue: 0x0000FF
};
// UI Elements
var scoreTxt, streakTxt, commandTxt, timerTxt;
var redButton, greenButton, blueButton;
var classicModeButton, practiceModeButton;
var timerBar, timerBarBg;
var modeSelectContainer, gameContainer;
// Initialize UI
function initializeUI() {
// Mode selection screen
modeSelectContainer = game.addChild(new Container());
var titleText = new Text2('Color Command Rush', {
size: 100,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 1024;
titleText.y = 800;
modeSelectContainer.addChild(titleText);
var instructionText = new Text2('Choose Your Mode:', {
size: 60,
fill: 0xCCCCCC
});
instructionText.anchor.set(0.5, 0.5);
instructionText.x = 1024;
instructionText.y = 1000;
modeSelectContainer.addChild(instructionText);
classicModeButton = modeSelectContainer.addChild(new ModeButton('classic', 'CLASSIC MODE'));
classicModeButton.x = 1024;
classicModeButton.y = 1300;
practiceModeButton = modeSelectContainer.addChild(new ModeButton('practice', 'PRACTICE MODE'));
practiceModeButton.x = 1024;
practiceModeButton.y = 1500;
var classicDesc = new Text2('Any mistake ends the game!', {
size: 40,
fill: 0xFF8888
});
classicDesc.anchor.set(0.5, 0.5);
classicDesc.x = 1024;
classicDesc.y = 1380;
modeSelectContainer.addChild(classicDesc);
var practiceDesc = new Text2('Build streaks, keep playing!', {
size: 40,
fill: 0x88FF88
});
practiceDesc.anchor.set(0.5, 0.5);
practiceDesc.x = 1024;
practiceDesc.y = 1580;
modeSelectContainer.addChild(practiceDesc);
// Game screen
gameContainer = game.addChild(new Container());
gameContainer.visible = false;
// Score display
scoreTxt = new Text2('Score: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
scoreTxt.y = 100;
// Streak display (for practice mode)
streakTxt = new Text2('Streak: 0', {
size: 60,
fill: 0xFFDD00
});
streakTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(streakTxt);
streakTxt.x = -20;
streakTxt.y = 200;
streakTxt.visible = false;
// Command display
commandTxt = new Text2('Get Ready!', {
size: 120,
fill: 0xFFFFFF
});
commandTxt.anchor.set(0.5, 0.5);
commandTxt.x = 1024;
commandTxt.y = 800;
gameContainer.addChild(commandTxt);
// Timer display
timerTxt = new Text2('5.0', {
size: 100,
fill: 0xFFFFFF
});
timerTxt.anchor.set(0.5, 0.5);
timerTxt.x = 1024;
timerTxt.y = 1000;
gameContainer.addChild(timerTxt);
// Timer bar background
timerBarBg = LK.getAsset('timerBar', {
anchorX: 0.5,
anchorY: 0.5,
tint: 0x333333
});
timerBarBg.x = 1024;
timerBarBg.y = 1150;
gameContainer.addChild(timerBarBg);
// Timer bar
timerBar = LK.getAsset('timerBar', {
anchorX: 0,
anchorY: 0.5
});
timerBar.x = 1024 - 900;
timerBar.y = 1150;
gameContainer.addChild(timerBar);
// Color buttons
redButton = gameContainer.addChild(new ColorButton('red', 0xFF0000));
redButton.x = 400;
redButton.y = 1800;
greenButton = gameContainer.addChild(new ColorButton('green', 0x00FF00));
greenButton.x = 1024;
greenButton.y = 1800;
blueButton = gameContainer.addChild(new ColorButton('blue', 0x0000FF));
blueButton.x = 1648;
blueButton.y = 1800;
}
function selectMode(mode) {
gameMode = mode;
gameState = 'playing';
score = 0;
streak = 0;
modeSelectContainer.visible = false;
gameContainer.visible = true;
if (gameMode === 'practice') {
streakTxt.visible = true;
}
updateScore();
updateStreak();
// Start first command after a short delay
LK.setTimeout(function () {
nextCommand();
}, 1000);
}
function nextCommand() {
if (gameState !== 'playing') return;
// Select random color
currentColor = colors[Math.floor(Math.random() * colors.length)];
// Update command text
commandTxt.setText(currentColor.toUpperCase() + '!');
commandTxt.tint = colorHexes[currentColor];
// Play voice command
LK.getSound('voice' + currentColor.charAt(0).toUpperCase() + currentColor.slice(1)).play();
// Reset timer
timeRemaining = 5.0;
updateTimer();
// Start countdown
if (countdownTimer) LK.clearInterval(countdownTimer);
countdownTimer = LK.setInterval(function () {
timeRemaining -= 0.1;
updateTimer();
if (timeRemaining <= 0) {
timeRemaining = 0;
updateTimer();
handleTimeout();
}
}, 100);
}
function updateTimer() {
timerTxt.setText(timeRemaining.toFixed(1));
// Update timer bar
var percentage = timeRemaining / 5.0;
timerBar.width = 1800 * percentage;
// Change color based on time remaining
if (timeRemaining > 3) {
timerBar.tint = 0x00FF00; // Green
} else if (timeRemaining > 1) {
timerBar.tint = 0xFFFF00; // Yellow
} else {
timerBar.tint = 0xFF0000; // Red
}
}
function checkAnswer(buttonColor) {
if (gameState !== 'playing') return;
LK.clearInterval(countdownTimer);
if (buttonColor === currentColor) {
// Correct answer
score++;
streak++;
updateScore();
updateStreak();
LK.getSound('correct').play();
// Flash screen green briefly
LK.effects.flashScreen(0x00FF00, 300);
// Next command after brief delay
LK.setTimeout(function () {
nextCommand();
}, 1000);
} else {
// Wrong answer
handleWrongAnswer();
}
}
function handleTimeout() {
LK.clearInterval(countdownTimer);
LK.getSound('timeout').play();
handleWrongAnswer();
}
function handleWrongAnswer() {
if (gameMode === 'classic') {
// Game over in classic mode
LK.effects.flashScreen(0xFF0000, 1000);
LK.setTimeout(function () {
LK.showGameOver();
}, 1000);
} else {
// Practice mode - reset streak but continue
streak = 0;
updateStreak();
LK.getSound('incorrect').play();
LK.effects.flashScreen(0xFF0000, 500);
// Continue with next command
LK.setTimeout(function () {
nextCommand();
}, 1500);
}
}
function updateScore() {
scoreTxt.setText('Score: ' + score);
LK.setScore(score);
}
function updateStreak() {
if (gameMode === 'practice') {
streakTxt.setText('Streak: ' + streak);
}
}
// Initialize everything
initializeUI();
game.update = function () {
// No continuous updates needed for this game
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,313 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+var storage = LK.import("@upit/storage.v1");
+
+/****
+* Classes
+****/
+var ColorButton = Container.expand(function (color, colorHex) {
+ var self = Container.call(this);
+ self.color = color;
+ self.colorHex = colorHex;
+ var buttonGraphics = self.attachAsset(color + 'Button', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.originalScale = 1.0;
+ self.pressedScale = 0.9;
+ self.press = function () {
+ tween(buttonGraphics, {
+ scaleX: self.pressedScale,
+ scaleY: self.pressedScale
+ }, {
+ duration: 100
+ });
+ tween(buttonGraphics, {
+ scaleX: self.originalScale,
+ scaleY: self.originalScale
+ }, {
+ duration: 100
+ });
+ };
+ self.down = function (x, y, obj) {
+ self.press();
+ if (gameState === 'playing') {
+ checkAnswer(self.color);
+ }
+ };
+ return self;
+});
+var ModeButton = Container.expand(function (mode, text) {
+ var self = Container.call(this);
+ self.mode = mode;
+ var buttonBg = self.attachAsset('modeButton', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var buttonText = new Text2(text, {
+ size: 60,
+ fill: 0xFFFFFF
+ });
+ buttonText.anchor.set(0.5, 0.5);
+ self.addChild(buttonText);
+ self.down = function (x, y, obj) {
+ selectMode(self.mode);
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x111111
+});
+
+/****
+* Game Code
+****/
+var gameState = 'modeSelect'; // 'modeSelect', 'playing', 'gameOver'
+var gameMode = ''; // 'classic' or 'practice'
+var currentColor = '';
+var score = 0;
+var streak = 0;
+var timeRemaining = 5.0;
+var commandTimer = null;
+var countdownTimer = null;
+var colors = ['red', 'green', 'blue'];
+var colorHexes = {
+ red: 0xFF0000,
+ green: 0x00FF00,
+ blue: 0x0000FF
+};
+// UI Elements
+var scoreTxt, streakTxt, commandTxt, timerTxt;
+var redButton, greenButton, blueButton;
+var classicModeButton, practiceModeButton;
+var timerBar, timerBarBg;
+var modeSelectContainer, gameContainer;
+// Initialize UI
+function initializeUI() {
+ // Mode selection screen
+ modeSelectContainer = game.addChild(new Container());
+ var titleText = new Text2('Color Command Rush', {
+ size: 100,
+ fill: 0xFFFFFF
+ });
+ titleText.anchor.set(0.5, 0.5);
+ titleText.x = 1024;
+ titleText.y = 800;
+ modeSelectContainer.addChild(titleText);
+ var instructionText = new Text2('Choose Your Mode:', {
+ size: 60,
+ fill: 0xCCCCCC
+ });
+ instructionText.anchor.set(0.5, 0.5);
+ instructionText.x = 1024;
+ instructionText.y = 1000;
+ modeSelectContainer.addChild(instructionText);
+ classicModeButton = modeSelectContainer.addChild(new ModeButton('classic', 'CLASSIC MODE'));
+ classicModeButton.x = 1024;
+ classicModeButton.y = 1300;
+ practiceModeButton = modeSelectContainer.addChild(new ModeButton('practice', 'PRACTICE MODE'));
+ practiceModeButton.x = 1024;
+ practiceModeButton.y = 1500;
+ var classicDesc = new Text2('Any mistake ends the game!', {
+ size: 40,
+ fill: 0xFF8888
+ });
+ classicDesc.anchor.set(0.5, 0.5);
+ classicDesc.x = 1024;
+ classicDesc.y = 1380;
+ modeSelectContainer.addChild(classicDesc);
+ var practiceDesc = new Text2('Build streaks, keep playing!', {
+ size: 40,
+ fill: 0x88FF88
+ });
+ practiceDesc.anchor.set(0.5, 0.5);
+ practiceDesc.x = 1024;
+ practiceDesc.y = 1580;
+ modeSelectContainer.addChild(practiceDesc);
+ // Game screen
+ gameContainer = game.addChild(new Container());
+ gameContainer.visible = false;
+ // Score display
+ scoreTxt = new Text2('Score: 0', {
+ size: 80,
+ fill: 0xFFFFFF
+ });
+ scoreTxt.anchor.set(0.5, 0);
+ LK.gui.top.addChild(scoreTxt);
+ scoreTxt.y = 100;
+ // Streak display (for practice mode)
+ streakTxt = new Text2('Streak: 0', {
+ size: 60,
+ fill: 0xFFDD00
+ });
+ streakTxt.anchor.set(1, 0);
+ LK.gui.topRight.addChild(streakTxt);
+ streakTxt.x = -20;
+ streakTxt.y = 200;
+ streakTxt.visible = false;
+ // Command display
+ commandTxt = new Text2('Get Ready!', {
+ size: 120,
+ fill: 0xFFFFFF
+ });
+ commandTxt.anchor.set(0.5, 0.5);
+ commandTxt.x = 1024;
+ commandTxt.y = 800;
+ gameContainer.addChild(commandTxt);
+ // Timer display
+ timerTxt = new Text2('5.0', {
+ size: 100,
+ fill: 0xFFFFFF
+ });
+ timerTxt.anchor.set(0.5, 0.5);
+ timerTxt.x = 1024;
+ timerTxt.y = 1000;
+ gameContainer.addChild(timerTxt);
+ // Timer bar background
+ timerBarBg = LK.getAsset('timerBar', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ tint: 0x333333
+ });
+ timerBarBg.x = 1024;
+ timerBarBg.y = 1150;
+ gameContainer.addChild(timerBarBg);
+ // Timer bar
+ timerBar = LK.getAsset('timerBar', {
+ anchorX: 0,
+ anchorY: 0.5
+ });
+ timerBar.x = 1024 - 900;
+ timerBar.y = 1150;
+ gameContainer.addChild(timerBar);
+ // Color buttons
+ redButton = gameContainer.addChild(new ColorButton('red', 0xFF0000));
+ redButton.x = 400;
+ redButton.y = 1800;
+ greenButton = gameContainer.addChild(new ColorButton('green', 0x00FF00));
+ greenButton.x = 1024;
+ greenButton.y = 1800;
+ blueButton = gameContainer.addChild(new ColorButton('blue', 0x0000FF));
+ blueButton.x = 1648;
+ blueButton.y = 1800;
+}
+function selectMode(mode) {
+ gameMode = mode;
+ gameState = 'playing';
+ score = 0;
+ streak = 0;
+ modeSelectContainer.visible = false;
+ gameContainer.visible = true;
+ if (gameMode === 'practice') {
+ streakTxt.visible = true;
+ }
+ updateScore();
+ updateStreak();
+ // Start first command after a short delay
+ LK.setTimeout(function () {
+ nextCommand();
+ }, 1000);
+}
+function nextCommand() {
+ if (gameState !== 'playing') return;
+ // Select random color
+ currentColor = colors[Math.floor(Math.random() * colors.length)];
+ // Update command text
+ commandTxt.setText(currentColor.toUpperCase() + '!');
+ commandTxt.tint = colorHexes[currentColor];
+ // Play voice command
+ LK.getSound('voice' + currentColor.charAt(0).toUpperCase() + currentColor.slice(1)).play();
+ // Reset timer
+ timeRemaining = 5.0;
+ updateTimer();
+ // Start countdown
+ if (countdownTimer) LK.clearInterval(countdownTimer);
+ countdownTimer = LK.setInterval(function () {
+ timeRemaining -= 0.1;
+ updateTimer();
+ if (timeRemaining <= 0) {
+ timeRemaining = 0;
+ updateTimer();
+ handleTimeout();
+ }
+ }, 100);
+}
+function updateTimer() {
+ timerTxt.setText(timeRemaining.toFixed(1));
+ // Update timer bar
+ var percentage = timeRemaining / 5.0;
+ timerBar.width = 1800 * percentage;
+ // Change color based on time remaining
+ if (timeRemaining > 3) {
+ timerBar.tint = 0x00FF00; // Green
+ } else if (timeRemaining > 1) {
+ timerBar.tint = 0xFFFF00; // Yellow
+ } else {
+ timerBar.tint = 0xFF0000; // Red
+ }
+}
+function checkAnswer(buttonColor) {
+ if (gameState !== 'playing') return;
+ LK.clearInterval(countdownTimer);
+ if (buttonColor === currentColor) {
+ // Correct answer
+ score++;
+ streak++;
+ updateScore();
+ updateStreak();
+ LK.getSound('correct').play();
+ // Flash screen green briefly
+ LK.effects.flashScreen(0x00FF00, 300);
+ // Next command after brief delay
+ LK.setTimeout(function () {
+ nextCommand();
+ }, 1000);
+ } else {
+ // Wrong answer
+ handleWrongAnswer();
+ }
+}
+function handleTimeout() {
+ LK.clearInterval(countdownTimer);
+ LK.getSound('timeout').play();
+ handleWrongAnswer();
+}
+function handleWrongAnswer() {
+ if (gameMode === 'classic') {
+ // Game over in classic mode
+ LK.effects.flashScreen(0xFF0000, 1000);
+ LK.setTimeout(function () {
+ LK.showGameOver();
+ }, 1000);
+ } else {
+ // Practice mode - reset streak but continue
+ streak = 0;
+ updateStreak();
+ LK.getSound('incorrect').play();
+ LK.effects.flashScreen(0xFF0000, 500);
+ // Continue with next command
+ LK.setTimeout(function () {
+ nextCommand();
+ }, 1500);
+ }
+}
+function updateScore() {
+ scoreTxt.setText('Score: ' + score);
+ LK.setScore(score);
+}
+function updateStreak() {
+ if (gameMode === 'practice') {
+ streakTxt.setText('Streak: ' + streak);
+ }
+}
+// Initialize everything
+initializeUI();
+game.update = function () {
+ // No continuous updates needed for this game
+};
\ No newline at end of file