var Vine = Container.expand(function () { var self = Container.call(this); var vineGraphics = self.createAsset('vine', 'Vine Graphics', .5, .5); }); 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 * 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(300, 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 < 10; i++) { var newBranch = new Branch(); newBranch.x = Math.random() * 2048; newBranch.y = Math.min(i * (2300 / 10), 2300); 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)) + 300; 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 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); var newVine = new Vine(); var vineBranch = eligibleBranches[Math.floor(Math.random() * eligibleBranches.length)]; newVine.x = vineBranch.x; newVine.y = vineBranch.y + 400; self.addChild(newVine); 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 spiders = []; 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); } } 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); }); });
var Vine = Container.expand(function () {
var self = Container.call(this);
var vineGraphics = self.createAsset('vine', 'Vine Graphics', .5, .5);
});
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 * 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(300, 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 < 10; i++) {
var newBranch = new Branch();
newBranch.x = Math.random() * 2048;
newBranch.y = Math.min(i * (2300 / 10), 2300);
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)) + 300;
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 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);
var newVine = new Vine();
var vineBranch = eligibleBranches[Math.floor(Math.random() * eligibleBranches.length)];
newVine.x = vineBranch.x;
newVine.y = vineBranch.y + 400;
self.addChild(newVine);
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 spiders = [];
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);
}
}
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);
});
});
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.