Sign in to follow this  
XanderDeseyn

Event Handling

Recommended Posts

Dear forum,

First post here ^^

I've been working on a tile-based game for the past few days. I've hit a wall. I can't figure out how to handle monsters, quests and other "events".

I have a mpa and can move around with perfect collision detection:

[img]http://i53.tinypic.com/1zgvxia.png[/img]




How do I handle NPCs, and loading different maps when entering a door, for example?


Thanks!

Share this post


Link to post
Share on other sites
Collision detection so far is done to avoid drawing the avatar on top of objects. Now define another kind of collision handling: Instead of canceling the avatar's movement, stop any user control, load the data of another level, set the avatar at the initial position, and continue. Use a tile showing a door for this collision, and render the avatar on top of it for visualization. You can also block the door tile like any other object if you want to indicate that the door is locked. You can implement picking up objects for the inventory in a similar manner: Make the tile enterable and let the collision detection invoke a handler that performs picking up.

Monsters are a totally different thing, because they have to act in some way. It is not very meaningful to discuss monster implementations without knowing how they should behave...

Share this post


Link to post
Share on other sites
Have a genereic "Map" object that can load level data in from either a TMX or XML file. If the player intersects with the door Map.loadmap(filename) is called. You could also load and store the maps the player might need in order to reduce/prevent load times.

Share this post


Link to post
Share on other sites
[quote name='GameGeazer' timestamp='1307808125' post='4822119']
Have a genereic "Map" object that can load level data in from either a TMX or XML file. If the player intersects with the door Map.loadmap(filename) is called. You could also load and store the maps the player might need in order to reduce/prevent load times.
[/quote]
I have all that, what I'm worried about is the filename. How do I know which one to pass, where to draw the new Player sprite, etc?


Share this post


Link to post
Share on other sites
[quote name='N1ghtly' timestamp='1307810288' post='4822131']
How do I know which one to pass[/quote]

You either have a single global configuration file with a known name that tells you these things, or you use some kind of naming scheme that lets you calculate the file name from the internal level ID.

[quote]where to draw the new Player sprite[/quote]

I.e., where the player starts when he appears on the map? That's part of the map data.

Share this post


Link to post
Share on other sites
[quote name='Zahlman' timestamp='1307838617' post='4822228']
I.e., where the player starts when he appears on the map? That's part of the map data.
[/quote]




Not really, since players can enter maps of different points :s


Share this post


Link to post
Share on other sites
Your map currently consists of one room.

Instead, you should probably change it so that it contains multiple rooms, and some of way of traversing between them. That way, you don't have to "load" anything when hitting a door tile, just change the current room number, and set the player in a new position. This info should be stored within the parameters of said door tile.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this