HTML and CSS Reference
In-Depth Information
newParticle = particlePool . pop ();
newParticle . dx = Math . random () * 3 ;
iif ( Math . random () < . 5 ){
newParticle . dx *= 1 ;
}
newParticle . dy = Math . random () * 3 ;
iif ( Math . random () < . 5 ){
newParticle . dy *= 1 ;
}
newParticle . life = Math . floor ( Math . random () * 30 + 30 );
newParticle . lifeCtr = 0 ;
newParticle . x = x ;
newParticle . width = 2 ;
newParticle . height = 2 ;
newParticle . y = y ;
newParticle . type = type ;
//ConsoleLog.log("newParticle.life=" + newParticle.life);
particles . push ( newParticle );
}
}
}
As the particle objects are created in createExplode() , we add a new type attribute to
them. When an explosion is triggered in the checkCollisions() function, the call to cre-
ateExplode() nowincludesthis type valuebasedontheobjectthatwasdestroyed.Eachrock
already has a scale parameter that varies from 1 to 3 based on its size. We use those as our
base type valuetopassinfortherocks.Nowweonlyneed type valuesfortheplayerandthe
saucer. For the saucer, we use 0 , and for the player, we use 4 . We pulled these id values out of
the air. We very well could have used 99 for the saucer and 200 for the player. We just could
not use 1 , 2 , or 3 because those values are used for the rocks. The type breakdown looks like
this:
▪ Saucer: type = 0
▪ Large rock: type = 1
▪ Medium rock: type = 2
▪ Small rock: type = 3
▪ Player: type = 4
Search WWH ::




Custom Search