Now: Tutorial for Web and Software Design > OS > Linux > OS Content
> Retro Gaming Hacks, Part 1: Clone Pong, Using Only SDL (and Your Brain) [Bookmark it]
Retro Gaming Hacks, Part 1: Clone Pong, Using Only SDL (and Your Brain)

Retro Gaming Hacks, Part 1: Clone Pong, Using Only SDL (and Your Brain)

by Josh Glover, contributor to Retro Gaming Hacks
12/15/2005

One of the great things about the games of yore is that they tended to be pretty simple, mostly because the hardware that pushed them only could do approximately 1.5 floating-point operations per day (FLOPD--an unfortunate acronym if ever I've seen one). Of course, one of the benefits of such spartan software is that in an actual game, you know, something "fun," has to exist at the kernel. When you don't have full-motion, cinema-quality cutscenes to distract the player, you had better serve up some serious gameplay. And the people working for Atari and Broderbund knew how to cook up games, including Atari's smash-hit video game Pong--one of the greatest games ever invented, and one of the simplest to implement.

So gather up your C programming skills, your dusty old eighth grade geometry book, and a copy of the Simple DirectMedia Layer (SDL)--we're going to show you how to clone Pong all by yourself. And stay tuned--this is the first of a three-part series. The next two articles (Adding Paddles to Your Pong and Add a Ball and Score to Your Pong) will build on what we do here, so look for those in the coming weeks.

SDL

As mentioned in the previous paragraph, SDL is the Simple DirectMedia Layer. If you are wondering how this has any relevance on the cloning of Pong, allow me to explain. In the heady, dot-com days of 1998, a company named Loki Entertainment Software was founded, with the mission of porting best-selling games to Linux. Their first port was of Civilization: Call to Power, which hit stores in April of 1999. Loki ported 19 other great games before they closed up shop at the end of January 2003.

As great as Loki's ports were, the crown jewel of its collection was not a game, but a game library: the Simple DirectMedia Layer. Loki, an open source company, released SDL under the GNU Lesser/Library Public License (LGPL), allowing anyone to download and use SDL to create his or her own games. SDL is written in C (and you can use it natively in C++ code), but bindings exist for Ada, Eiffel, Java, Lua, ML, Perl, PHP, Pike, Python, and Ruby. SDL does a great job of abstracting away the nasty details of game writing and letting you concentrate on the fun stuff, like writing your very own Pong clone! To install it, follow the directions for your Linux distribution:

Debian GNU/Linux

  1. Become root.
  2. Run the command:
  3. apt-get install libsdl1.2 libsdl-ttf1.2 libsdl1.2-dev \ 
    
     libsdl-ttf1.2-dev

Gentoo

  1. Become root.
  2. Run the command:
  3. emerge libsdl sdl-ttf

Red Hat Linux, Fedora, and Other RPM-Based Distributions

  1. Visit the SDL project's download page and save the RPMs for the latest Runtime and Development Libraries (Version 1.2.8-1, as of this writing) to your /tmp directory.
  2. Open a terminal window and become root, then run this command:
  3. rpm -Ivh /tmp/SDL-*.rpm

Other Linux/Unix Distributions

  1. Visit the SDL project's download page and save the latest source tarball (SDL-1.2.8.tar.gz, as of this writing) to your /tmp directory.
  2. Open a terminal window and become root, then run these commands:
  3. cd /tmp
    
    tar xvzf SDL-1.2.8.tar.gz && rm SDL-1.2.8.tar.gz
    
    cd SDL-1.2.8
    
    ./configure && make && make install

Other Operating Systems

Users of Windows, BeOS, and Mac OS (both Classic and X) can also visit the SDL project's download page, grab the appropriate distribution files for the latest Runtime and Development Libraries, and install them. You may find the "How to set up your SDL Build Environment" article on the Game Programming Wiki to be quite useful.

Note: Windows users can choose between Visual C++ and MingW32 versions of SDL. MingW32 is a free minimal Windows development environment that you can get using the Cygwin installer. If you choose the Cygwin route, it will closely resemble the Linux/Unix/Mac OS X-friendly instructions in the rest of this hack.

With SDL now installed, let's get on with the hacking of code.

A Rough Outline

As with any engineering project, a video game should start with a plan. We'll write our plan in C. Open up your favorite editor and create a new file. I recommend calling it sdl-pong.c.

Note: This hack assumes you are coding in a Unix, Linux, or Unix-like environment (Mac OS X, Cygwin, and so on). If you are not, you should know how to work your compiler, as when I say "gcc this, gcc that," you will have to translate to "File > Compile," and so on. For a pure hacking experience, install the GNU Compiler Collection (gcc) on your machine, and write your coding in a (programmer's) text editor, such as XEmacs or vi.

[1] [2] [3] [4] Next

[Bookmark][Print] [Close][To Top]
  • Prev Article-OS:

  • Next Article-OS:
  • Related Materias
    How to Deploy Software Usi
    Mastering Windows New Fire
    Creating Visual Studio Pro
    Better Registry Searching
    Using Data Compression in 
    How to Remove Startup Prog
    Registry Hacks for Servers
    Build a Virtual Routed Net
    How To Recover from Regist
    The Ultimate Free Windows 
    Topics
    Photoshop Tutorial
     

    Special Effect

      3D Effect
      Photoshop Articles
    Programming Tutorial
     

    C/C++ Tutorial

      Visual Basic
      C# Tutorial
    Database Tutorial
     

    MySQL Tutorial

      MS SQL Tutorial
      Oracle Tutorial
    Graphic Design Tutorial
     

    Coreldraw Tutorial

      Illustrator Tutorial
      3D Graphics Articles
    Webmaster Articles
     

    Domain Service

      Web Hosting
      Site Promotion
    Java Tutorial&Articles
     

    Java Servlets

      JavaEE Tutorial
     

    JavaBeans Tutorial

    XML Tutorial&Articles
     

    XML Style Tutorial

      AJAX Tutorial
      XML Mobile
    Flash Tutorial&Articles
     

    Flash Video

      Action Script
      Flash Articles
    OS Tutorial&Articles
     

    Linux Tutorial

      Symbian Tutorial
      MacOS Tutorial