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.
Experiments
ToDo List/Game
ToDo List/GamePlace a description in the Items field and put a time (in minutes) for how long the task will take and click Add Item. When complete, click the Complete button and that will strengthen your character.
Platformer
Desktop Version Mobile VersionPlayer must try to collect the diamond. They can click/touch the screen to create blocks to get to the diamond. Enemies can destroy any created blocks on touch.
Created Blocks can be removed by clicking/touching them again.
Unity
Unity Game TutorialSunday, May 26, 2013
Wednesday, May 22, 2013
Level Keeper and Created Blocks
Smallish update that resets just the player and the game state when the reset level button is pressed. Previously, the reset level button would reset the blocks from the random level generator.
Another change is that the created blocks have a new image associated with them. This will later be used to allow the player to remove a block they have placed which will add it back to their block count.
Tuesday, May 7, 2013
Random Level Generator
I added a random level generator to the game. It generates 12 blocks between 120 and 480 on the x axis and between 60 and 330 on the y axis. The code is as below...
for (var i = 0; i < 12; i++)
{
var x = Math.floor((Math.random()*10)+3) *40;
var y = Math.floor((Math.random()*9)+2) *30;
rects.push(rect(x, y, 20, 20));
}
The first 8 levels are randomly generated then the last 2 are pre generated.
for (var i = 0; i < 12; i++)
{
var x = Math.floor((Math.random()*10)+3) *40;
var y = Math.floor((Math.random()*9)+2) *30;
rects.push(rect(x, y, 20, 20));
}
The first 8 levels are randomly generated then the last 2 are pre generated.
Subscribe to:
Posts (Atom)