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");
/****
* 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
});
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;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a1a1a
});
/****
* Game Code
****/
var gameCircle;
var arrows = [];
var currentCommand = '';
var gameSpeed = 2000;
var minSpeed = 800;
var speedIncrease = 50;
var isGameActive = false;
var commandTimeout;
// UI Elements
var scoreTxt = new Text2('0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
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);
// Create game circle
gameCircle = game.addChild(new GameCircle());
gameCircle.x = 2048 / 2;
gameCircle.y = 2732 / 2;
gameCircle.originalX = gameCircle.x;
gameCircle.originalY = gameCircle.y;
// Create arrows around the circle
var arrowPositions = [{
dir: 'up-right',
x: gameCircle.x + 200,
y: gameCircle.y - 200
}, {
dir: 'up-left',
x: gameCircle.x - 200,
y: gameCircle.y - 200
}, {
dir: 'down-right',
x: gameCircle.x + 200,
y: gameCircle.y + 200
}, {
dir: 'down-left',
x: gameCircle.x - 200,
y: gameCircle.y + 200
}];
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 - game over
gameOver();
}
}, 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);
scoreTxt.setText(LK.getScore());
// 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 - game over
LK.getSound('wrong').play();
gameOver();
}
}
function gameOver() {
isGameActive = false;
LK.clearTimeout(commandTimeout);
currentCommand = '';
commandTxt.setText('');
// 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);
scoreTxt.setText('0');
gameSpeed = 2000;
// Start first command after a brief delay
LK.setTimeout(generateCommand, 1000);
}
// Start the game
startGame();
game.update = function () {
// Game tick logic if needed
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,237 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.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
+ });
+ 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;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x1a1a1a
+});
+
+/****
+* Game Code
+****/
+var gameCircle;
+var arrows = [];
+var currentCommand = '';
+var gameSpeed = 2000;
+var minSpeed = 800;
+var speedIncrease = 50;
+var isGameActive = false;
+var commandTimeout;
+// UI Elements
+var scoreTxt = new Text2('0', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+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);
+// Create game circle
+gameCircle = game.addChild(new GameCircle());
+gameCircle.x = 2048 / 2;
+gameCircle.y = 2732 / 2;
+gameCircle.originalX = gameCircle.x;
+gameCircle.originalY = gameCircle.y;
+// Create arrows around the circle
+var arrowPositions = [{
+ dir: 'up-right',
+ x: gameCircle.x + 200,
+ y: gameCircle.y - 200
+}, {
+ dir: 'up-left',
+ x: gameCircle.x - 200,
+ y: gameCircle.y - 200
+}, {
+ dir: 'down-right',
+ x: gameCircle.x + 200,
+ y: gameCircle.y + 200
+}, {
+ dir: 'down-left',
+ x: gameCircle.x - 200,
+ y: gameCircle.y + 200
+}];
+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 - game over
+ gameOver();
+ }
+ }, 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);
+ scoreTxt.setText(LK.getScore());
+ // 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 - game over
+ LK.getSound('wrong').play();
+ gameOver();
+ }
+}
+function gameOver() {
+ isGameActive = false;
+ LK.clearTimeout(commandTimeout);
+ currentCommand = '';
+ commandTxt.setText('');
+ // 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);
+ scoreTxt.setText('0');
+ gameSpeed = 2000;
+ // Start first command after a brief delay
+ LK.setTimeout(generateCommand, 1000);
+}
+// Start the game
+startGame();
+game.update = function () {
+ // Game tick logic if needed
+};
\ No newline at end of file