home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / pascal / anivga12 / example3.pas < prev    next >
Pascal/Delphi Source File  |  1993-07-11  |  3KB  |  98 lines

  1. {$A+,B-,D+,L+,N-,E-,O-,R-,S-,V-,G-,F-,I-,X-}
  2. {$M 16384,0,655360}
  3. PROGRAM Example3;
  4.  
  5. {Demonstrates usage of the Display_SHADOW and Display_SHADOWEXACT mode,     }
  6. {GetImage(), PutImage() and SetShadowTab() }
  7. {The same sprite is loaded twice (with different LOADnumbers) so that it can}
  8. {be used with different display modes. The shadow zone is done by redrawing }
  9. {the flower with display mode "Display_SHADOW" two pixels to the right and  }
  10. {below the flower drawn with display mode "Display_NORMAL"; note that the   }
  11. {outline of the shadow doesn't fully behave as wanted. To improve, one had  }
  12. {to use display mode Display_SHADOWEXACT, which you may do by pressing SPACE}
  13.  
  14. USES ANIVGA,CRT;
  15. CONST SpriteName='flower.COD';
  16.       Flower=10;
  17.       FlowerShadow=11;
  18.       brightness:BYTE=80;
  19.       ch:Char=#0;
  20. VAR i,j:Integer;
  21.     temp:BYTE;
  22.     p1:POINTER;
  23.  
  24. BEGIN
  25.  
  26.  IF (loadSprite(SpriteName,Flower)=0) OR     {load sprite 2x for different}
  27.     (loadSprite(SpriteName,FlowerShadow)=0)  {display modes!}
  28.   THEN BEGIN
  29.         WRITELN('Couldn''t access file '+SpriteName+' : '+GetErrorMessage);
  30.         halt(1)
  31.        END;
  32.  
  33.  SetModeByte(FlowerShadow,Display_SHADOW); {set mode of shadow sprite}
  34.  
  35.  SetShadowTab(brightness);
  36.  InitGraph;
  37.  
  38.  FOR i:=15 TO 78 DO
  39.   BEGIN {draw some colors on the screen}
  40.    Color:=i;
  41.    FOR j:=(i-15)*5 TO (i-15)*5+4 DO BackgroundLine(j,0,j,YMAX)
  42.   END;
  43.  
  44.  SpriteN[0]:=Flower; SpriteX[0]:=100; SpriteY[0]:=100;
  45.  {Use same flower for shadow zone:}
  46.  SpriteN[1]:=FlowerShadow;
  47.  SpriteX[1]:=SpriteX[0]+2; SpriteY[1]:=SpriteY[0]+2;
  48.  
  49.  Animate;
  50.  REPEAT
  51.   if keypressed
  52.    THEN BEGIN
  53.          while keypressed do ch:=upcase(readkey);
  54.          case ch of
  55.           ' ':BEGIN {toggle shadow mode}
  56.                temp:=GetModeByte(FlowerShadow);
  57.                IF temp=Display_SHADOW
  58.                 THEN SetModeByte(FlowerShadow,Display_SHADOWEXACT)
  59.                 ELSE SetModeByte(FlowerShadow,Display_SHADOW)
  60.               END;
  61.           'C':BEGIN
  62.                p1:=GetImage(0,0,50,30,1-PAGE);
  63.                PutImage(-10,-5,p1,BACKGNDPAGE);
  64.                PutImage(-11,60,p1,BACKGNDPAGE);
  65.                PutImage(-12,110,p1,BACKGNDPAGE);
  66.                PutImage(-13,180,p1,BACKGNDPAGE);
  67.                FreeImageMem(p1);
  68.               END;
  69.           'P':FOR i:=1 TO 1000 DO
  70.                BackgroundPutPixel(Random(XMAX+1),Random(YMAX+1),Random(256));
  71.           'I':BEGIN dec(SpriteY[0]); dec(SpriteY[1]) END;
  72.           'J':BEGIN dec(SpriteX[0]); dec(SpriteX[1]) END;
  73.           'K':BEGIN inc(SpriteX[0]); inc(SpriteX[1]) END;
  74.           'M':BEGIN inc(SpriteY[0]); inc(SpriteY[1]) END;
  75.           '+':IF brightness<100
  76.                THEN BEGIN
  77.                      inc(brightness); SetShadowTab(brightness)
  78.                     END
  79.                ELSE BEGIN
  80.                      sound(500); delay(100); nosound
  81.                     END;
  82.           '-':IF brightness>0
  83.                THEN BEGIN
  84.                      dec(brightness); SetShadowTab(brightness)
  85.                     END
  86.                ELSE BEGIN
  87.                      sound(500); delay(100); nosound
  88.                     END;
  89.          end;
  90.          if pos(ch,'PCIJKM+- ')>0 THEN Animate;
  91.         END;
  92.  
  93.  UNTIL (ch='Q') OR (ch=#27);
  94.  
  95.  CloseRoutines;
  96.  
  97. END.
  98.