I'll give my philosophy - it may not be textbook correct.
Quote:
Originally Posted by Greg
- Model, holds data on all objects. spaceship/enemy position, rotation, health, score.
Shouldn't this also hold info on how to draw the objects. ie. enemy1 = blue, enemy2 = green, battlement shape after being hit.
|
Sure, the model can know things like "I am green" or "I look like enemy.png". No problem.
Quote:
Originally Posted by Greg
- View, redraws the screen with info from the model... but wouldn't it be easier to ask each object to draw itself in a given context/view?
|
Many books for object-oriented languages start with the example of "shapes who know how to draw themselves" , and it may be very OOP, but it's not very MCV. In my game the model knows each object's position (in map squares, not pixels!) but the view loops through them and draws them.
You get a nice separation of code this way - if I wanted to change my view from layers to OpenGL, there's nothing to change in the model. If I change the camera view or the screen size, those changes are just in the view, not the model. I could go from 2d to 3d with very few changes in the model (replace the pngs with 3d chars).
Plus the code in the model stays very clean - I can move a player by one square by saying player.x +=1 instead of player.x+=MAP_SQUARE_WIDTH.