/****
* 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;
};
});
//<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
****/
//<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);
}
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);
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
@@ -1,84 +1,83 @@
-/****
+/****
* 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;
- };
+ 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;
+ };
});
//<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;
- };
+ 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
+ backgroundColor: 0x000000 //Init game with black background
});
-/****
+/****
* Game Code
-****/
-//<Write game logic code here, including initializing arrays and variables>
+****/
//<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
+ 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);
- }
- for (var i = fruits.length - 1; i >= 0; i--) {
- var fruit = fruits[i];
- fruit.update();
- if (fruit.y > 2732) {
- LK.showGameOver();
- return;
- }
- if (fruit.intersects(basket)) {
- 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;
- }
+ if (LK.ticks % 60 == 0) {
+ var newFruit = new Fruit();
+ newFruit.x = Math.random() * 2048;
+ newFruit.y = 0;
+ fruits.push(newFruit);
+ game.addChild(newFruit);
+ }
+ 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);
+ 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);
+ basket.down(x, y, obj);
};
\ No newline at end of file