/****
* Classes
****/
// Class for the bucket
var Bucket = Container.expand(function () {
var self = Container.call(this);
var bucketGraphics = self.attachAsset('bucket', {
anchorX: 0.5,
anchorY: 0.5
});
self.move = function (x) {
self.x = x;
};
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Class for the falling objects
var FallingObject = Container.expand(function () {
var self = Container.call(this);
var objectGraphics = self.attachAsset('fallingObject', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
self.y += self.speed;
};
});
// Class for the mole
var Mole = Container.expand(function () {
var self = Container.call(this);
var moleGraphics = self.attachAsset('mole', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
self.y += self.speed;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x006400 //Change background color to a sewer-like color
});
/****
* Game Code
****/
var background = game.addChild(LK.getAsset('background', {}));
// Initialize bucket
var bucket = game.addChild(new Bucket());
bucket.x = 2048 / 2;
bucket.y = 2500;
// Initialize mole
var mole = game.addChild(new Mole());
mole.x = Math.random() * 2048;
mole.y = 0;
// Array to keep track of falling objects
var fallingObjects = [];
// Function to handle move events
function handleMove(x, y, obj) {
bucket.move(x);
}
// Mouse or touch move on game object
game.move = handleMove;
// Game update function
game.update = function () {
// Update falling objects
for (var i = fallingObjects.length - 1; i >= 0; i--) {
var fallingObject = fallingObjects[i];
fallingObject.update();
// Check if the object is off-screen
if (fallingObject.y > 2732) {
fallingObject.destroy();
fallingObjects.splice(i, 1);
continue;
}
// Check for collision with the bucket
if (fallingObject.intersects(bucket)) {
// If the falling object is a mole, end the game
if (fallingObject instanceof Mole) {
LK.showGameOver();
} else {
// Increase score
LK.setScore(LK.getScore() + 1);
fallingObject.destroy();
fallingObjects.splice(i, 1);
}
}
}
// Spawn new falling object
if (LK.ticks % 60 == 0) {
var newFallingObject = new FallingObject();
newFallingObject.x = Math.random() * 2048;
newFallingObject.y = 0;
fallingObjects.push(newFallingObject);
game.addChild(newFallingObject);
}
// Spawn new mole
if (LK.ticks % 120 == 0) {
var newMole = new Mole();
newMole.x = Math.random() * 2048;
newMole.y = 0;
fallingObjects.push(newMole);
game.addChild(newMole);
}
};
// Display score
var scoreTxt = new Text2('0', {
size: 150,
fill: 0xFFFFFF
});
scoreTxt.setText(LK.getScore());
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
Mole. Single Game Texture. In-Game asset. Blank background. High contrast. No shadows
Drop Of water. Single Game Texture. In-Game asset. Blank background. High contrast. No shadows
Bucket. Single Game Texture. In-Game asset. Blank background. High contrast. No shadows
Sewer. Single Game Texture. In-Game asset. Blank background. High contrast. No shadows