2 DEMO01 - Sprites, page flipping and palette rotation
\r
3 Copyright (c) 1994 Alessandro Scotti
\r
10 (* Sprite structure *)
\r
12 X, Y : integer; (* Sprite coordinates *)
\r
13 DX,DY: integer; (* Deltas for sprite movement *)
\r
14 W, H : integer; (* Sprite width and height *)
\r
15 Image: array[ 1..16, 1..16 ] of byte; (* 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
71 (* Initialize library *)
\r
74 (* Enter graphics mode *)
\r
75 mxSetMode( MX_320x240 );
\r
77 (* Print initialization message *)
\r
78 mxSetTextColor( 15, OP_TRANS );
\r
79 mxOutStr( 4, 4, 'Initializing...' );
\r
81 (* Initialize sprites *)
\r
82 for I:=1 to MAX_SPRITE do sxInit( S[I] );
\r
84 (* Draw background *)
\r
85 for I:=1 to 192 do begin
\r
86 mxCircle( 160, 480+120, I, I+63 );
\r
87 mxCircle( 161, 480+120, I, I+63 );
\r
90 (* Compute and set palette *)
\r
91 for I:=1 to 192 do with Palette[I+63] do begin
\r
97 else if( I < 128 ) then
\r
98 G := (I-64) shr 1+31
\r
100 B := (I-128) shr 1+31;
\r
102 mxSetPalette( @Palette[64], 64, 192 );
\r
106 while( not KeyPressed ) do begin
\r
107 (* Set clip region to current page *)
\r
108 mxSetClipRegion( 0, Page, 320, 240 );
\r
110 (* Restore background *)
\r
111 mxBitBlt( 0, 480, 320, 240, 0, Page );
\r
113 for I:=1 to MAX_SPRITE do sxMove( S[I] );
\r
114 (* Print message *)
\r
115 mxOutStr( 4, Page+4, 'Some sprites moving...' );
\r
117 mxStartLine( Page );
\r
119 (* Animate palette *)
\r
120 mxSetPalette( @Palette[64], 64, 192 );
\r
121 mxRotatePalette( @Palette[64], 192, 3 );
\r
124 mxSetMode( MX_TEXT );
\r