2 DEMO01 - Sprites, page flipping and palette rotation
\r
3 Copyright (c) 1994 Alessandro Scotti
\r
7 #DEFINE MAX_SPRITE 100
\r
9 /* Sprite structure */
\r
11 int X, Y; /* Sprite coordinates */
\r
12 int DX,DY; /* Deltas for sprite movement */
\r
13 int W, H; /* Sprite width and height */
\r
14 unsigned char Image[16,16]; /* Sprite image data */
\r
17 /* RGB color structure */
\r
22 S : array[ 1..MAX_SPRITE ] of TSprite; /* An array of sprites */
\r
23 Palette: array[ byte ] of TRgb; /* Palette */
\r
24 Page : word; /* Page offset */
\r
27 /* Initializes a sprite structure */
\r
28 procedure sxInit( var S: TSprite );
\r
32 S.X = Random( 320 ); /* Initialize position with random values */
\r
33 S.Y = Random( 240 );
\r
34 S.DX = Random( 7 )-3; /* Initialize speed with random values */
\r
35 S.DY = Random( 7 )-3;
\r
36 S.W = 16; /* Size is fixed in this program */
\r
38 /* The image is a square with a hole inside */
\r
39 FillChar( S.Image, SizeOf(S.Image), Random(15)+1 );
\r
40 for I=5 to 12 do FillChar( S.Image[ I, 5 ], 8, 0 );
\r
43 /* Moves a sprite */
\r
44 procedure sxMove( var S: TSprite );
\r
46 Inc( S.X, S.DX ); /* Get new position */
\r
48 /* Check sprite position, change delta if needed */
\r
49 if( S.X > 320 ) then begin
\r
53 if( S.X < -16 ) then begin
\r
57 if( S.Y > 240 ) then begin
\r
61 if( S.Y < -16 ) then begin
\r
65 /* Draw the sprite, note the Page offset added to the */
\r
66 /* Y coordinate of the image */
\r
67 mxPutImage( @S.Image, S.X, Page+S.Y, S.W, S.H, OP_TRANS );
\r
73 /* Initialize library */
\r
76 /* Enter graphics mode */
\r
77 mxSetMode( MX_320x240 );
\r
79 /* Print initialization message */
\r
80 mxSetTextColor( 15, OP_TRANS );
\r
81 mxOutStr( 4, 4, 'Initializing...' );
\r
83 /* Initialize sprites */
\r
84 for(i=1;i<=MAX_SPRITE;i++)
\r
87 /* Draw background */
\r
90 mxCircle( 160, 480+120, I, I+63 );
\r
91 mxCircle( 161, 480+120, I, I+63 );
\r
94 /* Compute and set palette */
\r
95 for(i=1;i<= 192;Palette[i+63])
\r
103 G = (i-64) shr 1+31
\r
105 B = (i-128) shr 1+31;
\r
107 mxSetPalette( @Palette[64], 64, 192 );
\r
113 /* Set clip region to current page */
\r
114 mxSetClipRegion( 0, Page, 320, 240 );
\r
116 /* Restore background */
\r
117 mxBitBlt( 0, 480, 320, 240, 0, Page );
\r
119 for(i=1; i <= MAX_SPRITE; sxMove( S[i] ));
\r
120 /* Print message */
\r
121 mxOutStr( 4, Page+4, 'Some sprites moving...' );
\r
123 mxStartLine( Page );
\r
125 /* Animate palette */
\r
126 mxSetPalette( @Palette[64], 64, 192 );
\r
127 mxRotatePalette( @Palette[64], 192, 3 );
\r
130 mxSetMode( MX_TEXT );
\r