/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
//<Write entity 'classes' with empty functions for important behavior here>
var ClickableCircle = Container.expand(function () {
var self = Container.call(this);
var circleGraphics = self.attachAsset('circle', {
anchorX: 0.5,
anchorY: 0.5
});
self.down = function (x, y, obj) {
// Increase score on click
LK.setScore(LK.getScore() + 1);
// Update score text
scoreTxt.setText(LK.getScore());
// Play sound 't' on click
LK.getSound('t').play();
var scoreText = game.addChild(new ScoreText());
scoreText.x = 2048 / 2;
scoreText.y = scoreTxt.y + scoreTxt.height + 100;
scoreText.alpha = 1;
// Check if score is a multiple of 100
if (LK.getScore() % 100 === 0) {
var congratsText = new Text2('Congratulations!', {
size: 200,
fill: 0xFFFFFF
});
congratsText.anchor.set(0.5, 0);
congratsText.x = 2048 / 2;
congratsText.y = 2732 / 2;
game.addChild(congratsText);
// Add a tween to fade out the 'Congratulations!' text after 2 seconds
tween(congratsText, {
alpha: 0
}, {
duration: 2000
});
}
};
});
var ScoreText = Text2.expand(function () {
var self = Text2.call(this, '+1', {
size: 100,
fill: 0xFFFFFF
});
self.anchor.set(0.5, 0);
self.alpha = 0;
self.update = function () {
if (self.alpha > 0) {
self.alpha -= 0.01;
self.y -= 1;
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
//<Write game logic code here, including initializing arrays and variables>
var scoreTxt = new Text2('0', {
size: 150,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var circle = game.addChild(new ClickableCircle());
circle.x = 2048 / 2;
circle.y = 2732 / 2 + 50;
// Add the background image to the game
var background = game.addChildAt(LK.getAsset('arkaplan', {
anchorX: 0.5,
anchorY: 0.5
}), 0);
background.x = 2048 / 2;
background.y = 2732 / 2;
game.update = function () {
// Game logic updates
};