/****
* Classes
****/
var Basket = Container.expand(function () {
var self = Container.call(this);
var basketGraphics = self.attachAsset('basket', {
anchorX: 0.5,
anchorY: 0.5
});
self.down = function (x, y, obj) {
self.x = x;
self.y = y;
};
});
var Bomb = Container.expand(function () {
var self = Container.call(this);
var bombGraphics = self.attachAsset('bomb', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2; // Initial falling speed
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
//<Write imports for supported plugins here>
//<Write entity 'classes' with empty functions for important behavior here>
var Fruit = Container.expand(function () {
var self = Container.call(this);
var fruitGraphics = self.attachAsset('fruit', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2; // Initial falling speed
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
var background = game.addChild(LK.getAsset('background', {
anchorX: 0,
anchorY: 0
}));
background.x = 0;
background.y = 0;
//<Assets used in the game will automatically appear here>
//<Write game logic code here, including initializing arrays and variables>
var fruits = [];
var basket = game.addChild(new Basket());
basket.x = 2048 / 2;
basket.y = 2500;
var score = 0;
var scoreTxt = new Text2('Score: 0', {
size: 100,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var speedIncreaseInterval = 5000; // Increase speed every 5 seconds
var lastSpeedIncrease = 0;
game.update = function () {
if (LK.ticks % 60 == 0) {
var newFruit = new Fruit();
newFruit.x = Math.random() * 2048;
newFruit.y = 0;
fruits.push(newFruit);
game.addChild(newFruit);
if (Math.random() < 0.1) {
// 10% chance to spawn a bomb instead of a fruit
var newBomb = new Bomb();
newBomb.x = Math.random() * 2048;
newBomb.y = 0;
fruits.push(newBomb);
game.addChild(newBomb);
}
}
for (var i = fruits.length - 1; i >= 0; i--) {
var fruit = fruits[i];
fruit.update();
if (fruit.intersects(basket)) {
if (fruit instanceof Bomb) {
LK.showGameOver();
} else {
score += 10;
scoreTxt.setText('Score: ' + score);
}
fruit.destroy();
fruits.splice(i, 1);
}
}
if (LK.ticks - lastSpeedIncrease > speedIncreaseInterval) {
for (var i = 0; i < fruits.length; i++) {
fruits[i].speed += 0.5;
}
lastSpeedIncrease = LK.ticks;
}
};
game.down = function (x, y, obj) {
basket.down(x, y, obj);
}; ===================================================================
--- original.js
+++ change.js
@@ -11,8 +11,22 @@
self.x = x;
self.y = y;
};
});
+var Bomb = Container.expand(function () {
+ var self = Container.call(this);
+ var bombGraphics = self.attachAsset('bomb', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 2; // Initial falling speed
+ self.update = function () {
+ self.y += self.speed;
+ if (self.y > 2732) {
+ self.destroy();
+ }
+ };
+});
//<Write imports for supported plugins here>
//<Write entity 'classes' with empty functions for important behavior here>
var Fruit = Container.expand(function () {
var self = Container.call(this);
@@ -66,15 +80,27 @@
newFruit.x = Math.random() * 2048;
newFruit.y = 0;
fruits.push(newFruit);
game.addChild(newFruit);
+ if (Math.random() < 0.1) {
+ // 10% chance to spawn a bomb instead of a fruit
+ var newBomb = new Bomb();
+ newBomb.x = Math.random() * 2048;
+ newBomb.y = 0;
+ fruits.push(newBomb);
+ game.addChild(newBomb);
+ }
}
for (var i = fruits.length - 1; i >= 0; i--) {
var fruit = fruits[i];
fruit.update();
if (fruit.intersects(basket)) {
- score += 10;
- scoreTxt.setText('Score: ' + score);
+ if (fruit instanceof Bomb) {
+ LK.showGameOver();
+ } else {
+ score += 10;
+ scoreTxt.setText('Score: ' + score);
+ }
fruit.destroy();
fruits.splice(i, 1);
}
}