Skip to main content
gamedev.net
🔒 Locked

Map Manager.

Started by julian boolean Jan 8, 2007 at 6:40 PM 0 replies 500+ views
Original Post
julian boolean
julian boolean
Hey all! I'm trying to create a manager that will keep track of what area/map the player is in (I'm using C++, Allegro, and a program called Mappy.) Let's just say there are 5 different maps called mTop, mLeft, mMiddle, mRight, and mBottom (they're all classes.) If I was in mMiddle and I went too far left, going off the boundary of that map, then the program would switch over to the mLeft map. At the moment I'm using some code I found while searching a different forum (which works really well for the game states.) I figured it would work for the maps as well since its sorta the same idea. Anyone know if this is a good way to go about doing this?

class GameState {
   public:
      virtual void Input() = 0;
      virtual int Logic() = 0;   // returns the next state
      virtual void Draw(BITMAP *) = 0;
};

// then come a bunch of classes that implement the above interface
...

// the main loop part of the program:
void game() {
   vector<GameState *> states;

   // fill the states vector with pointers to various game state objects
   ...

   GameState *currentState = states[0];

   while (true) {
      // input
      currentState->Input();

      // do logic
      int next = currentState->Logic();
      if (next == EXIT_GAME) {
         break;
      }

      // draw
      currentState->Draw(buffer);

      // witch to next state
      currentState = states[next];
   }
}(edit)


For the game states, I just created a function called buttonCheck to switch back and forth between states. For the maps I was thinking something similar, called boundaryCheck, which would just check to see if the player went off the edge of the map.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.