Author Topic: Okay...this is a big request...  (Read 4862 times)

hebedaymun

  • Guest
Okay...this is a big request...
« on: 2006-03-01, 09:20:10 AM »
   Okay, I need a script.  This one is for an attack.  I want you to imagine something for a moment:  Imagine Metroid....Super Metroid, if you will.  Imagine you shooting an energy ball.  Okay?  That's what I have in my game.  Now, after you shoot this ball, I just want a script to detect if that sprite or sprite template hits a solid, it deletes that sprite and plays a small animation where it hit.  Now, I kind of want it like Metroid, where you shoot a beam and it hits a wall, and a small explosion follows after deleting the sprite. 

Could someone help me with this?  I know it must be easy, it's not an awful lot.  Just detect if a sprite hit a solid catagory and play the animation after deleting it.  That's all.

And before Durnurd suggests it (it's not like I have a problem with it), I have used the scripting wizard, but as you can imagine, it can't take your attack this far.

Help would be greatly appreciated.

*pulls up chair and eats while waiting*

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: Okay...this is a big request...
« Reply #1 on: 2006-03-01, 11:37:48 AM »
I wasn't about to suggest the scripting wizard.  Since you say you already have the energy ball shooting, that's totally unnecessary.

Code: [Select]
Dim ShotName, ExplosionName
ShotName = "Bullet"
ExplosionName = "Explosion"


Sub Player_OnAfterMoveSprites()
   Layer = ProjectObj.GamePlayer.PlayerSprite.rDef.rLayer
   Dim Sprite
   For Sprite = 0 to Layer.SpriteCount
      if Layer.Sprite(Sprite).rDef.Name = ShotName then
         Layer.Sprite(Sprite).ReactToSolid()
         if Layer.Sprite(Sprite).bHitSolid then
            Dim X, Y
            Layer.RemoveSprite(Sprite)
            X = Layer.Sprites(Sprite).X
            Y = Layer.Sprites(Sprite).Y
            Dim ExplosionSprite
            Set ExplosionSprite = Layer.pMap.SpriteDefs.MakeInstance
            ExplosionSprite.X = X
            ExplosionSprite.Y = Y
            Layer.AddSprite(ExplosionSprite)
         end if
      end if
   Next
End Sub

If you just enter the right names, this should work.  Unless, of course, there's a bug (which there probably is).  You just need to create a sprite definition for the explosion that's one of those single-point with a delay sprites that follows exact path and deletes itself at the end of its path.  This has been discussed several times on the forums.  If you need any help with that, just ask.
Edward Dassmesser

hebedaymun

  • Guest
Re: Okay...this is a big request...
« Reply #2 on: 2006-03-01, 01:00:26 PM »
I wasn't about to suggest the scripting wizard.  Since you say you already have the energy ball shooting, that's totally unnecessary.

I know, I was just making sure.  Well, it looks like this might be what I'm looking for.  Oh, I already knew about that 'delay the path; after delay delte 'EOP'' thing.  I just needed a script to help detect that the sprite was hitting a solid.  Thanks for the help, man.  You've been helping me a lot.  Are you the main help guy around here, or just the best at scripting (besides the big cheese, which I KNOW he's better, he made the engine).

Well, anyway, thanks.  I'm off to go check it out.

*leaves his food sitting on the table and sets off with his code*

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: Okay...this is a big request...
« Reply #3 on: 2006-03-01, 04:09:05 PM »
I guess I'm pretty good at scripting (at least when I'm doing it, so I can debug easily).  I just help out a lot because I'm not busy making my own games.

Edit:

I did some debugging of the script, (as I suspected, it had several bugs).  Here's one that works:

Code: [Select]
Dim ShotName, ExplosionName
ShotName = "Bullet"
ExplosionName = "Explosion"


Sub Player_OnAfterMoveSprites()
   Dim Layer
   Set Layer = ProjectObj.GamePlayer.PlayerSprite.rDef.rLayer
   Dim Sprite
   For Sprite = 0 to Layer.SpriteCount - 1
      if Layer.Sprite(Sprite).rDef.Name = 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
            Layer.RemoveSprite(Sprite)
            Dim ExplosionSprite
            Set ExplosionSprite = Layer.pMap.SpriteDefs(ExplosionName).MakeInstance
            ExplosionSprite.X = X
            ExplosionSprite.Y = Y
            Layer.AddSprite(ExplosionSprite)
         end if
      end if
   Next
End Sub

HostObj.SinkObjectEvents ProjectObj.GamePlayer, "Player"
HostObj.ConnectEventsNow()
ProjectObj.GamePlayer.Play 16
« Last Edit: 2006-03-01, 04:17:52 PM by durnurd »
Edward Dassmesser

hebedaymun

  • Guest
Re: Okay...this is a big request...
« Reply #4 on: 2006-03-01, 04:55:57 PM »
Thatnks for this revised version.  I was about to come on these forums and ask "What the hell went wrong?".  I'll check this one out.  by the way, it sure is nice to have someone on these forums make some code for you free of charge!  Man, it's actually a nice feeling.

Well, I'm outta here.

*Finishes his food and walks out with his new code*

hebedaymun

  • Guest
Re: Okay...this is a big request...
« Reply #5 on: 2006-03-01, 05:30:44 PM »
Hey, this script works really, really well.  There's just one problem.  I need it so it can detect maybe... "BulletLeft" "BulletRight" and "Explosion".  All three... do you think you can add that for me?  Just maybe duplicate it once for the Left side and add a Right side?  And only make one explosion sprite.  Help would be greatly appreciated!

Thanks again, man.

*sits and waits*

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: Okay...this is a big request...
« Reply #6 on: 2006-03-01, 06:59:43 PM »
I assume you mean that you want it to detect when two different sprites hit the wall, yes?  Not when BulletLeft, BulletRight, or Explosion hits the wall.  Also, does it make more than one explosion sprite?  Or what are you referring to when you say "And only make one explosion sprite".

Anyway, you can change it to recognize any spite that has a name that begins with "bullet" with one change:

Change this:
Code: [Select]
if Layer.Sprite(Sprite).rDef.Name = ShotName then
To this:
Code: [Select]
if left(Layer.Sprite(Sprite).rDef.Name,len(ShotName)) = ShotName then
Edward Dassmesser

hebedaymun

  • Guest
Re: Okay...this is a big request...
« Reply #7 on: 2006-03-01, 07:03:58 PM »
Hmmm... so this will make the script detect if a bullet shot to the left hits the wall OR if a bullet shot to the right hits a wall, then it creates an explosion?  because, right now, those are two different sprites (Left and Right).  Oh, heh, forget what I said about " only one explosion ', kind of a screwed up thing to say.

thanks.

Edit --

Oh crap, forget what i asked, i just tested it, and it works.  Thanks a lot, buddy!

Thanks.
« Last Edit: 2006-03-01, 07:08:14 PM by hebedaymun »

hebedaymun

  • Guest
Re: Okay...this is a big request...
« Reply #8 on: 2006-03-01, 08:04:51 PM »
Welll.... I experimented with it some more, and found out that, even though the "Explosion" is set to delete itself after a delay, it wont.  I don't know why, but it only happens if the sprite is created by the script.  Also, the sprite seems to want to follow it's path, regardless of what I've set it to do.  I checked the "relative to path" thing and it's still not working.

--I just set it to path vector, or whatever, it stays put now, but it's still not deleting itself.  I have "delete at end of path" checked and I even set a delay so that it will delete itself.  is there something I'm doing wrong here??

Help would be appreciated.

EDIT:

Okay, forget that path vector thing, I switched it back to approximate path.  Why the hell wont it stay putt!?  I did the relative to path thing...  Something tells me that the script did something to sprite, because everything is normal when the script doesn't create it.
« Last Edit: 2006-03-01, 08:23:55 PM by hebedaymun »

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: Okay...this is a big request...
« Reply #9 on: 2006-03-01, 09:13:22 PM »
I looked into how SGDK creates sprites relative to a trigger, and you have to include a few more lines.  Put these two lines after the line about ExplosionSprite.Y:
Code: [Select]
ExplosionSprite.PathOffsetX = ExplosionSprite.X - ExplosionSprite.rDef.rPath.PointX(0)
ExplosionSprite.PathOffsetY = ExplosionSprite.Y - ExplosionSprite.rDef.rPath.PointY(0)

So the complete version is (with a few simplifications):
Code: [Select]
Dim ShotName, ExplosionName
ShotName = "Bullet"
ExplosionName = "Explosion"


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
            Layer.RemoveSprite(Sprite)
            Dim ExplosionSprite
            Set ExplosionSprite = Layer.pMap.SpriteDefs(ExplosionName).MakeInstance
            With ExplosionSprite
               .X = X
               .Y = Y
               .PathOffsetX = .X - .rDef.rPath.PointX(0)
               .PathOffsetY = .Y - .rDef.rPath.PointY(0)
            End With
            Layer.AddSprite(ExplosionSprite)
         end if
      end if
   Next
End Sub

HostObj.SinkObjectEvents ProjectObj.GamePlayer, "Player"
HostObj.ConnectEventsNow()
ProjectObj.GamePlayer.Play 16
Edward Dassmesser

hebedaymun

  • Guest
Re: Okay...this is a big request...
« Reply #10 on: 2006-03-01, 09:21:01 PM »
Wow, I don't know how you did it, but it works now!  Thanks a bunch Durnurd.

I don't have anything to give you for your help...but you can have a cookie.

*gives Durnurd a cookie*

Thanks.

*walks out*