Crash Course in Game Programming? 142
Lullabye_Muse asks: "I want to write a game program for an independent research class I am taking at my High School. I have until June to deliver a final product or a good demo. I'm somewhat new to programming and will be doing work at home, and at school (Linux and Windows, so cross platform OSS is best). What is the best language to learn to code games in, and do you have suggestions for any useful sites, on game programming?"
SDL Graphics library (Score:5, Informative)
I'd suggest C++ for programming languages, but that's probably just because it's what I've used for years.
--trb
Easy (Score:3, Informative)
The design pattern for most simple java games is model view controller. You create an object oriented game model with map, player, item classes etc. Then you create a view, or the gui that looks at this game model and translates the data into graphics or text on the screen. Then the controller portion interprets player input and modifies the game model accordingly.
This is a very good pattern to follow for games, especially for research projects. This is because the game itself usually isn't the research, but some underlying CS principle or algorithm. And this makes very simple cross platform games to which you can attach or embed your real research very easily.
You can also follow this same approach with python, or ruby or even C++. Python might even be a better choice since it might beat java in performance and is used quite often in the game industry.
Get Python + Pygame (Score:5, Informative)
The downside with Python is that it can be slow (a fact that can be remedied to some degree, but not entirely, by also installing Psyco [sourceforge.net]). Fortunately, the slowness doesn't matter (unless your aim is to compete with the next id Software engine). I've written a simple engine for a 2D platformer in Python myself, and even with a game logic and collision detection, 90% of the processor time is spent blitting the graphics to the screen. Since Pygame (written in C) does the rendering, using C++ for your game code won't provide any big advantage.
Good luck!
Try blender (Score:5, Informative)
http://www.blender3d.org/cms/Game_Blender.365.0.h
It's a 3d design package, that gives you a game engine, so you could have the graphics part solved, and can worry just about the actual game. I believe you can program for it with python.
It works on MSWindows, GNU/Linux, and other platforms, and it can generate
Re:Get Python + Pygame (Score:3, Informative)
Game sites (Score:5, Informative)
-m
SDL, C and Pygame (Score:5, Informative)
For serious game programming, you need to learn C or C++. I would guess that 99% of all commercial games for the PC are written in mostly C or C++. This doesn't mean you need to write all of your code in a low level language. Even the original Quake used an interpreted language (QuakeC) for the game logic. But almost no language other than C or C++ will provide the speed or memory usage necessary for most commercial games.
If you'd rather concentrate on writing your game rather than learning C, try Python [python.org] with Pygame [pygame.org]. Pygame is a Python binding to SDL. It is fairly fast since all the low level graphics stuff is done using SDL. Certain things will be slower in Python (collision detection, physics, etc.) but most code isn't speed critical anyway. Some things will be harder in Python since it's easier to manipulate bytes and bits in C.
Also check out PyOpenGL [sourceforge.net] if you want to learn OpenGL. It can be used in conjunction with Pygame. I used this when I was learning OpenGL and it's quite nice. The API is almost exactly like the C based API, but it is easier to use. At least one of the popular OpenGL tutorials has been ported to PyOpenGL.
Re:New To Games? (Score:2, Informative)
Re:Game sites (Score:5, Informative)
Don't forget http://www.gamasutra.com/ [gamasutra.com] and the PCGPE, even if it's older than dirt.
Good Links (Score:2, Informative)
Click here [bios10h.net] and under 'Game Development'...
I highly recommend FlipCode [flipcode.com] and GameDev.net [gamedev.net] for game-programming-related content. They have tons of stuff for beginners.
With the information you provided, it is pretty hard to direct you to *the* website you need because we don't know if you wanna do 3D or 2D, Ogl or DX, game genre?
There are also some crappy 'game toolkits' but if you know how to write C++ code, I'd recommend you stay away from these things.
Get Python + PyOgre (Score:2, Informative)
Linux bindings are not ready yet, but they shouldn't be too far off into the future. You should check the the API Reference and Manual for most starting information, and use the ogre Wiki and forums for most questions you have.
I know I will probably be modded down... (Score:4, Informative)
Javascript, CSS, and DHTML are each well documented on the internet, and there are numerous books to get you started, as well.
Finally, before you cry out "but Javascript won't let me create a cool game!" - take a look at this:
Illumia RPG [illumia-rpg.com]
and especially this:
TRIGLAV RPG [smokymonkeys.com]
Re:New To Games? (Score:3, Informative)
For my degree project I took freecraft and made it 3D and make it client-server. Looked nice.
But I spent most of my time fighting the code. Not because it was particulary bad or anything, but because I had to convert it all over to C++ compatible from C (there are incompatibilities. I hit every one I'm sure), fight the Makefile's (at the time they had their own custom make system), fight event-loops (freecraft and the graphical engine), and so on.
It turned out looking pretty nice, but I got poor marks (relatively - it was 68% when a 1st is 70%. But I was getting 75+% in everything else, so...). I attribute the poor marks partly to be unable to really explain where my time and code was. "Well I spent a week adding this c++ library to the makefile...".
As a side point, I never bothered to release my code. It required so many libraries that it was a nightmare to set up to compile.
Ignore everything else you've read here. (Score:5, Informative)
Ignore everything you've read here about graphics and sound libraries, existing game code, existing game libraries, and (for now), choice of languages. If you've never done any programming before and intend to use this as a vehicle to start programming, read this first. Clear your mind, and ignore the details for now.
More important than anything else you can ask right now is to find out what you're trying to achieve. Saying "I want to write a game" isn't specific enough, as humanity has invented tens of thousands of games over the years using all sorts of different mechanisms (cards, dice, boards, pieces, pots, beans, joysticks, vector graphics, role playing, puzzles...). So first, figure out what you want to write.
Next, take the game you want to write, and stick it on a mental shelf. Everyone would love to write Grand Theft Auto: San Andreas as their first game, but it isn't going to happen.
My first piece of advice: don't try to create a new game for your first project. Take something you already know, and know well, and implement it first. Try to pick something that has finite states that are easily describable, and then work from there. Preferably something that has mechanical rules and won;t require too much "artificial intelligence" on the part of the computer (ie: you may know Chess really well, and it has a finite number of pieces, the logic required to decide how to have the computer move is exceedingly complex. Companies like IBM have spent millions trying to perfect such algorithms).
Two classes of games which are typically excellent candidates for first projects are card and dice games. Both are fairly easy to program, as they involve numbers, and have a finite number of possibilities (ie: 52 cards, 6 sides per die). When selecting a game to implement, find something you enjoy, but preferably something that again, won't require an M.Sc. in Artificial Intelligence. Blackjack is an excellent candidate (many Universities use this as a first year programming assignment anyhow, so you'd be getting a leg-up on others if you plan on persuing Computer Science in higher education), as the compter can act as the dealer, and has very specific rules it always follows (requiring no AI at all). Don't worry about how many times the game has already been done -- your goal is to learn programming, and not to create the next Halo 2.
Once you've selected a good candidate game, you need to code the game mechanics before you code anything else. So again -- forget everything anyone here has told you about graphics and sound libraries, or even languages. You won't need these until later.
Continuing with Blackjack as an example, here are some of the things you need ot think about first:
If you can get all of this down in code, you'll be off to an excellent start. From here, you can graft whatever user interface you want atop the "game engine" you've just created. And you'll find you'lll learn a lot about the basics of programming (variables, arrays, functions, objects, random numbers, sorting, comparisons, etc.)
You'll probably want to be able to test things out as you go along, which will require a minimal user interface. To start, you'll probably want to use just text to represent everything (ie: "10 Hearts", "A Spades", etc.).
vote for python + pygame (Score:2, Informative)
If you want to do something simple and don't know how to program at all, this is definitely the way to go.
Python is not only easy to learn, it's a great starting language. (enforces proper formatting, doesn't use crazy things like ; line endings ;)
Python.org Beginner's Guide [python.org]Dive Into Python [diveintopython.org] (free on-line book, well written IMO)
and of course the http://pygame.org/ [pygame.org] which the parent poster already said.
I would NOT suggest using PyOpenGL if you're new to programming, it's an unnecessary layer of complexity for very simple projects. Use it after you know how to program and have created at least a few simple things already. :)
Anyway, just wanted to give my vote for Python.
Re:putting flamesuit on...but how about flash? (Score:2, Informative)
If you don't use Flash you should already have many your libraries completed so students don't have to do a lot of work to get results. If you do use Flash try to make it's proprietary shortcomings painfully obvious but don't directly refer to them. That way your students will eventually revolt against Flash and will think they are the first generation to support free and open source software.
Re:putting flamesuit on...but how about flash? (Score:2, Informative)
Re:New To Games? (Score:2, Informative)
Re:Get Python + Pygame (Score:2, Informative)
Of course, you still have to 'update' the bits that have changed, but for the rest it should be faster than doing a full update.
while 1:
for event in pygame.event.get():
if event.type == QUIT or \
(event.type == KEYDOWN and event.key == K_ESCAPE):
return
keystate = pygame.key.get_pressed()
direction = keystate[K_RIGHT] - keystate[K_LEFT]
if direction == 1:
screen.blit(screen, (10, 0), (0, 0, screen.get_width() - 10, screen.get_height()))
pygame.display.update()
if direction == -1:
screen.blit(screen, (0, 0), (10, 0, screen.get_width() - 10, screen.get_height()))
pygame.display.update()