Author Topic: Realistic Explosions  (Read 3101 times)

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Realistic Explosions
« 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.

Code: [Select]
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
Edward Dassmesser

hebedaymun

  • Guest
Re: Realistic Explosions
« Reply #1 on: 2006-03-02, 05:09:34 PM »
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?

??

cbass

  • Expert
  • Regular
  • *****
  • Posts: 97
  • script this
    • View Profile
    • Squest RPG
Re: Realistic Explosions
« Reply #2 on: 2006-03-02, 05:20:52 PM »
you almost forgot:



*sits down and starts eating hamburger while waiting for durnurd*
 ;D

hebedaymun

  • Guest
Re: Realistic Explosions
« Reply #3 on: 2006-03-02, 06:24:04 PM »
Oh, damn, I did, thanks for that!!

*Sits and eats a buffet of food and invites Cbass...*

*...while waiting for Durnurd*

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: Realistic Explosions
« Reply #4 on: 2006-03-02, 07:02:59 PM »
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.
Edward Dassmesser

hebedaymun

  • Guest
Re: Realistic Explosions
« Reply #5 on: 2006-03-02, 08:08:12 PM »
Yeah, I agree.  I'll just stick with what I have.