VgaGames2
=========

Thematical index of functions (html-manuals)

Tutorials


>> OVERVIEW <<

VgaGames is a library created in C for UNIX-like OS
(tested with Linux, FreeBSD, OpenBSD, NetBSD)
for programming games with a resolution of 320x200 pixels (256 colors).
Distributed under the terms of GNU General Public Licence.

VgaGames comes with the intention to have as few dependencies as possible;
required is a graphic library and eventually a sound library (if using ALSA).

Graphical support:
 - svgalib for Linux
 - libvgl for FreeBSD
 - X window
Sound support:
 - OSS
 - ALSA (since version 0.9)
 - Sun audio
Network support
 - TCP and UDP
 - IPv4 and IPv6

Using the library

Although there are many functions, not all are essential.

Important are:
 - initializing (the first call)
 - creating a window
 - loading a bitmap
 - getting keystrokes
 - examinating keystrokes
 - clearing the window
 - copying a bitmap to the window
 - drawing s.th. to the window
 - flushing out the window
 - time delaying for having each game loop use the same time
 - closing the window

Here an example:

#include <stdlib.h>
#include <vgagames2.h>

int main(int argc, char ** argv) {
  bitmap * bmp;
  int x,y,color;

  /* first call: initialize vgagames, always pass argv[0] */
  if (vg_init_vgagames(argv[0],0,NULL) < 0) {exit(1);}

  /* creating window */
  if (vg_window_open("Some titlename",0,0) < 0) {exit(1);}

  /* load a bitmap */
  bmp=vg_bitmap_createfromfile("bitmaps/bmp.vga");
  if (bmp==NULL) {vg_window_close(); exit(1);}  // error

  /* program loop */
  for (;;) {

    /* get keystrokes */
    vg_key_update();

    /* examinate keystrokes: check for Space-key to leave the loop */
    if (vg_key_pressed(KEY_SPACE, SHORTKEY)) {break;}

    /* clear the window (not visible unless called vg_window_flush()) */
    vg_bitmap_clear(NULL, RGB_BLACK);  // bitmap NULL represents the window

    /* copy the bitmap bmp to the window at position x,y */
    x=10; y=10;
    vg_bitmap_copyto(NULL,x,y,bmp,0,0,0,0,RGB_FULL);

    /* draw a yellow line from 100,50 to 150,50 to the window */
    color=vg_color_index(CL_YELLOW,100);  // get index of current yellow color
    vg_draw_line(NULL,100,50,150,50,color);

    /* flush out the window (make it visible) */
    vg_window_flush();

    /* wait a time until 70 milliseconds for this loop have been reached */
    vg_wait_time(70);
  }  /* end of game loop */

  /* close the window */
  vg_window_close();
  exit(0);
}
To compile with: cc program.c `vgag2-config --cflags --libs` -o program Not really an exciting program. More questions appear: - can i use the mouse? yes, if it is found (see htmlman/index.html: Initializing, window-, key- and mouse-functions) - can i change the colormap? you can load another colormap and set the brightness of the current colors (see htmlman/index.html: color functions) - can i draw a text? yes, you can directly draw a text or create a bitmap with a text (see htmlman/vg_bitmap_createfromtext() and htmlman/vg_draw_text()) For multilanguage games, use htmlman/vg_get_textformat() - how can i modify an existing bitmap? there are several possibilities: - use drawing functions (see htmlman/index.html: drawing functions) - use bitmap functions, e.g. to rotate, zoom, mirror a bitmap (see htmlman/index.html: bitmap functions) With htmlman/vg_bitmap_overlap() you can check whether two bitmaps overlap on the window - are there animated bitmaps? yes, they are called sprites (see htmlman/index.html: sprite functions) - what else? - you can play a film (see htmlman/index.html: film functions) - you can of course play sound using a multichannel sound-server (see htmlman/index.html: sound functions) - you can use network (ipv4 and ipv6), + where one "master" does all the work + and many "clients" only get the object positions from the "master" to show them on the window and send keystrokes back to the "master" (see htmlman/index.html: network functions) - what about options? if you press in a running game the ESCAPE-key, you'll get to the VgaGames-system-menu. There you can change - X11 options (virtual size, fullscreen, ...) - mouse options (speed, if supported) - sound options (fragments, sample rate, mono/stereo, volume, ...) - the language (which must be supported by the game) The changed values are stored in "share/.vgag.rc" and are loaded again at the next start. Read the intro-*.html files at htmlman/ for more informations.