I'm creating a 2D based RPG game. Similar to that of Pokemon for the Gameboy. Basically, my games maps are created up by x by x size terrain. There are also scenery objects (trees, shrubs, etc.) as well as intractable things (i.e. signs, doors, items, etc.). Currently, I've been hard coding these objects in. The problem is, every time I add a scenery object, terrain tile, or anything else, it requires me to go through and add a class for it, specify some different data, etc. Basically, I feel like I have to do a lot of repetitive tasks to do something so simple.
I'm scared that later, my project will become unmanageable. Each piece of new terrain, scenery, or other object inherited from a class called 'GridElement'.
So, would it be better to have all the tile, scenery, etc. information put into an external XML file and loaded at run time, or continue hard coding these elements in?
The main problem is, most of these elements require specific functions to be applied to them. Some of them need to call events when they are stepped on. Some elements are also dynamic (the tile changes every couple seconds, e.g. water, flower, etc.).
Thanks for the help!
Cheers!
As a loose rule, you should create a new class only when you want to represent behaviour, and control the parameters of this class with your data.
In your case, you probably want one scenery class for your flowers, shrubs, walls and such things. You can then customise objects of this class by calling functions to set the bitmap(s), the animation speed. It then doesn't really matter then where this data comes from, it could be hardcoded, come from an object factory or read from xml.
When you come to your interactable objects, you do need additional classes, but try to make them more generic than specific. So if you want to display a message when your user interacts with an object you have a generic interact class, rather than a sign class. This class can then be used for signs, bookshelves, mysterious looking items.
When it comes to special events you have a few options. The simplest is to create a generic event class, which can direct new actors to appear on screen or to bestow objects on the player. Alternately you could pass a function pointer/delegate to the object which is called when the user hits certain triggers (ie, step into a square, defeat a monster). Finally, most complicated of all but most likely what Pokemon and similar games use, you could create/use your own scripting language.