home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l045 / 1.ddi / MOVEPOLY.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1987-12-23  |  4.4 KB  |  141 lines

  1.  
  2. {           Copyright (c) 1985, 87 by Borland International, Inc.            }
  3.  
  4. program MovePolygon;
  5.  
  6. {$I Float.inc}  { Determines what type Float means. }
  7.  
  8. uses
  9.   Dos, Crt, GDriver, GKernel, GWindow, GShell;
  10.  
  11. var
  12.   ArrowAngle : integer;
  13.   Ch : char;
  14.   Arrow : PlotArray;
  15.   CurrX, CurrY, IncrX, IncrY, Size, Speed : Float;
  16.   ArrowIncr : array[0..7, 1..2] of Float;
  17.  
  18. procedure MakeArrow;
  19. begin
  20.   Arrow[1, 1] := 0;                    { PlotArray init for the arrowhead }
  21.   Arrow[1, 2] := 0;
  22.   Arrow[2, 1] := Size;
  23.   Arrow[2, 2] := -Size;
  24.   Arrow[3, 1] := 0;
  25.   Arrow[3, 2] := Size;
  26.   Arrow[4, 1] := -Size;
  27.   Arrow[4, 2] := -Size;
  28.   Arrow[5, 1] := 0;
  29.   Arrow[5, 2] := 0;
  30. end; { MakeArrow }
  31.  
  32. procedure MakeMoveTable;
  33. begin
  34.   ArrowIncr[0, 1] := 0;                { Component velocities for radial moves }
  35.   ArrowIncr[0, 2] := 1;
  36.   ArrowIncr[1, 1] := -1;
  37.   ArrowIncr[1, 2] := 1;
  38.   ArrowIncr[2, 1] := -1;
  39.   ArrowIncr[2, 2] := 0;
  40.   ArrowIncr[3, 1] := -1;
  41.   ArrowIncr[3, 2] := -1;
  42.   ArrowIncr[4, 1] := 0;
  43.   ArrowIncr[4, 2] := -1;
  44.   ArrowIncr[5, 1] := 1;
  45.   ArrowIncr[5, 2] := -1;
  46.   ArrowIncr[6, 1] := 1;
  47.   ArrowIncr[6, 2] := 0;
  48.   ArrowIncr[7, 1] := 1;
  49.   ArrowIncr[7, 2] := 1;
  50. end; { MakeMoveTable }
  51.  
  52. procedure MoveForward;                 { Routine to move polygon forward }
  53. begin
  54.   SetColorBlack;                       { Draw over old polygon to erase it }
  55.   DrawPolygon(Arrow, 1, -5, 0, 0, 0);
  56.   CurrX := CurrX + IncrX;              { Move to new position }
  57.   CurrY := CurrY + IncrY;
  58.   TranslatePolygon(Arrow, 5, IncrX, IncrY);
  59.   SetColorWhite;                       { Draw polygon in new position }
  60.   DrawPolygon(Arrow, 1, -5, 0, 0, 0);
  61. end; { MoveForward }
  62.  
  63. procedure MoveBack;                    { Routine to move polygon back }
  64. begin
  65.   SetColorBlack;                       { Same as above }
  66.   DrawPolygon(Arrow, 1, -5, 0, 0, 0);
  67.   CurrX := CurrX - IncrX;
  68.   CurrY := CurrY - IncrY;
  69.   TranslatePolygon(Arrow, 5, -IncrX, -IncrY);
  70.   SetColorWhite;
  71.   DrawPolygon(Arrow, 1, -5, 0, 0, 0);
  72. end; { MoveBack }
  73.  
  74. procedure TurnLeft;                    { Rotate polygon counter-clockwise }
  75. begin
  76.   SetColorBlack;                       { Erase old polygon }
  77.   DrawPolygon(Arrow, 1, -5, 0, 0, 0);
  78.   RotatePolygon(Arrow, 5, 45);         { Rotate it 45 degrees }
  79.   ArrowAngle := ArrowAngle + 1;
  80.   if ArrowAngle > 7 then
  81.     ArrowAngle := 0;
  82.   IncrX := Speed * ArrowIncr[ArrowAngle, 1];  { Get new velocity }
  83.   Incry := Speed * ArrowIncr[ArrowAngle, 2];
  84.   SetColorWhite;                       { Draw rotated polygon }
  85.   DrawPolygon(Arrow, 1, -5, 0, 0, 0);
  86. end; { TurnLeft }
  87.  
  88. procedure TurnRight;                   { Rotate polygon clockwise }
  89. begin
  90.   SetColorBlack;                       { Same as above }
  91.   DrawPolygon(Arrow, 1, -5, 0, 0, 0);
  92.   RotatePolygon(Arrow, 5, -45);
  93.   ArrowAngle := ArrowAngle - 1;
  94.   if ArrowAngle < 0 then
  95.     ArrowAngle := 7;
  96.   IncrX := Speed * ArrowIncr[ArrowAngle, 1];
  97.   Incry := Speed * ArrowIncr[ArrowAngle, 2];
  98.   SetColorWhite;
  99.   DrawPolygon(Arrow, 1, -5, 0, 0, 0);
  100. end; { TurnRight }
  101.  
  102.  
  103. begin
  104.   InitGraphic;                         { Initialize the graphics system }
  105.  
  106.   DefineWindow(1, 0, 0, XMaxGlb, YMaxGlb);
  107.  
  108.   DefineWorld(1, -1000, -1000, 1000, 1000); { Give it a world coordinate system }
  109.  
  110.   SelectWorld(1);                      { Select its world }
  111.   SelectWindow(1);                     { Select window }
  112.   SetBackground(0);                    { Give it a black background }
  113.  
  114.   Size := 100;
  115.   Speed := 30;
  116.   CurrX := 0;
  117.   CurrY := 0;
  118.   ArrowAngle := 0;
  119.   IncrX := 0;
  120.   IncrY := Speed;
  121.  
  122.   MakeArrow;                           { Make the arrowhead }
  123.   MakeMoveTable;                       { Make the move table }
  124.   DrawPolygon(Arrow, 1, 5, 0, 0, 0);   { Draw it pointing up }
  125.  
  126.   repeat
  127.     Ch := ReadKey;                     { Read the keystroke }
  128.  
  129.     if (Ch = #0) and KeyPressed then   { Test for an extended scan code  }
  130.       Ch := ReadKey;                   { on either an IBM or Zenith Z100 }
  131.     case Ch of
  132.       'A', 'H' : MoveForward;          { Up arrow }
  133.       'D', 'K' : TurnLeft;             { Left arrow }
  134.       'C', 'M' : TurnRight;            { Right arrow }
  135.       'B', 'P' : MoveBack;             { Down arrow }
  136.     end;
  137.   until Ch = ' ';                      { Space character exits program }
  138.  
  139.   LeaveGraphic;                        { Leave the graphics system }
  140. end. { MovePolygon }
  141.