User prompt
que las flechas estén alineada en la parte superior de la pantalla
Code edit (1 edits merged)
Please save this source code
User prompt
Arrow Direction Circle
Initial prompt
que tengan flecha apuntando en diagonal hacia arriba y hacia la derecha y flecha apuntando en diagonal hacia arriba y a la derecha y un circulo flecha apuntando en diagonal hacia arriba y hacia la izquierda y flecha apuntando en diagonal hacia arriba y a la izquierda
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Arrow = Container.expand(function (direction) {
var self = Container.call(this);
var arrowGraphics = self.attachAsset('arrow', {
anchorX: 0.5,
anchorY: 0.5
});
self.direction = direction;
self.isPressed = false;
// Set rotation based on direction
if (direction === 'up-right') {
arrowGraphics.rotation = -Math.PI / 4;
} else if (direction === 'up-left') {
arrowGraphics.rotation = -3 * Math.PI / 4;
} else if (direction === 'down-right') {
arrowGraphics.rotation = Math.PI / 4;
} else if (direction === 'down-left') {
arrowGraphics.rotation = 3 * Math.PI / 4;
}
self.highlight = function () {
arrowGraphics.tint = 0xFFFF00;
self.isPressed = true;
};
self.unhighlight = function () {
arrowGraphics.tint = 0xFFFFFF;
self.isPressed = false;
};
self.down = function (x, y, obj) {
checkArrowPress(self.direction);
};
return self;
});
var GameCircle = Container.expand(function () {
var self = Container.call(this);
var circleGraphics = self.attachAsset('circle', {
anchorX: 0.5,
anchorY: 0.5
});
// Rotate to make it point upward like an arrow
circleGraphics.rotation = -Math.PI / 2;
self.originalX = 0;
self.originalY = 0;
self.moveInDirection = function (direction) {
var targetX = self.originalX;
var targetY = self.originalY;
var moveDistance = 50;
if (direction === 'up-right') {
targetX += moveDistance;
targetY -= moveDistance;
} else if (direction === 'up-left') {
targetX -= moveDistance;
targetY -= moveDistance;
} else if (direction === 'down-right') {
targetX += moveDistance;
targetY += moveDistance;
} else if (direction === 'down-left') {
targetX -= moveDistance;
targetY += moveDistance;
}
tween(self, {
x: targetX,
y: targetY
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self, {
x: self.originalX,
y: self.originalY
}, {
duration: 200,
easing: tween.easeOut
});
}
});
};
return self;
});
var MovingArrow = Container.expand(function (direction) {
var self = Container.call(this);
var arrowGraphics = self.attachAsset('arrow', {
anchorX: 0.5,
anchorY: 0.5
});
self.direction = direction;
self.speed = 12.65;
self.targetY = 500; // Same height as static arrows
self.lastY = undefined;
self.createdAt = LK.ticks; // Track creation time
// Set rotation based on direction
if (direction === 'up-right') {
arrowGraphics.rotation = -Math.PI / 4;
} else if (direction === 'up-left') {
arrowGraphics.rotation = -3 * Math.PI / 4;
} else if (direction === 'down-right') {
arrowGraphics.rotation = Math.PI / 4;
} else if (direction === 'down-left') {
arrowGraphics.rotation = 3 * Math.PI / 4;
}
self.update = function () {
// Track last Y position
if (self.lastY === undefined) self.lastY = self.y;
// Move upward
self.y -= self.speed;
};
self.down = function (x, y, obj) {
// Check if 2 seconds have passed since creation (120 ticks at 60 FPS)
if (LK.ticks - self.createdAt < 120) {
return; // Cannot destroy yet
}
// Destroy this arrow when clicked
for (var i = movingArrows.length - 1; i >= 0; i--) {
if (movingArrows[i] === self) {
totalDestroyedCount++;
destroyedTxt.setText('Destroyed: ' + totalDestroyedCount);
self.destroy();
movingArrows.splice(i, 1);
break;
}
}
};
return self;
});
var MovingCircle = Container.expand(function () {
var self = Container.call(this);
var circleGraphics = self.attachAsset('circle', {
anchorX: 0.5,
anchorY: 0.5
});
// Rotate to make it point upward like an arrow
circleGraphics.rotation = -Math.PI / 2;
self.speed = 12.65;
self.targetY = 500; // Same height as static circle
self.lastY = undefined;
self.createdAt = LK.ticks; // Track creation time
self.update = function () {
// Track last Y position
if (self.lastY === undefined) self.lastY = self.y;
// Move upward
self.y -= self.speed;
};
self.down = function (x, y, obj) {
// Check if 2 seconds have passed since creation (120 ticks at 60 FPS)
if (LK.ticks - self.createdAt < 120) {
return; // Cannot destroy yet
}
// Destroy this circle when clicked
for (var i = movingCircles.length - 1; i >= 0; i--) {
if (movingCircles[i] === self) {
totalDestroyedCount++;
destroyedTxt.setText('Destroyed: ' + totalDestroyedCount);
self.destroy();
movingCircles.splice(i, 1);
break;
}
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a1a1a
});
/****
* Game Code
****/
// Add fan background
var fanBackground = game.addChild(LK.getAsset('ImagenDeFondo', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 20.48,
// Scale to fit width (2048/100)
scaleY: 27.32 // Scale to fit height (2732/100)
}));
fanBackground.x = 2048 / 2;
fanBackground.y = 2732 / 2;
var gameCircle;
var arrows = [];
var movingArrows = [];
var movingCircles = [];
var currentCommand = '';
var gameSpeed = 2000;
var minSpeed = 800;
var speedIncrease = 50;
var isGameActive = false;
var commandTimeout;
var passedArrowsCount = 0;
var passedCirclesCount = 0;
var totalDestroyedCount = 0;
var speedMultiplier = 1;
var lastSpeedIncreaseTime = 0;
// UI Elements
var commandTxt = new Text2('', {
size: 60,
fill: 0xFFFFFF
});
commandTxt.anchor.set(0.5, 0.5);
// Position command text
commandTxt.x = 2048 / 2;
commandTxt.y = 400;
game.addChild(commandTxt);
// Destroyed arrows counter text
var destroyedTxt = new Text2('Destroyed: 0', {
size: 50,
fill: 0xFFFFFF
});
destroyedTxt.anchor.set(0.5, 1);
LK.gui.bottom.addChild(destroyedTxt);
// High score text
var highScoreTxt = new Text2('High Score: 0', {
size: 50,
fill: 0xFFFFFF
});
highScoreTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(highScoreTxt);
// Create game circle
gameCircle = game.addChild(new GameCircle());
gameCircle.x = 2048 / 2;
gameCircle.y = 500; // Position circle at the same height as arrows
gameCircle.originalX = gameCircle.x;
gameCircle.originalY = gameCircle.y;
// Create arrows aligned at the top of the screen
var arrowPositions = [{
dir: 'up-right',
x: 2048 / 2 + 700,
y: 500
}, {
dir: 'up-left',
x: 2048 / 2 + 300,
y: 500
}, {
dir: 'down-right',
x: 2048 / 2 - 300,
y: 500
}, {
dir: 'down-left',
x: 2048 / 2 - 700,
y: 500
}];
for (var i = 0; i < arrowPositions.length; i++) {
var arrow = new Arrow(arrowPositions[i].dir);
arrow.x = arrowPositions[i].x;
arrow.y = arrowPositions[i].y;
arrows.push(arrow);
game.addChild(arrow);
}
// Game functions
function getRandomDirection() {
var directions = ['up-right', 'up-left', 'down-right', 'down-left'];
return directions[Math.floor(Math.random() * directions.length)];
}
function generateCommand() {
if (!isGameActive) return;
currentCommand = getRandomDirection();
commandTxt.setText(currentCommand.toUpperCase());
// Flash command text
tween(commandTxt, {
alpha: 0.3
}, {
duration: 100,
onFinish: function onFinish() {
tween(commandTxt, {
alpha: 1
}, {
duration: 100
});
}
});
// Set timeout for next command
commandTimeout = LK.setTimeout(function () {
if (isGameActive) {
// Player didn't respond in time - just generate new command
currentCommand = '';
commandTxt.setText('');
generateCommand();
}
}, gameSpeed);
}
function checkArrowPress(direction) {
if (!isGameActive || currentCommand === '') return;
// Clear timeout
LK.clearTimeout(commandTimeout);
// Find and highlight the pressed arrow
for (var i = 0; i < arrows.length; i++) {
if (arrows[i].direction === direction) {
arrows[i].highlight();
LK.setTimeout(function () {
arrows[i].unhighlight();
}, 200);
break;
}
}
if (direction === currentCommand) {
// Correct answer
LK.getSound('correct').play();
LK.setScore(LK.getScore() + 10);
// Move circle in correct direction
gameCircle.moveInDirection(direction);
// Increase speed slightly
gameSpeed = Math.max(minSpeed, gameSpeed - speedIncrease);
// Clear command and generate new one
currentCommand = '';
commandTxt.setText('');
LK.setTimeout(generateCommand, 500);
} else {
// Wrong answer - continue game
LK.getSound('wrong').play();
// Just generate a new command instead of game over
currentCommand = '';
commandTxt.setText('');
LK.setTimeout(generateCommand, 500);
}
}
function gameOver() {
isGameActive = false;
LK.clearTimeout(commandTimeout);
currentCommand = '';
commandTxt.setText('');
// Check and update high score
var currentHighScore = storage.highScore || 0;
if (totalDestroyedCount > currentHighScore) {
storage.highScore = totalDestroyedCount;
highScoreTxt.setText('High Score: ' + totalDestroyedCount);
}
// Reset level counters
passedArrowsCount = 0;
passedCirclesCount = 0;
totalDestroyedCount = 0;
speedMultiplier = 1;
lastSpeedIncreaseTime = LK.ticks;
// Clear all moving arrows and circles
for (var i = movingArrows.length - 1; i >= 0; i--) {
movingArrows[i].destroy();
movingArrows.splice(i, 1);
}
for (var j = movingCircles.length - 1; j >= 0; j--) {
movingCircles[j].destroy();
movingCircles.splice(j, 1);
}
// Restart music
LK.playMusic('can');
// Flash screen red
LK.effects.flashScreen(0xff0000, 1000);
// Show game over after flash
LK.setTimeout(function () {
LK.showGameOver();
}, 500);
}
function startGame() {
isGameActive = true;
LK.setScore(0);
gameSpeed = 2000;
passedArrowsCount = 0;
passedCirclesCount = 0;
totalDestroyedCount = 0;
speedMultiplier = 1;
lastSpeedIncreaseTime = LK.ticks;
// Update destroyed counter display
destroyedTxt.setText('Destroyed: ' + totalDestroyedCount);
// Initialize and display high score
var highScore = storage.highScore || 0;
highScoreTxt.setText('High Score: ' + highScore);
// Start first command after a brief delay
LK.setTimeout(generateCommand, 1000);
}
// Keyboard event handler
game.keydown = function (keyCode) {
if (keyCode === 55) {
// Key '7' - Destroy up-left arrows
for (var i = movingArrows.length - 1; i >= 0; i--) {
var arrow = movingArrows[i];
if (arrow.direction === 'up-left' && LK.ticks - arrow.createdAt >= 120) {
totalDestroyedCount++;
destroyedTxt.setText('Destroyed: ' + totalDestroyedCount);
arrow.destroy();
movingArrows.splice(i, 1);
}
}
} else if (keyCode === 57) {
// Key '9' - Destroy up-right arrows
for (var i = movingArrows.length - 1; i >= 0; i--) {
var arrow = movingArrows[i];
if (arrow.direction === 'up-right' && LK.ticks - arrow.createdAt >= 120) {
totalDestroyedCount++;
destroyedTxt.setText('Destroyed: ' + totalDestroyedCount);
arrow.destroy();
movingArrows.splice(i, 1);
}
}
} else if (keyCode === 49) {
// Key '1' - Destroy down-left arrows
for (var i = movingArrows.length - 1; i >= 0; i--) {
var arrow = movingArrows[i];
if (arrow.direction === 'down-left' && LK.ticks - arrow.createdAt >= 120) {
totalDestroyedCount++;
destroyedTxt.setText('Destroyed: ' + totalDestroyedCount);
arrow.destroy();
movingArrows.splice(i, 1);
}
}
} else if (keyCode === 51) {
// Key '3' - Destroy down-right arrows
for (var i = movingArrows.length - 1; i >= 0; i--) {
var arrow = movingArrows[i];
if (arrow.direction === 'down-right' && LK.ticks - arrow.createdAt >= 120) {
totalDestroyedCount++;
destroyedTxt.setText('Destroyed: ' + totalDestroyedCount);
arrow.destroy();
movingArrows.splice(i, 1);
}
}
} else if (keyCode === 53) {
// Key '5' - Destroy all moving circles
for (var i = movingCircles.length - 1; i >= 0; i--) {
var circle = movingCircles[i];
if (LK.ticks - circle.createdAt >= 120) {
totalDestroyedCount++;
destroyedTxt.setText('Destroyed: ' + totalDestroyedCount);
circle.destroy();
movingCircles.splice(i, 1);
}
}
} else if (keyCode === 81) {
// Key 'Q' - Triple the speed of all moving arrows and circles
for (var i = 0; i < movingArrows.length; i++) {
movingArrows[i].speed *= 3;
}
for (var j = 0; j < movingCircles.length; j++) {
movingCircles[j].speed *= 3;
}
}
};
// Right-click event handler
game.rightdown = function (x, y, obj) {
// Increase speed of all moving arrows
for (var i = 0; i < movingArrows.length; i++) {
movingArrows[i].speed += 1;
}
// Increase speed of all moving circles
for (var j = 0; j < movingCircles.length; j++) {
movingCircles[j].speed += 1;
}
// Increase overall game speed (reduce command timeout)
gameSpeed = Math.max(minSpeed, gameSpeed - speedIncrease);
};
// Start the game
startGame();
// Play background music
LK.playMusic('can');
game.update = function () {
// Check if 1 minute (3600 ticks at 60 FPS) has passed since last speed increase
if (LK.ticks - lastSpeedIncreaseTime >= 3600) {
speedMultiplier += 0.5; // Increase speed multiplier by 0.5x
lastSpeedIncreaseTime = LK.ticks;
// Apply speed increase to all existing moving arrows
for (var k = 0; k < movingArrows.length; k++) {
movingArrows[k].speed = 12.65 * speedMultiplier;
}
// Apply speed increase to all existing moving circles
for (var l = 0; l < movingCircles.length; l++) {
movingCircles[l].speed = 12.65 * speedMultiplier;
}
}
// Spawn moving arrows periodically
if (LK.ticks % 60 === 0) {
var directions = ['up-right', 'up-left', 'down-right', 'down-left'];
var randomDirection = directions[Math.floor(Math.random() * directions.length)];
var movingArrow = new MovingArrow(randomDirection);
// Position at bottom of screen, aligned with corresponding static arrow
var arrowX = 2048 / 2;
if (randomDirection === 'up-right') arrowX = 2048 / 2 + 700;else if (randomDirection === 'up-left') arrowX = 2048 / 2 + 300;else if (randomDirection === 'down-right') arrowX = 2048 / 2 - 300;else if (randomDirection === 'down-left') arrowX = 2048 / 2 - 700;
movingArrow.x = arrowX;
movingArrow.y = 2732; // Start at bottom of screen
// Set initial speed based on current speed multiplier
movingArrow.speed = 12.65 * speedMultiplier;
movingArrows.push(movingArrow);
game.addChild(movingArrow);
}
// Spawn moving circles periodically
if (LK.ticks % 90 === 0) {
var movingCircle = new MovingCircle();
movingCircle.x = 2048 / 2; // Center position like static circle
movingCircle.y = 2732; // Start at bottom of screen
// Set initial speed based on current speed multiplier
movingCircle.speed = 12.65 * speedMultiplier;
movingCircles.push(movingCircle);
game.addChild(movingCircle);
}
// Update moving arrows
for (var i = movingArrows.length - 1; i >= 0; i--) {
var arrow = movingArrows[i];
// Increase speed by 0.05 for existing arrows
arrow.speed += 0.05;
if (arrow.lastY === undefined) arrow.lastY = arrow.y;
// Check if arrow passed the static arrows (y position 500)
if (arrow.lastY >= 500 && arrow.y < 500) {
passedArrowsCount++;
if (passedArrowsCount >= 10) {
gameOver();
return;
}
}
arrow.lastY = arrow.y;
}
// Update moving circles
for (var j = movingCircles.length - 1; j >= 0; j--) {
var circle = movingCircles[j];
// Increase speed by 0.05 for existing circles
circle.speed += 0.05;
if (circle.lastY === undefined) circle.lastY = circle.y;
// Check if circle passed the static circle (y position 500)
if (circle.lastY >= 500 && circle.y < 500) {
passedCirclesCount++;
if (passedCirclesCount >= 10) {
gameOver();
return;
}
}
circle.lastY = circle.y;
}
}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Arrow = Container.expand(function (direction) {
var self = Container.call(this);
var arrowGraphics = self.attachAsset('arrow', {
anchorX: 0.5,
anchorY: 0.5
});
self.direction = direction;
self.isPressed = false;
// Set rotation based on direction
if (direction === 'up-right') {
arrowGraphics.rotation = -Math.PI / 4;
} else if (direction === 'up-left') {
arrowGraphics.rotation = -3 * Math.PI / 4;
} else if (direction === 'down-right') {
arrowGraphics.rotation = Math.PI / 4;
} else if (direction === 'down-left') {
arrowGraphics.rotation = 3 * Math.PI / 4;
}
self.highlight = function () {
arrowGraphics.tint = 0xFFFF00;
self.isPressed = true;
};
self.unhighlight = function () {
arrowGraphics.tint = 0xFFFFFF;
self.isPressed = false;
};
self.down = function (x, y, obj) {
checkArrowPress(self.direction);
};
return self;
});
var GameCircle = Container.expand(function () {
var self = Container.call(this);
var circleGraphics = self.attachAsset('circle', {
anchorX: 0.5,
anchorY: 0.5
});
// Rotate to make it point upward like an arrow
circleGraphics.rotation = -Math.PI / 2;
self.originalX = 0;
self.originalY = 0;
self.moveInDirection = function (direction) {
var targetX = self.originalX;
var targetY = self.originalY;
var moveDistance = 50;
if (direction === 'up-right') {
targetX += moveDistance;
targetY -= moveDistance;
} else if (direction === 'up-left') {
targetX -= moveDistance;
targetY -= moveDistance;
} else if (direction === 'down-right') {
targetX += moveDistance;
targetY += moveDistance;
} else if (direction === 'down-left') {
targetX -= moveDistance;
targetY += moveDistance;
}
tween(self, {
x: targetX,
y: targetY
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self, {
x: self.originalX,
y: self.originalY
}, {
duration: 200,
easing: tween.easeOut
});
}
});
};
return self;
});
var MovingArrow = Container.expand(function (direction) {
var self = Container.call(this);
var arrowGraphics = self.attachAsset('arrow', {
anchorX: 0.5,
anchorY: 0.5
});
self.direction = direction;
self.speed = 12.65;
self.targetY = 500; // Same height as static arrows
self.lastY = undefined;
self.createdAt = LK.ticks; // Track creation time
// Set rotation based on direction
if (direction === 'up-right') {
arrowGraphics.rotation = -Math.PI / 4;
} else if (direction === 'up-left') {
arrowGraphics.rotation = -3 * Math.PI / 4;
} else if (direction === 'down-right') {
arrowGraphics.rotation = Math.PI / 4;
} else if (direction === 'down-left') {
arrowGraphics.rotation = 3 * Math.PI / 4;
}
self.update = function () {
// Track last Y position
if (self.lastY === undefined) self.lastY = self.y;
// Move upward
self.y -= self.speed;
};
self.down = function (x, y, obj) {
// Check if 2 seconds have passed since creation (120 ticks at 60 FPS)
if (LK.ticks - self.createdAt < 120) {
return; // Cannot destroy yet
}
// Destroy this arrow when clicked
for (var i = movingArrows.length - 1; i >= 0; i--) {
if (movingArrows[i] === self) {
totalDestroyedCount++;
destroyedTxt.setText('Destroyed: ' + totalDestroyedCount);
self.destroy();
movingArrows.splice(i, 1);
break;
}
}
};
return self;
});
var MovingCircle = Container.expand(function () {
var self = Container.call(this);
var circleGraphics = self.attachAsset('circle', {
anchorX: 0.5,
anchorY: 0.5
});
// Rotate to make it point upward like an arrow
circleGraphics.rotation = -Math.PI / 2;
self.speed = 12.65;
self.targetY = 500; // Same height as static circle
self.lastY = undefined;
self.createdAt = LK.ticks; // Track creation time
self.update = function () {
// Track last Y position
if (self.lastY === undefined) self.lastY = self.y;
// Move upward
self.y -= self.speed;
};
self.down = function (x, y, obj) {
// Check if 2 seconds have passed since creation (120 ticks at 60 FPS)
if (LK.ticks - self.createdAt < 120) {
return; // Cannot destroy yet
}
// Destroy this circle when clicked
for (var i = movingCircles.length - 1; i >= 0; i--) {
if (movingCircles[i] === self) {
totalDestroyedCount++;
destroyedTxt.setText('Destroyed: ' + totalDestroyedCount);
self.destroy();
movingCircles.splice(i, 1);
break;
}
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a1a1a
});
/****
* Game Code
****/
// Add fan background
var fanBackground = game.addChild(LK.getAsset('ImagenDeFondo', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 20.48,
// Scale to fit width (2048/100)
scaleY: 27.32 // Scale to fit height (2732/100)
}));
fanBackground.x = 2048 / 2;
fanBackground.y = 2732 / 2;
var gameCircle;
var arrows = [];
var movingArrows = [];
var movingCircles = [];
var currentCommand = '';
var gameSpeed = 2000;
var minSpeed = 800;
var speedIncrease = 50;
var isGameActive = false;
var commandTimeout;
var passedArrowsCount = 0;
var passedCirclesCount = 0;
var totalDestroyedCount = 0;
var speedMultiplier = 1;
var lastSpeedIncreaseTime = 0;
// UI Elements
var commandTxt = new Text2('', {
size: 60,
fill: 0xFFFFFF
});
commandTxt.anchor.set(0.5, 0.5);
// Position command text
commandTxt.x = 2048 / 2;
commandTxt.y = 400;
game.addChild(commandTxt);
// Destroyed arrows counter text
var destroyedTxt = new Text2('Destroyed: 0', {
size: 50,
fill: 0xFFFFFF
});
destroyedTxt.anchor.set(0.5, 1);
LK.gui.bottom.addChild(destroyedTxt);
// High score text
var highScoreTxt = new Text2('High Score: 0', {
size: 50,
fill: 0xFFFFFF
});
highScoreTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(highScoreTxt);
// Create game circle
gameCircle = game.addChild(new GameCircle());
gameCircle.x = 2048 / 2;
gameCircle.y = 500; // Position circle at the same height as arrows
gameCircle.originalX = gameCircle.x;
gameCircle.originalY = gameCircle.y;
// Create arrows aligned at the top of the screen
var arrowPositions = [{
dir: 'up-right',
x: 2048 / 2 + 700,
y: 500
}, {
dir: 'up-left',
x: 2048 / 2 + 300,
y: 500
}, {
dir: 'down-right',
x: 2048 / 2 - 300,
y: 500
}, {
dir: 'down-left',
x: 2048 / 2 - 700,
y: 500
}];
for (var i = 0; i < arrowPositions.length; i++) {
var arrow = new Arrow(arrowPositions[i].dir);
arrow.x = arrowPositions[i].x;
arrow.y = arrowPositions[i].y;
arrows.push(arrow);
game.addChild(arrow);
}
// Game functions
function getRandomDirection() {
var directions = ['up-right', 'up-left', 'down-right', 'down-left'];
return directions[Math.floor(Math.random() * directions.length)];
}
function generateCommand() {
if (!isGameActive) return;
currentCommand = getRandomDirection();
commandTxt.setText(currentCommand.toUpperCase());
// Flash command text
tween(commandTxt, {
alpha: 0.3
}, {
duration: 100,
onFinish: function onFinish() {
tween(commandTxt, {
alpha: 1
}, {
duration: 100
});
}
});
// Set timeout for next command
commandTimeout = LK.setTimeout(function () {
if (isGameActive) {
// Player didn't respond in time - just generate new command
currentCommand = '';
commandTxt.setText('');
generateCommand();
}
}, gameSpeed);
}
function checkArrowPress(direction) {
if (!isGameActive || currentCommand === '') return;
// Clear timeout
LK.clearTimeout(commandTimeout);
// Find and highlight the pressed arrow
for (var i = 0; i < arrows.length; i++) {
if (arrows[i].direction === direction) {
arrows[i].highlight();
LK.setTimeout(function () {
arrows[i].unhighlight();
}, 200);
break;
}
}
if (direction === currentCommand) {
// Correct answer
LK.getSound('correct').play();
LK.setScore(LK.getScore() + 10);
// Move circle in correct direction
gameCircle.moveInDirection(direction);
// Increase speed slightly
gameSpeed = Math.max(minSpeed, gameSpeed - speedIncrease);
// Clear command and generate new one
currentCommand = '';
commandTxt.setText('');
LK.setTimeout(generateCommand, 500);
} else {
// Wrong answer - continue game
LK.getSound('wrong').play();
// Just generate a new command instead of game over
currentCommand = '';
commandTxt.setText('');
LK.setTimeout(generateCommand, 500);
}
}
function gameOver() {
isGameActive = false;
LK.clearTimeout(commandTimeout);
currentCommand = '';
commandTxt.setText('');
// Check and update high score
var currentHighScore = storage.highScore || 0;
if (totalDestroyedCount > currentHighScore) {
storage.highScore = totalDestroyedCount;
highScoreTxt.setText('High Score: ' + totalDestroyedCount);
}
// Reset level counters
passedArrowsCount = 0;
passedCirclesCount = 0;
totalDestroyedCount = 0;
speedMultiplier = 1;
lastSpeedIncreaseTime = LK.ticks;
// Clear all moving arrows and circles
for (var i = movingArrows.length - 1; i >= 0; i--) {
movingArrows[i].destroy();
movingArrows.splice(i, 1);
}
for (var j = movingCircles.length - 1; j >= 0; j--) {
movingCircles[j].destroy();
movingCircles.splice(j, 1);
}
// Restart music
LK.playMusic('can');
// Flash screen red
LK.effects.flashScreen(0xff0000, 1000);
// Show game over after flash
LK.setTimeout(function () {
LK.showGameOver();
}, 500);
}
function startGame() {
isGameActive = true;
LK.setScore(0);
gameSpeed = 2000;
passedArrowsCount = 0;
passedCirclesCount = 0;
totalDestroyedCount = 0;
speedMultiplier = 1;
lastSpeedIncreaseTime = LK.ticks;
// Update destroyed counter display
destroyedTxt.setText('Destroyed: ' + totalDestroyedCount);
// Initialize and display high score
var highScore = storage.highScore || 0;
highScoreTxt.setText('High Score: ' + highScore);
// Start first command after a brief delay
LK.setTimeout(generateCommand, 1000);
}
// Keyboard event handler
game.keydown = function (keyCode) {
if (keyCode === 55) {
// Key '7' - Destroy up-left arrows
for (var i = movingArrows.length - 1; i >= 0; i--) {
var arrow = movingArrows[i];
if (arrow.direction === 'up-left' && LK.ticks - arrow.createdAt >= 120) {
totalDestroyedCount++;
destroyedTxt.setText('Destroyed: ' + totalDestroyedCount);
arrow.destroy();
movingArrows.splice(i, 1);
}
}
} else if (keyCode === 57) {
// Key '9' - Destroy up-right arrows
for (var i = movingArrows.length - 1; i >= 0; i--) {
var arrow = movingArrows[i];
if (arrow.direction === 'up-right' && LK.ticks - arrow.createdAt >= 120) {
totalDestroyedCount++;
destroyedTxt.setText('Destroyed: ' + totalDestroyedCount);
arrow.destroy();
movingArrows.splice(i, 1);
}
}
} else if (keyCode === 49) {
// Key '1' - Destroy down-left arrows
for (var i = movingArrows.length - 1; i >= 0; i--) {
var arrow = movingArrows[i];
if (arrow.direction === 'down-left' && LK.ticks - arrow.createdAt >= 120) {
totalDestroyedCount++;
destroyedTxt.setText('Destroyed: ' + totalDestroyedCount);
arrow.destroy();
movingArrows.splice(i, 1);
}
}
} else if (keyCode === 51) {
// Key '3' - Destroy down-right arrows
for (var i = movingArrows.length - 1; i >= 0; i--) {
var arrow = movingArrows[i];
if (arrow.direction === 'down-right' && LK.ticks - arrow.createdAt >= 120) {
totalDestroyedCount++;
destroyedTxt.setText('Destroyed: ' + totalDestroyedCount);
arrow.destroy();
movingArrows.splice(i, 1);
}
}
} else if (keyCode === 53) {
// Key '5' - Destroy all moving circles
for (var i = movingCircles.length - 1; i >= 0; i--) {
var circle = movingCircles[i];
if (LK.ticks - circle.createdAt >= 120) {
totalDestroyedCount++;
destroyedTxt.setText('Destroyed: ' + totalDestroyedCount);
circle.destroy();
movingCircles.splice(i, 1);
}
}
} else if (keyCode === 81) {
// Key 'Q' - Triple the speed of all moving arrows and circles
for (var i = 0; i < movingArrows.length; i++) {
movingArrows[i].speed *= 3;
}
for (var j = 0; j < movingCircles.length; j++) {
movingCircles[j].speed *= 3;
}
}
};
// Right-click event handler
game.rightdown = function (x, y, obj) {
// Increase speed of all moving arrows
for (var i = 0; i < movingArrows.length; i++) {
movingArrows[i].speed += 1;
}
// Increase speed of all moving circles
for (var j = 0; j < movingCircles.length; j++) {
movingCircles[j].speed += 1;
}
// Increase overall game speed (reduce command timeout)
gameSpeed = Math.max(minSpeed, gameSpeed - speedIncrease);
};
// Start the game
startGame();
// Play background music
LK.playMusic('can');
game.update = function () {
// Check if 1 minute (3600 ticks at 60 FPS) has passed since last speed increase
if (LK.ticks - lastSpeedIncreaseTime >= 3600) {
speedMultiplier += 0.5; // Increase speed multiplier by 0.5x
lastSpeedIncreaseTime = LK.ticks;
// Apply speed increase to all existing moving arrows
for (var k = 0; k < movingArrows.length; k++) {
movingArrows[k].speed = 12.65 * speedMultiplier;
}
// Apply speed increase to all existing moving circles
for (var l = 0; l < movingCircles.length; l++) {
movingCircles[l].speed = 12.65 * speedMultiplier;
}
}
// Spawn moving arrows periodically
if (LK.ticks % 60 === 0) {
var directions = ['up-right', 'up-left', 'down-right', 'down-left'];
var randomDirection = directions[Math.floor(Math.random() * directions.length)];
var movingArrow = new MovingArrow(randomDirection);
// Position at bottom of screen, aligned with corresponding static arrow
var arrowX = 2048 / 2;
if (randomDirection === 'up-right') arrowX = 2048 / 2 + 700;else if (randomDirection === 'up-left') arrowX = 2048 / 2 + 300;else if (randomDirection === 'down-right') arrowX = 2048 / 2 - 300;else if (randomDirection === 'down-left') arrowX = 2048 / 2 - 700;
movingArrow.x = arrowX;
movingArrow.y = 2732; // Start at bottom of screen
// Set initial speed based on current speed multiplier
movingArrow.speed = 12.65 * speedMultiplier;
movingArrows.push(movingArrow);
game.addChild(movingArrow);
}
// Spawn moving circles periodically
if (LK.ticks % 90 === 0) {
var movingCircle = new MovingCircle();
movingCircle.x = 2048 / 2; // Center position like static circle
movingCircle.y = 2732; // Start at bottom of screen
// Set initial speed based on current speed multiplier
movingCircle.speed = 12.65 * speedMultiplier;
movingCircles.push(movingCircle);
game.addChild(movingCircle);
}
// Update moving arrows
for (var i = movingArrows.length - 1; i >= 0; i--) {
var arrow = movingArrows[i];
// Increase speed by 0.05 for existing arrows
arrow.speed += 0.05;
if (arrow.lastY === undefined) arrow.lastY = arrow.y;
// Check if arrow passed the static arrows (y position 500)
if (arrow.lastY >= 500 && arrow.y < 500) {
passedArrowsCount++;
if (passedArrowsCount >= 10) {
gameOver();
return;
}
}
arrow.lastY = arrow.y;
}
// Update moving circles
for (var j = movingCircles.length - 1; j >= 0; j--) {
var circle = movingCircles[j];
// Increase speed by 0.05 for existing circles
circle.speed += 0.05;
if (circle.lastY === undefined) circle.lastY = circle.y;
// Check if circle passed the static circle (y position 500)
if (circle.lastY >= 500 && circle.y < 500) {
passedCirclesCount++;
if (passedCirclesCount >= 10) {
gameOver();
return;
}
}
circle.lastY = circle.y;
}
};