Slashdot Mirror


Crash Course in Game Programming?

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?"

17 of 142 comments (clear)

  1. New To Games? by johnkoer · · Score: 4, Insightful

    Since you said you are new to programming, you might want to consider taking on an OSS game that is already out there and modifying it to suit your purpose. It will help you learn a lot of the basics of programming, but it will also give a great starting point.

    If you are dead set on writing an entire game yourself, best of luck to you. Even for an experienced programmer, throwing together a game (or even a demo) in three - four months is a feat.

    1. Re:New To Games? by _pruegel_ · · Score: 4, Insightful

      I disagree. I believe modifying most OSS games out there requires more knowledge and most importantly more time and effort than writing a simple game from ground up. Those games might have huge code bases and usually there is little documentation especially for starters.
      The author of this "Ask Slashdot" did not mention "First Person Shooter" or even 3D at all. And there are games which are very simple but still fun. Games like Pong, Mine Sweeper, Snake and many more can each be done in a couple of hours. There are even programming languages made for simple game development although I would prefer a "real" language like Java or Python. I once wrote a small game to learn Tcl/Tk and that was fun and I did it in less then a day.

  2. SDL Graphics library by (trb001) · · Score: 4, Informative

    Languages aside, SDL (Simple Directmedia Layer) 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

  3. Easy by Apreche · · Score: 3, Informative

    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.

    --
    The GeekNights podcast is going strong. Listen!
  4. Get Python + Pygame by fredrikj · · Score: 5, Informative

    You should definitely get Python and Pygame. Python is both easy to learn and more powerful than most languages. Better yet, there are plenty of example games to study. If you want to do 3D, also get PyOpenGL, and get the started with the NeHe tutorials (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). 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!

  5. It's going to need to be simple.... by Grygonos · · Score: 5, Insightful

    If you're new to programming, and actually want to code this yourself, it's going to need to be a simply game with little to no graphics. Implementing a OpenGL game is NO trivial task. A game I did in Java was the simple squares game where the object is to arrange the pieces like so .. 1 2 3 4 5 6 7 8 * So I wrote a Java app that would mix up the squares like so 4 7 2 * 1 8 6 5 3 and allow you to move the pieces around via the *blank* square. This still wasn't trivial, especially for someone new to Java, much less programming in general. Not trying to disparrage your efforts, but being new to coding is probably your biggest disadvantage.

  6. Back in my day by madaxe42 · · Score: 3, Funny

    We used to program games in Basic, on BBC Micros! First game I ever wrote was a donkey kong clone, and a poor one at that - about 1500 lines of code, max.

    Also, back in my day, we had to burn our feet as fuel, we were so poor. And we had no monitors. And we only had one keyed morse-code based keyboards. Bah!

  7. Try blender by orasio · · Score: 4, Informative

    http://www.blender3d.org/
    http://www.blender3d.org/cms/Game_Blender.365.0.ht ml

    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.

  8. My Suggestion as a Game Programmer in HS by Prien715 · · Score: 4, Interesting

    My suggestion would be Java, simply because the graphics libraries are pretty decent and it's not hard to write a decent GUI. Additionally, it's cross-platform and would probably help you in the real world later.

    But the real question is, how much experience do you have currently? I started programming in HS by doing games on those little calculators (TI-81 to 85 completely self-taught) and enjoyed the experience so much I decided to do CS in college (graduated last year). If I were in your shoes, you may want to think small. Many of the early video games were text-based, many made by one person. Nowadays due to complication, you need teams. So it may not be a bad idea to write something simple and textbased in whatever language. Text-based doesn't need to mean uncomplicated or compromised gameplay; chess, othello, hearts, and dungeon-crawlers were all very popular and I still know people who prefer these over newer games.

    --
    -- Political fascism requires a Fuhrer.
  9. Game sites by magic · · Score: 4, Informative

    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

    1. Re:Game sites by vasqzr · · Score: 5, Informative


      Don't forget http://www.gamasutra.com/ and the PCGPE, even if it's older than dirt.

  10. SDL, C and Pygame by Electrum · · Score: 4, Informative

    Without a doubt, Simple Directmedia Layer (SDL) 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 with Pygame. 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 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.

  11. putting flamesuit on...but how about flash? by avi33 · · Score: 4, Interesting

    Before the locals gather their pitchforks to run me out of town, here's why:

    -If you don't know much about programming, even something basic like vectors or graphics libraries could be more than a little daunting. Flash makes graphics dog-dumb easy, leaving you to focus on the logic. A lot of the abstractions (game speed, display parameters, collision detection) can be handled easily, leaving you to learn how to program.

    -You can do some OO programming with Actionscript, so you can start with a simple program, and when you get skilled, learn how to extract that functionality into libraries or classes.

    -You should be able to focus on some simple programming aspects like game physics, or making it fun (which doesn't have much to do with programming).

    -There are a zillion sites out there with bits of code that you can learn from and modify. Granted, lots of it sucks (i.e. it works, but it will not show you how to be a 'good' coder). Offhand, I don't know what to recommend to become a good coder, but at the least, I'd recommend plowing through at least the first 3 chapters of Bruce Eckel's Thinking in C++ (free online). Once you get through pointers and address references, actionscript will look like child's play. Sure, there are sites out there with sample PyGame/Java/etc. code, but Flash code is easier to cherry pick and drop in.

    -You have to realize that what you're doing is similar to saying "I've never turned a wrench before, but I want to build a car in 4 months." Game programming can be exceptionally difficult on a number of levels.

  12. Re:Flash by pezpunk · · Score: 4, Interesting

    it's funny, but you'll probably get flamed or modded to oblivion just for posting about the only reasonable solution to his conundrum. i seriously doubt this kid is going to learn the Java API and throw together something on the scale most of these people are talking about in the 3 months or so of after-school time he has to work with.

    Flash is a great medium for 2D games. the graphics are drag and drop, and the actionscripting is a perfect introduction to handling the logic associated with managing a game.

    but, this being slashdot, anything mentioning Flash in a positive light will probably get modded downward and derided by the community.

    --
    i could live a little longer in this prison
  13. I know I will probably be modded down... by cr0sh · · Score: 3, Informative
    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

    and especially this:

    TRIGLAV RPG

    --
    Reason is the Path to God - Anon
  14. Ignore everything else you've read here. by Yaztromo · · 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:

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

    1. Re:Ignore everything else you've read here. by Ramses0 · · Score: 3, Interesting
      I have to agree. I'm currently making Dominoes as an online board game. I've been programming professionally for ~5 years now, have 4 years of college, 2 years of High School, and 4-5 years of self-study in programming. Programming a complete working version of anything can be difficult, so keep it simple. As an example of what you might end up facing, here's a dump of my latest directory structure:

      domino.php --- 1k
      dominoes.php --- 3k
      dominoesBoard.php --- 10k
      dominoesGame.php --- 13k
      dominoesGui.php --- 18k
      dominoesHand.php --- 2k
      opHandler.php --- 3k
      rules.php --- 2k
      test_domino.php --- 1k
      test_dominoes.php --- 1k
      test_dominoesBoard.php --- 9k
      test_dominoesGame.php --- 10k
      test_dominoesHand.php --- 10k

      WRITE YOUR TESTS! Notice almost 50% of my code is tests (and I feel that it's not enough, I currently got ahead of myself and need to catch up on my tests before I feel comfortable adding more functionality).

      I would do a lot of thinking about what the parent poster said, specifically: Start Simple. Think About Your Win/Lose Conditions.

      I'd like to add the note: Write Tests. To continue the blackjack example, what happens when a user has an "A, J" in their hand? (blackjack). How can you test that? Write a test for it. What happens when they have "J, K, Q" in their hand? (bust) How can you test for that? Write a test for it. What happens when they run out of money? What happens when they try to bet too much money? A negative amount of money? Write tests and repeat as necessary.

      A whirlwind tour of my dominoes layout (this is to back-up the parent poster about the game libraries, and mechanics, etc):

      • domino - a single domino
      • dominoesHand - hand containing many dominoes
      • dominoesBoard - all the dominoes that have been played
      • dominoesGame - all the win conditions, lose conditions, points, drawing, etc (game logic)
      • dominoesGui - mostly HTML, and a lot of drawing functions
      • dominoes.php - what the user ends up interacting with (mostly passes off to dominoesGame)
      • test_* - a bunch of tests that load up the other files, use them, and print out "pass/fail" for each situation


      For the GUI code, it's mostly HTML text to display stuff to the user, which is why it's so big. But even then, recognize that the bulk of the work is in stuff that the user doesn't even see (Board, Game) ... good luck! Ask questions to your teachers, and WRITE YOUR TESTS! :^)

      --Robert