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 X, Y : integer; (* Sprite coordinates *)
\r
12 DX,DY: integer; (* Deltas for sprite movement *)
\r
13 W, H : integer; (* Sprite width and height *)
\r
14 Image: array[ 1..16, 1..16 ] of byte; (* Sprite image data *)
\r
16 (* RGB color structure *)
\r
21 S : array[ 1..MAX_SPRITE ] of TSprite; (* An array of sprites *)
\r
22 Palette: array[ byte ] of TRgb; (* Palette *)
\r
23 Page : word; (* Page offset *)
\r
26 (* Initializes a sprite structure *)
\r
27 procedure sxInit( var S: TSprite );
\r
31 S.X := Random( 320 ); (* Initialize position with random values *)
\r
32 S.Y := Random( 240 );
\r
33 S.DX := Random( 7 )-3; (* Initialize speed with random values *)
\r
34 S.DY := Random( 7 )-3;
\r
35 S.W := 16; (* Size is fixed in this program *)
\r
37 (* The image is a square with a hole inside *)
\r
38 FillChar( S.Image, SizeOf(S.Image), Random(15)+1 );
\r
39 for I:=5 to 12 do FillChar( S.Image[ I, 5 ], 8, 0 );
\r
42 (* Moves a sprite *)
\r
43 procedure sxMove( var S: TSprite );
\r
45 Inc( S.X, S.DX ); (* Get new position *)
\r
47 (* Check sprite position, change delta if needed *)
\r
48 if( S.X > 320 ) then begin
\r
52 if( S.X < -16 ) then begin
\r
56 if( S.Y > 240 ) then begin
\r
60 if( S.Y < -16 ) then begin
\r
64 (* Draw the sprite, note the Page offset added to the *)
\r
65 (* Y coordinate of the image *)
\r
66 mxPutImage( @S.Image, S.X, Page+S.Y, S.W, S.H, OP_TRANS );
\r
70 (* Initialize library *)
\r
73 (* Enter graphics mode *)
\r
74 mxSetMode( MX_320x240 );
\r
76 (* Print initialization message *)
\r
77 mxSetTextColor( 15, OP_TRANS );
\r
78 mxOutStr( 4, 4, 'Initializing...' );
\r
80 (* Initialize sprites *)
\r
81 for I:=1 to MAX_SPRITE do sxInit( S[I] );
\r
83 (* Draw background *)
\r
84 for I:=1 to 192 do begin
\r
85 mxCircle( 160, 480+120, I, I+63 );
\r
86 mxCircle( 161, 480+120, I, I+63 );
\r
89 (* Compute and set palette *)
\r
90 for I:=1 to 192 do with Palette[I+63] do begin
\r
96 else if( I < 128 ) then
\r
97 G := (I-64) shr 1+31
\r
99 B := (I-128) shr 1+31;
\r
101 mxSetPalette( @Palette[64], 64, 192 );
\r
105 while( not KeyPressed ) do begin
\r
106 (* Set clip region to current page *)
\r
107 mxSetClipRegion( 0, Page, 320, 240 );
\r
109 (* Restore background *)
\r
110 mxBitBlt( 0, 480, 320, 240, 0, Page );
\r
112 for I:=1 to MAX_SPRITE do sxMove( S[I] );
\r
113 (* Print message *)
\r
114 mxOutStr( 4, Page+4, 'Some sprites moving...' );
\r
116 mxStartLine( Page );
\r
118 (* Animate palette *)
\r
119 mxSetPalette( @Palette[64], 64, 192 );
\r
120 mxRotatePalette( @Palette[64], 192, 3 );
\r
123 mxSetMode( MX_TEXT );
\r