Code edit (1 edits merged)
Please save this source code
User prompt
当玩家在砖块碰到线时点到砖块时在砖块周围出现一个光圈,完美为金色,良好为蓝色,一般为灰色
Code edit (1 edits merged)
Please save this source code
User prompt
使提示文字在下一行
Code edit (9 edits merged)
Please save this source code
User prompt
使砖块下落间隔为随机数,区间在0.4到1.5之间
User prompt
使砖块下落间隔为随机数,区间在0.4到1.5之间
User prompt
使砖块下落时间为随机数,区间在0.4-1.5之间
Code edit (2 edits merged)
Please save this source code
User prompt
使线高一些
User prompt
使线高一些
Code edit (1 edits merged)
Please save this source code
User prompt
当砖块经过线,但玩家没有点到砖块时,扣1分,并显示“失误”
Code edit (1 edits merged)
Please save this source code
User prompt
使中砖块细一些
User prompt
使中砖块更粗
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
// Class for falling blocks
var FallingBlock = Container.expand(function () {
var self = Container.call(this);
self.containsPoint = function (point) {
var localPoint = self.toLocal(point);
return localPoint.x >= 0 && localPoint.y >= 0 && localPoint.x <= self.width && localPoint.y <= self.height;
};
var blockGraphics = self.attachAsset('block', {
anchorX: 0.5,
anchorY: 0.5
});
var smallBlockGraphics = self.attachAsset('smallBlock', {
width: 500,
height: 500,
anchorX: 0.5,
anchorY: 0.5
});
var smallestBlockGraphics = self.attachAsset('smallestBlock', {
width: 500,
height: 125,
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 30;
self.update = function () {
self.y += self.speed;
if (self.y > 2732 || self.x < 0 || self.x > 2048) {
self.destroy();
}
};
self.down = function (x, y, obj) {
if (Math.abs(self.y - 2632) < 50) {
LK.setScore(LK.getScore() + 2);
scoreTxt.setText(LK.getScore() + " 良好");
self.destroy();
} else if (Math.abs(self.y + smallBlockGraphics.height / 2 - 2632) < 50) {
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore() + " 一般");
self.destroy();
} else if (Math.abs(self.y + smallestBlockGraphics.height / 2 - 2632) < 50) {
LK.setScore(LK.getScore() + 3);
scoreTxt.setText(LK.getScore() + " 完美");
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
LK.on('keydown', function (event) {
if (event.key >= '1' && event.key <= '4') {
var laneIndex = parseInt(event.key) - 1;
for (var i = 0; i < blocks.length; i++) {
if (blocks[i].x === lanes[laneIndex]) {
blocks[i].down(blocks[i].x, blocks[i].y, {
global: {
x: blocks[i].x,
y: blocks[i].y
}
});
break;
}
}
}
});
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.setText(LK.getScore());
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var blocks = [];
var lanes = [512, 1024, 1536, 2048];
var whiteLine = new Container();
var whiteLineGraphics = whiteLine.attachAsset('line', {
width: 2048,
height: 10,
color: 0xffffff,
x: 0,
y: 2632
});
game.addChild(whiteLine);
function spawnBlock() {
var lane = Math.max(50, Math.min(1898, lanes[Math.floor(Math.random() * lanes.length)]));
var newBlock = new FallingBlock();
newBlock.x = lane;
newBlock.y = 0;
blocks.push(newBlock);
game.addChild(newBlock);
}
var spawnInterval = LK.setInterval(spawnBlock, 1000);
game.update = function () {
for (var i = blocks.length - 1; i >= 0; i--) {
if (blocks[i].y > 2732) {
blocks[i].destroy();
blocks.splice(i, 1);
}
}
};
game.down = function (x, y, obj) {
for (var i = 0; i < blocks.length; i++) {
if (blocks[i].containsPoint({
x: x,
y: y
})) {
blocks[i].down(x, y, obj);
break;
}
}
};