我正在制作HTML5游戏,但无法生成将出现在屏幕底部的硬币。我有另一个对象,它是随机生成从屏幕顶部掉落的块。当我添加生成硬币的功能时,块的生成不起作用,并且控制台错误表明无法定义其他内容。我的功能有问题吗?
function animateRandomBlocks()
{
var time = Date.now();
if(time>lastSpawn+spawnRate)
{
lastSpawn = time;
spawnRandomBlocks();
}
for(var i = 0; i < blocks.length; i++)
{
var block = blocks[i];
block.y += spawnRateOfDescent;
if (block.status == 1)
{
ctx.beginPath();
ctx.fillStyle = block.type;
ctx.fillRect(block.x, block.y, block.width, block.height);
ctx.closePath();
}
var blockRight = block.x;
var blockLeft = block.x + block.width;
var blockTop = block.y
var blockBottom = block.y + block.height;
var bobRight = bobX;
var bobLeft = bobX + bobWidth;
var bobTop = bobY;
var bobBottom = bobY + bobHeight;
if (blockRight > bobLeft && blockLeft < bobRight && blockBottom > bobTop && blockTop < bobBottom && block.status == 1)
{
block.status = 0;
}
}
}