Friday, April 20, 2012

Practise the random function

Here is an idea to
  • make bullets drop from the top of the stage,
  • from a random x position and
  • at random speeds.
  • The same bullet will stop falling when it hits a sprite called DubDub or when it gets to the bottom of the stage
  • The script also braodcasts a message to DubDub when DubDub is hit so that he will die when all his lives are up.
when green flag clicked - to start the game       
show - to make sure you can see the bullet, since the bullets disappear when the game is over       
forever   - so that the bullet will keep falling
     set y to 183 - start at the top of the stage           
     set x to (pick random -240 to 240)  - pick one of the possible x values on the stage
     set "speed" to (pick random -10 to -1)  - the speed is negative since the y values decrease when you  
                                 move down on the stage.  It will move faster at a speed of -10 than a speed of -1           
     repeat until (((y position) < "-180") or (touching s[DubDub]?))  - stop at the bottom of the stage or  
                                        when you hit DubDub               
               change y by (speed) - use the random value selected for speed           
               if (touching s[DubDub]?)
               broadcast "Hit" - so that DubDub can lose a life and eventually to stop the game

No comments:

Post a Comment