Author Topic: Continually checking for contact  (Read 7472 times)

Bulbaboy

  • Regular
  • **
  • Posts: 36
    • View Profile
Continually checking for contact
« on: 2006-03-15, 08:16:19 PM »
Okay, new problem.  I'm pretty sure this has a really simple solution, but I'm not quite sure what it would be.  How would one continually check to see if an arbitrary sprite is in contact with a map tile or another sprite?

Right now I'm thinking maybe create a second invisible sprite where the first one is, and either use a sprite collision or the equivalent map tile event.  Now, that'll work for one-time checks, but there are two problems: first, I have NO clue how to see if a *non*-player sprite is in contact with a wall, as bHitSolid didn't seem to work the way I wanted - though would it be set to 1 when you first make the sprite?; and second, I don't think it's going to work well if I have to continually see if the first sprite is in contact with something.  Any thoughts?

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Continually checking for contact
« Reply #1 on: 2006-03-15, 10:12:12 PM »
You might be able to determine if the sprite is touching a tile by following these steps:

1) Create a MapInteract object using Engine.NewMapInteract
2) Attach event handlers to it with HostObj.SinkObjectEvents
3) Implement an event handler that handles the OnTouchTile event of the MapInteract object
4) Create a TileGroup object (Engine.NewTileGroup) and tell it all the tiles you're interested in knowing about (which tiles you want to detect contact with).
5) During OnAfterMoveSprites, call MapInteract.Move to tell the object about the sprite's new position
6) Then call MapInteract.TouchTest, passing in the sprite object and TileGroup object.  This will cause the OnTouchTile event to be triggered for every "interesting" tile (tile in the tilegroup) that the specified sprite is touching.

This is a woefully incomplete description of the solution, but it might get you on the right track, depending how motivated you are to try figuring that out on your own. :)

If it helps, MapInteract is the class that GameDev uses internally to detect interactions between the player sprite and the tile interactions defined for the player.

Maybe when I have more time I can elaborate if you're interested in pursuing this solution.

Bulbaboy

  • Regular
  • **
  • Posts: 36
    • View Profile
Re: Continually checking for contact
« Reply #2 on: 2006-03-16, 01:25:31 AM »
Sweet, so there IS a way to have non-player sprites interact with the map.

Luckily, I eventually tried using a map interaction that set a variable to 1, and constantly zeroed it when I didn't want it to be checked, so I think I'm good then...  Thanks!  Now to just figure out exactly what code I need...

Bulbaboy

  • Regular
  • **
  • Posts: 36
    • View Profile
Re: Continually checking for contact
« Reply #3 on: 2006-03-16, 05:00:39 PM »
Okay, so... how do I get it to work with HostObj.SinkObjectEvents?  It's stopping at character 1 on that line and saying it's a type mismatch.  What do I have to do?  And, if it makes a difference, I'm using the CurrentDisplay object, so the script's in two parts.

hebedaymun

  • Guest
Re: Continually checking for contact
« Reply #4 on: 2006-03-16, 07:29:19 PM »
Why doesn't anyone just make this script for him?  That would obviously be the easiest solution.  I know Durnurd found the time to write one for me!

That's what you want, right Bulbaboy?


(By the way, congradulate me on my return from my ban!)

billybob884

  • Contributor
  • Fanatic
  • **
  • Posts: 355
    • AOL Instant Messenger - billybob884
    • View Profile
Re: Continually checking for contact
« Reply #5 on: 2006-03-16, 09:30:23 PM »
Why doesn't anyone just make this script for him?
"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." :: Hitchhiker's Guide to the Galaxy

Bulbaboy

  • Regular
  • **
  • Posts: 36
    • View Profile
Re: Continually checking for contact
« Reply #6 on: 2006-03-16, 10:05:06 PM »
Yeah, while it would be cool to just clap my hands and have an awesome game appear out of nowhere, that's not how computers work, and people have an annoying habit of insisting on getting paid.  So, unless you're volunteering for what might qualify as slavery, how 'bout you not imply I'm dumb for not automatically knowing how to do this particular thing, okay?  Now, if there were some obvious example of how to do it, that'd be different, but I have no clue if there's even one game using that type of code right now.

Bulbaboy

  • Regular
  • **
  • Posts: 36
    • View Profile
