property sNum
property speed -- how often do they fall?
property spriteHeight, spriteWidth -- dimensions of sprite
property lastRainTick -- last time a drop fell
property onlyWhileMouseOver -- only generate ripples while over, pauseEffect otherwise
property paused -- generate ripples or not
on getBehaviorDescription me
return "This behavior will place random ripples on the sprite to generate a rain effect."
end
on getPropertyDescriptionList me
set list = [:]
addProp list, #speed, [#comment: "Speed:", #format: #integer, #default: 60, #range: [#max: 100, #min:1]]
addProp list, #onlyWhileMouseOver , [#comment: "Only While Mouse Over", #format: #boolean, #default: FALSE]
return list
end
on beginSprite me
set sNum = the spriteNum of me
set spriteWidth = the width of sprite sNum
set spriteHeight = the height of sprite sNum
set lastRainTick = 0
ripple(sprite sNum)
if onlyWhileMouseOver then
if not rollover(sNum) then
PauseEffect(sprite sNum, #ripple)
exit
end if
end if
Add(the actorList, me)
end
on endSprite me
set pos = getone(the actorList, me)
if pos then
deleteAt(the actorList, pos)
end if
end
on stepFrame me
set nextRainTick = lastRainTick + 101 - speed
if the ticks >= nextRainTick then -- time for another drop
RainDrop(me)
set lastRainTick = the ticks
end if
end
on RainDrop me, h, v
if integerP(h) then
set x = h
else
set x = random(spriteWidth)
end if
if integerP(v) then
set y = v
else
set y = random(spriteHeight)
end if
ripple(sprite sNum, [#xLocation: x, #yLocation: y])
end
on StopEffect me, sym
-- removes this behavior from the actorList
if not voidP(sym) then
if sym <> #ripple then exit
end if
set pos = getone(the actorList, me)
if pos then
deleteAt(the actorList, pos)
PauseEffect(sprite sNum, #ripple)
end if
end
on ResumeEffect me, sym
-- adds this behavior to the actorList
if not voidP(sym) then
if sym <> #ripple then exit
end if
set pos = getone(the actorList, me)
if pos = 0 then
Add(the actorList, me)
ContinueEffect(sprite sNum, #ripple)
end if
end
on mouseEnter me
if onlyWhileMouseOver then
ResumeEffect(me)
end if
end
on mouseLeave me
if onlyWhileMouseOver then
StopEffect(me)
end if
end
|