/****
* Classes
****/
//<Assets used in the game will automatically appear here>
// SandCastle class
var SandCastle = Container.expand(function () {
var self = Container.call(this);
var sandCastleGraphics = self.attachAsset('sandCastle', {
anchorX: 0.5,
anchorY: 0.5
});
self.down = function (x, y, obj) {
// Increment score when sand castle is clicked
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore());
// Animate the sand castle
self.animate();
// Play the 'SandcastleClick' sound
LK.getSound('SandcastleClick').play();
};
self.animate = function () {
// Save the original position
var originalPositionX = self.x;
var originalPositionY = self.y;
// Check if the sand castle is already enlarged
if (self.scale.x > 1 || self.scale.y > 1) {
// Reset the scale to original size
self.scale.x = 1;
self.scale.y = 1;
} else {
// Save the original scale
var originalScaleX = self.scale.x;
var originalScaleY = self.scale.y;
// Increase the scale
self.scale.x = originalScaleX * 1.1;
self.scale.y = originalScaleY * 1.1;
// Adjust the position to compensate for the scale change
self.x = originalPositionX - self.width * 0.05;
self.y = originalPositionY - self.height * 0.05;
// Create a timer to reset the scale and position
var timer = LK.setTimeout(function () {
self.scale.x = originalScaleX;
self.scale.y = originalScaleY;
self.x = originalPositionX;
self.y = originalPositionY;
}, 100);
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game();
/****
* Game Code
****/
// Initialize score text
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.setText(LK.getScore());
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Create and position the background
var background = game.addChild(LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5
}));
background.x = 2048 / 2;
background.y = 2732 / 2;
// Create and position the sand castle
var sandCastle = game.addChild(new SandCastle());
sandCastle.x = 2048 / 2;
sandCastle.y = 2732 - sandCastle.height / 2 - 350;
// Update function
game.update = function () {
// No additional update logic needed for this simple game
};
// Mouse or touch down on the game object
game.down = function (x, y, obj) {
// Check if the click is on the sand castle
if (sandCastle.intersects(obj)) {
sandCastle.down(x, y, obj);
}
};