/*\r
- DEMO01 - Sprites, page flipping and palette rotation\r
- Copyright (c) 1994 Alessandro Scotti\r
+ DEMO01 - Sprites, page flipping and palette rotation\r
+ Copyright (c) 1994 Alessandro Scotti\r
*/\r
uses Crt, Modex;\r
\r
#DEFINE MAX_SPRITE 100\r
+\r
type\r
- (* Sprite structure *)\r
- TSprite = record\r
- X, Y : integer; (* Sprite coordinates *)\r
- DX,DY: integer; (* Deltas for sprite movement *)\r
- W, H : integer; (* Sprite width and height *)\r
- Image: array[ 1..16, 1..16 ] of byte; (* Sprite image data *)\r
- end;\r
- (* RGB color structure *)\r
- TRgb = record\r
- R, G, B: byte;\r
- end;\r
+ /* Sprite structure */\r
+ TSprite = record\r
+ X, Y : integer; /* Sprite coordinates */\r
+ DX,DY: integer; /* Deltas for sprite movement */\r
+ W, H : integer; /* Sprite width and height */\r
+ Image: array[ 1..16, 1..16 ] of byte; /* Sprite image data */\r
+ }\r
+ /* RGB color structure */\r
+ TRgb = record\r
+ R, G, B: byte;\r
+ }\r
var\r
- S : array[ 1..MAX_SPRITE ] of TSprite; (* An array of sprites *)\r
- Palette: array[ byte ] of TRgb; (* Palette *)\r
- Page : word; (* Page offset *)\r
- I : word;\r
+ S : array[ 1..MAX_SPRITE ] of TSprite; /* An array of sprites */\r
+ Palette: array[ byte ] of TRgb; /* Palette */\r
+ Page : word; /* Page offset */\r
+ I : word;\r
\r
-(* Initializes a sprite structure *)\r
+/* Initializes a sprite structure */\r
procedure sxInit( var S: TSprite );\r
var\r
- I: word;\r
+ I: word;\r
begin\r
- S.X := Random( 320 ); (* Initialize position with random values *)\r
- S.Y := Random( 240 );\r
- S.DX := Random( 7 )-3; (* Initialize speed with random values *)\r
- S.DY := Random( 7 )-3;\r
- S.W := 16; (* Size is fixed in this program *)\r
- S.H := 16;\r
- (* The image is a square with a hole inside *)\r
- FillChar( S.Image, SizeOf(S.Image), Random(15)+1 );\r
- for I:=5 to 12 do FillChar( S.Image[ I, 5 ], 8, 0 );\r
-end;\r
+ S.X := Random( 320 ); /* Initialize position with random values */\r
+ S.Y := Random( 240 );\r
+ S.DX := Random( 7 )-3; /* Initialize speed with random values */\r
+ S.DY := Random( 7 )-3;\r
+ S.W := 16; /* Size is fixed in this program */\r
+ S.H := 16;\r
+ /* The image is a square with a hole inside */\r
+ FillChar( S.Image, SizeOf(S.Image), Random(15)+1 );\r
+ for I:=5 to 12 do FillChar( S.Image[ I, 5 ], 8, 0 );\r
+}\r
\r
-(* Moves a sprite *)\r
+/* Moves a sprite */\r
procedure sxMove( var S: TSprite );\r
begin\r
- Inc( S.X, S.DX ); (* Get new position *)\r
- Inc( S.Y, S.DY );\r
- (* Check sprite position, change delta if needed *)\r
- if( S.X > 320 ) then begin\r
- S.X := 320;\r
- S.DX := -S.DX;\r
- end;\r
- if( S.X < -16 ) then begin\r
- S.X := -16;\r
- S.DX := -S.DX;\r
- end;\r
- if( S.Y > 240 ) then begin\r
- S.Y := 240;\r
- S.DY := -S.DY;\r
- end;\r
- if( S.Y < -16 ) then begin\r
- S.Y := -16;\r
- S.DY := -S.DY;\r
- end;\r
- (* Draw the sprite, note the Page offset added to the *)\r
- (* Y coordinate of the image *)\r
- mxPutImage( @S.Image, S.X, Page+S.Y, S.W, S.H, OP_TRANS );\r
-end;\r
+ Inc( S.X, S.DX ); /* Get new position */\r
+ Inc( S.Y, S.DY );\r
+ /* Check sprite position, change delta if needed */\r
+ if( S.X > 320 ) then begin\r
+ S.X := 320;\r
+ S.DX := -S.DX;\r
+ }\r
+ if( S.X < -16 ) then begin\r
+ S.X := -16;\r
+ S.DX := -S.DX;\r
+ }\r
+ if( S.Y > 240 ) then begin\r
+ S.Y := 240;\r
+ S.DY := -S.DY;\r
+ }\r
+ if( S.Y < -16 ) then begin\r
+ S.Y := -16;\r
+ S.DY := -S.DY;\r
+ }\r
+ /* Draw the sprite, note the Page offset added to the */\r
+ /* Y coordinate of the image */\r
+ mxPutImage( @S.Image, S.X, Page+S.Y, S.W, S.H, OP_TRANS );\r
+}\r
\r
-begin\r
- (* Initialize library *)\r
- mxInit;\r
+void main()\r
+{\r
+ int i;\r
+ /* Initialize library */\r
+ mxInit();\r
+\r
+ /* Enter graphics mode */\r
+ mxSetMode( MX_320x240 );\r
\r
- (* Enter graphics mode *)\r
- mxSetMode( MX_320x240 );\r
+ /* Print initialization message */\r
+ mxSetTextColor( 15, OP_TRANS );\r
+ mxOutStr( 4, 4, 'Initializing...' );\r
\r
- (* Print initialization message *)\r
- mxSetTextColor( 15, OP_TRANS );\r
- mxOutStr( 4, 4, 'Initializing...' );\r
+ /* Initialize sprites */\r
+ for(i=1;i<=MAX_SPRITE;i++)\r
+ sxInit( S[i] );\r
\r
- (* Initialize sprites *)\r
- for I:=1 to MAX_SPRITE do sxInit( S[I] );\r
+ /* Draw background */\r
+ for(i=1;i<=192;i++)\r
+ {\r
+ mxCircle( 160, 480+120, I, I+63 );\r
+ mxCircle( 161, 480+120, I, I+63 );\r
+ }\r
\r
- (* Draw background *)\r
- for I:=1 to 192 do begin\r
- mxCircle( 160, 480+120, I, I+63 );\r
- mxCircle( 161, 480+120, I, I+63 );\r
- end;\r
+ /* Compute and set palette */\r
+ for I:=1 to 192 do with Palette[I+63] do begin\r
+ R := 0;\r
+ G := 0;\r
+ B := 0;\r
+ if( I < 64 ) then\r
+ R := I shr 1+31\r
+ else if( i < 128 )\r
+ G := (I-64) shr 1+31\r
+ else\r
+ B := (I-128) shr 1+31;\r
+ }\r
+ mxSetPalette( @Palette[64], 64, 192 );\r
\r
- (* Compute and set palette *)\r
- for I:=1 to 192 do with Palette[I+63] do begin\r
- R := 0;\r
- G := 0;\r
- B := 0;\r
- if( I < 64 ) then\r
- R := I shr 1+31\r
- else if( I < 128 ) then\r
- G := (I-64) shr 1+31\r
- else\r
- B := (I-128) shr 1+31;\r
- end;\r
- mxSetPalette( @Palette[64], 64, 192 );\r
+ /* Main loop */\r
+ Page := 240;\r
+ while(!kbhit())\r
+ {\r
+ /* Set clip region to current page */\r
+ mxSetClipRegion( 0, Page, 320, 240 );\r
+ mxSetClip( TRUE );\r
+ /* Restore background */\r
+ mxBitBlt( 0, 480, 320, 240, 0, Page );\r
+ /* Draw sprites */\r
+ for I:=1 to MAX_SPRITE do sxMove( S[I] );\r
+ /* Print message */\r
+ mxOutStr( 4, Page+4, 'Some sprites moving...' );\r
+ /* Flip page */\r
+ mxStartLine( Page );\r
+ Page := 240-Page;\r
+ /* Animate palette */\r
+ mxSetPalette( @Palette[64], 64, 192 );\r
+ mxRotatePalette( @Palette[64], 192, 3 );\r
+ }\r
\r
- (* Main loop *)\r
- Page := 240;\r
- while( not KeyPressed ) do begin\r
- (* Set clip region to current page *)\r
- mxSetClipRegion( 0, Page, 320, 240 );\r
- mxSetClip( TRUE );\r
- (* Restore background *)\r
- mxBitBlt( 0, 480, 320, 240, 0, Page );\r
- (* Draw sprites *)\r
- for I:=1 to MAX_SPRITE do sxMove( S[I] );\r
- (* Print message *)\r
- mxOutStr( 4, Page+4, 'Some sprites moving...' );\r
- (* Flip page *)\r
- mxStartLine( Page );\r
- Page := 240-Page;\r
- (* Animate palette *)\r
- mxSetPalette( @Palette[64], 64, 192 );\r
- mxRotatePalette( @Palette[64], 192, 3 );\r
- end;\r
+ mxSetMode( MX_TEXT );\r
+ mxTerm;\r
\r
- mxSetMode( MX_TEXT );\r
- mxTerm;\r
-end.\r
+}\r