1

I was reading this article on using the MVC design pattern in game development, and I'd love to give it a go, but I'm a little confused as to how to dynamically create MVC objects. In the article they're talking about the creation of a shooter game, but what I don't understand is how a soldier could throw a grenade for example. It's easy enough for the soldier model to create a grenade model, but how would the view and controller get set up without the soldier model having to know about the view and controller of the grenade mvc?

1 Answer 1

1

imho, I think you taking it the wrong way..

Every game has a board or a map.
Your map "model" should be the orchestra of creations.

So if a solider is throwing a grenade:
1. your ui-controller (or solider controller) fires an event for throwing a grenade.
2. your map-model get that event and create the model for the grenade being thrown.
3. while the grenade is flying it should receive information from the map regarding obstacles passing by and etc..
Shortly put - the map is the orchestra of all visible objects on the map.
In relation to the article notice that the view is described as the "EntityRepresentation" or the map in my words.
It is NOT a nested MVC pattern as you expect to find in rich client applications. Good Luck! :)

Sign up to request clarification or add additional context in comments.

1 Comment

The author of the article was kind enough to explain in a few emails how this works, and what you said was absolutely correct. 'In our code, the RepresentationManager gets notified when an entity is added to the EntityManager (it could be a generic listener on the EntityManager). It then creates the EntityRepresentation. For that you'd use a factory pattern. Something like: map = { { "Entity", "EntityRep" }, { "EntityA", "EntityARep" }, ... } RepresentationManager::OnEntityAdded(Entity *e) { string rep_type = map[e->GetType()]; EntityRep *rep = factory->Create(rep_type) ... }'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.