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
User prompt
the grizzly bear is a sprite with a running animation
Code edit (1 edits merged)
Please save this source code
Code edit (3 edits merged)
Please save this source code
User prompt
The bear is not at the same ground level as the rest of the assets, correct it.
User prompt
add trees to the background
Code edit (1 edits merged)
Please save this source code
User prompt
the bear should jump from the bottom and have a gravity effect to make the jump feel natural
User prompt
the bear should stay at the left corner, and it jumps when the screen is touched
Initial prompt
Grizzly and the Lemmings
/**** * Classes ****/ // Grizzly Bear class var GrizzlyBear = Container.expand(function () { var self = Container.call(this); var bearGraphics = self.createAsset('grizzlyBear', 'Grizzly Bear running', 0.5, 1); self.isJumping = false; self.jumpHeight = 1500; self.jumpSpeed = 20; self.gravity = 2; self.jump = function () { if (!self.isJumping) { self.isJumping = true; self.jumpSpeed = -50; } }; 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 = self.createAsset('tree', 'Background tree', 0.5, 1); 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 = self.createAsset('lemming', 'Lemming running away', 0.5, 1); 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 = self.createAsset('rock', 'Obstacle rock', 0.5, 1); self.speed = 2; self.move = function () { self.x -= self.speed; if (self.x < -self.width) { self.destroy(); } }; }); /**** * 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 = 100; 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); } } // Update score display text scoreTxt.setText(score.toString()); // Spawn Rocks at intervals if (LK.ticks % 1200 === 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 intervals if (LK.ticks % 240 === 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
@@ -146,11 +146,11 @@
// Spawn Rocks at intervals
if (LK.ticks % 1200 === 0) {
var newRock = new Rock();
newRock.x = 2048;
- newRock.y = 2732 - newRock.height + 300;
+ newRock.y = 2732 - newRock.height;
rocks.push(newRock);
- game.addChildAt(newRock, 0);
+ game.addChildAt(newRock, game.children.length);
}
// Spawn Lemmings at intervals
if (LK.ticks % 240 === 0) {
var newLemming = new Lemming();
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.