Jump to content
  • Advertisement
Sign in to follow this  

Basic MVC Architecture Question

This topic is 3772 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey everyone, I'm new to game programming and fairly new to the gamedev.net community, and I have a couple of questions regarding the MVC paradigm. I've got a couple of games under my belt (Tic-tac-toe and Pong clones) that use SDL, but instead of employing any sort of OOP functionality, I've relied on basic C programming -- functions, structs, etc. Before moving forward with my next projects (Space Invaders, Tetris, and 2D sidescroller clones), I've decided that it would be worthwhile to make the jump to OO Programming (specifically using the MVC Design Pattern). So, while designing my classes and their interfaces, I ran into some problems. My issues specifically pertain to drawing the various game objects. The way it stands now, I have an std::list of GameObjects that serves as the model. When it comes time to render, the Controller loops through the list, and sends information about each object to the View class, which in turn renders that object onto the screen surface. Now here is where I get lost. Currently, I use an enum called ObjectType that is a member of each GameObject. Depending on what the value of that enumerator is, the View will render a specific SDL_Surface to the screen. For instance, let's say we have a GameObject that represents an "invader" from Space Invaders. It has various values, such as its x coordinate, its y coordinate, direction that it's traveling, and its ObjectType. In this case, the ObjectType would be INVADER as defined by the ObjectType enumerator. The View also knows about this enumerator, so it knows what surface to apply. That way, the View is notified of the type of surface that it should draw at the coordinates. I realize that this is probably not the "prettiest" or "proper" way to do things -- the best way would most likely involve some form of inheritance/polymorphism, where every type of game object inherits from the base class called GameObject. But, using polymorhism, I cannot think of a clean way to notify the View of the type of surface to render -- keeping the Model class and View classes separate is one of the fundamental aspects of the MVC paradigm. How would you suggest that I approach this? Am I on the right track? I know that this post could've been more concise, and if any part of it is unclear, let me know and I will try to clarify. Thanks in advance.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!