/****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Mole class to represent each mole in the game
var Mole = Container.expand(function () {
var self = Container.call(this);
var moleGraphics = self.attachAsset('mole', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = Math.random() * 2 + 1; // Random speed for each mole
self.visible = false; // Initially not visible
// Method to show the mole
self.show = function () {
self.visible = true;
self.y = 0; // Start from the hole
};
// Method to hide the mole
self.hide = function () {
self.visible = false;
};
// Event handler called when a press happens on element
self.down = function (x, y, obj) {
self.hide();
score++;
scoreTxt.setText('Score: ' + score);
};
// Update method for mole movement
self.update = function () {
if (self.visible) {
self.y += self.speed;
self.x += (Math.random() - 0.5) * 20; // Random horizontal movement
if (self.x < 0) {
self.x = 0;
} // Ensure mole does not move out of the left boundary
if (self.x > 2048) {
self.x = 2048;
} // Ensure mole does not move out of the right boundary
if (self.y > 2000) {
// Change one life point to red
if (lifePoints.length > 0) {
var heart = lifePoints.pop();
heart.tint = 0xff0000; // Change heart color to red
// Start slowmotion
isPaused = true;
LK.setTimeout(function () {
isPaused = false;
}, 5000);
}
// If mole is fully out, hide it
self.hide();
// Delete half of the stars and moles
var halfStars = Math.floor(game.children.filter(function (child) {
return child instanceof Star;
}).length / 2);
var halfMoles = Math.floor(moles.length / 2);
for (var i = 0; i < halfStars; i++) {
var star = game.children.find(function (child) {
return child instanceof Star;
});
game.removeChild(star);
}
for (var i = 0; i < halfMoles; i++) {
var mole = moles[i];
mole.hide();
moles.splice(moles.indexOf(mole), 1);
}
// Ensure life points remain visible
lifePoints.forEach(function (heart) {
if (!game.children.includes(heart)) {
game.addChild(heart);
}
});
// Check if all life points are red (game over condition)
if (lifePoints.length === 0) {
LK.showGameOver(); // Display game over
}
}
}
};
});
var Star = Container.expand(function () {
var self = Container.call(this);
var starGraphics = self.attachAsset('star', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = (Math.random() * 2 + 1) * 2; // Double the speed for each star
self.visible = false; // Initially not visible
// Method to show the star
self.show = function () {
self.visible = true;
self.y = 0; // Start from the top
};
// Method to hide the star
self.hide = function () {
self.visible = false;
};
// Update method for star movement
self.update = function () {
if (self.visible) {
self.y += self.speed;
self.x += (Math.random() - 0.5) * 20; // Random horizontal movement
if (self.x < 0) {
self.x = 0;
} // Ensure star does not move out of the left boundary
if (self.x > 2048) {
self.x = 2048;
} // Ensure star does not move out of the right boundary
if (self.y > 2000) {
// If star is fully out, hide it
self.hide();
// Add a mole when a star reaches the green surface
var mole = new Mole();
mole.x = Math.random() * 2048;
mole.y = 500;
moles.push(mole);
game.addChild(mole);
}
}
};
// Event handler called when a press happens on element
self.down = function (x, y, obj) {
self.hide();
score += 10;
scoreTxt.setText('Score: ' + score);
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb // Light blue background
});
/****
* Game Code
****/
// Game state variables
var score = 0;
var moles = [];
var lifePoints = [];
var hammerCursor;
var scoreMilestones = []; // Track score milestones
var isPaused = false;
// Initialize the game board
function initBoard() {
var greenSurface = LK.getAsset('greenSurface', {
anchorX: 0.0,
anchorY: 0.0,
x: 0,
y: 2000
});
game.addChild(greenSurface);
for (var i = 0; i < 1; i++) {
var mole = new Mole();
mole.x = Math.random() * 2048;
mole.y = 500;
moles.push(mole);
game.addChild(mole);
var star = new Star();
star.x = Math.random() * 2048;
star.y = 0;
game.addChild(star);
}
}
// Initialize the game interface
function initInterface() {
// Score display
scoreTxt = new Text2('Score: 0', {
size: 100,
fill: 0x000000,
fontWeight: "bold"
});
scoreTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(scoreTxt);
// Level display
levelTxt = new Text2('Level: 0', {
size: 100,
fill: 0x000000,
fontWeight: "bold"
});
levelTxt.anchor.set(0, 0);
LK.gui.topLeft.addChild(levelTxt);
// Pause/Unpause button
var pauseButton = new Text2('Slowmotion', {
size: 80,
fill: 0xFF4500 // Fiery color
});
pauseButton.anchor.set(0, 1);
pauseButton.stroke = 0x000000; // Black color for the line
pauseButton.strokeThickness = 5; // Thickness of the line
// Life points display
for (var i = 0; i < 3; i++) {
var heart = LK.getAsset('heart', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024 - i * 60,
y: 2366
});
game.addChild(heart); // Add hearts to the game scene
lifePoints.push(heart);
}
// Add "Life Points" text below the life points
var lifePointsText = new Text2('Life Points', {
size: 80,
fill: 0x0000FF,
fontWeight: "bold",
fontFamily: "'Comic Sans MS', cursive, sans-serif"
});
lifePointsText.anchor.set(0.5, 0);
lifePointsText.x = 1024;
lifePointsText.y = 2426; // Position below the hearts
game.addChild(lifePointsText);
LK.gui.bottomLeft.addChild(pauseButton);
// Event listeners for buttons
pauseButton.down = function () {
isPaused = !isPaused;
pauseButton.setText(isPaused ? 'Normal speed' : 'Slowmotion');
};
}
// Reset game state
function resetGame() {
score = 0;
moles.forEach(function (mole) {
return mole.hide();
});
}
// Show the starting menu
function showMenu() {
// Implement menu display logic
}
// Game update loop
game.update = function () {
// Add stars at specific score milestones
if (score % 10 === 0 && score <= 100 && !scoreMilestones.includes(score)) {
var numberOfStars = score / 10 + 1; // Calculate number of stars based on milestone
for (var i = 0; i < numberOfStars; i++) {
var star = new Star();
star.x = Math.random() * 2048;
star.y = 0;
game.addChild(star);
}
scoreMilestones.push(score); // Track the milestone
// Update level display
levelTxt.setText('Level: ' + Math.floor(score / 10));
// Remove all the stars after every level
if (scoreMilestones.length % 10 === 0) {
var starsToRemove = game.children.filter(function (child) {
return child instanceof Star;
});
starsToRemove.forEach(function (star) {
return game.removeChild(star);
});
}
}
if (isPaused) {
return;
}
moles.forEach(function (mole) {
mole.update();
if (!mole.visible && Math.random() < 0.01) {
mole.show();
}
});
game.children.forEach(function (child) {
if (child instanceof Star) {
child.update();
if (!child.visible && Math.random() < 0.01) {
child.show();
}
}
});
};
// Initialize the game
initBoard();
initInterface();
showMenu(); /****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Mole class to represent each mole in the game
var Mole = Container.expand(function () {
var self = Container.call(this);
var moleGraphics = self.attachAsset('mole', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = Math.random() * 2 + 1; // Random speed for each mole
self.visible = false; // Initially not visible
// Method to show the mole
self.show = function () {
self.visible = true;
self.y = 0; // Start from the hole
};
// Method to hide the mole
self.hide = function () {
self.visible = false;
};
// Event handler called when a press happens on element
self.down = function (x, y, obj) {
self.hide();
score++;
scoreTxt.setText('Score: ' + score);
};
// Update method for mole movement
self.update = function () {
if (self.visible) {
self.y += self.speed;
self.x += (Math.random() - 0.5) * 20; // Random horizontal movement
if (self.x < 0) {
self.x = 0;
} // Ensure mole does not move out of the left boundary
if (self.x > 2048) {
self.x = 2048;
} // Ensure mole does not move out of the right boundary
if (self.y > 2000) {
// Change one life point to red
if (lifePoints.length > 0) {
var heart = lifePoints.pop();
heart.tint = 0xff0000; // Change heart color to red
// Start slowmotion
isPaused = true;
LK.setTimeout(function () {
isPaused = false;
}, 5000);
}
// If mole is fully out, hide it
self.hide();
// Delete half of the stars and moles
var halfStars = Math.floor(game.children.filter(function (child) {
return child instanceof Star;
}).length / 2);
var halfMoles = Math.floor(moles.length / 2);
for (var i = 0; i < halfStars; i++) {
var star = game.children.find(function (child) {
return child instanceof Star;
});
game.removeChild(star);
}
for (var i = 0; i < halfMoles; i++) {
var mole = moles[i];
mole.hide();
moles.splice(moles.indexOf(mole), 1);
}
// Ensure life points remain visible
lifePoints.forEach(function (heart) {
if (!game.children.includes(heart)) {
game.addChild(heart);
}
});
// Check if all life points are red (game over condition)
if (lifePoints.length === 0) {
LK.showGameOver(); // Display game over
}
}
}
};
});
var Star = Container.expand(function () {
var self = Container.call(this);
var starGraphics = self.attachAsset('star', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = (Math.random() * 2 + 1) * 2; // Double the speed for each star
self.visible = false; // Initially not visible
// Method to show the star
self.show = function () {
self.visible = true;
self.y = 0; // Start from the top
};
// Method to hide the star
self.hide = function () {
self.visible = false;
};
// Update method for star movement
self.update = function () {
if (self.visible) {
self.y += self.speed;
self.x += (Math.random() - 0.5) * 20; // Random horizontal movement
if (self.x < 0) {
self.x = 0;
} // Ensure star does not move out of the left boundary
if (self.x > 2048) {
self.x = 2048;
} // Ensure star does not move out of the right boundary
if (self.y > 2000) {
// If star is fully out, hide it
self.hide();
// Add a mole when a star reaches the green surface
var mole = new Mole();
mole.x = Math.random() * 2048;
mole.y = 500;
moles.push(mole);
game.addChild(mole);
}
}
};
// Event handler called when a press happens on element
self.down = function (x, y, obj) {
self.hide();
score += 10;
scoreTxt.setText('Score: ' + score);
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb // Light blue background
});
/****
* Game Code
****/
// Game state variables
var score = 0;
var moles = [];
var lifePoints = [];
var hammerCursor;
var scoreMilestones = []; // Track score milestones
var isPaused = false;
// Initialize the game board
function initBoard() {
var greenSurface = LK.getAsset('greenSurface', {
anchorX: 0.0,
anchorY: 0.0,
x: 0,
y: 2000
});
game.addChild(greenSurface);
for (var i = 0; i < 1; i++) {
var mole = new Mole();
mole.x = Math.random() * 2048;
mole.y = 500;
moles.push(mole);
game.addChild(mole);
var star = new Star();
star.x = Math.random() * 2048;
star.y = 0;
game.addChild(star);
}
}
// Initialize the game interface
function initInterface() {
// Score display
scoreTxt = new Text2('Score: 0', {
size: 100,
fill: 0x000000,
fontWeight: "bold"
});
scoreTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(scoreTxt);
// Level display
levelTxt = new Text2('Level: 0', {
size: 100,
fill: 0x000000,
fontWeight: "bold"
});
levelTxt.anchor.set(0, 0);
LK.gui.topLeft.addChild(levelTxt);
// Pause/Unpause button
var pauseButton = new Text2('Slowmotion', {
size: 80,
fill: 0xFF4500 // Fiery color
});
pauseButton.anchor.set(0, 1);
pauseButton.stroke = 0x000000; // Black color for the line
pauseButton.strokeThickness = 5; // Thickness of the line
// Life points display
for (var i = 0; i < 3; i++) {
var heart = LK.getAsset('heart', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024 - i * 60,
y: 2366
});
game.addChild(heart); // Add hearts to the game scene
lifePoints.push(heart);
}
// Add "Life Points" text below the life points
var lifePointsText = new Text2('Life Points', {
size: 80,
fill: 0x0000FF,
fontWeight: "bold",
fontFamily: "'Comic Sans MS', cursive, sans-serif"
});
lifePointsText.anchor.set(0.5, 0);
lifePointsText.x = 1024;
lifePointsText.y = 2426; // Position below the hearts
game.addChild(lifePointsText);
LK.gui.bottomLeft.addChild(pauseButton);
// Event listeners for buttons
pauseButton.down = function () {
isPaused = !isPaused;
pauseButton.setText(isPaused ? 'Normal speed' : 'Slowmotion');
};
}
// Reset game state
function resetGame() {
score = 0;
moles.forEach(function (mole) {
return mole.hide();
});
}
// Show the starting menu
function showMenu() {
// Implement menu display logic
}
// Game update loop
game.update = function () {
// Add stars at specific score milestones
if (score % 10 === 0 && score <= 100 && !scoreMilestones.includes(score)) {
var numberOfStars = score / 10 + 1; // Calculate number of stars based on milestone
for (var i = 0; i < numberOfStars; i++) {
var star = new Star();
star.x = Math.random() * 2048;
star.y = 0;
game.addChild(star);
}
scoreMilestones.push(score); // Track the milestone
// Update level display
levelTxt.setText('Level: ' + Math.floor(score / 10));
// Remove all the stars after every level
if (scoreMilestones.length % 10 === 0) {
var starsToRemove = game.children.filter(function (child) {
return child instanceof Star;
});
starsToRemove.forEach(function (star) {
return game.removeChild(star);
});
}
}
if (isPaused) {
return;
}
moles.forEach(function (mole) {
mole.update();
if (!mole.visible && Math.random() < 0.01) {
mole.show();
}
});
game.children.forEach(function (child) {
if (child instanceof Star) {
child.update();
if (!child.visible && Math.random() < 0.01) {
child.show();
}
}
});
};
// Initialize the game
initBoard();
initInterface();
showMenu();