/****
* Classes
****/
// Bee class representing the bees to avoid
var Bee = Container.expand(function () {
var self = Container.call(this);
var beeGraphics = self.attachAsset('bee', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Bees move left in a loop
self.x -= 5;
if (self.x < -100) {
self.x = 2048 + 100;
}
};
});
// Fly class representing the flies to be eaten
var Fly = Container.expand(function () {
var self = Container.call(this);
var flyGraphics = self.attachAsset('fly', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Flies move left in a loop
self.x -= 5;
if (self.x < -100) {
self.x = 2048 + 100;
}
};
});
// PowerUp class representing the invincibility power-up
var PowerUp = Container.expand(function () {
var self = Container.call(this);
var powerUpGraphics = self.attachAsset('powerUp', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// PowerUps move left in a loop
self.x -= 5;
if (self.x < -100) {
self.x = 2048 + 100;
}
};
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Prana class representing the player character
var Prana = Container.expand(function () {
var self = Container.call(this);
var pranaGraphics = self.attachAsset('prana', {
anchorX: 0.5,
anchorY: 0.5
});
self.jumpHeight = -60;
self.gravity = 2;
self.velocityY = 0;
self.update = function () {
self.velocityY += self.gravity;
self.y += self.velocityY;
// Prevent Prana from falling below the screen
if (self.y > 2732 - pranaGraphics.height / 2) {
self.y = 2732 - pranaGraphics.height / 2;
self.velocityY = 0;
}
};
self.jump = function () {
self.velocityY = self.jumpHeight;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Light blue background
});
/****
* Game Code
****/
var background = game.attachAsset('background', {
anchorX: 0.5,
anchorY: 0.5
});
background.x = 2048 / 2;
background.y = 2732 / 2;
// Initialize game elements
var prana = game.addChild(new Prana());
prana.x = 2048 / 2;
prana.y = 2732 - 100;
var flies = [];
var bees = [];
var powerUps = [];
// Function to spawn flies
function spawnFly() {
var fly = new Fly();
fly.x = Math.random() * 2048;
fly.y = Math.random() * (2732 / 2) + 2732 / 4; // Spawn flies a bit lower
flies.push(fly);
game.addChild(fly);
}
// Function to spawn bees
function spawnPowerUp() {
var powerUp = new PowerUp();
powerUp.x = Math.random() * 2048;
powerUp.y = Math.random() * (2732 / 2) + 2732 / 4; // Spawn power-ups a bit lower
powerUps.push(powerUp);
game.addChild(powerUp);
}
function spawnBee() {
var bee = new Bee();
bee.x = Math.random() * 2048;
bee.y = Math.random() * (2732 / 2) + 2732 / 4; // Spawn bees a bit lower
bees.push(bee);
game.addChild(bee);
}
// Spawn initial flies and bees
for (var i = 0; i < 10; i++) {
spawnFly();
spawnBee();
}
// Handle game updates
game.update = function () {
prana.update();
// Update movement for each fly
for (var i = 0; i < flies.length; i++) {
flies[i].update();
}
// Update movement for each bee
for (var i = 0; i < bees.length; i++) {
bees[i].update();
}
// Check for collisions with flies
for (var i = flies.length - 1; i >= 0; i--) {
if (prana.intersects(flies[i])) {
flies[i].destroy();
flies.splice(i, 1);
// Increase score when prana catches a fly
LK.setScore(LK.getScore() + 1);
}
}
// Check for collisions with power-ups
for (var i = powerUps.length - 1; i >= 0; i--) {
if (prana.intersects(powerUps[i])) {
powerUps[i].destroy();
powerUps.splice(i, 1);
// Make Prana invincible for 5 seconds
prana.invincible = true;
LK.setTimeout(function () {
prana.invincible = false;
// Notify the player that the power-up has ended
LK.effects.flashScreen(0xff0000, 1000);
}, 5000);
}
}
// Check for collisions with bees
for (var i = bees.length - 1; i >= 0; i--) {
if (prana.intersects(bees[i]) && !prana.invincible) {
// Handle game over or other actions
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
// Periodically spawn new flies and bees
if (LK.ticks % 60 === 0) {
spawnFly();
}
if (LK.ticks % 300 === 0) {
spawnPowerUp();
}
if (LK.ticks % 180 === 0) {
spawnBee();
}
};
// Handle touch events for jumping
game.down = function (x, y, obj) {
if (prana.y >= 2732 - prana.height / 2) {
prana.jump();
}
};
pixel hungery plant. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
pixel bee faceing left. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
pixel fly facing left. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
jungle. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
rain drop. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows