Articles Archive
Articles Search
Director Wiki
 

Whack a mole

January 24, 1999
by Pat McClellan

Dear Multimedia Handyman,

I am working on an interactive game for a client....very, VERY simple idea. A sprite pops on and off randomly, and if you "hit" the sprite while it is popped up, the player's score goes up one. (similar to the hammer dropping on those arcade heads before they go away.) As soon as they have ten points, the game ends and plays a finish movie loop. If you could give me any input, I would appreciate it. Thank you.

Jeff

Hi Jeff,

I'd do it like this. Create a behavior which you attach to all the sprites that are targets. On each exitFrame, the Behavior on each sprite will generate a random number. In this example, it's a number between 1 and 8. If the number is less than 3 (2 chance in 8), then the sprite will appear on the stage. Otherwise, it will be moved to a locH offstage. Use the tempo channel to adjust the speed. In this example, I've got it set to 2 fps.


-- PopUp Behavior
-- copyright © 1999, ZZP Online, LLC
property mySprite, myLocH
global gScore
on beginSprite me
  set mySprite = the spriteNum of me
  set myLocH = the locH of sprite mySprite
end
on exitFrame
  if random(8) < 3 then
    set the locH of sprite mySprite to myLocH
  else
    set the locH of sprite mySprite to myLocH + 800
  end if
end
on mouseDown me
        -- global gScore declared at top of behavior
    set gScore = gScore + 1 
end
on mouseUp me
  if gScore > 9 then
    go to "win"
    set gScore = 0
  end if
end

The score is tracked in a global variable called gScore, which gets initialized and set to 0 in the startMovie Script. In the behavior, on mouseDown, I increment gScore. Then, on the mouseUp, I test to see if gScore is 10. If so, we go to the "win" frame and reset gScore to 0.

Good luck with your program!

Patrick McClellan is Director Online's co-founder. Pat is Vice President, Managing Director for Jack Morton Worldwide, a global experiential marketing company. He is responsible for the San Francisco office, which helps major technology clients to develop marketing communications programs to reach enterprise and consumer audiences.

Copyright 1997-2024, Director Online. Article content copyright by respective authors.