home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD2.bin
/
bbs
/
dev
/
cmanual-3.0.lha
/
CManual
/
Graphics
/
Sprites
/
Example3.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-12
|
12KB
|
382 lines
/***********************************************************/
/* */
/* Amiga C Encyclopedia (ACE) V3.0 Amiga C Club (ACC) */
/* ------------------------------- ------------------ */
/* */
/* Book: ACM Graphics Amiga C Club */
/* Chapter: Sprites Tulevagen 22 */
/* File: Example3.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 program shows how to set up a 15 coloured sprite, and how to */
/* move it around. */
#include <intuition/intuition.h>
/* Include this file since you are using sprites: */
#include <graphics/sprite.h>
/* Declare the functions we are going to use: */
void main();
void free_memory();
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 Window structure: */
struct Window *my_window = NULL;
/* Declare and initialize your NewWindow structure: */
struct NewWindow my_new_window=
{
50, /* LeftEdge x position of the window. */
25, /* TopEdge y positio of the window. */
320, /* Width 320 pixels wide. */
100, /* Height 100 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 */
RAWKEY, /* user has selected the Close window gad, */
/* or if the user has pressed a key. */
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. */
"15-COLOURED SPRITE",/* Title Title of the window. */
NULL, /* Screen Connected to the Workbench Screen. */
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 */
300, /* MaxWidth than 300 x 200. */
200, /* MaxHeight */
WBENCHSCREEN /* Type Connected to the Workbench Screen. */
};
/********************************************************/
/* 1. Declare and initialize some sprite graphics data: */
/********************************************************/
/* Sprite Data for the Bottom Sprite: */
UWORD chip bottom_sprite_data[36]=
{
0x0000, 0x0000,
/* Bitplane */
/* ZERO ONE */
0x0000, 0x0000,
0xFFFF, 0x0000,
0x0000, 0xFFFF,
0xFFFF, 0xFFFF,
0x0000, 0x0000,
0xFFFF, 0x0000,
0x0000, 0xFFFF,
0xFFFF, 0xFFFF,
0x0000, 0x0000,
0xFFFF, 0x0000,
0x0000, 0xFFFF,
0xFFFF, 0xFFFF,
0x0000, 0x0000,
0xFFFF, 0x0000,
0x0000, 0xFFFF,
0xFFFF, 0xFFFF,
0x0000, 0x0000
};
/* Sprite Data for the Top Sprite: */
UWORD chip top_sprite_data[36]=
{
0x0000, SPRITE_ATTACHED, /* We attach the Top Sprite to the Bottom */
/* Sprite. */
/* Bitplane */
/* TWO THREE */
0x0000, 0x0000,
0x0000, 0x0000,
0x0000, 0x0000,
0x0000, 0x0000,
0xFFFF, 0x0000,
0xFFFF, 0x0000,
0xFFFF, 0x0000,
0xFFFF, 0x0000,
0x0000, 0xFFFF,
0x0000, 0xFFFF,
0x0000, 0xFFFF,
0x0000, 0xFFFF,
0xFFFF, 0xFFFF,
0xFFFF, 0xFFFF,
0xFFFF, 0xFFFF,
0xFFFF, 0xFFFF,
0x0000, 0x0000
};
/*********************************************************/
/* 2. Declare and initialize two SimpleSprite structure: */
/*********************************************************/
/* Bottom sprite: */
struct SimpleSprite bottom_sprite=
{
bottom_sprite_data, /* posctldata, pointer to the sprite data. */
16, /* height, 16 lines tall. */
40, 80, /* x, y, position on the screen. */
-1, /* num, this field is automatically initialized */
/* when you call the GetSprite() function, so */
/* we set it to -1 for the moment. */
};
/* Top sprite: */
struct SimpleSprite top_sprite=
{
top_sprite_data, /* posctldata, pointer to the sprite data. */
16, /* height, 16 lines tall. */
40, 80, /* x, y, position on the screen. */
-1, /* num, this field is automatically initialized */
/* when you call the GetSprite() function, so */
/* we set it to -1 for the moment. */
};
void main()
{
/* Sprite position: (We use only one pair of coordinates since the */
/* two sprites will be attached to each other.) */
WORD x = bottom_sprite.x;
WORD y = bottom_sprite.y;
/* Direction of the sprite: */
WORD x_direction = 0;
WORD y_direction = 0;
/* Boolean variable used for the while loop: */
BOOL close_me = FALSE;
ULONG class; /* IDCMP */
USHORT code; /* Code */
/* Declare a pointer to an IntuiMessage structure: */
struct IntuiMessage *my_message;
/* Open the Intuition Library: */
IntuitionBase = (struct IntuitionBase *)
OpenLibrary( "intuition.library", 0 );
if( IntuitionBase == NULL )
free_memory("Could NOT open the Intuition 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 )
free_memory("Could NOT open the Graphics Library!");
/* 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)
free_memory("Could NOT open the Window!");
/* Change the colour register 17 - 31: */
/* NOTE! Since we change colour register 17, 18 and 19 we will */
/* change the colour of Intuition's Pointer (Sprite 0). We do */
/* not bother about that in this Example but you should be */
/* careful with these three colour registers. */
SetRGB4( &my_window->WScreen->ViewPort, 17, 0x0, 0xF, 0x0 );
SetRGB4( &my_window->WScreen->ViewPort, 18, 0x0, 0xD, 0x0 );
SetRGB4( &my_window->WScreen->ViewPort, 19, 0x0, 0xB, 0x0 );
SetRGB4( &my_window->WScreen->ViewPort, 20, 0x0, 0x9, 0x0 );
SetRGB4( &my_window->WScreen->ViewPort, 21, 0x0, 0x7, 0x1 );
SetRGB4( &my_window->WScreen->ViewPort, 22, 0x0, 0x5, 0x3 );
SetRGB4( &my_window->WScreen->ViewPort, 23, 0x0, 0x3, 0x5 );
SetRGB4( &my_window->WScreen->ViewPort, 24, 0x1, 0x1, 0x7 );
SetRGB4( &my_window->WScreen->ViewPort, 25, 0x3, 0x0, 0x5 );
SetRGB4( &my_window->WScreen->ViewPort, 26, 0x5, 0x0, 0x3 );
SetRGB4( &my_window->WScreen->ViewPort, 27, 0x7, 0x0, 0x1 );
SetRGB4( &my_window->WScreen->ViewPort, 28, 0x9, 0x0, 0x0 );
SetRGB4( &my_window->WScreen->ViewPort, 29, 0xB, 0x0, 0x0 );
SetRGB4( &my_window->WScreen->ViewPort, 30, 0xD, 0x0, 0x0 );
SetRGB4( &my_window->WScreen->ViewPort, 31, 0xF, 0x0, 0x0 );
/* Reserve sprite 2 as Bottom Sprite: */
if( GetSprite( &bottom_spri