0

Warning: Xna Noobie here.

I'm making a 2d, top-down rpg, kind of like Pokemon. In my game I have, along with the main game class, a class for the player and a class for the map. Should I have separate classes for each region of the map (for example, Town.cs, Forest.cs, River.cs) and if so, should they inherit from a parent class? Or should I have just one generic MapRegion class, and have each region of the map just be an instance of MapRegion?

Mike Wills
  • 20,959
  • 28
  • 93
  • 149
jae
  • 1
  • 2
  • "Depends". Normally you want all common data and functionality in one place (BaseClass) and special data and functionality in special places (ChildClasses). So if a Town *behaves* differently than a Forest or a River, then have different child classes. It doesn't hurt to have lots of child classes so long as you remember to keep all the common stuff in the base class. If you ever want to copy&paste code from one child class to another one: don't! Put it in the base class instead. And whenever you *work* with map variables make them of type base class and fill them with the fitting child class. – Corak Apr 12 '13 at 17:09
  • I think you'd be better off having a single class `MapRegion` that reads in some sort of configuration to create all the "stuff" on it. Use subclasses of the MapRegion if the whole region needs to behave differently, otherwise I'd make a MapRegion simply composed of a bunch of tiles. Each tile can specify its own behavior and events so that the Map can stay simple... – Chris Pfohl Apr 12 '13 at 17:14

2 Answers2

1

The decision depends on whether or not different regions are going to need different functionality. If the only difference is the terrain/obstacles/buildings/that sort of thing, then it would make more sense to go with a generic MapRegion class and have the different maps stored in external data files to be loaded in by each MapRegion. However, if the regions differ significantly in how they're handled in your code (which is probably unlikely for a Pokémon-style game) you would make different subclasses. It basically comes down to whether they're functionally different or just hold different data.

Animatinator
  • 410
  • 2
  • 6
  • and even then, with just a few different functions you could make a `MapRegion` that takes in a couple `Action` variables - no inheritance necessary. –  Apr 13 '13 at 06:13
0

I think its not good to have different classses for each level but you can have some special levels which require a different class. In most cases I would make a base class and if I need a special map I would make a child class.

A basic map class would have some more generic members:

  1. List Structures
  2. List NPCS
  3. Background Texture

and so on....

Svexo
  • 523
  • 1
  • 4
  • 15
  • This is another thing I was wondering about. I've just made a mock-up so I can test some basic things before I go into making the actual game, so I'm just using [this](http://www.spriters-resource.com/gameboy_advance/mother3/alecshouseoutside.png) image from Mother 3 as my map. Should I have each seperate object (e.g the house, the cacti, the mountains) as a "structure", instead of having just one image? – jae Apr 12 '13 at 17:42
  • Do these structures have different properties, for example `bool Passable`? Usually these kinds of games work with tiles. Now whether to have *one* tile class or several child tile classes... "depends". ^^; – Corak Apr 12 '13 at 18:00
  • That brings us into collision detection, which is a whole other question entirely ... – jae Apr 12 '13 at 18:20
  • I think its better to have different structures in a map than just loading an image it gives you more control – Svexo Apr 13 '13 at 14:06