Scrolling Game Development Kit Forum
SGDK Version 1 => Script => Topic started by: durnurd on 2006-03-02, 04:36:42 PM
-
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
-
Hey, is this kind of a beefed up version of the script you gave me? the one about a beam or whatever. Would you suggest I use this one instead?
??
-
you almost forgot:
*sits down and starts eating hamburger while waiting for durnurd*
;D
-
Oh, damn, I did, thanks for that!!
*Sits and eats a buffet of food and invites Cbass...*
*...while waiting for Durnurd*
-
You can feel free to use it if you like, but I think shaking the screen every time a laser hits a wall would be distracting and would get old really quickly. You could take that part out (By changing the line "ShakeLength = 15" to "ShakeLength = 0") and just use what I gave you along with the ability to play a sound effect at the same time. This also matches the center of the bullet sprite to the center of the explosion sprite, instead of matching the top-left corners.
-
Yeah, I agree. I'll just stick with what I have.