home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / ANIVGA.ZIP / EXAMPLE3.PAS < prev    next >
Pascal/Delphi Source File  |  1992-08-17  |  3KB  |  96 lines

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