IOCCC image by Matt Zucker

The International Obfuscated C Code Contest

2014/maffiodo1 - Homage to a classic game

homage to a popular game

Author:

To build:

This entry requires SDL to be installed. See the FAQ on “SDL1 and SDL2” if you don’t know how to do this for your system.

    make

Bugs and (Mis)features:

The current status of this entry is:

STATUS: INABIAF - please DO NOT fix

For more detailed information see 2014/maffiodo1 in bugs.html.

To use:

    cat game.level | ./prog 320 200 800 300 128 144 game.rgba game.wav 10343679

The parameters to the program are:

  1. Window width.
  2. Window height.
  3. Level width.
  4. Level height.
  5. Sprites image width.
  6. Sprites image height.
  7. Filename of the sprites image (raw RGBA image).
  8. Filename of the music (WAVE 8000 Hz 8bit Mono).
  9. Sky color. This number depends on the system where you run the program. See note on macOS.

Try:

    ./giana.sh

    ./mario.sh

If you end up telnetting to the server (feature of mario.sh script) you can try:

    ls # show files including games
    wumpus.bas # play Hunt the Wumpus
    advent.gam # you know what this is! :-)
    starwars # animated Star Wars 'film'

If you wish to change the width and height, defaulting at 640 x 480, say to 800 x 800, try:

    ROWS=800 COLS=800 ./mario.sh

    ROWS=800 COLS=800 ./giana.sh

Judges’ remarks:

A classic for a particular generation. Like all good programs, being data driven means you can do fun things in small spaces.

NOTE: the author states to use tabsize=4 to see the magic of the formatting of the code. In vim you can do:

    :set tabstop=4

in command mode to see this effect. You don’t need to modify your .vimrc file! You can also use expand as described below by the author if your terminal has enough rows and you don’t want to move about in the code. The vim command should immediately take effect.

Author’s remarks:

Remarks

Use tabsize=4 to see the magic.

    expand -t 4 prog.c

The program returns 0 if the player wins or non-zero if the player loses so you can test it and make something useful (or not), like this:

    cat mario.level | ./prog 320 200 800 300 128 144 mario.rgba mario8.wav 10343679 && telnet telehack.com 23

and type in: starwars

This is an engine for platform game. It can be used to create games like the legendary Super Mario Bros.

With this simple and clear source code you can create all the games you want, for free!

In my two tests I tried to create one level of Super Mario Bros and one of The Great Giana Sisters.

Both games are classic platform games and both share the same fundamental rules:

Running under macOS

The color of the sky is wrong on macOS. You need to flip some bytes from the last parameter of the program:

Regarding how to compile

The code requires SDL1.

The build process will generate some warnings (~60 with clang) about:

How it works

Parameters

  1. Window width.
  2. Window height.
  3. Level width.
  4. Level height.
  5. Sprites image width.
  6. Sprites image height.
  7. Filename of the sprites image (raw RGBA image).
  8. Filename of the music (WAVE 8000 Hz 8bit Mono).
  9. Sky color. This number depends on the system where you run the program. See note on macOS.

Sprites

The program read a single image that contains all the game sprites. The image must be a grid of 8xN sprites. The size of a single sprite must be square. The program calculates the size in this way:

    sprite_size = image_width / 8

Each sprite is identified by its position inside the grid, counting line by line, from left to right (for example sprite 0 is the top left sprite in the grid, sprite 8 is the first sprite of the second row of the grid etc.).

Some positions of the grid have a predefined purpose:

All the others sprites can be used as you want, depending on the game you want to create.

Levels

The program reads the level description from stdin.

The level description is a sequence of rows where each row describe an object. You can input as many objects as you want but the maximum number of objects handled by the program is 333. You can modify this value by editing the source here:

    C[333*7],d=333;

Each row has six columns:

  1. Screen X : x position of the object in the level.
  2. Screen Y : y position of the object in the level.
  3. Sprite : id of the sprite to be used for the object.
  4. CLASSFLAGS : a bitmask that describe how the object behaves.
  5. CLASSPARAM0: a parameter that depends on CLASSFLAGS.
  6. CLASSPARAM1: a parameter that depends on CLASSFLAGS.

CLASSFLAGS must be a combination (bitwise OR) of some of these constants:

If CLASSFLAGS is 0 the object only has an aesthetic function.

The last row of the level descriptor must have all its columns set equal to -1.

Limitations

Some classical features are missing: throwing objects, shooting, multiple lives, score tracking. You can add those features if you want!

The program allows only one level. It’s easy to add a menu and multiple levels but the size of the engine would too big for the contest.

When the Super character becomes bigger (ZOOM flag), the character can collide with blocks and get stuck inside them. This is a KNOWN BUG. When your player become bigger, stay away from blocks!

There’s only one audio track (game effects are missing).

Credits

Some of the sprites used in the examples are identical to those of the original games; the others were designed by me.

The music used in the examples have been resampled, starting from the original versions for the Commodore Amiga and Nintendo NES.

Super Mario Bros is a game created by Nintendo Co., Ltd. My use of the sprites does not intend to infringe the intellectual property of Nintendo but only demonstrates the operation of the program. From my point of view this is a tribute to the legendary game Super Mario Bros!

The Great Giana Sisters is the game created by Time Warp Productions and my justification for the sprites for Mario are the same for this game. Long live The Great Giana Sisters !! :)

Inventory for 2014/maffiodo1

Primary files

Secondary files


Jump to: top