NewI\O example3

example3.nio is animation demo of a small bar crossing the bottom of the screen.
It came fom an SDL tutorial website, but I have lost the link.

Here is a screenshot:

Here is the source code:

/******************************************************************************
 *
 *    example3.c
 *
 *    Copyright (C) 2005  Chris Nystrom
 *
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but without any warranty whatsoever.
 *
 *    For more license information see:
 *
 *      http://www.gnu.org/copyleft/gpl.html
 *
 *    Contact Author at:
 *
 *    Chris Nystrom
 *    11013 Prairie Dove Circle
 *    Austin, Texas  78758
 *
 *    E-Mail: cnystrom@gmail.com
 *    Blog:   http://conversazione.blogspot.com
 *    AIM:    nystromchris
 *
 *    Soli Deo Gloria
 *
 */

#include "nio_lib.h"

#define INC_FACTOR (1)

static color black;
static color white;
static int xi = 1;
static int font_num;
static int image_num;

void draw_screen(void)
{
        nio_clear_screen(black, FALSE);
        nio_print_at(0, 0, "\nEXAMPLE 3 version 0.01\n", FALSE);
        nio_draw_image(image_num, xi, 450, FALSE);
        nio_paint();
}

void example3_init(void)
{
        black = nio_get_color("black");
        white = nio_get_color("white");

        font_num = nio_load_sys_font(NIO_DEFAULT_FONT,
                                     NIO_DEFAULT_PTSIZE,
                                     NIO_STYLE_NORMAL, white, black);

        nio_term_init(font_num, black, 10, 10, 24, 80);

        nio_print_at(1, 0, "EXAMPLE 3 version 0.01", FALSE);

        nio_print_at(3, 0, "Loading image file...", FALSE);

        nio_paint();

        image_num = nio_load_image("bumper.bmp");
}

int main(int argc, char *argv[])
{
        bool f_exit = FALSE;
        int xinc = INC_FACTOR;

        nio_app_init("example3", "0.1");
//      nio_set_write_wait(1000);

        nio_set_screen(640, 480, black);

        example3_init();

        while (!f_exit) {
                int key;
                mouse_state ms;

                draw_screen();

                key = nio_get_key();
                ms = nio_mouse_click();

                if (ms.b1 || key == ESC) {
                        f_exit = TRUE;
                }

                xi += xinc;

                if (xi > 540) {
                        xinc = -(INC_FACTOR);
                }

                if (xi < 1) {
                        xinc = INC_FACTOR;
                }
        }

        nio_free_image(image_num);
        nio_free_font(font_num);
        nio_exit();
        exit(0);
}

You can download the source code here:

ftp://ftp.newio.org/pub/nio_apps/example3.0.009_004_020106.tar.gz


Updated: 01/25/06 ccn