views:

312

answers:

4

I'm coming from a background mostly developing websites, and maybe some simple form-based apps. MVC works well for that, but I don't quite see how that's applicable to a game. So how do you guys do it?

I'm developing with Qt and OpenGL, if that's relevant. I have a QGLWidget which I'm basically using as a central hub at the moment. Should it pass off input to a Player object so that it can handle it, or should it control the player directly? Should objects draw themselves, or should there another handler for that? Basically, what goes where? Who handles what?

Links to relevant articles, answers to some of these questions, tips, or file structures are all appreciated. I don't really care about how to program it, just how to modularize nicely.

Thanks :)

+4  A: 

Well, the cliche starting point for game development seems to be gamedev. There are a number of tutorials and articles to start from, there. It also has quite an active forum. There is also book, "Programming Linux Games" (I assume through Qt that you're using Linux), but I believe it costs money. A number of books, however, can be found on the internet, and that may be one of them.

There's also the "black art of game programming", a wiki with truly terrifying chapter titles. Here is a link to a particularly relevant chapter, though of course you can view the whole thing: Chapter 2.

Hope this helps, - Agor

Agor
I was hoping for something a little more specific than "gamedev". That black art of game programming... is pretty terrible. It mostly describes how the game should appear to the end user, and in a rather rigid fashion (play a death animation with lots of sounds and stuff, then display a high score screen!). It describes a basic event loop, but I was hoping for something a little more complicated than how to write a 200-line game in a single file. That I can do. I didn't quite mean THAT simple. I can't tell if it was written by a 15 year old, or a 60 year old PhD prof trying to act "teh" cool.
Mark
I guess I got a little carried away there. I'll dig through it a bit more, there might be some gems later on, but the first bit isn't of much use. Yes, I'm programming on linux for this particular project... it's just so much easier to get the libraries I need installed properly. But I jump back and forth but between windows and Ubuntu... but design principles aren't really OS-dependent anyway. Anyway.. thanks, I'll look through it more.
Mark
No worries. If you're looking for more level of detail, it may be helpful to provide more info on *what kind* of game your making. I'd imagine that, say, real-time-strategy games have quite different code-structure than first-person-shooters, or puzzle-games, or whatever. As another suggestion: there are (of course) open-source games of any genre, so you can look to them for guidance. Personally, I can never make heads or tails of the source code, but maybe you're more adept. :) [And yeah, I was embarrassed by the "black art" thing, but it seemed appropriate at the time? :)]
Agor
Yeah... I hate going through someone else's source unless it's extremely simple and barebones. Some things just have so many levels of abstraction, you have to dig through several files just to figure out what a single function is doing. Thank God for modern IDEs (ctrl-click!) :) The game is a side scrolling shooter. Sort of half way between Super Metroid and Metal Slug I guess. With physics. :)
Mark
A: 

It's probably more basic than you are looking for, but I have been learning with pygame, and their is a book by apress about it that teaches basic gamedev if others are interested.

Javed Ahamed
People keep suggesting pygame... I'm not really interested in switching over or learning a new library, *but* I will look through the documentation to see how they structure things. If it really is that great, it *must* be well designed right? Thanks.
Mark
Scratch that. It doesn't look like pygame provides any structure... it's just a big utility library isn't it? Doesn't appeal at all to me.
Mark
+2  A: 

Look at this tutorial:

http://ezide.com/games/writing-games.html

It is written for python and explains MVC for games very good.

Good Luck!

Xidobix
Yes! Thank you! Now this is on-topic and very relevant. Much closer to what I'm looking for.
Mark
A: 

I almost want to scream duplicate of my question but that would be lame. :)

Anyway look through those answers. I think if you don't have much experience in game dev, jump into it. Don't think so much about the planning stage, just worry about getting something on the screen, get something working, then refactor and mess with your code (without changing your output) and you'll figure out what works and what looks best.

I am a big fan of writing something that works, then going back and refactoring. You can learn a lot that way, and you spend less time going in hypothetical circles trying to figure things out in your head and getting nothing done. (And not to say that that's what you'd end up doing, maybe you're an excellent planner, but I personally have done that plenty of times.)

Ricket
That's the problem. I always *do* jump right in and never plan, and then I wind up with a huge mess on my hands that bothers the heck out of me and then I "refactor" the entire program back into nothingness. Better to start with some structure so that I'm not so tempted to rip it apart. I have little game experience, but not none. I've got a super basic mario clone, and another game... but when you try to add more elements (like a menu screen) everything just falls apart. Like if your player is the only object that handles input...what happens when he dies?
Mark
Anyway, you're right. It's quite similar to your question, I'll read through those answers too. Thanks :)
Mark
http://dev.koonsolo.com/9/model-view-controller-for-games/That's a good one. I always thought of "Model" as "database" and Controller as... I dunno, handling post data and such and sending it off to the model, and Views are views.... had to twist my head a bit to see how I could apply this to a game. Helpful :)
Mark
Well if you get to the opint where your player is the only object that handles input and you have to make him die, then you refactor; highlight that input code, cut, paste it into a new class with calls to the new class in your player. Then move it one level up; put the input stuff into whatever class manages the player, and have it manipulate the player like a puppet using public methods rather than direct manipulation of the player variables. Keep moving it around like this, one step/layer at a time. That's what refactoring is all about.
Ricket
You are right in exploring how to structure a game from the beginning to minimize the need to completely change everything halfway through. And that's why I asked the same question. It's good to have a general idea. I find that it helps if I sit down and write requirements - what are all the things I want my game to do. Then draw some real simple UML diagrams and make sure that they can accomplish those requirements. That's sort of the process that the business world uses, and I think it's very clean for making a game too; plus, it forces you to have a clear idea of your game from the start.
Ricket
Yeah... well, sooner or later I'll have to refactor anyway, and sure I'd follow a similar method like you've mentioned. But minimizing the refactoring when you *know* you'll need at least a few levels of abstraction right off the bat doesn't hurt either. Moving something up a level of abstraction isn't so bad, but you can get yourself into other situations where refactoring is a little more difficult. Thanks for the tips :)
Mark