User prompt
更改背景
User prompt
把背景颜色变成蓝色
User prompt
当碰到炸弹时游戏结束
User prompt
当炸弹到屏幕上方时游戏不结束
User prompt
新增一个炸弹种类,碰到扣1分
User prompt
水果移动速度随着积分提升而加快
User prompt
随机水果的大小但只改变大小,不改变形状
User prompt
随机水果的大小并保持纵横比不变
User prompt
让水果的大小随机
User prompt
如果有水果到达屏幕上方则游戏失败
User prompt
Please fix the bug: 'Uncaught TypeError: fruits[i].containsPoint is not a function' in or related to this line: 'if (fruits[i].containsPoint({' Line Number: 57
Initial prompt
切水果
/**** * Classes ****/ //<Assets used in the game will automatically appear here> // Fruit class var Fruit = Container.expand(function () { var self = Container.call(this); var fruitGraphics = self.attachAsset('fruit', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { self.y -= self.speed; if (self.y < -fruitGraphics.height) { self.destroy(); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize score var score = 0; var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Array to keep track of fruits var fruits = []; // Function to spawn a new fruit function spawnFruit() { var newFruit = new Fruit(); newFruit.x = Math.random() * 2048; newFruit.y = 2732 + newFruit.height; fruits.push(newFruit); game.addChild(newFruit); } // Function to handle slicing fruits function handleSlice(x, y, obj) { for (var i = fruits.length - 1; i >= 0; i--) { if (fruits[i].containsPoint({ x: x, y: y })) { fruits[i].destroy(); fruits.splice(i, 1); score += 1; scoreTxt.setText(score); } } } // Set up game event listeners game.down = function (x, y, obj) { handleSlice(x, y, obj); }; game.move = function (x, y, obj) { handleSlice(x, y, obj); }; // Game update function game.update = function () { for (var i = fruits.length - 1; i >= 0; i--) { fruits[i].update(); } if (LK.ticks % 60 == 0) { spawnFruit(); } };
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
// Fruit class
var Fruit = Container.expand(function () {
var self = Container.call(this);
var fruitGraphics = self.attachAsset('fruit', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
self.y -= self.speed;
if (self.y < -fruitGraphics.height) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize score
var score = 0;
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Array to keep track of fruits
var fruits = [];
// Function to spawn a new fruit
function spawnFruit() {
var newFruit = new Fruit();
newFruit.x = Math.random() * 2048;
newFruit.y = 2732 + newFruit.height;
fruits.push(newFruit);
game.addChild(newFruit);
}
// Function to handle slicing fruits
function handleSlice(x, y, obj) {
for (var i = fruits.length - 1; i >= 0; i--) {
if (fruits[i].containsPoint({
x: x,
y: y
})) {
fruits[i].destroy();
fruits.splice(i, 1);
score += 1;
scoreTxt.setText(score);
}
}
}
// Set up game event listeners
game.down = function (x, y, obj) {
handleSlice(x, y, obj);
};
game.move = function (x, y, obj) {
handleSlice(x, y, obj);
};
// Game update function
game.update = function () {
for (var i = fruits.length - 1; i >= 0; i--) {
fruits[i].update();
}
if (LK.ticks % 60 == 0) {
spawnFruit();
}
};