Main Page | Data Structures | File List | Data Fields | Globals

ex4.c

00001 /*=========================================================================
00002 
00003 GFX EXAMPLE CODE - #4
00004         "moving sprites"
00005 
00006 Copyright (C) 2004  Rafael de Oliveira Jannone
00007 
00008 This example's source code is Public Domain.
00009 
00010 WARNING: The author makes no guarantees and holds no responsibility for 
00011 any damage, injury or loss that may result from the use of this source 
00012 code. USE IT AT YOUR OWN RISK.
00013 
00014 Contact the author:
00015         by e-mail : rafael AT jannone DOT org
00016         homepage  : http://jannone.org/gfxlib
00017         ICQ UIN   : 10115284
00018 
00019 =========================================================================*/
00020 
00021 #include <stdio.h>
00022 #include <math.h>
00023 #include "gfx.h"
00024 
00025 typedef struct {
00026         int x;
00027         int y;
00028 } point_t;
00029 
00030 #define MAX_POINT       256
00031 
00032 main() {
00033         double  M_PI;
00034         double  a;
00035         int     c, i, l;
00036         point_t p[MAX_POINT];
00037 
00038         printf("calculating, wait...");
00039 
00040         M_PI = 8.0 * atan(1.0);
00041 
00042         // precalculate trajetory
00043         for (c = 0; c < MAX_POINT; c++) {
00044                 a = (M_PI * (double)c) / (double)MAX_POINT;
00045                 p[c].x = ((int)(100.0 * cos(a))) + (128 - 8);
00046                 p[c].y = ((int)(80.0 * sin(a))) + (96 - 8);
00047 
00048                 if (c & 8)
00049                         putch('.');
00050         }
00051         printf("done!\n");
00052         
00053         // set graphic screen
00054         set_color(15, 1, 1);
00055         set_mode(mode_2);
00056         set_sprite_mode(sprite_large);
00057 
00058         fill(MODE2_ATTR, 0xF1, MODE2_MAX);
00059 
00060         // create one sprite with a shape from the character table
00061         set_sprite_16(0, (void*)(0x1BBF + 8));
00062 
00063         while (!get_trigger(0)) 
00064                 for (c = 0; c < MAX_POINT; c++) { // for each starting point
00065                         for (i = 0; i < 8; i++) { // set location for the 8 sprites contiguously
00066                                 l = (c + (i << 4)) % MAX_POINT;
00067                                 put_sprite_16(i, p[l].x, p[l].y, 0, i + 2);
00068                         }
00069                 }
00070 
00071         set_mode(mode_0);
00072 }

Generated on Thu Mar 3 19:55:01 2005 for GFX lib by  doxygen 1.4.1