User prompt
Limit branch y position to be no less than 350, except for the topBranch
User prompt
Limit branch y position to 400, except for the topBranch
User prompt
Make it 10 branches instead of 15
User prompt
No branches should be positioned after y position 2300
User prompt
No branches should be positioned after y position 2500
User prompt
Apply physics lattice algorithm to evenly distribute branches after they are placed
User prompt
Limit bird y position to no less than 300
User prompt
Offset initial bird y position by +300
User prompt
Determine a "game field" area that starts at (0, 300) and ends at (2048, 2543). Ensure birds are initially positioned inside this area, each bird randomly placed at 1/3 of this area
User prompt
Move monkey initial position setup to inside setupLevel
User prompt
Move monkey initial position setup to setupLevel
User prompt
Setup monkey initial position as first thing in setupLevel
User prompt
Bird starting y position should be a random between 300 and above the monkey
User prompt
topBranch height should be hardcoded as 300 and topBranch y position should be hardcoded as 150
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'y')' in this line: 'newBird.y = Math.random() * (self.topBranch.y + self.topBranch.height, monkey.y);' Line Number: 162
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'y')' in this line: 'newBird.y = Math.random() * (self.topBranch.y + self.topBranch.height, monkey.y);' Line Number: 161
User prompt
Bird's starting Y position must be random between below the top branch and above the monkey. Therefore, only setup birds after the top branch is setup
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'y')' in this line: 'self.y = Math.max(self.topBranch.y + self.topBranch.height, Math.min(monkey.y - self.height, self.y + Math.random() * 10 - 5));' Line Number: 66
User prompt
Bird Y position must be random between below the top branch and above the monkey
User prompt
Brid speed should be random between the current speed and half of it
User prompt
Ensure there are is at least 1 branch at every 15th of the screen
User prompt
Ensure there is at least one branch at every 3rd of the screen
User prompt
randomly position the 15 branches snapping them to an imaginary grid
User prompt
Have 15 branches on a level
User prompt
When determining branches positions, select from a grid-like positioning where there is 10% spacing between branches (vertically and horizontally)
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.state = 'idle'; self.originalY = self.y; self.update = function () { switch (self.state) { case 'idle': self.state = 'moveDown'; break; case 'moveDown': self.y += 5; if (self.y >= self.originalY + 3 * self.height) { self.state = 'moveUp'; } break; case 'moveUp': self.y -= 5; if (self.y <= self.originalY) { self.state = 'idle'; } break; default: break; } }; }); 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 * (Math.random() * 3.5 + 3.5); 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); 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.floor(Math.random() * 5) * 409.6 + 204.8; newBranch.y = (i + 1) * 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 < 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 eligibleBranches = branches.filter(function (branch) { return branch.y < 2732 * 2 / 3; }); var randomBranch = eligibleBranches[Math.floor(Math.random() * eligibleBranches.length)]; newSpider.x = randomBranch.x; newSpider.y = randomBranch.y + randomBranch.height; newSpider.originalY = newSpider.y; self.addChild(newSpider); spiders.push(newSpider); branches.sort(function (a, b) { return a.y - b.y; }); self.topBranch = new TopBranch(); self.topBranch.height = 300; self.topBranch.y = 150; self.addChild(self.topBranch); branches[0] = self.topBranch; for (var i = 0; i < 2 + level; i++) { var newBird = new Bird(); newBird.x = Math.random() * 2048; if (self.topBranch) { newBird.y = Math.random() * (self.topBranch.y + self.topBranch.height - 300) + 300; } birds.push(newBird); self.addChild(newBird); } }; var branches = []; var birds = []; var bananas = []; var spiders = []; var level = 1; self.setupLevel(); monkey = self.addChild(new Monkey()); monkey.x = 1024; monkey.y = 2732 - monkey.height; 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); 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); } } for (var i = 0; i < spiders.length; i++) { spiders[i].update(); if (monkey.intersects(spiders[i])) { LK.showGameOver(); } } }); 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
@@ -171,9 +171,9 @@
var bananas = [];
var spiders = [];
var level = 1;
self.setupLevel();
- var monkey = self.addChild(new Monkey());
+ monkey = self.addChild(new Monkey());
monkey.x = 1024;
monkey.y = 2732 - monkey.height;
var levelTxt = new Text2('Level: ' + level, {
size: 75,
@@ -187,11 +187,8 @@
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();
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.