/****
* Classes
****/
// Position player near the bottom of the screen
// Define the Package class
var Package = Container.expand(function () {
var self = Container.call(this);
var packageGraphics = self.attachAsset('package', {
anchorX: 0.5,
anchorY: 0.5
});
self.value = 0;
self.revealed = false;
self.revealValue = function () {
if (!self.revealed) {
self.revealed = true;
var valueText = new Text2(self.value.toString(), {
size: 100,
fill: "#ffffff"
});
valueText.anchor.set(0.5, 0.5);
valueText.x = self.width / 2;
valueText.y = self.height / 2;
self.addChild(valueText);
LK.setTimeout(function () {
self.visible = false;
}, 500);
}
};
});
var GameOverScreen = Container.expand(function () {
var self = Container.call(this);
self.show = function (value) {
var winText = new Text2('You won \'', {
size: 150,
fill: "#ffffff"
});
winText.anchor.set(0.5, 0.5);
winText.x = 2048 / 2;
winText.y = 2732 / 2 - 200;
self.addChild(winText);
var valueText = new Text2('€' + value.toString(), {
size: 150,
fill: "#ffffff"
});
valueText.anchor.set(0.5, 0.5);
valueText.x = 2048 / 2;
valueText.y = 2732 / 2;
self.addChild(valueText);
LK.setTimeout(function () {
LK.showGameOver();
}, 3000);
};
});
/****
* Initialize Game
****/
// Game tick event
// Initialize packages with hidden values
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Initialize packages with hidden values
// Game tick event
// Add the background image to the game
var background = game.addChild(LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5
}));
background.x = 2048 / 2;
background.y = 2732 / 2;
var gameOverScreen = game.addChild(new GameOverScreen());
// Initialize important asset arrays
var obstacles = [];
var player;
var gameOverScreen;
// Initialize packages with hidden values
var packages = [];
var packageValues = [0, 0.25, 0.50, 0.75, 1, 1.5, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 16, 18, 20];
for (var i = 0; i < 20; i++) {
var newPackage = new Package();
newPackage.value = packageValues.splice(Math.floor(Math.random() * packageValues.length), 1)[0];
packages.push(newPackage);
game.addChild(newPackage);
}
// Position packages uniformly on the screen
var rows = 4;
var columns = 5;
var packageIndex = 0;
var packageWidth = packages[0].width;
var packageHeight = packages[0].height;
var horizontalSpacing = (2048 - packageWidth * columns) / (columns + 1);
var verticalSpacing = (2732 - packageHeight * rows) / (rows + 1);
for (var row = 0; row < rows; row++) {
for (var col = 0; col < columns; col++) {
var pkg = packages[packageIndex++];
pkg.x = horizontalSpacing + col * (packageWidth + horizontalSpacing);
pkg.y = verticalSpacing + row * (packageHeight + verticalSpacing);
if (packageIndex >= packages.length) {
break;
}
}
}
// Handle swipe events
function handleSwipe(obj) {
var event = obj.event;
var direction = getSwipeDirection(event);
player.swipe(direction);
}
// Utility function to determine swipe direction
function getSwipeDirection(event) {
// Placeholder for swipe direction logic
return 'left'; // Example direction
}
// Add event listener for package touch and check if all packages are revealed
var revealedPackagesCount = 0;
packages.forEach(function (pkg) {
pkg.on('down', function () {
if (!pkg.revealed) {
revealedPackagesCount++;
}
pkg.revealValue();
if (revealedPackagesCount === packages.length) {
gameOverScreen.show(pkg.value);
}
});
});
// Game tick event
LK.on('tick', function () {});
// Note: Additional game logic, asset loading, and event handling would be added here as needed.