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 = self.createAsset('grizzlyBearRun', 'Grizzly Bear running animation', 0.5, 1); bearGraphics.animationSpeed = 0.5; bearGraphics.play(); 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 >= 2732 - self.height) { self.y = 2732 - 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 > 2048) { self.destroy(); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Sky blue background }); /**** * Game Code ****/ // Initialize important asset arrays var lemmings = []; var trees = []; var grizzlyBear; // Create the Grizzly Bear grizzlyBear = game.addChild(new GrizzlyBear()); grizzlyBear.x = 100; grizzlyBear.y = 2732 - grizzlyBear.height + 100; // Game tick event LK.on('tick', function () { // Make the Grizzly Bear fall grizzlyBear.fall(); // Move each Lemming for (var i = lemmings.length - 1; i >= 0; i--) { lemmings[i].move(); // Check if Lemming is off screen and destroy it if (lemmings[i].x > 2048) { lemmings[i].destroy(); lemmings.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); } } // Spawn Lemmings at intervals if (LK.ticks % 120 === 0) { var newLemming = new Lemming(); newLemming.x = -newLemming.width; newLemming.y = 2732 - newLemming.height; lemmings.push(newLemming); game.addChild(newLemming); } // Spawn Trees at intervals if (LK.ticks % 240 === 0) { var newTree = new Tree(); newTree.x = 2048; newTree.y = 2732 - newTree.height; trees.push(newTree); game.addChild(newTree); } }); // Touch event for Grizzly Bear to jump game.on('down', function () { grizzlyBear.jump(); });
/****
* Classes
****/
// Grizzly Bear class
var GrizzlyBear = Container.expand(function () {
var self = Container.call(this);
var bearGraphics = self.createAsset('grizzlyBearRun', 'Grizzly Bear running animation', 0.5, 1);
bearGraphics.animationSpeed = 0.5;
bearGraphics.play();
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 >= 2732 - self.height) {
self.y = 2732 - 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 > 2048) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Sky blue background
});
/****
* Game Code
****/
// Initialize important asset arrays
var lemmings = [];
var trees = [];
var grizzlyBear;
// Create the Grizzly Bear
grizzlyBear = game.addChild(new GrizzlyBear());
grizzlyBear.x = 100;
grizzlyBear.y = 2732 - grizzlyBear.height + 100;
// Game tick event
LK.on('tick', function () {
// Make the Grizzly Bear fall
grizzlyBear.fall();
// Move each Lemming
for (var i = lemmings.length - 1; i >= 0; i--) {
lemmings[i].move();
// Check if Lemming is off screen and destroy it
if (lemmings[i].x > 2048) {
lemmings[i].destroy();
lemmings.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);
}
}
// Spawn Lemmings at intervals
if (LK.ticks % 120 === 0) {
var newLemming = new Lemming();
newLemming.x = -newLemming.width;
newLemming.y = 2732 - newLemming.height;
lemmings.push(newLemming);
game.addChild(newLemming);
}
// Spawn Trees at intervals
if (LK.ticks % 240 === 0) {
var newTree = new Tree();
newTree.x = 2048;
newTree.y = 2732 - newTree.height;
trees.push(newTree);
game.addChild(newTree);
}
});
// Touch event for Grizzly Bear to jump
game.on('down', function () {
grizzlyBear.jump();
});
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.