VgaGames4

VgaGames4 - film man-pages

[.. upper level ..]

# Film functions

A film consists of instructions, when to draw an image, where to put it, when to play sound ... dependend on film-loops. There are check-points, which define at which film-loop they begin. The instructions themself are relative to the check-points. For example - a film-loop takes 100 milliseconds - a check-point is defined to begin at the 80th film-loop, so after 8 seconds - a DRAW-instruction is positioned after this check-point, so it is valid from this check-point until to the next one - a SOUND-instruction is also positioned after this check-point, but has a VALID-subkey defined, which limits its validness additionally Instructions between check-points are executed simultaneously. See also the command: vg4 film -h

- Functions
- vg4->film->play()
  Play film.
- Environment variables
- VG_DUMP_ON_EXIT
  Whether dump film-data on exit, when calling VG_dest(): - 0: no - 1: yes, dump on stdout - 2: yes, dump on stderr

## Example

    example.c

    /* show a film */

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <sys/types.h>
    #include <unistd.h>
    #include <errno.h>
    #include <vgagames4.h>

    int main(int argc, char **argv) {
      struct VG_Rect rect;
      VG_BOOL filmskip;

      (void)argc; (void)argv;

      /* initialize and open window and audio */
      if (!VG_init("test")) { exit(1); }
      if (!vg4->window->open(VG_WINDOW_SIZE_LOW, VG_WINDOW_SCALE_BEST)) { VG_dest(); exit(1); }
      if (!vg4->audio->open(VG_AUDIO_FREQ_MEDIUM, VG_FALSE)) { VG_dest(); exit(1); }

      /* add multilanguage files */
      vg4->mlang->fb_locale("en");
      vg4->mlang->add("mlang");

      vg4->window->fill(VG_COLOR_BLUE);

      /* play film in a centered rectangle, allow skipping */
      rect.x = 30; rect.w = 260;
      rect.y = 20; rect.h = 160;
      vg4->film->play("film", &rect, &filmskip, NULL);
      if (filmskip) { printf("Film was skipped\n"); }

      /* destroy and exit */
      VG_dest();
      exit(0);
    }

    film/film

    [FILM RESOLUTION=260x160 FADEOUT=0 FLOOP=50]

    CP_START: 0

    # red and yellow sunnyboys moving, hitting and vanishing
    CP_SUNNYBOY_RED_START: CP_START
    CP_SUNNYBOY_YELLOW_START: CP_START + 30
    CP_SUNNYBOY_RED_YELLOW_HIT: CP_SUNNYBOY_YELLOW_START + 40
    CP_SUNNYBOY_RED_YELLOW_END: CP_SUNNYBOY_RED_YELLOW_HIT + 15

    # green sunnyboy moving
    CP_SUNNYBOY_GREEN_START: CP_START + 50
    CP_SUNNYBOY_GREEN_END: CP_SUNNYBOY_GREEN_START + 60

    film/sb-red.story

    [STORY DRAWLEVEL=1]

    CHECK: CP_SUNNYBOY_RED_START

    # red sunnyboy moves to its hit-position (160,80)
    DRAW:
      IMAGE: data/sb_red.bmp
      POSX: 160 * $percent / 100
      POSY: 80

    # red sunnyboy greets yellow sunnyboy
    DRAW:
      VALID: $percent -ge 80
      TEXT: data/hi.txt
      POSX: 160
      POSY: 60

    CHECK: CP_SUNNYBOY_RED_YELLOW_HIT

    # play hit-sound
    SOUND:
      VALID: $percent -eq 1
      FILE: data/hit.wav

    # red sunnyboy vanishes
    DRAW:
      IMAGE: data/sb_red.bmp
      POSX: 160
      POSY: 80
      BRIGHT: 100 - ($percent * 100 / 100)

    CHECK: CP_SUNNYBOY_RED_YELLOW_END

    film/data/hi.txt

    %{mlang[fgcolor=0xcc0000]: main:HI%}

    mlang/en/main/file.mlang

    [[HI]]
    Hi, Sunnyboy!

    film/sb-yellow.story

    [STORY DRAWLEVEL=1]

    CHECK: CP_SUNNYBOY_YELLOW_START

    # yellow sunnyboy moves to its hit-position (180,80)
    DRAW:
      IMAGE: data/sb_yellow.bmp
      POSX: 260 - (260 - 180) * $percent / 100
      POSY: 80

    CHECK: CP_SUNNYBOY_RED_YELLOW_HIT

    # yellow sunnyboy vanishes
    DRAW:
      IMAGE: data/sb_yellow.bmp
      POSX: 180
      POSY: 80
      BRIGHT: 100 - ($percent * 100 / 100)

    CHECK: CP_SUNNYBOY_RED_YELLOW_END

    film/sb-green.story

    [STORY DRAWLEVEL=1]

    CHECK: CP_SUNNYBOY_GREEN_START

    # green sunnyboy moves from top to botton
    DRAW:
      IMAGE: data/sb_green.bmp
      POSX: 100
      POSY: (160 + 32) * $percent / 100

    CHECK: CP_SUNNYBOY_GREEN_END

    film/music.story

    [STORY]

    CHECK: CP_START

    # play background-music
    MUSIC:
      FILE: data/music.wav
      PLAY: END

    # as music-playing will not end at end of its story, the end-checkpoint can be equal to the start-checkpoint
    CHECK: CP_START