Monday, June 24, 2013

Lava Levels

Biggish update today. I decided to add a new level set. This new level set is the Lava Levels. It includes 10 new, random levels that introduces balls of lava that can kill the player and destroy blocks.

The balls of lava are created with an initial location below the viewing area. I then set a random timeout between 0.45 seconds and 4.5 seconds. This updates their vertical speed (negative) until they reach almost the top of the area. At this point, I set the speed for them to fall (positive).

Timeout:
setTimeout(function () {
    lavaB.velocity.y = -3;
}, Math.random() * 4500);

Update Speed:
if (lavaB.yPosition < top) {
    lavaB.velocity.y = 3;
}
else {
    if (lavaB.yPosition > bottom) {
        lavaB.velocity.y = 0;
    }
}
 

No comments:

Post a Comment