/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var MovingSquare = Container.expand(function () {
var self = Container.call(this);
var squareGraphics = self.attachAsset('movingSquare', {
anchorX: 0.5,
anchorY: 0.5
});
self.moveToRandomPosition = function () {
var padding = 100;
var newX = padding + Math.random() * (2048 - padding * 2);
var newY = padding + Math.random() * (2732 - padding * 2);
tween(self, {
x: newX,
y: newY
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
LK.getSound('moveSound').play();
}
});
};
self.down = function (x, y, obj) {
currentScore++;
LK.setScore(currentScore);
scoreText.setText(currentScore);
LK.getSound('tapSound').play();
// Flash effect on successful tap
LK.effects.flashObject(self, 0xffffff, 200);
// Move to new position immediately after tap
self.moveToRandomPosition();
// Reset move timer
if (moveTimer) {
LK.clearInterval(moveTimer);
}
moveTimer = LK.setInterval(function () {
self.moveToRandomPosition();
}, moveInterval);
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2c3e50
});
/****
* Game Code
****/
var currentScore = 0;
var gameTimeLeft = 60;
var gameActive = false;
var moveInterval = 2000; // Square moves every 2 seconds
var moveTimer = null;
var gameTimer = null;
// Create score display
var scoreText = new Text2('0', {
size: 80,
fill: '#ffffff'
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
// Create time display
var timeText = new Text2('60', {
size: 60,
fill: '#e74c3c'
});
timeText.anchor.set(1, 0);
timeText.x = -20;
timeText.y = 20;
LK.gui.topRight.addChild(timeText);
// Create the moving square
var movingSquare = game.addChild(new MovingSquare());
movingSquare.x = 1024;
movingSquare.y = 1366;
// Start the game
function startGame() {
gameActive = true;
currentScore = 0;
gameTimeLeft = 60;
LK.setScore(0);
scoreText.setText('0');
timeText.setText('60');
// Position square at center initially
movingSquare.x = 1024;
movingSquare.y = 1366;
// Start moving the square
moveTimer = LK.setInterval(function () {
if (gameActive) {
movingSquare.moveToRandomPosition();
}
}, moveInterval);
// Start game timer
gameTimer = LK.setInterval(function () {
if (gameActive) {
gameTimeLeft--;
timeText.setText(gameTimeLeft.toString());
if (gameTimeLeft <= 0) {
endGame();
}
}
}, 1000);
// Move square to first random position after a short delay
LK.setTimeout(function () {
movingSquare.moveToRandomPosition();
}, 1000);
}
function endGame() {
gameActive = false;
if (moveTimer) {
LK.clearInterval(moveTimer);
moveTimer = null;
}
if (gameTimer) {
LK.clearInterval(gameTimer);
gameTimer = null;
}
// Stop all tweens on the square
tween.stop(movingSquare);
LK.showGameOver();
}
// Start the game automatically
startGame();
game.update = function () {
// Main game loop - checking if game should continue
if (!gameActive && gameTimeLeft > 0) {
// Game might have been paused, resume if needed
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,139 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var MovingSquare = Container.expand(function () {
+ var self = Container.call(this);
+ var squareGraphics = self.attachAsset('movingSquare', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.moveToRandomPosition = function () {
+ var padding = 100;
+ var newX = padding + Math.random() * (2048 - padding * 2);
+ var newY = padding + Math.random() * (2732 - padding * 2);
+ tween(self, {
+ x: newX,
+ y: newY
+ }, {
+ duration: 300,
+ easing: tween.easeOut,
+ onFinish: function onFinish() {
+ LK.getSound('moveSound').play();
+ }
+ });
+ };
+ self.down = function (x, y, obj) {
+ currentScore++;
+ LK.setScore(currentScore);
+ scoreText.setText(currentScore);
+ LK.getSound('tapSound').play();
+ // Flash effect on successful tap
+ LK.effects.flashObject(self, 0xffffff, 200);
+ // Move to new position immediately after tap
+ self.moveToRandomPosition();
+ // Reset move timer
+ if (moveTimer) {
+ LK.clearInterval(moveTimer);
+ }
+ moveTimer = LK.setInterval(function () {
+ self.moveToRandomPosition();
+ }, moveInterval);
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x2c3e50
+});
+
+/****
+* Game Code
+****/
+var currentScore = 0;
+var gameTimeLeft = 60;
+var gameActive = false;
+var moveInterval = 2000; // Square moves every 2 seconds
+var moveTimer = null;
+var gameTimer = null;
+// Create score display
+var scoreText = new Text2('0', {
+ size: 80,
+ fill: '#ffffff'
+});
+scoreText.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreText);
+// Create time display
+var timeText = new Text2('60', {
+ size: 60,
+ fill: '#e74c3c'
+});
+timeText.anchor.set(1, 0);
+timeText.x = -20;
+timeText.y = 20;
+LK.gui.topRight.addChild(timeText);
+// Create the moving square
+var movingSquare = game.addChild(new MovingSquare());
+movingSquare.x = 1024;
+movingSquare.y = 1366;
+// Start the game
+function startGame() {
+ gameActive = true;
+ currentScore = 0;
+ gameTimeLeft = 60;
+ LK.setScore(0);
+ scoreText.setText('0');
+ timeText.setText('60');
+ // Position square at center initially
+ movingSquare.x = 1024;
+ movingSquare.y = 1366;
+ // Start moving the square
+ moveTimer = LK.setInterval(function () {
+ if (gameActive) {
+ movingSquare.moveToRandomPosition();
+ }
+ }, moveInterval);
+ // Start game timer
+ gameTimer = LK.setInterval(function () {
+ if (gameActive) {
+ gameTimeLeft--;
+ timeText.setText(gameTimeLeft.toString());
+ if (gameTimeLeft <= 0) {
+ endGame();
+ }
+ }
+ }, 1000);
+ // Move square to first random position after a short delay
+ LK.setTimeout(function () {
+ movingSquare.moveToRandomPosition();
+ }, 1000);
+}
+function endGame() {
+ gameActive = false;
+ if (moveTimer) {
+ LK.clearInterval(moveTimer);
+ moveTimer = null;
+ }
+ if (gameTimer) {
+ LK.clearInterval(gameTimer);
+ gameTimer = null;
+ }
+ // Stop all tweens on the square
+ tween.stop(movingSquare);
+ LK.showGameOver();
+}
+// Start the game automatically
+startGame();
+game.update = function () {
+ // Main game loop - checking if game should continue
+ if (!gameActive && gameTimeLeft > 0) {
+ // Game might have been paused, resume if needed
+ }
+};
\ No newline at end of file