Contents
Articles
Behaviors
Books
Director News
Director Web Sites
FAQ
Games
Mailing Lists
News Groups
Project Examples
Reviews
Software
Tools
Useful Web Sites
Utilities
Xtras

Don't miss these
Find Drive Movie Is Plating From
MIAW Event Leak
Shockwave for Dummies With CDROM
Function Key Keycodes
Vector Shapes - Create Donut
Popup Xtra
Write a file
ADOXtra Lite
Macromedia Director 8 Shockwave Studio- Illustrated Introductory
Append a File
 

 

 

Behavior Light Up Game Controller

Added on 9/19/1999

 

Compatibilities:
behavior D7 D8 Mac PC Shockwave

Rating:

Author: MediaMacros (website)

Arrange rows from left to right and top to bottom. Example with source code is available in the Games Area.

--Copyright 1999 Chuck Neal
--chuck@mediamacros.com
--If you find this code helpful, send me an e-mail and let me know. :-)

property toggleState, spriteNum, myPrefix
global gFirstToggle, gLastToggle, gNumberPerLine, totalTries

on beginSprite me
  --change to match the number of items you have per line
  -------------------------------------------------
  if gNumberPerLine = void then gNumberPerLine = 5
  -------------------------------------------------
  if totalTries <> 0 then totalTries = 0
  if gFirstToggle = void then gFirstToggle = 999
  if gLastToggle = void then gLastToggle = 0
  toggleState = random(0,1)
  the itemDelimiter = "-"
  myPrefix = sprite(spriteNum).member.name.item[1]
  checkToggleState()
  if gFirstToggle > spriteNum then gFirstToggle = spriteNum
  if gLastToggle < spriteNum then gLastToggle = spriteNum
end

on mouseUp me
  totalTries = totalTries + 1
  toggleState = not(toggleState)
  --not the last on the right
  if ((spriteNum + 1) mod gNumberPerLine) <> (gFirstToggle mod gNumberPerLine) then
    sprite(spriteNum + 1).toggleState = not(sprite(spriteNum + 1).toggleState)
  end if
  --not the last on the left
  if ((spriteNum - 1) mod gNumberPerLine) <> (gLastToggle mod gNumberPerLine) then
    sprite(spriteNum - 1).toggleState = not(sprite(spriteNum - 1).toggleState)
  end if
  if (spriteNum + gNumberPerLine) <= gLastToggle then
    sprite(spriteNum + gNumberPerLine).toggleState = not( sprite(spriteNum + gNumberPerLine).toggleState)
  end if
  if (spriteNum - gNumberPerLine) >= gFirstToggle then
    sprite(spriteNum - gNumberPerLine).toggleState = not(sprite(spriteNum - gNumberPerLine).toggleState)
  end if
  sendAllSprites(#checkToggleState)
  updateStage
  set myList = []
  sendAllSprites(#checkForDone, myList)
  if myList.getOne(0) < 1 then
    go to "done"
  end if
end

on checkToggleState me
  if sprite(spriteNum).member <> member(myPrefix & "-" & string(toggleState)) then
    sprite(spriteNum).member = member(myPrefix & "-" & string(toggleState))
  end if
end

on checkForDone me, theList
  add theList, the toggleState of me
end

on getBehaviorDescription me
  describe = "This behavior controls a simple light up game."
  describe = describe & return & "Create 2 graphics, one for the on state, one for the off state, and label them with the same prefix followed by a (-) and either a 0 (off) or a 1 (on)."
  describe = describe & return & "For example...Name your graphics light-0 and light-1"
  describe = describe & return & "Arrange them in the score from left to right starting with the top row. If the first sprite is 1 then you would place the next graphic on the same row and to the right and in sprite channel 2"
  describe = describe & return & "The lights are then set randomly on the beginSprite handler and the lights are turned on."
  return describe
end

 


Contact

MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA

Send e-mail