User prompt
manage the timer with score
User prompt
make this game more intresting
User prompt
fix all the bug
Code edit (1 edits merged)
Please save this source code
User prompt
fix the bug
User prompt
remove the top level text
User prompt
make this game fantastic
User prompt
fix the bug
Code edit (1 edits merged)
Please save this source code
User prompt
increase the timer 20 seconds to 30 seconds
User prompt
reduce the popup time of hamster to 3 seconds when player scored 10 points
User prompt
play the background music in loop
User prompt
play a background music. when the game starts
User prompt
play the background music when the game starts
User prompt
Please fix the bug: 'Uncaught TypeError: Graphics is not a constructor' in or related to this line: 'var border = new Graphics();' Line Number: 135
User prompt
add border to the screen
User prompt
give 10 seconds to timer when player reached level 2
User prompt
add 10 seconds to the timer when player scored 10 points
User prompt
increase the timer +10 seconds when player scored 10 points
User prompt
make the game little hard when player scored 10 points
User prompt
increase the popup speed of the hamster , bomb, when player reached level 2
User prompt
increase the pop up speed when player scored 10 points
User prompt
when player scored 30 points level 3 text should appear in the same place od level 2
User prompt
after player scored 30 points again congratulations should appear
User prompt
move the congratulations to center
/**** * Classes ****/ // Bomb class var Bomb = Container.expand(function () { var self = Container.call(this); var bombGraphics = self.attachAsset('bomb', { anchorX: -1.5, anchorY: 2.5 }); self.visible = false; self.isPoppedUp = false; self.popUp = function () { self.visible = true; self.isPoppedUp = true; LK.setTimeout(function () { self.popDown(); }, 3000); }; self.popDown = function () { self.visible = false; self.isPoppedUp = false; }; self.hit = function () { if (self.isPoppedUp) { self.popDown(); gameTimer -= 10; // Subtract 10 seconds from the timer timerTxt.setText(gameTimer.toString()); // Update the timer display } }; 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: -1.5, anchorY: 2.5 }); self.visible = false; self.isPoppedUp = false; self.popUp = function () { self.visible = true; self.isPoppedUp = true; self.scaleX = 0; self.scaleY = 0; var scaleInterval = LK.setInterval(function () { if (self.scaleX < 1) { self.scaleX += 0.1; self.scaleY += 0.1; } else { LK.clearInterval(scaleInterval); } }, 50); LK.setTimeout(function () { self.popDown(); }, 3000); }; self.popDown = function () { self.visible = false; self.isPoppedUp = false; }; self.hit = function () { if (self.isPoppedUp) { self.popDown(); LK.setScore(LK.getScore() + 1); scoreTxt.setText(LK.getScore()); gameTimer += 2; // Add 6 seconds to the timer timerTxt.setText(gameTimer.toString()); // Update the timer display } }; self.down = function (x, y, obj) { self.hit(); }; }); // Health class var Health = Container.expand(function () { var self = Container.call(this); var healthGraphics = self.attachAsset('health', { anchorX: -1.5, anchorY: 2.5 }); self.visible = false; self.isPoppedUp = false; self.popUp = function () { self.visible = true; self.isPoppedUp = true; LK.setTimeout(function () { self.popDown(); }, 3000); }; self.popDown = function () { self.visible = false; self.isPoppedUp = false; }; self.hit = function () { if (self.isPoppedUp) { self.popDown(); gameTimer += 10; // Add 10 seconds to the timer timerTxt.setText(gameTimer.toString()); // Update the timer display } }; self.down = function (x, y, obj) { self.hit(); }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ LK.getSound('backgroundMusic').play({ loop: true }); var background = game.attachAsset('background', { anchorX: 0, anchorY: 0 }); // Create a border for the game screen var border = game.attachAsset('border', { anchorX: 0, anchorY: 0 }); game.addChild(border); LK.setTimeout(function () { var randomIndex = Math.floor(Math.random() * healths.length); healths[randomIndex].popUp(); }, 10000); // Set interval to pop up health // Initialize score text var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(1, 1); LK.gui.bottomRight.addChild(scoreTxt); var bottomRightText = new Text2('SCORE:', { size: 100, fill: "#ffffff" }); bottomRightText.anchor.set(1.5, 1.2); LK.gui.bottomRight.addChild(bottomRightText); // Initialize gameTimer var gameTimer = 30; // Initialize timer text var timerTxt = new Text2(gameTimer.toString(), { size: 150, fill: "#ffffff" }); timerTxt.anchor.set(0, 1); LK.gui.bottomLeft.addChild(timerTxt); var bottomLeftText = new Text2(':TIMER', { size: 100, fill: "#ffffff" }); bottomLeftText.anchor.set(-0.8, 1.2); LK.gui.bottomLeft.addChild(bottomLeftText); // Initialize hamsters, bombs, health and gameTimer var hamsters = []; var bombs = []; var healths = []; 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 health = new Health(); health.x = i % 3 * 600 + 400; health.y = Math.floor(i / 3) * 600 + 400; game.addChild(health); healths.push(health); } // Function to randomly pop up hamsters or bombs function randomPopUp() { var randomIndex1 = Math.floor(Math.random() * hamsters.length); var randomIndex2 = Math.floor(Math.random() * bombs.length); while (randomIndex1 == randomIndex2) { randomIndex2 = Math.floor(Math.random() * bombs.length); } hamsters[randomIndex1].popUp(); bombs[randomIndex2].popUp(); } // Set interval to pop up hamsters var popUpInterval = LK.setInterval(randomPopUp, 1000); // Game update function game.update = function () { // Decrease gameTimer by 1 every second if (LK.ticks % 60 == 0) { gameTimer--; timerTxt.setText(gameTimer.toString()); } checkGameOver(); }; // Game over condition function checkGameOver() { // Check if the game is over if (gameTimer <= 0) { LK.showGameOver(); } } // Add game over check to update function game.update = function () { // Decrease gameTimer by 1 every second if (LK.ticks % 60 == 0) { gameTimer--; timerTxt.setText(gameTimer.toString()); } checkGameOver(); if (LK.getScore() == 10) { level01.setText('LEVEL 2'); LK.clearInterval(popUpInterval); popUpInterval = LK.setInterval(randomPopUp, 3000); } else if (LK.getScore() == 30) { level01.setText('LEVEL 3'); var conversationText = new Text2('LEVEL 3', { size: 100, fill: "#ffffff" }); conversationText.anchor.set(0.5, 0.5); conversationText.x = game.width / 2; conversationText.y = game.height / 2; game.addChild(conversationText); LK.setTimeout(function () { game.removeChild(conversationText); }, 2000); } }; // Add a text at the top center of the screen var topCenterText = new Text2('Top Center Text', { size: 100, fill: "#ffffff" }); topCenterText.anchor.set(0.5, 0); var level01 = new Text2('LEVEL 1', { size: 100, fill: "#ffffff" }); level01.anchor.set(0.5, 0); LK.gui.top.addChild(level01);
===================================================================
--- original.js
+++ change.js
@@ -149,9 +149,9 @@
});
bottomRightText.anchor.set(1.5, 1.2);
LK.gui.bottomRight.addChild(bottomRightText);
// Initialize gameTimer
-var gameTimer = 20;
+var gameTimer = 30;
// Initialize timer text
var timerTxt = new Text2(gameTimer.toString(), {
size: 150,
fill: "#ffffff"
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.