Please create an account to participate in the Slashdot moderation system

 



Forgot your password?
typodupeerror
×
Programming Technology Entertainment Games

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?"
This discussion has been archived. No new comments can be posted.

Crash Course in Game Programming?

Comments Filter:
  • SDL Graphics library (Score:5, Informative)

    by (trb001) ( 224998 ) on Friday January 28, 2005 @01:18PM (#11504863) Homepage
    Languages aside, SDL (Simple Directmedia Layer) [libsdl.org] is a great library for graphics/sound/network programming. Simple, easy to learn, cross platform. For a class project, it should do the trick.

    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)

    by Apreche ( 239272 ) on Friday January 28, 2005 @01:18PM (#11504867) Homepage Journal
    Since you are doing this in high school, and want it cross platform, it obviously doesn't have to be a high performance 3D super game of awesome. So make it in java.

    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)

    by fredrikj ( 629833 ) * on Friday January 28, 2005 @01:19PM (#11504885) Homepage
    You should definitely get Python [python.org] and Pygame [pygame.org]. Python is both easy to learn and more powerful than most languages. Better yet, there are plenty of example games [pygame.org] to study. If you want to do 3D, also get PyOpenGL [sourceforge.net], and get the started with the NeHe tutorials [gamedev.net] (Python code available).

    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)

    by orasio ( 188021 ) on Friday January 28, 2005 @01:22PM (#11504923) Homepage
    http://www.blender3d.org/ [blender3d.org]
    http://www.blender3d.org/cms/Game_Blender.365.0.ht ml [blender3d.org]

    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 .EXE or web 3d games viewable with its own (small) plugin.
  • by fredrikj ( 629833 ) * on Friday January 28, 2005 @01:26PM (#11504976) Homepage
    To clarify, the 10% of processor time I got for my game code was enough to do what I wanted. If you use OpenGL, which uses the graphics processor for rendering, you'll instead get 90% of the processor time. That way there will be a bigger relative advantage for C++, but it'll also be even more likely that you'll get enough time to do what you want in Python.
  • Game sites (Score:5, Informative)

    by magic ( 19621 ) on Friday January 28, 2005 @01:32PM (#11505051) Homepage
    Check out the community sites garagegames.com, flipcode.org, and gamedev.org to meet other people in similar situations. The forums are really good for getting quick answers to beginner questions.

    -m
  • SDL, C and Pygame (Score:5, Informative)

    by Electrum ( 94638 ) <david@acz.org> on Friday January 28, 2005 @01:32PM (#11505053) Homepage
    Without a doubt, Simple Directmedia Layer (SDL) [libsdl.org] is the best platform for writing cross platform games. It provides a very clean abstraction layer to the high performance APIs (DirectX, etc.) available on each platform. Many people who code only for Windows use it since the API is a lot nicer than the COM based DirectX API. A number of commercial games have been ported to Linux using SDL.

    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)

    by abradsn ( 542213 ) on Friday January 28, 2005 @01:47PM (#11505240) Homepage
    I agree. And to add to this comment, if you are still dead set on writing a game, use the highest level langauge you can find. Since you are new to programming, you will want to use Visual Basic, or C#. They are the easiest to learn in the shortest amount of time. Keep in mind that a computer programming course in college is a few months long. You will be hard pressed as it is just to learn the programming skills necessary to write a game. The best advice on a short project is to let performance fly to the wind. If you see two solutions and one performs well but takes more time to code, just do it the other way and save that time. For example, instead of using a binary tree, just iterate over every element in the array. If some has just read this part of the comment and skipped the rest of the comment, please re-read the rest of the comment. Thanks.
  • Re:Game sites (Score:5, Informative)

    by vasqzr ( 619165 ) <vasqzr@ne t s c a p e . net> on Friday January 28, 2005 @01:58PM (#11505392)

    Don't forget http://www.gamasutra.com/ [gamasutra.com] and the PCGPE, even if it's older than dirt.
  • Good Links (Score:2, Informative)

    by bios10h ( 323061 ) <.moc.zeranib. .ta. .s.> on Friday January 28, 2005 @02:02PM (#11505469) Homepage
    Disclaimer: it is my website. I'm not plugging my website's links collection; I just think it might be useful to starting developers. I have a pretty collection of websites useful for game programmers.

    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)

    by Clay_Culver ( 583328 ) on Friday January 28, 2005 @02:06PM (#11505525)
    If you are going to do 3D game programming, I would also suggest you look at PyOgre. Ogre [ogre3d.org] is a powerful open source graphics engine written in C++. You can download the python bindings for it here [idleengineer.net]. Download it and check out the demos that come with it (the demos are placed in you python directory in a folder called ogredemo).

    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.
  • by cr0sh ( 43134 ) on Friday January 28, 2005 @03:11PM (#11506428) Homepage
    I would say try your hand at writing javascript games - no, I am serious! Amazingly enough, if you have a recent browser which can support javascript and CSS (ie, DHTML) - you have everything needed to create a basic game. Drop the game "page(s)" on a webserver and add in some CGI processing, and you have a way to save/load information as well (game save points, scores, levels, etc).

    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)

    by JohnFluxx ( 413620 ) on Friday January 28, 2005 @04:00PM (#11507059)
    I second the disagreement.

    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.
  • by Yaztromo ( 655250 ) on Friday January 28, 2005 @04:12PM (#11507236) Homepage Journal

    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:

    • How will the computer store the information about a card (and again, don't think about the graphics for the card at this point -- right now you need a way for the computer to be able to tell the difference between a 3 and a Queen, a Diamond and a Club)?
    • How will you group cards together? (For the hands, the cards remaining in the desk, etc.)?
    • How will you perform actions on the cards such as shuffling?
    • What are the win states? What are the lose states? What are the draw states (if any)?
    • What are the rules the computer has to play by?
    • What options should the user have at each junction (ie: draw, hold, split, double)? When is each approperiate?

    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.).

  • by neura ( 675378 ) on Friday January 28, 2005 @04:45PM (#11507616)

    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.

  • by zeasier ( 708695 ) on Friday January 28, 2005 @04:58PM (#11507828)
    I agree that Flash is your best option, especially if the class is only one semester long. Video games make so many otherwise boring subjects in high school interesting. The math and physics teachers will thank you, because when their students ask why they need to learn those subjects they will just say, "Because then you can take can take a class on video games next semester. Woot!" It's important to lower the bar so the class is accessible to as many students as possible.

    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.
  • by dj_cel ( 744926 ) on Friday January 28, 2005 @07:58PM (#11509746)
    I was thinking the exact same thing whe I read this post, I recently graduated an animation program and one of the courses was a two semster run of Flash and fairly extensive actionscripting. flashkit.com has some great examples of prebuilt games to learn from quickly, as well as tutorials for non-action scripters to get into the nitty gritty. I seriously think this is the most viable option for the time frame and experience level.
  • Re:New To Games? (Score:2, Informative)

    by iocat ( 572367 ) on Friday January 28, 2005 @08:12PM (#11509846) Homepage Journal
    No offense, but I say screw that -- get a GBA emulator and development environment at GBA dev [gbadev.org], and you can work cross-platform with all F/OSS on some hardware that has lots of easy graphic capabilities and input methods built in. Plus there are tons of well commented demo apps that will get you up and started in a flash. PCs are too complex for a first project -- GBAs are more limited and easier to get your head around.
  • by elhedran ( 768858 ) on Monday January 31, 2005 @02:18AM (#11526114)
    yep, screen.blit works, and pretty fast if you remember to limit the source rect to where you want to copy from. (although that may just be my machine).

    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()

Machines have less problems. I'd like to be a machine. -- Andy Warhol

Working...