/****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Flower class representing the falling flowers
var Flower = Container.expand(function () {
var self = Container.call(this);
var flowerGraphics = self.attachAsset('flower', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5; // Speed at which the flower falls
self.update = function () {
self.y += self.speed;
};
});
// Pot class representing the player's pot
var Pot = Container.expand(function () {
var self = Container.call(this);
var potGraphics = self.attachAsset('pot', {
anchorX: 0.5,
anchorY: 0.5
});
self.down = function (x, y, obj) {
var game_position = game.toLocal(obj.global);
self.x = game_position.x;
};
});
// RedFlower class representing the falling red flowers
var RedFlower = Container.expand(function () {
var self = Container.call(this);
var redFlowerGraphics = self.attachAsset('redFlower', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5; // Speed at which the red flower falls
self.update = function () {
self.y += self.speed;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Light blue background to represent the sky
});
/****
* Game Code
****/
var flowers = [];
var pot = game.addChild(new Pot());
pot.x = 2048 / 2;
pot.y = 2500; // Position the pot near the bottom of the screen
var score = 0;
var scoreTxt = new Text2('Score: 0', {
size: 100,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
game.update = function () {
for (var i = flowers.length - 1; i >= 0; i--) {
var flower = flowers[i];
if (flower.y > 2732 && flower instanceof Flower) {
// Flower hit the ground
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
return;
}
if (flower.intersects(pot)) {
// Flower caught by the pot
if (flower instanceof RedFlower) {
// If red flower hits player, reduce 5 points
score -= 5;
// If score is negative, end game
if (score < 0) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
return;
}
} else {
score += 1;
// Increase the speed of the falling flowers every time the score reaches a multiple of 20
if (score % 20 == 0) {
Flower.prototype.speed += 0.5;
RedFlower.prototype.speed += 0.5;
}
}
scoreTxt.setText('Score: ' + score);
flower.destroy();
flowers.splice(i, 1);
continue;
}
}
if (LK.ticks % 60 == 0) {
// Create a new flower every second
var newFlower = new Flower();
newFlower.x = Math.random() * 2048;
newFlower.y = 0;
flowers.push(newFlower);
game.addChild(newFlower);
// Create a new red flower every 3 seconds
if (score >= 20 && LK.ticks % 120 == 0) {
var newRedFlower = new RedFlower();
newRedFlower.x = Math.random() * 2048;
newRedFlower.y = 0;
flowers.push(newRedFlower);
game.addChild(newRedFlower);
}
}
};
game.down = function (x, y, obj) {
pot.down(x, y, obj);
}; /****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Flower class representing the falling flowers
var Flower = Container.expand(function () {
var self = Container.call(this);
var flowerGraphics = self.attachAsset('flower', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5; // Speed at which the flower falls
self.update = function () {
self.y += self.speed;
};
});
// Pot class representing the player's pot
var Pot = Container.expand(function () {
var self = Container.call(this);
var potGraphics = self.attachAsset('pot', {
anchorX: 0.5,
anchorY: 0.5
});
self.down = function (x, y, obj) {
var game_position = game.toLocal(obj.global);
self.x = game_position.x;
};
});
// RedFlower class representing the falling red flowers
var RedFlower = Container.expand(function () {
var self = Container.call(this);
var redFlowerGraphics = self.attachAsset('redFlower', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5; // Speed at which the red flower falls
self.update = function () {
self.y += self.speed;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Light blue background to represent the sky
});
/****
* Game Code
****/
var flowers = [];
var pot = game.addChild(new Pot());
pot.x = 2048 / 2;
pot.y = 2500; // Position the pot near the bottom of the screen
var score = 0;
var scoreTxt = new Text2('Score: 0', {
size: 100,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
game.update = function () {
for (var i = flowers.length - 1; i >= 0; i--) {
var flower = flowers[i];
if (flower.y > 2732 && flower instanceof Flower) {
// Flower hit the ground
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
return;
}
if (flower.intersects(pot)) {
// Flower caught by the pot
if (flower instanceof RedFlower) {
// If red flower hits player, reduce 5 points
score -= 5;
// If score is negative, end game
if (score < 0) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
return;
}
} else {
score += 1;
// Increase the speed of the falling flowers every time the score reaches a multiple of 20
if (score % 20 == 0) {
Flower.prototype.speed += 0.5;
RedFlower.prototype.speed += 0.5;
}
}
scoreTxt.setText('Score: ' + score);
flower.destroy();
flowers.splice(i, 1);
continue;
}
}
if (LK.ticks % 60 == 0) {
// Create a new flower every second
var newFlower = new Flower();
newFlower.x = Math.random() * 2048;
newFlower.y = 0;
flowers.push(newFlower);
game.addChild(newFlower);
// Create a new red flower every 3 seconds
if (score >= 20 && LK.ticks % 120 == 0) {
var newRedFlower = new RedFlower();
newRedFlower.x = Math.random() * 2048;
newRedFlower.y = 0;
flowers.push(newRedFlower);
game.addChild(newRedFlower);
}
}
};
game.down = function (x, y, obj) {
pot.down(x, y, obj);
};