Event Handling

Started by
6 comments, last by shurcool 12 years, 10 months ago
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!

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...
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?
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.

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?



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.

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


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.

This topic is closed to new replies.

Advertisement