Jump to content
  • Advertisement
Sign in to follow this  
by

Triggers in Tile Map

This topic is 4522 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, i wonder about putting a action trigger into a tile, that held in a 2d map array. like tile[128][128]. For example, when player comes to tile[29][10], how can i trigger an "x" action. i think function name would be taken from directly tile's info. then use pointers to start "x" action? example: falldownsomerocks(29, 10); thanks.

Share this post


Link to post
Share on other sites
Advertisement
Not entirely sure what your question is, but if you are asking how to store a function in an array, (and you are programing in C), you are looking for 'function pointers'.

In C++ you would want to look into boost::function once you have learned about function pointers.

Share this post


Link to post
Share on other sites
Quote:
Original post by swiftcoder
Not entirely sure what your question is, but if you are asking how to store a function in an array, (and you are programing in C), you are looking for 'function pointers'.

In C++ you would want to look into boost::function once you have learned about function pointers.


Yes, i am using C++. And yes, i am asking about storing a function in a array. Maybe than i would point it to the real function :)

Share this post


Link to post
Share on other sites
Storing function pointers won't help you build a trigger system.

Usually you'll have your triggers instanciated and wait until someone (the player in your case) walks into them, and if some conditions are valid (most likely you'll want your "falldownsomerocks" to be called just once...) then trigger the action.

If you can, avoid scripting your gameplay directly in code... use configuration files or something, then maybe use a factory to instanciate your triggers.

Hope this helps

Share this post


Link to post
Share on other sites
I agree, I don't think function pointers are a good approach. Of course it depends on the complexity of your game, but writing functions for every situation is going to be annoying in the end. You're better off designing an entity system where various entities can trigger and interact with each other.

An example: you write an Entity class, containing a virtual think() and trigger() function and a location and what other data every entity would need.
You then derive a Trigger class from it, which contains a list of pointers to entities (it's targers) and has a rectangle, or shape, to check collision against. You give it a think() function of it's own, where it checks if it's hit by the player. When it is, it calls the trigger() function of the entities it is configured to trigger.
The Rock (or probably better, FallingObject) class, also derived from Entity, has a trigger() function of it's own, that makes it start to fall.

And indeed, initializing a triggers target and shape by reading it's properties from a script or level file isn't a bad idea. Level-designers usually don't like to modify code to create levels. :)

Above is just an example, but I hope you get the idea. Thinking a little more object-oriented...

Share this post


Link to post
Share on other sites
Thank you very much, you helped me so much :).

-Read trigger properties from a file sounds good. Any little code snippets about this?

-So, how bad it would be if i...

make a triggermanager class that has got addtrigger, update etc. functions. (addtrigger function creates a new trigger object and let it read its own properties from a conf file, and adds it to vector container for update)(update function does a for loop in vector's items. updates every single triggers state)

make a trigger class that has got update, load etc. functions. (update function checks if someone collides with trigger area, amd if so, runs action function) (load function is confusing please describe :))

thanks again.

Share this post


Link to post
Share on other sites
If you want to do it in an array of somekind it might be worth doing:

[tilex][tiley][function_number]

where the function number is referenced to another file containing a list of all the functions on that map or globablly (with 0 being none)

Share this post


Link to post
Share on other sites
You can store trigger properties in an .INI file.
http://www.codeproject.com/useritems/IniReader.asp has some classes that help you do this. Editing INI files is relatively easy, their syntax is something like:

[General]
Sound=False
BackgroundSound=False
FlybyHelp=False
InSpeed=9
OutSpeed=10
SortDuringDeal=False
AutoDiscard=False
RevealSkill=True
RevealAllHands=False
SaveIcon=True

[Misc]
Cardback=14
FirstSession=False
LastSavedGameNumber=2

[Rules]
StartingCash=999999
Ante=10
MaxRaises=3
MinBet=10
MediumBet=25
MaxBet=50
CheckRaise=True
DrawFourOnAce=True
LastRaiserStarts=False
RedealAfterAllCheck=True

[Player 1]
Name=Stranger

[Player 2]
Name=(random)
Active=True
Sex=0
Skill=0
Style=0

[Player 3]
Name=(random)
Active=True
Sex=0
Skill=0
Style=0

[Player 4]
Name=(random)
Active=True
Sex=0
Skill=0
Style=0

[Player 5]
Name=(random)
Active=True
Sex=0
Skill=0
Style=0

[Player 6]
Name=(random)
Active=True
Sex=0
Skill=0
Style=0

[Main Window]
Left=328
Top=134
[Options Dialog]
Left=386
Top=283
[Stats Window]
Left=424
Top=586
Visible=True
State=0
[Odds Window]
Left=77
Top=229
Visible=True
State=0


// Some random INI file on my computer

Share this post


Link to post
Share on other sites
Quote:
Original post by Iccarus
If you want to do it in an array of somekind it might be worth doing:

[tilex][tiley][function_number]

where the function number is referenced to another file containing a list of all the functions on that map or globablly (with 0 being none)


At first i was thinking same with you. :) But i think making a management system for all triggers with a class would be more useful. :)

AcePilot@ The link you've given is a great source. Thank you.

Share this post


Link to post
Share on other sites
I'd definitely go with XML, as its easy to use and quite standard...

I've used TinyXML in the past, and its quite good and easy to use.

Also, I'd inverse the logic you said... I'd read a file which would call some AddTriggers, instead of having addtrigger to read a file. This way, if you want to add a new trigger in the map, all you need to do is change the configuration file.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!