C++ Beginner game programming: Keeping track of objects, inventory lists, arrays of different amnts of object/characters, etc

I was just playing an old SNES RPG (Secret of Mana, if anyone cares) and was wondering a few general things about game programming.

Sorry for some of the brain-dead questions, I'm really a beginner. :)

These questions are quite general, but use SNES-style RPGs as a "template" to get an idea of what I mean:

  1. How do games keep track of all the objects, triggered events, etc in its "world"? For example, how does it keep track of which treasure chests have already been opened, which doors are locked, which story events have already triggered?

    Does it basically create an array of elements each corresponding to a chest/door/event/etc and "mark" each (change its value from 0 to 1) when it has been opened/triggered? If there are multiple approaches, what are they?

  2. How are "variable lists" handled? Ie, if you have a game when you can have a huge inventory of objects (ie: armor, swords) and have X of each object, how is this done?

    My guess: have a struct that has a big array with a spot for every possible object (an array of X ints, where X is number of possible objects to own) where each element's value represent how many of that object you have, and then have a giant enum of every object so that an object is matched to a corresponding index, and access it, like: numberOfSwords = inventory[SWORDS] where SWORDS is part of an enum and has some integer number associated with it. How close am I?

  3. How about the case where the number of objects can vary? Ie, if I have a game where I have some amount of enemies on the screen and they can get killed / give birth to new enemies at any point, it would seem to me like I would need an array of "enemy" objects to loop through and process, but that the number of elements would vary at any one time. What is the usual approach to this? Linked lists?

Any help / hint / pointers are really appreciated.

12
задан Pablo Claus 25 August 2012 в 03:07
поделиться