home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / SAT / myPlatform ƒ / sPlatform.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-21  |  2.4 KB  |  99 lines  |  [TEXT/KAHL]

  1. /* Platform sprite, experimental faceless sprite */
  2.  
  3. #include "SAT.h"
  4. #include "myPlatform.h"
  5.  
  6. void InitPlatform()
  7. {
  8. /* nada*/
  9. }
  10.  
  11. pascal void SetupPlatform(SpritePtr me)
  12. {
  13.     Rect            r;
  14.     PolyHandle    pol;
  15.     
  16.     me->face = nil; /* = faceless! */
  17.     SetRect(&(me->hotrect), 0, 0, 100, 16);
  18.     r = me->hotrect;
  19.     OffsetRect(&r, me->position.h, me->position.v);
  20.     SetPort(backScreen); /* or SATSetPortBackScreen if in a hurry*/
  21.     FillRect(&r, dkGray);
  22.  
  23.     pol = OpenPoly();
  24.     MoveTo(r.left, r.top);
  25.     LineTo(r.left + 5, r.top - 5);
  26.     LineTo(r.right + 5, r.top - 5);
  27.     LineTo(r.right, r.top);
  28.     LineTo(r.left, r.top);
  29.     LineTo(r.right, r.top);
  30.  
  31.     LineTo(r.right, r.bottom);
  32.     LineTo(r.right + 5, r.bottom - 5);
  33.     LineTo(r.right + 5, r.top - 5);
  34.     LineTo(r.right, r.top);
  35.  
  36.     ClosePoly();
  37.     ErasePoly(pol);
  38.     FramePoly(pol);
  39.     KillPoly(pol);
  40.  
  41.     r.top = r.top - 5;
  42.     r.right = r.right + 5;
  43.     SATBackChanged(r); /* Tell SAT to draw it when appropriate */
  44.  
  45.     me->layer = -me->position.v;
  46. }
  47.  
  48. pascal void HandlePlatform(SpritePtr me)
  49. {
  50.     /*me->face = nil;*/ 
  51. }
  52.  
  53. pascal void HitPlatform(SpritePtr me, SpritePtr him)
  54. {
  55.     int    mini, i, min;
  56.     int    diff[5];
  57.     
  58.     if (him->task != HandlePlatform){
  59.         diff[1] = -me->hotrect2.top + (him->hotrect2.bottom);        /* TtoB */
  60.         diff[2] = -him->hotrect2.top + (me->hotrect2.bottom);         /* BtoT */
  61.         diff[3] = -me->hotrect2.left + (him->hotrect2.right);        /* LtoR */
  62.         diff[4] = -him->hotrect2.left + (me->hotrect2.right);        /* RtoL */
  63.         mini = 0;
  64.         min = 10000;
  65.         for(i = 1; i <= 4 ; i++){
  66.             if(min > diff[i]){
  67.                 min = diff[i];
  68.                 mini = i;
  69.             } /* if */
  70.         }
  71.         switch(mini){
  72.             case 1: /*floor*/
  73.                     him->position.v = him->position.v - diff[1] + 1; 
  74.                     him->kind = 10; /* Signal to him, as if we used KindCollision */
  75.                     if(him->speed.v > 0)
  76.                         him->speed.v = 0;
  77.                     break;
  78.             case 2: /* ceiling */
  79.                     him->position.v = him->position.v + diff[2] + 1;
  80. /*We don't signal here. A hit in the ceiling should just send him back down again.*/
  81.                     if(him->speed.v < 0)
  82.                         him->speed.v = -him->speed.v;
  83.                     break;
  84.             case 3: /*left*/
  85.                     him->position.h = him->position.h - diff[3] - 1;
  86.                     him->kind = 10;  /* Signal to him, as if we used KindCollision */
  87.                     if(him->speed.h > 0)
  88.                         him->speed.h = -him->speed.h;
  89.                     break;
  90.             case 4: /*right*/
  91.                     him->position.h = him->position.h + diff[4] + 1;
  92.                     him->kind = 10;  /* Signal to him, as if we used KindCollision */
  93.                     if(him->speed.h < 0)
  94.                         him->speed.h = -him->speed.h;
  95.                     break;
  96.         } /* switch */
  97.     }
  98. }
  99.