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
Send E-mail using Buddy API
Wait for explode to finish
Go to NetMovie
3D controller example
System Info into a field member
Make Projector
Import image (at runtime)
A Lingo Timer Script
Generic MP3 Player
Orbiter
 

 

 

Behavior Get Crazy

Added on 6/7/1999

 

Compatibilities:
behavior D6_5 Mac PC

This item has not yet been rated

Author: DetlefBeyer

GetCrazy behavior Detlef Beyer (d.beyer@hermes.de)

property pSpeed,pDir,pSprite,pH,pV,pMv,pMh,pStageL,pStageR,pStageT,pStageB,pStageW,pStageH,
                                    pStartTime,pOldH,pOldV,pAlarmCnt

on beginSprite me,wichSprite
  
  set pSprite = the spriteNum of me
  puppetSprite pSprite,TRUE
  
  set myDummy = random(the ticks)
  
  set pSpeed = 1
  set pDir = random(8)
  set pMv = the mouseV
  set pMh = the mouseH
  set pOldH = pH
  set pOldV = pV
  set pAlarmCnt = 0
  set pStageW = the stageRight - the stageLeft
  set pStageH = the stageBottom - the stageTop
  set pStageL = the width of member (the memberNum of sprite pSprite) / 2
  set pStageR = pStageW - the width of member (the memberNum of sprite pSprite) / 2
  set pStageT = the height of member (the memberNum of sprite pSprite) / 2
  set pStageB = pStageH - the height of member (the memberNum of sprite pSprite) / 2
  set pH = the locH of sprite pSprite
  set pV = the locV of sprite pSprite
  set pStartTime = the ticks
  
  set the locH of sprite pSprite to pH
  set the locV of sprite pSprite to pV
end beginSprite


on exitFrame me
  if the ticks > pStartTime + pSpeed then
    mSetSpeed(me)
    
    mSetNewDir(me)
    
    set pStartTime = the ticks
    
    mGoPuppet(me)
  end if
end exitFrame


on mGoPuppet me
  case pDir of
    1 :
      set pH = pH
      set pV = pV - 1
    2 :
      set pH = pH + 1
      set pV = pV - 1
    3 :
      set pH = pH + 1
      set pV = pV
    4 :
      set pH = pH + 1
      set pV = pV + 1
    5 :
      set pH = pH
      set pV = pV + 1
    6 :
      set pH = pH - 1
      set pV = pV + 1
    7 :
      set pH = pH - 1
      set pV = pV
    8 :
      set pH = pH - 1
      set pV = pV - 1
  end case
  
  set the locH of sprite pSprite = pH
  set the locV of sprite pSprite = pV
end mGoPuppet


on mSetNewDir me
  if mCheckWall(me) then
    set pDir = mCheckWallDir(me)
  else
    if pSpeed < 5 then
      set pDir = mCheckDir()
    end if
  end if
end mSetNewDir


on mReverseDir me
  set pDir = pDir + 4
  if pDir > 8 then
    set pDir = pDir - 8
  end if
end mReverseDir


on mCheckWall me
  -- Hit the Wall?
  if pH < pStageL OR pH > pStageR OR pV < pStageT OR pV > pStageB then
    return TRUE
  else
    return FALSE
  end if
end mCheckWall


on mSetSpeed me
  set newDist = mCheckSpeed(me)
  
  if newDist > 100 then
    set pSpeed = 20
  else
    if newDist > 80 then
      set pSpeed = 13
    else
      if newDist > 60 then
        set pSpeed = 8
      else
        if newDist > 40 then
          set pSpeed = 5
        else
          if newDist > 20 then
            set pSpeed = 1
          else
            set pSpeed = 0
          end if
        end if
      end if
    end if
  end if
end mSetSpeed


on mCheckSpeed me
  
  set pMv = the mouseV
  set pMh = the mouseH
  
  set n = pMh - pH
  set m = pMv - pV
  
  if n < 0 then
    set n = n * (-1)
  end if
  if m < 0 then
    set m = m * (-1)
  end if
  
  return n + m
end mCheckSpeed


on mCheckDir me
  if pMh > pH then
    if pMv > pV then
      set newDir = 8
    else
      if pMv < pV then
        set newDir = 6
      else
        -- pMv = pV
        set newDir = 7
      end if
    end if
  else
    if pMh < pH then
      if pMv > pV then
        set newDir = 2
      else
        if pMv < pV then
          set newDir = 4
        else
          -- pMv = pV
          set newDir = 3
        end if
      end if
    else
      -- pMh = pH
      if pMv > pV then
        set newDir = 1
      else
        if pMv < pV then
          set newDir = 5
        else
          -- pMv = pV
          set newDir = 0
        end if
      end if
    end if
  end if
  
  -- Tolleranz
  if pMv < pV then
    if pMh < pH then
      if (pH - pMh < 1 AND pV - pMv < 2) then
        set newDir = 0
      end if
    else
      if (pMh - pH < 1 AND pV - pMv < 2) then
        set newDir = 0
      end if
    end if
  else
    if pMh < pH then
      if (pH - pMh < 1 AND pMv - pV < 2) then
        set newDir = 0
      end if
    else
      if (pMh - pH < 1 AND pMv - pV < 2) then
        set newDir = 0
      end if
    end if
  end if
  return newDir
end mCheckDir


on mCheckWallDir me
  if pH > pStageR then
    if pV > pStageB then
      set newDir = 8
    else
      if pV < pStageT then
        set newDir = 6
      else
        set newDir = 7
      end if
    end if
  else
    if pH < pStageL then
      if pV > pStageB then
        set newDir = 2
      else
        if pV < pStageT then
          set newDir = 4
        else
          set newDir = 3
        end if
      end if
    else
      if pV > pStageB then
        set newDir = 1
      else
        if pV < pStageT then
          set newDir = 5
        else
          set newDir = pDir
        end if
      end if
    end if
  end if
  
  return newDir
end mCheckWallDir


on mKillMe me
  puppetSprite pSprite,FALSE
end mKillMe

---

on getBehaviorDescription
  return "moves the sprite randomly over the stage and tries to" &
                             "get away from the mouse. Detlef Beyer (d.beyer@hermes.de)"
end getBehaviorDescription

 


Contact

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

Send e-mail