User prompt
When a bird is created, there's a 50% chance it flies left-to-right, and 50% chance right-to-left. Birds should not be destroyed, when reaching the screen boundaries, a bird's position is reset to original
User prompt
Add 3 birds per level flying around. When monkey touches a bird, it's game over
User prompt
Keep track of the top-most branch (the one with lower Y position). When the monkey touches this branch, level is finished
User prompt
Level should also finish when the top-most branch is touched
User prompt
setupLevel should destroy the branches itself
User prompt
Refactor to have a centralised function where a level is set up
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'push')' in this line: 'birds.push(newBird);' Line Number: 59
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'push')' in this line: 'birds.push(newBird);' Line Number: 58
User prompt
Add 3 birds flying on every new level. When the monkey touches a bird, it's game over
User prompt
For every new level, remove all branches and create new random ones
User prompt
Actually, let's finish the level when the monkey reaches the top branch, instead of the top of the screen
User prompt
Show level indicator on top. Starts at level 1. When the monkey reaches the very top of the screen, a new level is generated, the level indicator increases and the monkey position is reset
User prompt
Limit monkey's X position to the screen boundaries
User prompt
When jumping from a branch, ignore collision with it until falling down again
User prompt
Limit jump angle so that it can only jump towards the top
User prompt
Limit jump height by half again
User prompt
Reduce jump height by half
User prompt
Make jump 10 times higher
User prompt
Stop monkey movement when it touches the ground or a branch
User prompt
There's a problem: monkey is not moving when I click anywhere
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'x')' in this line: 'var dx = target.x - self.x;' Line Number: 20
User prompt
Limit monkey position to not fall through the ground
User prompt
Fix Bug: 'TypeError: branches[i].containsPoint is not a function' in this line: 'if (branches[i].containsPoint(pos)) {' Line Number: 78
User prompt
When clicking a branch, monkey jumps in the branch's direction. It has an initial acceleration towards it. Velocity and gravity are properly simulated.
User prompt
Create 20 branches upfront and avoid creating branches on tick
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.move = function () {}; self.update = function () {}; }); 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.jumpingFrom = null; self.jump = function (target, branch) { if (target) { 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 = branch; } }; self.update = function () { self.x = Math.max(0, Math.min(2048 - self.width, self.x + self.vx)); self.y += self.vy; self.vy += self.gravity; if (self.vy > 0) { self.jumpingFrom = null; } if (self.y > 2732 - self.height) { self.y = 2732 - self.height; self.vy = 0; self.vx = 0; } }; }); var Game = Container.expand(function () { var self = Container.call(this); var branches = []; for (var i = 0; i < 20; i++) { var newBranch = new Branch(); newBranch.x = Math.random() * 2048; newBranch.y = i * (2732 / 20); branches.push(newBranch); self.addChild(newBranch); } for (var i = 0; i < 3; i++) { var newBird = new Bird(); newBird.x = Math.random() * 2048; self.addChild(newBird); birds.push(newBird); } var level = 1; var levelTxt = new Text2('Level: ' + level, { size: 150, fill: '#ffffff' }); levelTxt.anchor.set(.5, 0); LK.gui.topCenter.addChild(levelTxt); var monkey = self.addChild(new Monkey()); monkey.x = 1024; monkey.y = 2732 - monkey.height; var birds = []; for (var i = 0; i < 3; i++) { var newBird = new Bird(); newBird.x = Math.random() * 2048; self.addChild(newBird); birds.push(newBird); } 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(); if (birds[i].y > 2732) { birds[i].destroy(); birds.splice(i, 1); i--; } } for (var i = 0; i < branches.length; i++) { if (branches[i] !== monkey.jumpingFrom && monkey.intersects(branches[i])) { monkey.vx = 0; monkey.vy = 0; } } if (monkey.y <= branches[0].y) { monkey.x = 1024; monkey.y = 2732 - monkey.height; level++; levelTxt.setText('Level: ' + level); for (var i = 0; i < branches.length; i++) { branches[i].destroy(); } branches = []; for (var i = 0; i < 20; i++) { var newBranch = new Branch(); newBranch.x = Math.random() * 2048; newBranch.y = i * (2732 / 20); branches.push(newBranch); self.addChild(newBranch); } } for (var i = 0; i < birds.length; i++) { if (monkey.intersects(birds[i])) { LK.showGameOver(); } } }); stage.on('down', function (obj) { var pos = obj.event.getLocalPosition(self); var currentBranch = null; for (var i = 0; i < branches.length; i++) { if (monkey.intersects(branches[i])) { currentBranch = branches[i]; break; } } monkey.jump({ x: pos.x, y: pos.y }, currentBranch); }); });
===================================================================
--- original.js
+++ change.js
@@ -68,8 +68,14 @@
var monkey = self.addChild(new Monkey());
monkey.x = 1024;
monkey.y = 2732 - monkey.height;
var birds = [];
+ for (var i = 0; i < 3; i++) {
+ var newBird = new Bird();
+ newBird.x = Math.random() * 2048;
+ self.addChild(newBird);
+ birds.push(newBird);
+ }
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.