I have now introduced the ability to remove a placed block by clicking/touching it again. It will add the block back to your block count. The code was relatively simple as shown below:
for (var i = 0; i < rectsCreated.length; i++) {
if (x > rectsCreated[i].x && x < rectsCreated[i].x + rectsCreated[i].w &&
y > rectsCreated[i].y && y < rectsCreated[i].y + rectsCreated[i].h)
{
blockCount++;
document.getElementById("blockNum").innerText = blockCount;
createBlock = false;
rectsCreated.splice(i, 1);
}
}
It just checks the rectangle area in each created block to see whether the click is actually inside of it. If it is, increment the block count and remove the block from the screen.
This comes in handy for the Fish level that was added as well. The Fish level is a survive as long as you can level. You need to survive by staying above the spikes as long as you can while the fish chase after you and destroy your blocks.
No comments:
Post a Comment