/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var ClickableObject = Container.expand(function () { var self = Container.call(this); var objectGraphics = self.attachAsset('clickableObject', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Gentle pulsing animation var scale = 1 + Math.sin(LK.ticks * 0.05) * 0.1; objectGraphics.scaleX = scale; objectGraphics.scaleY = scale; }; self.down = function (x, y, obj) { // Only allow clicking when game is active if (!gameActive) return; // Increase click count clickCount++; clickCountTxt.setText('Clicks: ' + clickCount); // Play click sound LK.getSound('click').play(); // Visual feedback - quick scale animation tween(objectGraphics, { scaleX: 1.3, scaleY: 1.3 }, { duration: 1000, onFinish: function onFinish() { tween(objectGraphics, { scaleX: 1, scaleY: 1 }, { duration: 100 }); } }); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x0066CC }); /**** * Game Code ****/ // Game variables var clickableObject; var clickCount = 0; var clickCountTxt; var backgroundImage; var bananaBackgroundImage; var timerTxt; var timeLeft = 25; var gameActive = false; var gameStartTime; var gameStarted = false; var startScreen; var playButton; var finalScoreTxt; var restartButton; // Function to start the game function startGame() { gameStarted = true; gameActive = true; clickCount = 0; timeLeft = 25; gameStartTime = null; // Hide start screen if (startScreen) { startScreen.visible = false; } // Hide banana background if (bananaBackgroundImage) { bananaBackgroundImage.visible = false; } // Remove any existing game over elements if (finalScoreTxt) { finalScoreTxt.destroy(); finalScoreTxt = null; } if (restartButton) { restartButton.destroy(); restartButton = null; } // Add forest background if not exists if (!backgroundImage) { backgroundImage = game.addChild(LK.getAsset('forestBackground', { anchorX: 0, anchorY: 0, x: 0, y: 0 })); } // Create clickable object if not exists if (!clickableObject) { clickableObject = game.addChild(new ClickableObject()); clickableObject.x = 1024; // Center horizontally (2048/2) clickableObject.y = 1366; // Center vertically (2732/2) } clickableObject.visible = true; // Create click counter display if not exists if (!clickCountTxt) { clickCountTxt = new Text2('Clicks: 0', { size: 100, fill: 0xFFFFFF }); clickCountTxt.anchor.set(0.5, 0); LK.gui.top.addChild(clickCountTxt); } clickCountTxt.setText('Clicks: 0'); clickCountTxt.visible = true; // Create timer display in top right if not exists if (!timerTxt) { timerTxt = new Text2('Time: 25', { size: 80, fill: 0xFFFFFF }); timerTxt.anchor.set(1, 0); LK.gui.topRight.addChild(timerTxt); } timerTxt.setText('Time: 25'); timerTxt.visible = true; } // Function to show start screen function showStartScreen() { // Hide game elements if (clickableObject) clickableObject.visible = false; if (clickCountTxt) clickCountTxt.visible = false; if (timerTxt) timerTxt.visible = false; // Set purple background for start screen game.setBackgroundColor(0x800080); // Add banana background image if not exists if (!bananaBackgroundImage) { bananaBackgroundImage = game.addChild(LK.getAsset('bananaBackground', { anchorX: 0, anchorY: 0, x: 0, y: 0 })); } bananaBackgroundImage.visible = true; // Create start screen container if (!startScreen) { // Start color changing animation for button background var _animateButtonColor = function animateButtonColor() { tween(playButtonBg, { tint: 0xFF0000 }, { duration: 1000, onFinish: function onFinish() { tween(playButtonBg, { tint: 0x00FF00 }, { duration: 1000, onFinish: function onFinish() { tween(playButtonBg, { tint: 0x0000FF }, { duration: 1000, onFinish: function onFinish() { tween(playButtonBg, { tint: 0xFFFF00 }, { duration: 1000, onFinish: function onFinish() { tween(playButtonBg, { tint: 0xFF00FF }, { duration: 1000, onFinish: function onFinish() { tween(playButtonBg, { tint: 0x00FFFF }, { duration: 1000, onFinish: _animateButtonColor }); } }); } }); } }); } }); } }); }; startScreen = new Container(); game.addChild(startScreen); // Create square background for play button var playButtonBg = LK.getAsset('clickableObject', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.5, scaleY: 1.5, tint: 0x00FF00 }); playButtonBg.x = 1024; playButtonBg.y = 1366; startScreen.addChild(playButtonBg); // Create play button text playButton = new Text2('PLAY', { size: 120, fill: 0xFFFFFF }); playButton.anchor.set(0.5, 0.5); playButton.x = 1024; playButton.y = 1366; startScreen.addChild(playButton); // Add click handler to both button background and text playButtonBg.down = function (x, y, obj) { startGame(); }; playButton.down = function (x, y, obj) { startGame(); }; // Add title with italic styling var titleTxt = new Text2('Banana Clicker', { size: 200, fill: 0xFFFFFF, fontStyle: 'italic', fontWeight: 'bold' }); titleTxt.anchor.set(0.5, 0.5); titleTxt.x = 1024; titleTxt.y = 800; startScreen.addChild(titleTxt); } startScreen.visible = true; } // Initialize start screen showStartScreen(); // Game update loop (minimal for this simple game) game.update = function () { if (gameActive && gameStarted) { // Initialize game start time if (!gameStartTime) { gameStartTime = LK.ticks; } // Calculate time elapsed (LK.ticks runs at 60fps) var timeElapsed = Math.floor((LK.ticks - gameStartTime) / 60); timeLeft = Math.max(0, 25 - timeElapsed); timerTxt.setText('Time: ' + timeLeft); // Check if time is up if (timeLeft <= 0) { gameActive = false; // Hide clickable object clickableObject.visible = false; // Show final score finalScoreTxt = new Text2('Final Score: ' + clickCount + ' clicks!', { size: 120, fill: 0xFFFF00 }); finalScoreTxt.anchor.set(0.5, 0.5); finalScoreTxt.x = 1024; finalScoreTxt.y = 1200; game.addChild(finalScoreTxt); // Show restart button restartButton = new Text2('TEKRAR DENE', { size: 100, fill: 0x00FF00 }); restartButton.anchor.set(0.5, 0.5); restartButton.x = 1024; restartButton.y = 1500; game.addChild(restartButton); // Add click handler to restart button restartButton.down = function (x, y, obj) { startGame(); }; } } };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var ClickableObject = Container.expand(function () {
var self = Container.call(this);
var objectGraphics = self.attachAsset('clickableObject', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Gentle pulsing animation
var scale = 1 + Math.sin(LK.ticks * 0.05) * 0.1;
objectGraphics.scaleX = scale;
objectGraphics.scaleY = scale;
};
self.down = function (x, y, obj) {
// Only allow clicking when game is active
if (!gameActive) return;
// Increase click count
clickCount++;
clickCountTxt.setText('Clicks: ' + clickCount);
// Play click sound
LK.getSound('click').play();
// Visual feedback - quick scale animation
tween(objectGraphics, {
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 1000,
onFinish: function onFinish() {
tween(objectGraphics, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
}
});
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x0066CC
});
/****
* Game Code
****/
// Game variables
var clickableObject;
var clickCount = 0;
var clickCountTxt;
var backgroundImage;
var bananaBackgroundImage;
var timerTxt;
var timeLeft = 25;
var gameActive = false;
var gameStartTime;
var gameStarted = false;
var startScreen;
var playButton;
var finalScoreTxt;
var restartButton;
// Function to start the game
function startGame() {
gameStarted = true;
gameActive = true;
clickCount = 0;
timeLeft = 25;
gameStartTime = null;
// Hide start screen
if (startScreen) {
startScreen.visible = false;
}
// Hide banana background
if (bananaBackgroundImage) {
bananaBackgroundImage.visible = false;
}
// Remove any existing game over elements
if (finalScoreTxt) {
finalScoreTxt.destroy();
finalScoreTxt = null;
}
if (restartButton) {
restartButton.destroy();
restartButton = null;
}
// Add forest background if not exists
if (!backgroundImage) {
backgroundImage = game.addChild(LK.getAsset('forestBackground', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
}));
}
// Create clickable object if not exists
if (!clickableObject) {
clickableObject = game.addChild(new ClickableObject());
clickableObject.x = 1024; // Center horizontally (2048/2)
clickableObject.y = 1366; // Center vertically (2732/2)
}
clickableObject.visible = true;
// Create click counter display if not exists
if (!clickCountTxt) {
clickCountTxt = new Text2('Clicks: 0', {
size: 100,
fill: 0xFFFFFF
});
clickCountTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(clickCountTxt);
}
clickCountTxt.setText('Clicks: 0');
clickCountTxt.visible = true;
// Create timer display in top right if not exists
if (!timerTxt) {
timerTxt = new Text2('Time: 25', {
size: 80,
fill: 0xFFFFFF
});
timerTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(timerTxt);
}
timerTxt.setText('Time: 25');
timerTxt.visible = true;
}
// Function to show start screen
function showStartScreen() {
// Hide game elements
if (clickableObject) clickableObject.visible = false;
if (clickCountTxt) clickCountTxt.visible = false;
if (timerTxt) timerTxt.visible = false;
// Set purple background for start screen
game.setBackgroundColor(0x800080);
// Add banana background image if not exists
if (!bananaBackgroundImage) {
bananaBackgroundImage = game.addChild(LK.getAsset('bananaBackground', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
}));
}
bananaBackgroundImage.visible = true;
// Create start screen container
if (!startScreen) {
// Start color changing animation for button background
var _animateButtonColor = function animateButtonColor() {
tween(playButtonBg, {
tint: 0xFF0000
}, {
duration: 1000,
onFinish: function onFinish() {
tween(playButtonBg, {
tint: 0x00FF00
}, {
duration: 1000,
onFinish: function onFinish() {
tween(playButtonBg, {
tint: 0x0000FF
}, {
duration: 1000,
onFinish: function onFinish() {
tween(playButtonBg, {
tint: 0xFFFF00
}, {
duration: 1000,
onFinish: function onFinish() {
tween(playButtonBg, {
tint: 0xFF00FF
}, {
duration: 1000,
onFinish: function onFinish() {
tween(playButtonBg, {
tint: 0x00FFFF
}, {
duration: 1000,
onFinish: _animateButtonColor
});
}
});
}
});
}
});
}
});
}
});
};
startScreen = new Container();
game.addChild(startScreen);
// Create square background for play button
var playButtonBg = LK.getAsset('clickableObject', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5,
scaleY: 1.5,
tint: 0x00FF00
});
playButtonBg.x = 1024;
playButtonBg.y = 1366;
startScreen.addChild(playButtonBg);
// Create play button text
playButton = new Text2('PLAY', {
size: 120,
fill: 0xFFFFFF
});
playButton.anchor.set(0.5, 0.5);
playButton.x = 1024;
playButton.y = 1366;
startScreen.addChild(playButton);
// Add click handler to both button background and text
playButtonBg.down = function (x, y, obj) {
startGame();
};
playButton.down = function (x, y, obj) {
startGame();
};
// Add title with italic styling
var titleTxt = new Text2('Banana Clicker', {
size: 200,
fill: 0xFFFFFF,
fontStyle: 'italic',
fontWeight: 'bold'
});
titleTxt.anchor.set(0.5, 0.5);
titleTxt.x = 1024;
titleTxt.y = 800;
startScreen.addChild(titleTxt);
}
startScreen.visible = true;
}
// Initialize start screen
showStartScreen();
// Game update loop (minimal for this simple game)
game.update = function () {
if (gameActive && gameStarted) {
// Initialize game start time
if (!gameStartTime) {
gameStartTime = LK.ticks;
}
// Calculate time elapsed (LK.ticks runs at 60fps)
var timeElapsed = Math.floor((LK.ticks - gameStartTime) / 60);
timeLeft = Math.max(0, 25 - timeElapsed);
timerTxt.setText('Time: ' + timeLeft);
// Check if time is up
if (timeLeft <= 0) {
gameActive = false;
// Hide clickable object
clickableObject.visible = false;
// Show final score
finalScoreTxt = new Text2('Final Score: ' + clickCount + ' clicks!', {
size: 120,
fill: 0xFFFF00
});
finalScoreTxt.anchor.set(0.5, 0.5);
finalScoreTxt.x = 1024;
finalScoreTxt.y = 1200;
game.addChild(finalScoreTxt);
// Show restart button
restartButton = new Text2('TEKRAR DENE', {
size: 100,
fill: 0x00FF00
});
restartButton.anchor.set(0.5, 0.5);
restartButton.x = 1024;
restartButton.y = 1500;
game.addChild(restartButton);
// Add click handler to restart button
restartButton.down = function (x, y, obj) {
startGame();
};
}
}
};