• Advertisement
Sign in to follow this  

Event Handling

This topic is 2447 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

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:

1zgvxia.png




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
Advertisement
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
Very helpful post, Haegarr! But how do I let the program know which tile to load a new map from, what map, new position of player etc?

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

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.

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

How do I know which one to pass


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.

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

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





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
Sign in to follow this  

  • Advertisement