Imagine a turn-based tile game, that generally looks like Heroes' combat view. Except for the fact a player can choose any of his units to command.
Our team is implementing the game according to MVC paradigm.
Some logic needs to be defined in order to allow selecting only allied units, for instance. And the selected one should be highlighted by the View.
For now we have made a Controller responsible for this. But to me it feels strange when the View is rendering data that comes from the Controller itself instead of the Model.
Is there any common practice to put such logic in Model or Controller?
Answer
I'd warn against MVC for games in the first place, but putting said logic in the controller is fine. You can also put a small bit in the model if you want to be really pure. The Model contains a selection state and the Controller modifies this. Then the View uses this state to do its rendering.
Something like:
Model:
bool selected = false
Controller:
on click:
old_unit.selected = false
new_unit.selected = true
View:
on draw model:
if model.selected:
render selected mesh/sprite/effect
else:
render regular mesh/sprite
You can use more intricate state than just a boolaen if you need for better effects, such as timers to smoothly animate selection effects, or states for active player unit, active enemy unit, select for combat, select for movement, whatever.
No comments:
Post a Comment