javascript - How can make random images come out from the holes in Whack-a-Mole game instead of one image -


i wondering able me show me way able bring out random images holes instead of 1 image in whack mole game on javascript. following function used image come in random holes. 1 image i'd 10 different images coming out.

var wormimg = new image(); var worm;  wormimg.src = 'hobby.png'; wormimg.name = 'worm'; wormimg.onload = loadgfx;  function showworm() { if(currentworms == totalworms) {     showalert(); } else {        if(lastworm != null)     {         lastworm.onpress = null;         stage.removechild(lastworm);         stage.update();         lastworm = null;     }      var randompos = math.floor(math.random() * 8);      var worm = new bitmap (wormimg);       worm.x = wormsx[randompos];     worm.y = wormsy[randompos];     stage.addchild(worm);     worm.onpress = wormhit;      lastworm = worm;     lastworm.scaley = 0.3;     lastworm.y += 42;     stage.update();      tween.get(lastworm).to({scaley: 1, y: wormsy[randompos]}, 200).wait(1000).call(function(){currentworms++; showworm()}); } } 

i appreciate help, thank time.

you create array of possible values worm.src, , randomly select 1 whenever showing new worm


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

wso2esb - How to concatenate JSON array values in WSO2 ESB? -