Code edit (2 edits merged)
Please save this source code
User prompt
add a ground, it moves at the same speed as the tree
User prompt
Fix Bug: 'TypeError: self.attachAsset is not a function' in this line: 'var rockGraphics = self.attachAsset('rock', {' Line Number: 67
User prompt
Fix Bug: 'TypeError: self.attachAsset is not a function' in this line: 'var treeGraphics = self.attachAsset('tree', {' Line Number: 35
User prompt
Fix Bug: 'TypeError: self.attachAsset is not a function' in this line: 'var lemmingGraphics = self.attachAsset('lemming', {' Line Number: 50
User prompt
Fix Bug: 'Uncaught TypeError: self.attachAsset is not a function' in this line: 'var bearGraphics = self.attachAsset('grizzlyBear', {' Line Number: 7
Code edit (2 edits merged)
Please save this source code
User prompt
rocks and lemmings spawn randomly
Code edit (2 edits merged)
Please save this source code
User prompt
add a road, it should animate as the same speed as the trees
Code edit (6 edits merged)
Please save this source code
User prompt
you win when score reaches 100
Code edit (1 edits merged)
Please save this source code
Code edit (3 edits merged)
Please save this source code
User prompt
add rocks as obstacles to the bear
User prompt
bear and lemmings should be in front of trees always
Code edit (8 edits merged)
Please save this source code
User prompt
increase the score when the bear gets a lemming
User prompt
add a score count
User prompt
Fix Bug: 'TypeError: LK.gui.top.getChildByName is not a function' in this line: 'var scoreTxt = LK.gui.top.getChildByName('scoreTxt');' Line Number: 111
User prompt
add a score count
User prompt
when the bear gets a lemming, the lemming disappears
User prompt
lemmings start from the right and slowly go to the left
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'Uncaught TypeError: self.createSprite is not a function' in this line: 'var bearGraphics = self.createSprite('grizzlyBearRun', 'Grizzly Bear running animation', 0.5, 1);' Line Number: 7
/**** * Classes ****/ // Grizzly Bear class var GrizzlyBear = Container.expand(function () { var self = Container.call(this); var bearGraphics = LK.getAsset('grizzlyBear', { anchorX: 0.5, anchorY: 1 }); self.addChild(bearGraphics); self.isJumping = false; self.jumpSpeed = 0; self.gravity = 0.4; self.jump = function () { if (!self.isJumping) { self.isJumping = true; self.jumpSpeed = -18; } }; self.fall = function () { if (self.isJumping) { self.jumpSpeed += self.gravity; self.y += self.jumpSpeed; if (self.y >= 2832 - self.height) { self.y = 2832 - self.height; self.isJumping = false; } } }; }); // Tree class var Tree = Container.expand(function () { var self = Container.call(this); var treeGraphics = LK.getAsset('tree', { anchorX: 0.5, anchorY: 1 }); self.addChild(treeGraphics); self.speed = 1; self.move = function () { self.x -= self.speed; if (self.x < -self.width) { self.destroy(); } }; }); // Lemming class var Lemming = Container.expand(function () { var self = Container.call(this); var lemmingGraphics = LK.getAsset('lemming', { anchorX: 0.5, anchorY: 1 }); self.addChild(lemmingGraphics); self.speed = 3; self.move = function () { self.x -= self.speed; if (self.x < -self.width) { self.destroy(); } }; }); // Rock class var Rock = Container.expand(function () { var self = Container.call(this); var rockGraphics = LK.getAsset('rock', { anchorX: 0.5, anchorY: 1 }); self.addChild(rockGraphics); self.speed = 5; self.move = function () { self.x -= self.speed; if (self.x < -self.width) { self.destroy(); } }; }); // Ground class var Ground = Container.expand(function () { var self = Container.call(this); var groundGraphics = LK.getAsset('ground', { anchorX: 0.5, anchorY: 1 }); self.addChild(groundGraphics); self.speed = 1; self.move = function () { self.x -= self.speed; if (self.x < -2048) { // Assuming the ground asset is the same width as the game width self.x = 0; // Loop the ground to create a continuous moving effect } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Sky blue background }); /**** * Game Code ****/ // Initialize important asset arrays and score var lemmings = []; var trees = []; var score = 0; var rocks = []; var grizzlyBear; // Create the Grizzly Bear grizzlyBear = game.addChild(new GrizzlyBear()); grizzlyBear.x = 200; grizzlyBear.y = 2732 - grizzlyBear.height + 100; // Create score display var scoreTxt = new Text2(score.toString(), { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Game tick event LK.on('tick', function () { // Spawn Trees at intervals if (LK.ticks % 800 === 0) { var newTree = new Tree(); newTree.x = 2048; newTree.y = 2732 - newTree.height + 300; trees.push(newTree); game.addChildAt(newTree, 0); } // Make the Grizzly Bear fall grizzlyBear.fall(); // Move each Lemming and check for collision with GrizzlyBear for (var i = lemmings.length - 1; i >= 0; i--) { lemmings[i].move(); // Check if Lemming collides with GrizzlyBear and remove it if (grizzlyBear.intersects(lemmings[i])) { // Increase score by 10 when Grizzly Bear catches a Lemming score += 10; lemmings[i].destroy(); lemmings.splice(i, 1); continue; } // Check if Lemming is off screen and destroy it if (lemmings[i].x < -lemmings[i].width) { lemmings[i].destroy(); lemmings.splice(i, 1); } } // Move each Rock for (var i = rocks.length - 1; i >= 0; i--) { rocks[i].move(); // Check if Rock collides with GrizzlyBear and end the game if (grizzlyBear.intersects(rocks[i])) { LK.showGameOver(); } // Check if Rock is off screen and destroy it if (rocks[i].x < -rocks[i].width) { rocks[i].destroy(); rocks.splice(i, 1); } } // Move each Tree for (var i = trees.length - 1; i >= 0; i--) { trees[i].move(); // Check if Tree is off screen and destroy it if (trees[i].x < -trees[i].width) { trees[i].destroy(); trees.splice(i, 1); } } // Move the ground if (!game.ground) { game.ground = game.addChild(new Ground()); game.ground.x = 0; game.ground.y = 2632 - game.ground.height; // Position at the bottom of the screen } game.ground.move(); // Update score display text scoreTxt.setText(score.toString()); // Check if score reaches 100 and end the game as a win if (score >= 200) { LK.showGameOver(); } // Spawn Rocks at random intervals var rockSpawnInterval = Math.floor(Math.random() * 800) + 400; if (LK.ticks % rockSpawnInterval === 0) { var newRock = new Rock(); newRock.x = 2048; newRock.y = 2732 - newRock.height; rocks.push(newRock); game.addChildAt(newRock, game.children.length); } // Spawn Lemmings at random intervals var lemmingSpawnInterval = Math.floor(Math.random() * 200) + 40; if (LK.ticks % lemmingSpawnInterval === 0) { var newLemming = new Lemming(); newLemming.x = 2048; newLemming.y = 2732 - newLemming.height; lemmings.push(newLemming); game.addChildAt(newLemming, game.children.length); } }); // Touch event for Grizzly Bear to jump game.on('down', function () { grizzlyBear.jump(); });
===================================================================
--- original.js
+++ change.js
@@ -176,9 +176,9 @@
// Move the ground
if (!game.ground) {
game.ground = game.addChild(new Ground());
game.ground.x = 0;
- game.ground.y = 2732 - game.ground.height; // Position at the bottom of the screen
+ game.ground.y = 2632 - game.ground.height; // Position at the bottom of the screen
}
game.ground.move();
// Update score display text
scoreTxt.setText(score.toString());
Cartoon style cute apple tree with small branches. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Cartoon style cute rock. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A cute lemming running while holding a nutella cup. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. Cartoon style.