TIFFANY HOLMES>BREAKOUT GAME>SPRING04>HANDOUT CLASS 5

 

EVENTS>Examples of event handlers>You want to initialize all your variables in your global script with the event: on startmovie.

 

on startmovie me

  --in the startmovie event all global variables get initialized

 

  global gball, gbricks, gx, gy

  --gball is sprite channel number for ball

  gball=20

 

  --there are fifteen bricks in channels 1-15

  gbricks=15

 

  --gx and gy help change the direction of the ball (see ballbounce script in movie breakout_sample_intersects.dir in the Class 5 folder on the Files for Courses server.)

  gx=1

  gy=1

end

 

COMMANDS WITH REPEAT LOOPS: Sometimes you want to command a change to a large group of sprites.  This is where repeat loops come in handy.  HereÕs an example of a loop that tests to see whether the ball sprite (me.spritenum) hits any of the sprites in channels 1-15.  If there is a hit the brick moves off screen and a sound called ÒcherryÓ is played in channel 2.

 

repeat with b=1 to 15

    if sprite(me.spritenum).intersects(b) then

      sprite(b).loc=point(-100,-100)

      puppetsound 2, "cherry"

    end if

  end repeat

 

HELPFUL LIST SYNTAX (linear lists only)

 

Setting up a blank, or empty list:

Gbrickshit=[]

 

Adding an element to a list:

Append Gbrickshit=[6]

 

Getting the count of a list:

Put count(Gbrickshit) into field Òdata