Various guides and experiments

Pong in C/ncurses

This is a two players, one keyboard Pong written in C with “graphics” using the ncurses library. It was written over a year and a half ago and I haven’t read the code since, so it’s likely to be total or at least partial crap.

Playing it now I can spot two immediate flaws that I should’ve done something about. First of all the ball always moves at the same angle and speed. Second of all if you press and hold a key to move, the opponent can press a key and your movement will stop.

Other than that it’s pretty straight forward, just compile the C source file and play, against yourself or with a friend, an up and down key pair each.

It’s free as in free speech (and free beer) so you have no restrictions regarding usage or modifications to it, but it’s always nice to hear from anyone using what you make so feel free to post a comment or send me a mail. Any bug fixes, improvements or other additions would be neat to get so I can host any new versions here. :)


Posted in Projects | 5 Comments

5 responses to “Pong in C/ncurses”

  1. dbbolton says:

    Fails with gcc 4.6 on Debian wheezy:

    pong.c: In function ‘main’:
    pong.c:69:38: warning: incompatible implicit declaration of built-in function ‘strlen’ [enabled by default]
    /tmp/ccHRBQU5.o: In function `main’:
    pong.c:(.text+0x3c): undefined reference to `initscr’
    pong.c:(.text+0x41): undefined reference to `cbreak’
    pong.c:(.text+0xe2f): undefined reference to `stdscr’
    pong.c:(.text+0xe37): undefined reference to `wrefresh’
    collect2: ld returned 1 exit status

  2. nemrod says:

    @dbbolton: That’s because you’re not compiling it with ncurses (probably should have mentioned that in the post). Add -lncurses to the command and it should compile better. :)

  3. don_joe says:

    really mates ? ,

    no one coded a ncursed based pong game yet that is

    in the official repository !

    cant believe

    so i´m gonna do it

    its gonna be aw-( wait for it )-some ! ! !

  4. minimuor says:

    The code that is provide is not working.

    Compiling results into errors.

    ~/Downloads$ gcc pong.c -o pong -lncurses
    pong.c: In function ‘main’:
    pong.c:69: warning: incompatible implicit declaration of built-in function ‘strlen’
    /tmp/ccIfE2oq.o: In function `main’:
    pong.c:(.text+0x8d3): undefined reference to `pthread_create’
    collect2: ld returned 1 exit status

    Could you please improve the code (and posix’s it )?

    thanks a lot!

  5. nemrod says:

    @minimour Have you tried adding -pthread to the command?

Leave a Reply

Your email address will not be published. Required fields are marked *