Re: Continually checking for contact
« Reply #7 on: 2006-03-17, 12:55:39 AM »
Well, looks like I had to pass "HostObj.AsObject(MyMapInteract)" instead of just "MyMapInteract" when using HostObj.SinkObjectEvents, so unless something comes up, looks like I'm good for real this time.  Of course, since it's late and I've only made sure it can compile so far, there's always the possibility it's not working like I think it is, but I hope it's working...

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Continually checking for contact
« Reply #8 on: 2006-03-17, 06:29:16 AM »
Way to go on figuring that one out!  I thought for sure my explanation was inadequate, but it sounds like you're getting pretty close.

Welcome back to hebedaymun.  Let's give him the benefit of the doubt and assume he wasn't trying to imply anything in his last post, but just trying to make a suggestion ;).  Indeed I would have provided a sample script if I'd had time because, like I said, my instructions were quite vague, and often times a sample is the surest way to demonstrate that an idea works as designed.  Glad you were able to get as far as you did without further assistance!

hebedaymun

  • Guest
Re: Continually checking for contact
« Reply #9 on: 2006-03-17, 04:49:20 PM »
uuhhhh....hey, Bulbaboy, that post was kind of confusing to me.  Did you think I IMPLIED that you're a dumbass and that you don't know anything about computers or whatever?  Well, think agian.  Oh, guys ---  HE NEVER STATED THAT HE WANTED TO LEARN HOW TO SCRIPT.  All of you were assuming, and to be fair, so was I.  I just thought he wanted this script over with so he can get back to actually designing the game.  I dunno... maybe I assume too much.

That last post was still confusing.  Maybe while your learning how to script, you can learn to not fly off the handle so easily, Hmm?  Yes, is that what I heard?  Goooddd... now get back to work!! :P

(maybe I could learn how to not be an a******, while I'm at it ;D)

(and to hell with anyone who flames me after this post)

Bulbaboy

  • Regular
  • **
  • Posts: 36
    • View Profile
Re: Continually checking for contact
« Reply #10 on: 2006-03-17, 04:52:57 PM »
What the heck?  When I put this code inside the Display_MouseUp subroutine:

Code: [Select]
MyTileGroup = ProjectObj.TileSet(Large).Category(0).Group
MyBlob = arBlobParts(0)
MyMapInteract.TouchTest(MyBlob, MyTileGroup)

it says "Cannot use parentheses when calling a Sub" and then says the Object variable or With block variable isn't set.  What the hell does "Cannot use parentheses when calling a Sub" mean in this context?  How else am I supposed to use .TouchTest?  It seems to be quitting on the line with MyMapInteract.TouchTest, too, so I'd be *inclined* to say I'm properly referencing the TileSet and Category objects...  And if it makes a difference, the SinkObjectEvents code I'm using is as follows: HostObj.SinkObjectEvents HostObj.AsObject(MyMapInteract), "MapInteract"

Edit: looks like I wasn't referencing the tileset correctly, it's just it never got that far before exiting.  I guess I'll go with StateTilesetDef or something until I can figure out how it's really done.

And, hebedaymun, sorry - it's just that it's a non-trivial script, so it's not really the kind of thing I can get someone to do for free ;).  Guess we were just going on different assumptions of how complex the script is, and what my goals are...
« Last Edit: 2006-03-17, 05:04:15 PM by Bulbaboy »

hebedaymun

  • Guest
Re: Continually checking for contact
« Reply #11 on: 2006-03-17, 04:53:48 PM »
No harm meant.  Good luck with that.

Bulbaboy

  • Regular
  • **
  • Posts: 36
    • View Profile
Re: Continually checking for contact
« Reply #12 on: 2006-03-17, 05:06:16 PM »
Yeah, thanks.  I seem to be making decent progress so far, considering I don't have a wealth of easy-to-find sample code that shows me how to do this stuff.

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Continually checking for contact
« Reply #13 on: 2006-03-17, 06:27:13 PM »

Bulbaboy

  • Regular
  • **
  • Posts: 36
    • View Profile
Re: Continually checking for contact
« Reply #14 on: 2006-03-17, 10:06:59 PM »
So then why does the documentation give the syntax with the parentheses?

Anyway, it looks like it's working now, since I've figured out how to properly get the TileGroup name (glad you made GoldYoink!).  I still need to figure out how to get OnTouchTiles to work properly, but it'll probably come...

Edit: YES!  It works!  Just needed to call MyMapInteract.Move sometime (which also needed to not have parentheses...).  Thanks for the help.
« Last Edit: 2006-03-17, 10:27:36 PM by Bulbaboy »