home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD2.bin
/
bbs
/
dev
/
cmanual-3.0.lha
/
CManual
/
Graphics
/
VSprites
/
Example2.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-12
|
11KB
|
356 lines
/***********************************************************/
/* */
/* Amiga C Encyclopedia (ACE) V3.0 Amiga C Club (ACC) */
/* ------------------------------- ------------------ */
/* */
/* Book: ACM Graphics Amiga C Club */
/* Chapter: VSprites Tulevagen 22 */
/* File: Example2.c 181 41 LIDINGO */
/* Author: Anders Bjerin SWEDEN */
/* Date: 92-04-28 */
/* Version: 1.00 */
/* */
/* Copyright 1992, Anders Bjerin - Amiga C Club (ACC) */
/* */
/* Registered members may use this program freely in their */
/* own commercial/noncommercial programs/articles. */
/* */
/***********************************************************/
/* This example demonstrates how to use several VSprites */
/* each with its own colour table. */
/* Since we use Intuition, include this file: */
#include <intuition/intuition.h>
/* Include this file since you are using sprites: */
#include <graphics/gels.h>
/* We will use 15 VSprites: */
#define MAXVSPRITES 15
/* They will move two pixels each time: */
#define SPEED 2
/* Declare the functions we are going to use: */
void main();
void clean_up();
struct IntuitionBase *IntuitionBase = NULL;
/* We need to open the Graphics library since we are using sprites: */
struct GfxBase *GfxBase = NULL;
/* Declare a pointer to a Screen structure: */
struct Screen *my_screen;
/* Declare and initialize your NewScreen structure: */
struct NewScreen my_new_screen=
{
0, /* LeftEdge Should always be 0. */
0, /* TopEdge Top of the display.*/
320, /* Width We are using a low-resolution screen. */
200, /* Height Non-Interlaced NTSC (American) display. */
2, /* Depth 4 colours. */
0, /* DetailPen Text should be drawn with colour reg. 0 */
1, /* BlockPen Blocks should be drawn with colour reg. 1 */
SPRITES, /* ViewModes No special modes. (Low-res, Non-Interlaced) */
CUSTOMSCREEN, /* Type Your own customized screen. */
NULL, /* Font Default font. */
"MY SCREEN", /* Title The screen' title. */
NULL, /* Gadget Must for the moment be NULL. */
NULL /* BitMap No special CustomBitMap. */
};
/* Declare a pointer to a Window structure: */
struct Window *my_window = NULL;
/* Declare and initialize your NewWindow structure: */
struct NewWindow my_new_window=
{
0, /* LeftEdge x position of the window. */
0, /* TopEdge y positio of the window. */
320, /* Width 320 pixels wide. */
200, /* Height 200 lines high. */
0, /* DetailPen Text should be drawn with colour reg. 0 */
1, /* BlockPen Blocks should be drawn with colour reg. 1 */
CLOSEWINDOW, /* IDCMPFlags The window will give us a message if the */
/* user has selected the Close window gad. */
SMART_REFRESH| /* Flags Intuition should refresh the window. */
WINDOWCLOSE| /* Close Gadget. */
WINDOWDRAG| /* Drag gadget. */
WINDOWDEPTH| /* Depth arrange Gadgets. */
WINDOWSIZING| /* Sizing Gadget. */
ACTIVATE, /* The window should be Active when opened. */
NULL, /* FirstGadget No Custom gadgets. */
NULL, /* CheckMark Use Intuition's default CheckMark. */
"VSprites are great!", /* Title */
NULL, /* Screen Will later be connected to a custom scr. */
NULL, /* BitMap No Custom BitMap. */
80, /* MinWidth We will not allow the window to become */
30, /* MinHeight smaller than 80 x 30, and not bigger */
320, /* MaxWidth than 320 x 200. */
200, /* MaxHeight */
CUSTOMSCREEN /* Type Connected to the Workbench Screen. */
};
/* 1. Declare and initialize some sprite data: */
UWORD chip vsprite_data[]=
{
0x0180, 0x0000,
0x03C0, 0x0000,
0x07E0, 0x0000,
0x0FF0, 0x0000,
0x1FF8, 0x0000,
0x3FFC, 0x0000,
0x7FFE, 0x0000,
0x0000, 0xFFFF,
0x0000, 0xFFFF,
0x7FFE, 0x7FFE,
0x3FFC, 0x3FFC,
0x1FF8, 0x1FF8,
0x0FF0, 0x0FF0,
0x07E0, 0x07E0,
0x03C0, 0x03C0,
0x0180, 0x0180,
};
/* 2. Declare three VSprite structures. One will be used, */
/* the other two are "dummies": */
struct VSprite head, tail, vsprite[ MAXVSPRITES ];
/* 3. Declare the VSprites' colour tables: */
WORD colour_table[ MAXVSPRITES ][ 3 ];
/* 4. Declare a GelsInfo structure: */
struct GelsInfo ginfo;
/* This boolean variable will tell us if the VSprites are */
/* in the list or not: */
BOOL vsprite_on = FALSE;
/* This program will not open any console window if run from */
/* Workbench, but we must therefore not print anything. */
/* Functions like printf() must therefore not be used. */
void _main()
{
/* The GelsInfo structure needs the following arrays: */
WORD nextline[ 8 ];
WORD *lastcolor[ 8 ];
/* Direction of the sprite: */
WORD x_direction[ MAXVSPRITES ];
WORD y_direction[ MAXVSPRITES ];
/* Boolean variable used for the while loop: */
BOOL close_me = FALSE;
/* Declare a pointer to an IntuiMessage structure: */
struct IntuiMessage *my_message;
/* Used as counter in the for loop: */
UBYTE loop;
/* Open the Intuition Library: */
IntuitionBase = (struct IntuitionBase *)
OpenLibrary( "intuition.library", 0 );
if( IntuitionBase == NULL )
clean_up(); /* Could NOT open the Intuition Library! */
/* 5. Open the Graphics Library: */
/* Since we are using sprites we need to open the Graphics Library: */
/* Open the Graphics Library: */
GfxBase = (struct GfxBase *)
OpenLibrary( "graphics.library", 0);
if( GfxBase == NULL )
clean_up(); /* Could NOT open the Graphics Library! */
/* We will now try to open the screen: */
my_screen = (struct Screen *) OpenScreen( &my_new_screen );
/* Have we opened the screen succesfully? */
if(my_screen == NULL)
clean_up();
my_new_window.Screen = my_screen;
/* We will now try to open the window: */
my_window = (struct Window *) OpenWindow( &my_new_window );
/* Have we opened the window succesfully? */
if(my_window == NULL)
clean_up(); /* Could NOT open the Window! */
/* 6. Initialize the GelsInfo structure: */
/* All sprites except the first two may be used to draw */
/* the VSprites: ( 11111100 = 0xFC ) */
ginfo.sprRsrvd = 0xFC;
/* If we do not exclude the first two sprites, the mouse */
/* pointer's colours may be affected. */
/* Give the GelsInfo structure some memory: */
ginfo.nextLine = nextline;
ginfo.lastColor = lastcolor;
/* Give the Rastport a pointer to the GelsInfo structure: */
my_window->RPort->GelsInfo = &ginfo;
/* Give the GelsInfo structure to the system: */
InitGels( &head, &tail, &ginfo );
/* 7. Initialize the VSprite structures: */
/* Set a random seed: */
srand( 64 );
for( loop = 0; loop < MAXVSPRITES; loop++ )
{
/* Set the VSprite's colours: */
colour_table[ loop ][ 0 ] = loop; /* Blue */
colour_table[ loop ][ 1 ] = loop << 4; /* Green */
colour_table[ loop ][ 2 ] = loop << 8; /* Red */
/* Set the speed and direction of the VSprite: */
x_direction[ loop ] = SPEED;
y_direction[ loop ] = -SPEED;
vsprite[ loop ].Flags = VSPRITE; /* It is a VSprite. */
vsprite[ loop ].X = 10 + 20 * loop; /* X position. */
vsprite[ loop ].Y = 10 + 20 * loop; /* Y position. */
vsprite[