User prompt
Place the banana icon at the left of the banana's number
User prompt
Improve the banana's indicator by displaying a banana icon instead of the text "Bananas:"
User prompt
Make spider move a greater distance, 3 times height
User prompt
Remove the intro pop-up
User prompt
It's also game over when touching a spider
User prompt
When selecting the spider's branch, select among those located on the first 2/3 of the screen
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'y')' in this line: 'return branch && branch.y < 2 / 3 * 2732 && branch.y > monkey.y + monkey.height;' Line Number: 161
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'y')' in this line: 'return branch.y < 2 / 3 * 2732 && branch.y > monkey.y + monkey.height;' Line Number: 161
User prompt
When selecting the spider's branch, select among those located on the first 2/3 of the screen, away from the monkey
User prompt
Change spider distance from self.height to double it
User prompt
spider originalY must be setup on setupLevel
User prompt
The spider Y position should ping-pong between its original Y position and the (original Y position + height)
User prompt
The spider should keep it's original position and move relative to that
User prompt
I think there's no call to spider update
User prompt
The spider should move slowly down and slowly back up
User prompt
There's a problem, you are creating a setTimeout at every spider update on idle and moveDown states
User prompt
Use a state machine for the spider update, with a switch case
User prompt
Fix Bug: 'Uncaught ReferenceError: spiders is not defined' in this line: 'for (var i = 0; i < spiders.length; i++) {' Line Number: 150
User prompt
Let's have a new enemy type: spiders. On setupLevel, remove any existing spiders and add exactly one. A spider should sit right below one randomly selected branch. The spider should stay idle 2 seconds, then move down a distance of it's own height, sit idle for 2 seconds again, then go back up its original position
User prompt
on setupLevel, remove all bananas before adding new ones
User prompt
bananaTxt.anchor.set should be (1, 0);
User prompt
Move level indicator to top left corner with half the size. Banana's indicator half the size too
User prompt
Fix Bug: 'Uncaught ReferenceError: bananas is not defined' in this line: 'bananas.push(newBanana);' Line Number: 119
User prompt
Add a bananas indicator on the top right corner. When the monkey touches a banana, it disappears and the indicator increases its number
User prompt
on setupLevel, sprinkle 5 bananas randomly around the level that the monkey can collect
var Spider = Container.expand(function () { var self = Container.call(this); var spiderGraphics = self.createAsset('spider', 'Spider Graphics', .5, .5); self.idle = true; self.moveDown = false; self.moveUp = false; self.update = function () { if (self.idle) { LK.setTimeout(function () { self.idle = false; self.moveDown = true; }, 2000); } else if (self.moveDown) { self.y += self.height; self.moveDown = false; LK.setTimeout(function () { self.moveUp = true; }, 2000); } else if (self.moveUp) { self.y -= self.height; self.moveUp = false; self.idle = true; } }; }); var Banana = Container.expand(function () { var self = Container.call(this); var bananaGraphics = self.createAsset('banana', 'Banana Graphics', .5, .5); }); var TopBranch = Container.expand(function () { var self = Container.call(this); var topBranchGraphics = self.createAsset('topBranch', 'Top Branch Graphics', 0, .5); self.x = 0; self.y = 0; self.width = 2048; self.move = function () {}; self.update = function () {}; }); var Branch = Container.expand(function () { var self = Container.call(this); var branchGraphics = self.createAsset('branch', 'Branch Graphics', .5, .5); self.move = function () {}; self.update = function () {}; }); var Bird = Container.expand(function () { var self = Container.call(this); var birdGraphics = self.createAsset('bird', 'Bird Graphics', .5, .5); self.direction = Math.random() < 0.5 ? -1 : 1; self.originalX = self.direction === 1 ? 0 : 2048; self.move = function () {}; self.update = function () { self.x += self.direction * 7; if (self.direction === -1) { birdGraphics.scale.x = -1; } else { birdGraphics.scale.x = 1; } if (self.x < 0 || self.x > 2048) { self.x = self.originalX; } self.y = Math.max(50, Math.min(2732 - 50 - self.height, self.y + Math.random() * 10 - 5)); }; }); var Monkey = Container.expand(function () { var self = Container.call(this); var monkeyGraphics = self.createAsset('monkey', 'Monkey Graphics', .5, .5); self.vx = 0; self.vy = 0; self.gravity = 0.5; self.jumping = false; self.jump = function (target, branches) { if (target && !self.jumping) { self.jumping = true; var dx = target.x - self.x; var dy = target.y - self.y; if (dy > 0) return; var distance = Math.sqrt(dx * dx + dy * dy); self.vx = dx / distance * 25; self.vy = dy / distance * 25; self.jumpingFrom = branches; } }; self.update = function () { self.x = Math.max(0, Math.min(2048 - self.width, self.x + self.vx)); if (self.vx > 0) { monkeyGraphics.scale.x = -1; } else if (self.vx < 0) { monkeyGraphics.scale.x = 1; } self.y += self.vy; self.vy += self.gravity; if (self.vy > 0) { self.jumpingFrom = []; } if (self.y > 2732 - self.height) { self.y = 2732 - self.height; self.vy = 0; self.vx = 0; self.jumping = false; } }; }); var Game = Container.expand(function () { var self = Container.call(this); var introPopup = new Text2('Welcome to Monkey Climb!\nClick on branches to climb.\nAvoid the birds!', { size: 100, fill: '#ffffff' }); introPopup.anchor.set(.5, .5); introPopup.x = 1024; introPopup.y = 1366; self.addChildAt(introPopup, self.children.length); LK.setTimeout(function () { introPopup.destroy(); }, 5000); self.setupLevel = function () { for (var i = 0; i < branches.length; i++) { branches[i].destroy(); } branches = []; for (var i = 0; i < 15; i++) { var newBranch = new Branch(); newBranch.x = Math.random() * 2048; newBranch.y = i * (2732 / 15); branches.push(newBranch); self.addChild(newBranch); } for (var i = 0; i < birds.length; i++) { birds[i].destroy(); } birds = []; for (var i = 0; i < 2 + level; i++) { var newBird = new Bird(); newBird.x = Math.random() * 2048; newBird.y = i * (2732 / (2 + level)); birds.push(newBird); self.addChild(newBird); } for (var i = 0; i < bananas.length; i++) { bananas[i].destroy(); } bananas = []; for (var i = 0; i < 5; i++) { var newBanana = new Banana(); newBanana.x = Math.random() * 2048; newBanana.y = Math.random() * 2732; self.addChild(newBanana); bananas.push(newBanana); } for (var i = 0; i < spiders.length; i++) { spiders[i].destroy(); } spiders = []; var newSpider = new Spider(); var randomBranch = branches[Math.floor(Math.random() * branches.length)]; newSpider.x = randomBranch.x; newSpider.y = randomBranch.y + randomBranch.height; self.addChild(newSpider); spiders.push(newSpider); branches.sort(function (a, b) { return a.y - b.y; }); self.topBranch = new TopBranch(); self.topBranch.y = self.topBranch.height / 2; self.addChild(self.topBranch); branches[0] = self.topBranch; }; var branches = []; var birds = []; var bananas = []; var level = 1; self.setupLevel(); var levelTxt = new Text2('Level: ' + level, { size: 75, fill: '#ffffff' }); levelTxt.anchor.set(0, 0); LK.gui.topLeft.addChild(levelTxt); var bananaCount = 0; var bananaTxt = new Text2('Bananas: ' + bananaCount, { size: 75, fill: '#ffffff' }); bananaTxt.anchor.set(1, 0); LK.gui.topRight.addChild(bananaTxt); var monkey = self.addChild(new Monkey()); monkey.x = 1024; monkey.y = 2732 - monkey.height; LK.on('tick', function () { monkey.update(); for (var i = 0; i < branches.length; i++) { branches[i].update(); if (branches[i].y > 2732) { branches[i].destroy(); branches.splice(i, 1); i--; } } for (var i = 0; i < birds.length; i++) { birds[i].update(); } for (var i = 0; i < branches.length; i++) { if (!monkey.jumpingFrom.includes(branches[i]) && monkey.intersects(branches[i])) { monkey.vx = 0; monkey.vy = 0; monkey.jumping = false; } } if (monkey.intersects(self.topBranch)) { monkey.x = 1024; monkey.y = 2732 - monkey.height; level++; levelTxt.setText('Level: ' + level); self.setupLevel(); } for (var i = 0; i < birds.length; i++) { if (monkey.intersects(birds[i])) { LK.showGameOver(); } birds[i].update(); } for (var i = 0; i < bananas.length; i++) { if (monkey.intersects(bananas[i])) { bananas[i].destroy(); bananas.splice(i, 1); bananaCount++; bananaTxt.setText('Bananas: ' + bananaCount); } } }); stage.on('down', function (obj) { var pos = obj.event.getLocalPosition(self); var intersectedBranches = []; for (var i = 0; i < branches.length; i++) { if (monkey.intersects(branches[i])) { intersectedBranches.push(branches[i]); } } monkey.jump({ x: pos.x, y: pos.y }, intersectedBranches); }); });
===================================================================
--- original.js
+++ change.js
@@ -1,4 +1,29 @@
+var Spider = Container.expand(function () {
+ var self = Container.call(this);
+ var spiderGraphics = self.createAsset('spider', 'Spider Graphics', .5, .5);
+ self.idle = true;
+ self.moveDown = false;
+ self.moveUp = false;
+ self.update = function () {
+ if (self.idle) {
+ LK.setTimeout(function () {
+ self.idle = false;
+ self.moveDown = true;
+ }, 2000);
+ } else if (self.moveDown) {
+ self.y += self.height;
+ self.moveDown = false;
+ LK.setTimeout(function () {
+ self.moveUp = true;
+ }, 2000);
+ } else if (self.moveUp) {
+ self.y -= self.height;
+ self.moveUp = false;
+ self.idle = true;
+ }
+ };
+});
var Banana = Container.expand(function () {
var self = Container.call(this);
var bananaGraphics = self.createAsset('banana', 'Banana Graphics', .5, .5);
});
@@ -121,8 +146,18 @@
newBanana.y = Math.random() * 2732;
self.addChild(newBanana);
bananas.push(newBanana);
}
+ for (var i = 0; i < spiders.length; i++) {
+ spiders[i].destroy();
+ }
+ spiders = [];
+ var newSpider = new Spider();
+ var randomBranch = branches[Math.floor(Math.random() * branches.length)];
+ newSpider.x = randomBranch.x;
+ newSpider.y = randomBranch.y + randomBranch.height;
+ self.addChild(newSpider);
+ spiders.push(newSpider);
branches.sort(function (a, b) {
return a.y - b.y;
});
self.topBranch = new TopBranch();
A tree branch with green leaves Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A preying white bird flying ahead Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A cute monkey with arms up Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Wood texture Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Bananas Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Cartoony looking spider, with two big round eyes Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
One green vine Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.