/**** * Classes ****/ // Assets will be automatically created and loaded by the LK engine based on their usage in the code. // Class for the Couple var Couple = Container.expand(function () { var self = Container.call(this); var coupleGraphics = self.attachAsset('couple', { anchorX: 0.5, anchorY: 0.5 }); self.lives = 3; self.update = function () { // Update logic for the couple }; self.loseLife = function () { self.lives -= 1; if (self.lives <= 0) { LK.showGameOver(); } }; }); // Class for Falling Objects var FallingObject = Container.expand(function (type) { var self = Container.call(this); var assetId = type === 'heart' ? 'heart' : type === 'scream' ? 'scream' : 'slap'; var fallingObjectGraphics = self.attachAsset(assetId, { anchorX: 0.5, anchorY: 0.5 }); self.type = type; self.speed = FallingObject.prototype.speed || 10; self.update = function () { self.y += self.speed; if (self.y > 2732) { if (self.type === 'heart') { fallenHearts++; if (fallenHearts >= 5) { LK.showGameOver(); } } self.destroy(); } }; }); /**** * Initialize Game ****/ var game = new LK.Game(); /**** * Game Code ****/ LK.playMusic('gameMusic'); var background = game.attachAsset('Background', { anchorX: 0, anchorY: 0, width: 2048, height: 2732 }); // Initialize game variables var couple = game.addChild(new Couple()); couple.x = 2048 / 2; couple.y = 2732 - 200; var fallingObjects = []; var score = 0; var gameTime = 0; var fallenHearts = 0; // New variable to keep track of fallen hearts // Function to handle movement function handleMove(x, y, obj) { couple.x = x; } // Function to spawn falling objects function spawnFallingObject(type) { var newObject = new FallingObject(type); newObject.y = 0; // Ensure that no object have the same position in the horizontal line do { newObject.x = Math.random() * (2048 - newObject.width); var overlap = false; for (var i = 0; i < fallingObjects.length; i++) { if (Math.abs(newObject.x - fallingObjects[i].x) < newObject.width + 100) { // 100 pixels is approximately 1 cm on most screens overlap = true; break; } } } while (overlap); fallingObjects.push(newObject); game.addChild(newObject); } // Game update function game.update = function () { for (var i = fallingObjects.length - 1; i >= 0; i--) { if (fallingObjects[i].intersects(couple)) { if (fallingObjects[i].type === 'heart') { score += 10; } else { couple.loseLife(); } fallingObjects[i].destroy(); fallingObjects.splice(i, 1); } } if (LK.ticks % 240 === 0) { gameTime++; if (gameTime % 10 === 0) { FallingObject.prototype.speed += 5; } if (Math.random() < 0.52) { for (var i = 0; i < 3; i++) { spawnFallingObject('scream'); spawnFallingObject('slap'); } } } if (LK.ticks % 120 === 0) { spawnFallingObject('heart'); } }; // Event listeners game.move = handleMove; game.down = handleMove; game.up = function (x, y, obj) { // Handle touch release };
/****
* Classes
****/
// Assets will be automatically created and loaded by the LK engine based on their usage in the code.
// Class for the Couple
var Couple = Container.expand(function () {
var self = Container.call(this);
var coupleGraphics = self.attachAsset('couple', {
anchorX: 0.5,
anchorY: 0.5
});
self.lives = 3;
self.update = function () {
// Update logic for the couple
};
self.loseLife = function () {
self.lives -= 1;
if (self.lives <= 0) {
LK.showGameOver();
}
};
});
// Class for Falling Objects
var FallingObject = Container.expand(function (type) {
var self = Container.call(this);
var assetId = type === 'heart' ? 'heart' : type === 'scream' ? 'scream' : 'slap';
var fallingObjectGraphics = self.attachAsset(assetId, {
anchorX: 0.5,
anchorY: 0.5
});
self.type = type;
self.speed = FallingObject.prototype.speed || 10;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
if (self.type === 'heart') {
fallenHearts++;
if (fallenHearts >= 5) {
LK.showGameOver();
}
}
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game();
/****
* Game Code
****/
LK.playMusic('gameMusic');
var background = game.attachAsset('Background', {
anchorX: 0,
anchorY: 0,
width: 2048,
height: 2732
});
// Initialize game variables
var couple = game.addChild(new Couple());
couple.x = 2048 / 2;
couple.y = 2732 - 200;
var fallingObjects = [];
var score = 0;
var gameTime = 0;
var fallenHearts = 0; // New variable to keep track of fallen hearts
// Function to handle movement
function handleMove(x, y, obj) {
couple.x = x;
}
// Function to spawn falling objects
function spawnFallingObject(type) {
var newObject = new FallingObject(type);
newObject.y = 0;
// Ensure that no object have the same position in the horizontal line
do {
newObject.x = Math.random() * (2048 - newObject.width);
var overlap = false;
for (var i = 0; i < fallingObjects.length; i++) {
if (Math.abs(newObject.x - fallingObjects[i].x) < newObject.width + 100) {
// 100 pixels is approximately 1 cm on most screens
overlap = true;
break;
}
}
} while (overlap);
fallingObjects.push(newObject);
game.addChild(newObject);
}
// Game update function
game.update = function () {
for (var i = fallingObjects.length - 1; i >= 0; i--) {
if (fallingObjects[i].intersects(couple)) {
if (fallingObjects[i].type === 'heart') {
score += 10;
} else {
couple.loseLife();
}
fallingObjects[i].destroy();
fallingObjects.splice(i, 1);
}
}
if (LK.ticks % 240 === 0) {
gameTime++;
if (gameTime % 10 === 0) {
FallingObject.prototype.speed += 5;
}
if (Math.random() < 0.52) {
for (var i = 0; i < 3; i++) {
spawnFallingObject('scream');
spawnFallingObject('slap');
}
}
}
if (LK.ticks % 120 === 0) {
spawnFallingObject('heart');
}
};
// Event listeners
game.move = handleMove;
game.down = handleMove;
game.up = function (x, y, obj) {
// Handle touch release
};