NewI\O demo1
If you click the middle button it will clear the screen with a random color.
Dramatic background music should also be playing.
Right click to exit.
Here is a screenshot:
Here is the sourcecode:
You can download the source code here:
ftp://ftp.newio.org/pub/nio_apps/demo1.0.009_052b_020106.tar.gz
Updated: 01/25/06 ccn
/******************************************************************************
*
* demo1.c
*
* Copyright (C) 2004, 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 MAX_MODE (2)
int main(int argc, char *argv[])
{
int cls_flag = 1;
int font;
int mode = 0;
int mode_flag = 1;
color black, white;
nio_app_init("demo1", "0.1");
black = nio_get_color("black");
white = nio_get_color("white");
nio_set_screen(640, 480, black);
font = nio_load_sys_font(NIO_DEFAULT_FONT,
NIO_DEFAULT_PTSIZE,
NIO_STYLE_NORMAL, white, black);
nio_term_init(font, black, 10, 10, 34, 80);
nio_print_at(1, 1, "Downloading resources...", TRUE);
nio_load_music("demo1/Rome_Italy.ogg");
nio_clear_screen(black, TRUE);
nio_play_music(0);
while (1) {
int key, x, y;
mouse_state ms;
x = nio_rand_int(640);
y = nio_rand_int(480);
if (0 == mode) {
nio_draw_rectangle_rand(x, y, 10, 10, NO_ALPHA,
FILL, TRUE);
}
if (1 == mode) {
nio_draw_arc_rand(x, y, 10, NO_ALPHA, NO_FILL,
TRUE);
}
if (2 == mode) {
int x2, y2;
x2 = nio_rand_int(640);
y2 = nio_rand_int(480);
nio_draw_line_rand(x, y, x2, y2, NO_ALPHA, TRUE);
}
ms = nio_mouse_click();
key = nio_get_key();
if (ms.b1 || key == ENTER) {
if (mode_flag) {
mode++;
if (mode > MAX_MODE) {
mode = 0;
}
mode_flag = 0;
}
cls_flag = 1;
} else {
mode_flag = 1;
}
if (ms.b2 || key == SPACEBAR) {
if (cls_flag) {
nio_draw_rectangle_rand(0, 0, 640, 480,
NO_ALPHA, FILL,
TRUE);
cls_flag = 0;
}
mode_flag = 1;
} else {
cls_flag = 1;
}
if (ms.b3 || key == ESC) {
nio_stop_music();
nio_exit();
exit(0);
}
}
}
