Z88DK - Game Programming Library Functions


One of the aims of z88dk is to create a cross-platform API for producing games. This enables a game to be written once and then ported over to multiple platforms with a quick recompile. The library provides a variety of functions, such as a standard method of accessing joysticks, drawing sprites, producing sound effects and playing music. Example programs using many of the routines listed here are supplied with z88dk.

#include <games.h>

unsigned char joystick(int game_device);

joystick() returns the result of a scan of the gaming device. The value returned is a logical or of the following:

#define MOVE_RIGHT 1
#define MOVE_LEFT  2
#define MOVE_DOWN  4
#define MOVE_UP    8
#define MOVE_FIRE  16
#define MOVE_FIRE2 32
#define MOVE_FIRE3 64
#define MOVE_FIRE4 128

The header file provides a char *[] with a descriptive choice of the input devices available for the machine target. The program should present these to the user. There will be GAME_DEVICES number of different input options available for each machine type.

void putsprite(int ortype, int x, int y, void *sprite);

getsprite() permits the placement of variable width and height sprites on to the display. ortype should be one of the following SPR_AND, SPR_OR, SPR_XOR, SPR_MASK. SPR_AND/SPR_MASK `ands' the sprite into the existing display. SPR_OR 'ors' the sprite, and SPR_XOR 'xors' the sprite. Normal sprites are usually displayed using SPR_OR. However if you are using masked sprites then SPR_MASK should be used for the mask and then SPR_OR for the actual sprite.

void bksave(int x, int y, void *sprite);
void bkrestore(void *sprite);

These routines permit the saving and restoring of a sprite background.

#include <sound.h>

void bit_fx(int effect);
Plays a sound effect where 0 <= effect <= 7.

void bit_beep(int duration, int period);
Plays a single note. The parameters are the same as for the ZX Spectrum ROM3 beeper routine.
void bit_play(char *melody);

This routine is similar to the BASIC PLAY commands found on the Spectrum 128 and MSX computers. Plays a tune using the standard mnemonics: CDEFGAB. A number following affects the length of the note. + and  - raise and lower the pitch of the following notes an octave.

void bit_frequency(double duration, double frequency);

bit_frequency() plays a note of frequency (in Hertz) for a time of duration seconds.


z88dk /games_library.html
Last Updated 20/1/2002 dom