I combined two and a half scripts that I already had made to get this final script that creates a "more realistic" explosion when, in this case, a bomb is dropped and hits the floor. The bomb explodes as soon as it hits, creates an "explosion" sprite, plays an "explosion" sound effect, and shakes the screen slightly. More could be done with this, I imagine, but I just thought I'd post it for consumption. Most of this could be done with special functions, but part of the reason I'm posting this is to show that it's easier to use script than not sometimes.
Dim ShotName, ExplosionName 'Explosives
ShotName = "Bomb" 'Bomb Sprite Definition Name
ExplosionName = "Explosion" 'Explosion Sprite Definition Name
SoundEffect = "Explosion" 'Sound Effect Name
Dim ShakeDelta, ShakeMax, curShake, ShakeLength 'Shaking. Don't change these
ShakeDelta = 3
ShakeMax = 0
curShake = 0
ShakeLength = 15
Sub Player_OnAfterMoveSprites()
Dim Layer
Set Layer = ProjectObj.GamePlayer.PlayerSprite.rDef.rLayer
Dim Sprite
For Sprite = 0 to Layer.SpriteCount - 1
if left(Layer.Sprite(Sprite).rDef.Name,len(ShotName)) = ShotName then
Layer.Sprite(Sprite).ReactToSolid()
if Layer.Sprite(Sprite).bHitSolid then
Dim X, Y
X = Layer.Sprite(Sprite).X
Y = Layer.Sprite(Sprite).Y
Dim ExplosionSprite
Set ExplosionSprite = Layer.pMap.SpriteDefs(ExplosionName).MakeInstance
With ExplosionSprite
OffsetX = (.Width - Layer.Sprite(Sprite).Width) / 2
OffsetY = (.Height - Layer.Sprite(Sprite).Height) / 2
.X = X - OffsetX
.Y = Y - OffsetY
.PathOffsetX = .X - .rDef.rPath.PointX(0)
.PathOffsetY = .Y - .rDef.rPath.PointY(0)
End With
Layer.RemoveSprite(Sprite)
Layer.AddSprite(ExplosionSprite)
ProjectObj.MediaMgr.Clip(SoundEffect).StartClip
ShakeMax = ShakeLength
end if
end if
Next
If ShakeMax = 0 then exit sub
With ProjectObj.GamePlayer
.MapScrollX = .MapScrollX + ShakeDelta
.rMap.draw .MapScrollX, .MapScrollY
End With
curShake = curShake + ShakeDelta
If abs(curShake) >= abs(ShakeMax) then
ShakeDelta = ShakeDelta * -1
ShakeMax = ShakeMax * -1 + sgn(ShakeMax)
curShake = 0
End If
End Sub
HostObj.SinkObjectEvents ProjectObj.GamePlayer, "Player"
HostObj.ConnectEventsNow()
ProjectObj.GamePlayer.Play 16