home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / SAT / myPlatform ƒ / sHMovPlatform.p < prev    next >
Encoding:
Text File  |  1993-09-19  |  2.7 KB  |  105 lines  |  [TEXT/PJMM]

  1. { Platform sprite, horizontally moving version (not faceless) }
  2.  
  3. unit sHMovPlatForm;
  4.  
  5. interface
  6.  
  7.     uses
  8.         SAT, sPlatForm, sMovPlatForm;
  9.  
  10.     procedure InitHMovPlatForm;
  11.     procedure SetupHMovPlatForm (me: SpritePtr);
  12.     procedure HandleHMovPlatForm (me: SpritePtr);
  13.     procedure HitHMovPlatForm (me, him: SpritePtr);
  14.  
  15. implementation
  16.  
  17.     procedure InitHMovPlatForm;
  18.         var
  19.             i: integer;
  20.     begin
  21. {PlatFace := GetFace(138); same as vertically moving version, we use the same!}
  22.     end;
  23.  
  24.     procedure SetupHMovPlatForm (me: SpritePtr);
  25.         var
  26.             r: Rect;
  27.             pol: PolyHandle;
  28.     begin
  29.         me^.speed.h := -1 + Rand(2) * 2;
  30.         me^.kind := -2; {Enemy kind}
  31.         me^.face := PlatFace;
  32.         SetRect(me^.hotRect, 0, 3, 60, 20);
  33.     end;
  34.  
  35.     procedure HandleHMovPlatForm (me: SpritePtr);
  36.     begin
  37.         me^.position.h := me^.position.h + me^.speed.h;
  38.         if me^.position.h < 40 then
  39.             me^.speed.h := 1;
  40.         if me^.position.h > offSizeH - 100 then
  41.             me^.speed.h := -1;
  42.  
  43. {Move!}
  44.         if me^.speed.h = 0 then
  45.             if me^.position.h > offSizeH div 2 then
  46.                 me^.speed.h := -1
  47.             else
  48.                 me^.speed.h := 1;
  49.  
  50.         me^.layer := -me^.position.v;
  51.     end;
  52.  
  53.     procedure HitHMovPlatForm;
  54.         var
  55.             mini, i, min: integer;
  56.             diff: array[1..4] of integer;
  57.     begin
  58.         if him^.Task <> @HandlePlatForm then  {check for HandleMovPlatForm too?}
  59.             begin
  60.                 diff[1] := -me^.hotRect2.top + (him^.hotRect2.bottom);{TtoB}
  61.                 diff[2] := -him^.hotRect2.top + (me^.hotRect2.bottom);{BtoT}
  62.                 diff[3] := -me^.hotRect2.left + (him^.hotRect2.right);{LtoR}
  63.                 diff[4] := -him^.hotRect2.left + (me^.hotRect2.right);{RtoL}
  64.                 mini := 0;
  65.                 min := 10000;
  66.                 for i := 1 to 4 do
  67.                     if min > diff[i] then
  68.                         begin
  69.                             min := diff[i];
  70.                             mini := i;
  71.                         end;
  72.                 case mini of
  73.                     1: {floor}
  74.                         begin
  75.                             him^.position.v := him^.position.v - diff[1] + 1;
  76.                             him^.position.h := him^.position.h + me^.speed.h; {or perhaps him^speed?}
  77.                             him^.kind := 10; {Signal to him, as if we used KindCollision}
  78.                             if him^.speed.v > 0 then
  79.                                 him^.speed.v := 0;
  80.                         end;
  81.                     2: {cieling}
  82.                         begin
  83.                             him^.position.v := him^.position.v + diff[2] + 1;{me^.position.v + 17}
  84. {No signal here}
  85.                             if him^.speed.v < 0 then
  86.                                 him^.speed.v := -him^.speed.v;
  87.                         end;
  88.                     3: {left}
  89.                         begin
  90.                             him^.position.h := him^.position.h - diff[3] - 1;
  91.                             him^.kind := 10; {Signal to him, as if we used KindCollision}
  92.                             if him^.speed.h > 0 then
  93.                                 him^.speed.h := -him^.speed.h;
  94.                         end;
  95.                     4: {right}
  96.                         begin
  97.                             him^.position.h := him^.position.h + diff[4] + 1;{me^.position.h + 100}
  98.                             him^.kind := 10; {Signal to him, as if we used KindCollision}
  99.                             if him^.speed.h < 0 then
  100.                                 him^.speed.h := -him^.speed.h;
  101.                         end;
  102.                 end;{case}
  103.             end; {if}
  104.     end; {HitHMovPlatForm}
  105. end.{of unit}