OOP Game Design

mdavis1982
Unregistered
 
Post: #1
Hi all...

I'm doing a game at the moment, and was wondering if any of you experienced people could help a newb out! ;-)

I'm trying to write my game to be as OO as possible. And I'm just using a custom NSView to display all of my game's graphics.

Now... I have a couple of objects that need to draw themselves in the view.

What would be the correct method of doing this, from an OOP perspective?

I've got my classes as models, my controller handles the game logic, and my custom view handles the drawing. Should I:

a) In the custom view - (void)drawRect:(NSRect)rect method do [myController drawObjectAt:position]

b) Have the view do all the drawing by getting the information it needs from the controller's accessor methods for the game objects

c) Get each object to draw itself in it's own view, and then add all the object's views as sub-views of the custom view?

I'm really at a loss here... Suppose I have 2 player objects...

Should I ask the controller to draw the players in the drawRect method by doing something like: [myController drawPlayers]? Should I just get the information about each player in the drawRect method of the custom view and have all the drawing code in there? Or should I draw the player to its own view whenever I update any information about the player, and then add the player's own views as sub-views to my Custom View?

It's totally too complicated, and I can't find any good resources out there about doing this kind of thing in an OOP fashion!

Please help me before I give myself a brain tumour!

Thanks,

Matt
Quote this message in a reply
Oldtimer
Posts: 834
Joined: 2002.09
Post: #2
Welcome! Wink

I'd suggest C). If you have a an "object" class that represents a game entity, then you can have the view ask every object to draw itself. The view will not know what it is drawing, just managing the stuff. This isn't pure MVC, I know, but it is the way I prefer. Why? Because you can subclass the object class into players, enemies, pickups, particles, dinosaurs, special effects, explosions and the HUD, stick them into the "world model"'s list of objects and then ask the view to draw that. The view doesn't know what is in the list, and it doesn't care. The model know's what is in the list, but doesn't care about how to draw it. The objects know what they are and how to draw themselves, but they don't care about what the view or model does to them. That allows you to do funky stuff like, I don't know, motion blurring in the view class without having to tell each and every object how to blur itself. On the other hand, it allows you to subclass Object into, say, a particle system without even recompiling the view source file.
Quote this message in a reply
mdavis1982
Unregistered
 
Post: #3
Cool.. thanks for the advice!

I think I'll probably stick to that way of doing it, as it seems the simplest, and the most easily implemented!

So... in my controller, I should have a game world object which contains a list of everything that needs to be drawn? Then I can just draw all the stuff with one statement in my view?

That seems logical?

Cheers,

Matt
Quote this message in a reply
mdavis1982
Unregistered
 
Post: #4
Also.. it seems like you were really suggesting (a) from my original post. As if the view tells everybody to draw themselves, they can just spew out drawing commands and they will get rendered in the current view?

Thanks,

Matt
Quote this message in a reply
Member
Posts: 196
Joined: 2002.04
Post: #5
Just use method a.) to do everything. It's the simplest. That's the way I do everything.
Quote this message in a reply
Member
Posts: 567
Joined: 2004.07
Post: #6
use A. and also, check "disable smilies", or you'll come up with smilies in the middle of code. Or put the code in a ["code"]code here!["/code"] (without quotes, obviously) Grin

It's not magic, it's Ruby.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Platform Game Design mconnors 3 3,431 Apr 3, 2009 09:31 PM
Last Post: SethWillits