/**** * Classes ****/ // Bomb class var Bomb = Container.expand(function () { var self = Container.call(this); var bombGraphics = self.attachAsset('bomb', { anchorX: 0.5, anchorY: -0.5 }); self.visible = false; self.isPoppedUp = false; self.popDownTime = 2000; // Initial pop down time self.popUp = function () { self.visible = true; self.isPoppedUp = true; LK.setTimeout(function () { self.popDown(); }, self.popDownTime); }; self.popDown = function () { self.visible = false; self.isPoppedUp = false; }; self.hit = function () { if (self.isPoppedUp) { self.popDown(); LK.getSound('hitBomb').play(); // Play hit sound if (!godMode) { LK.setScore(LK.getScore() - 1); scoreTxt.setText(LK.getScore()); timer.timeLeft -= 5; // Decrease the time by 5 seconds } } }; self.down = function (x, y, obj) { self.hit(); }; }); var Bomb2 = Container.expand(function () { var self = Container.call(this); var bombGraphics = self.attachAsset('newBomb', { anchorX: 0.5, anchorY: -0.9 }); self.visible = false; self.isPoppedUp = false; self.popDownTime = 2000; // Initial pop down time self.popUp = function () { self.visible = true; self.isPoppedUp = true; LK.setTimeout(function () { self.popDown(); }, self.popDownTime); }; self.popDown = function () { self.visible = false; self.isPoppedUp = false; }; self.hit = function () { if (self.isPoppedUp) { self.popDown(); LK.getSound('hitBomb').play(); // Play hit sound if (!godMode) { LK.setScore(LK.getScore() - 2); // Decrease score by 2 scoreTxt.setText(LK.getScore()); timer.timeLeft -= 10; // Decrease the time by 10 seconds } } }; self.down = function (x, y, obj) { self.hit(); }; }); // Assets will be automatically created and loaded based on their usage in the code. // Hamster class var Hamster = Container.expand(function () { var self = Container.call(this); var hamsterGraphics = self.attachAsset('hamster', { anchorX: 0.5, anchorY: -0.6 }); self.visible = false; self.isPoppedUp = false; self.popUp = function () { self.visible = true; self.isPoppedUp = true; LK.setTimeout(function () { self.popDown(); }, LK.getScore() >= 30 ? 1000 : 2000); }; self.popDown = function () { self.visible = false; self.isPoppedUp = false; }; self.hit = function () { if (self.isPoppedUp) { self.popDown(); LK.getSound('hitHamster').play(); // Play hit sound LK.setScore(LK.getScore() + 1); scoreTxt.setText(LK.getScore()); timer.timeLeft += 2; // Increase the time by 2 seconds } }; self.down = function (x, y, obj) { self.hit(); }; }); // Timer class var Timer = Container.expand(function () { var self = Container.call(this); var timerGraphics = self.attachAsset('timer', { anchorX: 0.5, anchorY: 0.5 }); self.timeLeft = 25; // Set initial time to 60 seconds self.update = function () { if (self.timeLeft > 0) { self.timeLeft -= 1 / 60; // Decrease time by 1 second every 60 frames timerTxt.setText(Math.ceil(self.timeLeft)); // Update the timer text // Increase difficulty after 60 seconds if (self.timeLeft <= 60) { hamsters.forEach(function (hamster) { hamster.popDownTime = 1000; // Decrease pop down time to 1 second }); bombs.forEach(function (bomb) { bomb.popDownTime = 1000; // Decrease pop down time to 1 second }); } } else { LK.effects.flashScreen(0xff0000, 1000); // Flash screen red for 1 second LK.getSound('gameOverSound').play(); // Play game over sound LK.showGameOver(); // End the game when time runs out } }; self.getText = function () { return Math.ceil(self.timeLeft); // Round up to the nearest second }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Play background music var backgroundMusic = LK.getSound('backgroundMusic'); backgroundMusic.loop = true; // Loop the background music backgroundMusic.play(); // Initialize timer text var timerTxt = new Text2('60', { size: 150, fill: "#ffffff" }); // Initialize godMode variable var godMode = false; timerTxt.anchor.set(0, 0); LK.gui.topLeft.addChild(timerTxt); // Initialize timer var timer = new Timer(); timer.x = 2048 / 2; timer.y = 100; game.addChild(timer); // Add background image to the game var background = LK.getAsset('background', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 }); game.addChild(background); // Add frame to the game var frame = LK.getAsset('border', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 }); game.addChild(frame); // Initialize score text var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Initialize hamsters and bombs var hamsters = []; var bombs = []; for (var i = 0; i < 9; i++) { var hamster = new Hamster(); hamster.x = i % 3 * 600 + 400; hamster.y = Math.floor(i / 3) * 600 + 400; game.addChild(hamster); hamsters.push(hamster); var bomb = new Bomb(); bomb.x = i % 3 * 600 + 400; bomb.y = Math.floor(i / 3) * 600 + 400; game.addChild(bomb); bombs.push(bomb); var bomb2 = new Bomb2(); bomb2.x = i % 3 * 600 + 400; bomb2.y = Math.floor(i / 3) * 600 + 400; game.addChild(bomb2); bombs.push(bomb2); } // Function to randomly pop up hamsters function randomPopUp() { var randomIndex1 = Math.floor(Math.random() * hamsters.length); var randomIndex2, randomIndex3; do { randomIndex2 = Math.floor(Math.random() * bombs.length); randomIndex3 = Math.floor(Math.random() * bombs.length); } while (randomIndex1 == randomIndex2 || randomIndex1 == randomIndex3 || randomIndex2 == randomIndex3); hamsters[randomIndex1].popUp(); bombs[randomIndex2].popUp(); if (LK.getScore() >= 30) { bombs[randomIndex3].popUp(); } // Add a circle at the popup locations var circle1 = LK.getAsset('circle', { anchorX: 0.5, anchorY: -0.5, x: hamsters[randomIndex1].x, y: hamsters[randomIndex1].y }); game.addChild(circle1); var circle2 = LK.getAsset('circle', { anchorX: 0.5, anchorY: -0.5, x: bombs[randomIndex2].x, y: bombs[randomIndex2].y }); game.addChild(circle2); } // Set interval to pop up hamsters var popUpInterval = LK.setInterval(randomPopUp, 1000); // Game update function game.update = function () { // No need to update timer text here as it's already updated in Timer class }; // Game over condition function checkGameOver() { // Removed game over condition when player reached 10 points } // Add game over check to update function game.update = function () { checkGameOver(); };
/****
* Classes
****/
// Bomb class
var Bomb = Container.expand(function () {
var self = Container.call(this);
var bombGraphics = self.attachAsset('bomb', {
anchorX: 0.5,
anchorY: -0.5
});
self.visible = false;
self.isPoppedUp = false;
self.popDownTime = 2000; // Initial pop down time
self.popUp = function () {
self.visible = true;
self.isPoppedUp = true;
LK.setTimeout(function () {
self.popDown();
}, self.popDownTime);
};
self.popDown = function () {
self.visible = false;
self.isPoppedUp = false;
};
self.hit = function () {
if (self.isPoppedUp) {
self.popDown();
LK.getSound('hitBomb').play(); // Play hit sound
if (!godMode) {
LK.setScore(LK.getScore() - 1);
scoreTxt.setText(LK.getScore());
timer.timeLeft -= 5; // Decrease the time by 5 seconds
}
}
};
self.down = function (x, y, obj) {
self.hit();
};
});
var Bomb2 = Container.expand(function () {
var self = Container.call(this);
var bombGraphics = self.attachAsset('newBomb', {
anchorX: 0.5,
anchorY: -0.9
});
self.visible = false;
self.isPoppedUp = false;
self.popDownTime = 2000; // Initial pop down time
self.popUp = function () {
self.visible = true;
self.isPoppedUp = true;
LK.setTimeout(function () {
self.popDown();
}, self.popDownTime);
};
self.popDown = function () {
self.visible = false;
self.isPoppedUp = false;
};
self.hit = function () {
if (self.isPoppedUp) {
self.popDown();
LK.getSound('hitBomb').play(); // Play hit sound
if (!godMode) {
LK.setScore(LK.getScore() - 2); // Decrease score by 2
scoreTxt.setText(LK.getScore());
timer.timeLeft -= 10; // Decrease the time by 10 seconds
}
}
};
self.down = function (x, y, obj) {
self.hit();
};
});
// Assets will be automatically created and loaded based on their usage in the code.
// Hamster class
var Hamster = Container.expand(function () {
var self = Container.call(this);
var hamsterGraphics = self.attachAsset('hamster', {
anchorX: 0.5,
anchorY: -0.6
});
self.visible = false;
self.isPoppedUp = false;
self.popUp = function () {
self.visible = true;
self.isPoppedUp = true;
LK.setTimeout(function () {
self.popDown();
}, LK.getScore() >= 30 ? 1000 : 2000);
};
self.popDown = function () {
self.visible = false;
self.isPoppedUp = false;
};
self.hit = function () {
if (self.isPoppedUp) {
self.popDown();
LK.getSound('hitHamster').play(); // Play hit sound
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore());
timer.timeLeft += 2; // Increase the time by 2 seconds
}
};
self.down = function (x, y, obj) {
self.hit();
};
});
// Timer class
var Timer = Container.expand(function () {
var self = Container.call(this);
var timerGraphics = self.attachAsset('timer', {
anchorX: 0.5,
anchorY: 0.5
});
self.timeLeft = 25; // Set initial time to 60 seconds
self.update = function () {
if (self.timeLeft > 0) {
self.timeLeft -= 1 / 60; // Decrease time by 1 second every 60 frames
timerTxt.setText(Math.ceil(self.timeLeft)); // Update the timer text
// Increase difficulty after 60 seconds
if (self.timeLeft <= 60) {
hamsters.forEach(function (hamster) {
hamster.popDownTime = 1000; // Decrease pop down time to 1 second
});
bombs.forEach(function (bomb) {
bomb.popDownTime = 1000; // Decrease pop down time to 1 second
});
}
} else {
LK.effects.flashScreen(0xff0000, 1000); // Flash screen red for 1 second
LK.getSound('gameOverSound').play(); // Play game over sound
LK.showGameOver(); // End the game when time runs out
}
};
self.getText = function () {
return Math.ceil(self.timeLeft); // Round up to the nearest second
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Play background music
var backgroundMusic = LK.getSound('backgroundMusic');
backgroundMusic.loop = true; // Loop the background music
backgroundMusic.play();
// Initialize timer text
var timerTxt = new Text2('60', {
size: 150,
fill: "#ffffff"
});
// Initialize godMode variable
var godMode = false;
timerTxt.anchor.set(0, 0);
LK.gui.topLeft.addChild(timerTxt);
// Initialize timer
var timer = new Timer();
timer.x = 2048 / 2;
timer.y = 100;
game.addChild(timer);
// Add background image to the game
var background = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
});
game.addChild(background);
// Add frame to the game
var frame = LK.getAsset('border', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
});
game.addChild(frame);
// Initialize score text
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Initialize hamsters and bombs
var hamsters = [];
var bombs = [];
for (var i = 0; i < 9; i++) {
var hamster = new Hamster();
hamster.x = i % 3 * 600 + 400;
hamster.y = Math.floor(i / 3) * 600 + 400;
game.addChild(hamster);
hamsters.push(hamster);
var bomb = new Bomb();
bomb.x = i % 3 * 600 + 400;
bomb.y = Math.floor(i / 3) * 600 + 400;
game.addChild(bomb);
bombs.push(bomb);
var bomb2 = new Bomb2();
bomb2.x = i % 3 * 600 + 400;
bomb2.y = Math.floor(i / 3) * 600 + 400;
game.addChild(bomb2);
bombs.push(bomb2);
}
// Function to randomly pop up hamsters
function randomPopUp() {
var randomIndex1 = Math.floor(Math.random() * hamsters.length);
var randomIndex2, randomIndex3;
do {
randomIndex2 = Math.floor(Math.random() * bombs.length);
randomIndex3 = Math.floor(Math.random() * bombs.length);
} while (randomIndex1 == randomIndex2 || randomIndex1 == randomIndex3 || randomIndex2 == randomIndex3);
hamsters[randomIndex1].popUp();
bombs[randomIndex2].popUp();
if (LK.getScore() >= 30) {
bombs[randomIndex3].popUp();
}
// Add a circle at the popup locations
var circle1 = LK.getAsset('circle', {
anchorX: 0.5,
anchorY: -0.5,
x: hamsters[randomIndex1].x,
y: hamsters[randomIndex1].y
});
game.addChild(circle1);
var circle2 = LK.getAsset('circle', {
anchorX: 0.5,
anchorY: -0.5,
x: bombs[randomIndex2].x,
y: bombs[randomIndex2].y
});
game.addChild(circle2);
}
// Set interval to pop up hamsters
var popUpInterval = LK.setInterval(randomPopUp, 1000);
// Game update function
game.update = function () {
// No need to update timer text here as it's already updated in Timer class
};
// Game over condition
function checkGameOver() {
// Removed game over condition when player reached 10 points
}
// Add game over check to update function
game.update = function () {
checkGameOver();
};
curious hamster emerge from the cozy burrow background. Play the “Hit the Hamster” game. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
mud with grass field ground. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
sparking bomb inside MUD HOLE. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
hammer with lightning. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
score board. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
red bomb. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.