/****
* Classes
****/
//<Assets used in the game will automatically appear here>
// Arrow class
var Arrow = Container.expand(function () {
var self = Container.call(this);
var arrowGraphics = self.attachAsset('Arrow', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.direction = {
x: 0,
y: 0
};
self.update = function () {
self.x += self.direction.x * self.speed;
self.y += self.direction.y * self.speed;
for (var i = monsters.length - 1; i >= 0; i--) {
if (self.intersects(monsters[i])) {
if (monsters[i] instanceof Gorilla) {
monsters[i].hitCount++;
if (monsters[i].hitCount >= 5) {
monsters[i].destroy();
monsters.splice(i, 1);
// Update score
score += 20;
scoreText.setText('Score: ' + score);
// Increase arrow count by 5
arrowCount += 5;
arrowCountText.setText('Arrows: ' + arrowCount);
}
} else {
monsters[i].destroy();
monsters.splice(i, 1);
// Update score
score += 10;
scoreText.setText('Score: ' + score);
}
self.destroy();
return;
}
}
};
});
var Gorilla = Container.expand(function () {
var self = Container.call(this);
var gorillaGraphics = self.attachAsset('Gorilla', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.direction = {
x: 0,
y: 0
};
self.hitCount = 0;
self.update = function () {
self.x += self.direction.x * self.speed;
self.y += self.direction.y * self.speed;
};
});
// Monster class
var Monster = Container.expand(function () {
var self = Container.call(this);
var monsterGraphics = self.attachAsset('Monster', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.direction = {
x: 0,
y: 0
};
self.update = function () {
self.x += self.direction.x * self.speed;
self.y += self.direction.y * self.speed;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000,
name: 'Jungle Battle'
});
/****
* Game Code
****/
LK.playMusic('BGM');
var background = game.addChild(LK.getAsset('Background', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
}));
var archer = game.addChild(LK.getAsset('Archer', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
}));
var monsters = [];
game.update = function () {
if (LK.ticks < 1800 && LK.ticks % 120 == 0 || LK.ticks >= 1800 && LK.ticks % 84 == 0) {
var monster = game.addChild(new Monster());
var spawnSide = Math.floor(Math.random() * 4);
switch (spawnSide) {
case 0:
// top
monster.x = Math.random() * 2048;
monster.y = 0;
break;
case 1:
// right
monster.x = 2048;
monster.y = Math.random() * 2732;
break;
case 2:
// bottom
monster.x = Math.random() * 2048;
monster.y = 2732;
break;
case 3:
// left
monster.x = 0;
monster.y = Math.random() * 2732;
break;
}
var dx = archer.x - monster.x;
var dy = archer.y - monster.y;
var magnitude = Math.sqrt(dx * dx + dy * dy);
monster.direction.x = dx / magnitude;
monster.direction.y = dy / magnitude;
monsters.push(monster);
}
if (LK.ticks % 300 == 0) {
var orangutan = game.addChild(new Gorilla());
orangutan.x = Math.random() * 2048;
orangutan.y = 0;
var dx = archer.x - orangutan.x;
var dy = archer.y - orangutan.y;
var magnitude = Math.sqrt(dx * dx + dy * dy);
orangutan.direction.x = dx / magnitude;
orangutan.direction.y = dy / magnitude;
monsters.push(orangutan);
}
for (var i = monsters.length - 1; i >= 0; i--) {
if (monsters[i].intersects(archer)) {
LK.showGameOver();
}
}
};
// Initialize score
var score = 0;
// Initialize arrow count
var arrowCount = 10;
// Create score text
var scoreText = new Text2('Score: 0', {
size: 50,
fill: 0xFFFFFF
});
// Initialize last arrow shot time
var lastArrowShotTime = 0;
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
// Create arrow count text
var arrowCountText = new Text2('Arrows: 10', {
size: 100,
fill: 0xFF0000,
fontWeight: 'bold'
});
arrowCountText.anchor.set(1, 0);
LK.gui.topRight.addChild(arrowCountText);
// Create recharging reminder
var rechargeText = new Text2('Recharging', {
size: 80,
fill: 0xFF0000,
fontWeight: 'bold'
});
rechargeText.anchor.set(1, 0);
rechargeText.y = arrowCountText.height; // Position it below the arrow count text
rechargeText.visible = false; // Hide it initially
LK.gui.topRight.addChild(rechargeText);
game.down = function (x, y, obj) {
// Check if the last arrow was fired less than 100ms ago
if (this.lastArrowTime && Date.now() - this.lastArrowTime < 100) {
return;
}
// Check if there are any arrows left
if (arrowCount <= 0) {
// Check if 2 seconds have passed since the last arrow was shot
if (Date.now() - lastArrowShotTime >= 2000) {
// Recharge the arrows
arrowCount = 10;
arrowCountText.setText('Arrows: ' + arrowCount);
}
return;
}
this.lastArrowTime = Date.now();
var arrow = game.addChild(new Arrow());
arrow.x = archer.x;
arrow.y = archer.y;
var dx = x - archer.x;
var dy = y - archer.y;
var magnitude = Math.sqrt(dx * dx + dy * dy);
arrow.direction.x = dx / magnitude;
arrow.direction.y = dy / magnitude;
// Decrease the arrow count and update the text
arrowCount--;
arrowCountText.setText('Bananas: ' + arrowCount);
// If all arrows have been shot, store the time
if (arrowCount == 0) {
lastArrowShotTime = Date.now();
}
// Play the sound effect of the projectile asset
LK.getSound('projectile').play();
}; /****
* Classes
****/
//<Assets used in the game will automatically appear here>
// Arrow class
var Arrow = Container.expand(function () {
var self = Container.call(this);
var arrowGraphics = self.attachAsset('Arrow', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.direction = {
x: 0,
y: 0
};
self.update = function () {
self.x += self.direction.x * self.speed;
self.y += self.direction.y * self.speed;
for (var i = monsters.length - 1; i >= 0; i--) {
if (self.intersects(monsters[i])) {
if (monsters[i] instanceof Gorilla) {
monsters[i].hitCount++;
if (monsters[i].hitCount >= 5) {
monsters[i].destroy();
monsters.splice(i, 1);
// Update score
score += 20;
scoreText.setText('Score: ' + score);
// Increase arrow count by 5
arrowCount += 5;
arrowCountText.setText('Arrows: ' + arrowCount);
}
} else {
monsters[i].destroy();
monsters.splice(i, 1);
// Update score
score += 10;
scoreText.setText('Score: ' + score);
}
self.destroy();
return;
}
}
};
});
var Gorilla = Container.expand(function () {
var self = Container.call(this);
var gorillaGraphics = self.attachAsset('Gorilla', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.direction = {
x: 0,
y: 0
};
self.hitCount = 0;
self.update = function () {
self.x += self.direction.x * self.speed;
self.y += self.direction.y * self.speed;
};
});
// Monster class
var Monster = Container.expand(function () {
var self = Container.call(this);
var monsterGraphics = self.attachAsset('Monster', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.direction = {
x: 0,
y: 0
};
self.update = function () {
self.x += self.direction.x * self.speed;
self.y += self.direction.y * self.speed;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000,
name: 'Jungle Battle'
});
/****
* Game Code
****/
LK.playMusic('BGM');
var background = game.addChild(LK.getAsset('Background', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
}));
var archer = game.addChild(LK.getAsset('Archer', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
}));
var monsters = [];
game.update = function () {
if (LK.ticks < 1800 && LK.ticks % 120 == 0 || LK.ticks >= 1800 && LK.ticks % 84 == 0) {
var monster = game.addChild(new Monster());
var spawnSide = Math.floor(Math.random() * 4);
switch (spawnSide) {
case 0:
// top
monster.x = Math.random() * 2048;
monster.y = 0;
break;
case 1:
// right
monster.x = 2048;
monster.y = Math.random() * 2732;
break;
case 2:
// bottom
monster.x = Math.random() * 2048;
monster.y = 2732;
break;
case 3:
// left
monster.x = 0;
monster.y = Math.random() * 2732;
break;
}
var dx = archer.x - monster.x;
var dy = archer.y - monster.y;
var magnitude = Math.sqrt(dx * dx + dy * dy);
monster.direction.x = dx / magnitude;
monster.direction.y = dy / magnitude;
monsters.push(monster);
}
if (LK.ticks % 300 == 0) {
var orangutan = game.addChild(new Gorilla());
orangutan.x = Math.random() * 2048;
orangutan.y = 0;
var dx = archer.x - orangutan.x;
var dy = archer.y - orangutan.y;
var magnitude = Math.sqrt(dx * dx + dy * dy);
orangutan.direction.x = dx / magnitude;
orangutan.direction.y = dy / magnitude;
monsters.push(orangutan);
}
for (var i = monsters.length - 1; i >= 0; i--) {
if (monsters[i].intersects(archer)) {
LK.showGameOver();
}
}
};
// Initialize score
var score = 0;
// Initialize arrow count
var arrowCount = 10;
// Create score text
var scoreText = new Text2('Score: 0', {
size: 50,
fill: 0xFFFFFF
});
// Initialize last arrow shot time
var lastArrowShotTime = 0;
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
// Create arrow count text
var arrowCountText = new Text2('Arrows: 10', {
size: 100,
fill: 0xFF0000,
fontWeight: 'bold'
});
arrowCountText.anchor.set(1, 0);
LK.gui.topRight.addChild(arrowCountText);
// Create recharging reminder
var rechargeText = new Text2('Recharging', {
size: 80,
fill: 0xFF0000,
fontWeight: 'bold'
});
rechargeText.anchor.set(1, 0);
rechargeText.y = arrowCountText.height; // Position it below the arrow count text
rechargeText.visible = false; // Hide it initially
LK.gui.topRight.addChild(rechargeText);
game.down = function (x, y, obj) {
// Check if the last arrow was fired less than 100ms ago
if (this.lastArrowTime && Date.now() - this.lastArrowTime < 100) {
return;
}
// Check if there are any arrows left
if (arrowCount <= 0) {
// Check if 2 seconds have passed since the last arrow was shot
if (Date.now() - lastArrowShotTime >= 2000) {
// Recharge the arrows
arrowCount = 10;
arrowCountText.setText('Arrows: ' + arrowCount);
}
return;
}
this.lastArrowTime = Date.now();
var arrow = game.addChild(new Arrow());
arrow.x = archer.x;
arrow.y = archer.y;
var dx = x - archer.x;
var dy = y - archer.y;
var magnitude = Math.sqrt(dx * dx + dy * dy);
arrow.direction.x = dx / magnitude;
arrow.direction.y = dy / magnitude;
// Decrease the arrow count and update the text
arrowCount--;
arrowCountText.setText('Bananas: ' + arrowCount);
// If all arrows have been shot, store the time
if (arrowCount == 0) {
lastArrowShotTime = Date.now();
}
// Play the sound effect of the projectile asset
LK.getSound('projectile').play();
};
A single, cartoonish little monster. It has fur and a big mouth, and its movement posture looks as if it's about to pounce forward.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
It's a 2D planar background. It's a jungle with green grass growing all over the ground and thick forests surrounding it.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An orangutan in a cartoon image.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A bunch of bananas in a cartoon image.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.