User prompt
if the player scored 10 points popup congratulations text
User prompt
if player scored 10 points .popup a text congratulations and initiate level 2
User prompt
if the player scored 10 points ,start level 2
User prompt
create a level 2
User prompt
create a level 2
Code edit (11 edits merged)
Please save this source code
User prompt
add a text to bottom left corner
Code edit (1 edits merged)
Please save this source code
Code edit (18 edits merged)
Please save this source code
User prompt
add a text at the bottom right corner
User prompt
move the score to the bottom right corner
User prompt
place the timer at bottom left corner
User prompt
MOVE THE TIMER TO THE BOTTOM LEFT CORNER
User prompt
MOVE THE TIMER AND SCORE TO THE BOTTOM
Code edit (1 edits merged)
Please save this source code
Code edit (2 edits merged)
Please save this source code
User prompt
the hamster ,bomb,health should appear from hole only
User prompt
add a new icon called hole in all pop up location
User prompt
move all assets to the center
User prompt
place the hole too back
User prompt
Please fix the bug: 'Uncaught RangeError: Maximum call stack size exceeded' in or related to this line: 'var self = Container.call(this);' Line Number: 129
User prompt
make hole as a class
User prompt
all hole should be there at starting of the game
User prompt
dont make the hole disappear
User prompt
place hole in the places of hamster and bomb
/**** * Classes ****/ // Bomb class var Bomb = Container.expand(function () { var self = Container.call(this); var hole = new Hole(); hole.x = self.x; hole.y = self.y; game.addChild(hole); var bombGraphics = self.attachAsset('bomb', { anchorX: 1, anchorY: -2 }); self.visible = false; self.isPoppedUp = false; self.popUp = function () { self.visible = true; self.isPoppedUp = true; LK.setTimeout(function () { self.popDown(); }, 2000); }; self.popDown = function () { bombGraphics.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 hole = new Hole(); hole.x = self.x; hole.y = self.y; game.addChild(hole); var hamsterGraphics = self.attachAsset('hamster', { anchorX: 1, anchorY: -2 }); 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(); }, 2000); }; self.popDown = function () { hamsterGraphics.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, anchorY: -2 }); self.visible = false; self.isPoppedUp = false; self.popUp = function () { self.visible = true; self.isPoppedUp = true; LK.setTimeout(function () { self.popDown(); }, 2000); }; self.popDown = function () { healthGraphics.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(); }; }); // Hole class var Hole = Container.expand(function () { var self = Container.call(this); var hole = new Hole(); hole.x = self.x; hole.y = self.y; game.addChild(hole); }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ var background = game.attachAsset('background', { anchorX: 0, anchorY: 0 }); 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(0.5, 0); LK.gui.top.addChild(scoreTxt); // Initialize gameTimer var gameTimer = 20; // Initialize timer text var timerTxt = new Text2(gameTimer.toString(), { size: 150, fill: "#ffffff" }); timerTxt.anchor.set(0, 0); LK.gui.topLeft.addChild(timerTxt); // Initialize hamsters, bombs, health and gameTimer var hamsters = []; var bombs = []; var healths = []; for (var i = 0; i < 9; i++) { var hole = new Hole(); hole.x = i % 3 * 600 + 400; hole.y = Math.floor(i / 3) * 600 + 400; game.addChild(hole); hole.x = i % 3 * 600 + 400; hole.y = Math.floor(i / 3) * 600 + 400; game.addChild(hole); 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; do { randomIndex2 = Math.floor(Math.random() * bombs.length); } while (randomIndex1 == randomIndex2); 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(); };
===================================================================
--- original.js
+++ change.js
@@ -3,12 +3,12 @@
****/
// Bomb class
var Bomb = Container.expand(function () {
var self = Container.call(this);
- var holeGraphics = self.attachAsset('hole', {
- anchorX: 1,
- anchorY: -2
- });
+ var hole = new Hole();
+ hole.x = self.x;
+ hole.y = self.y;
+ game.addChild(hole);
var bombGraphics = self.attachAsset('bomb', {
anchorX: 1,
anchorY: -2
});
@@ -39,12 +39,12 @@
// 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 holeGraphics = self.attachAsset('hole', {
- anchorX: 1,
- anchorY: -2
- });
+ var hole = new Hole();
+ hole.x = self.x;
+ hole.y = self.y;
+ game.addChild(hole);
var hamsterGraphics = self.attachAsset('hamster', {
anchorX: 1,
anchorY: -2
});
@@ -114,8 +114,16 @@
self.down = function (x, y, obj) {
self.hit();
};
});
+// Hole class
+var Hole = Container.expand(function () {
+ var self = Container.call(this);
+ var hole = new Hole();
+ hole.x = self.x;
+ hole.y = self.y;
+ game.addChild(hole);
+});
/****
* Initialize Game
****/
@@ -155,15 +163,15 @@
var hamsters = [];
var bombs = [];
var healths = [];
for (var i = 0; i < 9; i++) {
- var hole = game.attachAsset('hole', {
- anchorX: 1,
- anchorY: -2
- });
+ var hole = new Hole();
hole.x = i % 3 * 600 + 400;
hole.y = Math.floor(i / 3) * 600 + 400;
game.addChild(hole);
+ hole.x = i % 3 * 600 + 400;
+ hole.y = Math.floor(i / 3) * 600 + 400;
+ game.addChild(hole);
var hamster = new Hamster();
hamster.x = i % 3 * 600 + 400;
hamster.y = Math.floor(i / 3) * 600 + 400;
game.addChild(hamster);
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.