home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 138.lha / Cycle / dobikes.c < prev    next >
C/C++ Source or Header  |  1986-11-20  |  3KB  |  126 lines

  1. /*
  2.  * This code is for moving the cycles around on the screen and
  3.  * updating their status at intervals
  4.  */
  5. #include "cycles.h"
  6.  
  7. extern long xdir[],ydir[];
  8. extern long num_players;
  9. extern long num_waiting;
  10. extern long num_alive;
  11.  
  12. long ties;
  13.  
  14. move_cycles(list)
  15. LIST *list;
  16. {
  17.   register CYCLE *c,*c2;
  18.   long na;
  19.  
  20.   na = num_alive;
  21.   c  = (CYCLE *)list->lh_Head;
  22.   if (c->node.ln_Succ) {     /* rotate the list so that    */
  23.        Remove(c);            /* each cycle gets a turn     */
  24.        AddTail(list,c);      /* at first reply             */
  25.   }
  26.   c = (CYCLE *)list->lh_Head;
  27.  
  28.   while(c2 = (CYCLE *)c->node.ln_Succ) {
  29.     switch(c->status) {
  30.  
  31.     case STATUS_GOT_MOVE:
  32.     case STATUS_NEED_NEW:
  33.       link_pix(c->colour,c->x,c->y,c->dir);
  34.       c->x += xdir[c->dir];
  35.       c->y += ydir[c->dir];
  36.       if (rpix(c->x,c->y)) {
  37.         c->status = STATUS_LOSER;
  38.         num_alive--;
  39.         if (num_alive == 0) {
  40.           ties++;
  41.           draw_scores();
  42.           flash_colour(0);
  43.         }
  44.       }
  45.       else {
  46.        if (na>1)
  47.          c->status = STATUS_NEED_NEW;
  48.        else {
  49.          scores[c->colour]++;
  50.          draw_scores();
  51.          c->status = STATUS_WINNER;
  52.          flash_colour(c->colour+3);
  53.          /* avoid the colours */
  54.          num_alive--;
  55.        }
  56.        wpix(c->colour,c->x,c->y,c->dir);
  57.      }
  58.      if (c->msg) {
  59.        c->msg->x      = c->x;
  60.        c->msg->y      = c->y;
  61.        c->msg->dir    = c->dir;
  62.        c->msg->status = c->status;
  63.        ReplyMsg(c->msg);
  64.        c->msg         = NULL;
  65.      }
  66.      break;
  67.  
  68.    default:
  69.      break;
  70.    } /* switch */
  71.    c = c2;
  72.  }
  73. }
  74.  
  75. free_cycles(list)
  76. LIST *list;
  77. {
  78.   register CYCLE *c,*c2;
  79.  
  80.   c = (CYCLE *)list->lh_Head;
  81.  
  82.   /* check all cycles... */
  83.   while (c2 = (CYCLE *)c->node.ln_Succ) {
  84.     /* if there is any sort of message pending */
  85.     if (c->msg) {
  86.       /* inform the client that he has been terminated */
  87.       c->msg->status = STATUS_REMOVED;
  88.       ReplyMsg(c->msg);
  89.       c->msg = NULL;
  90.       num_players--;
  91.     }
  92.     /* clean up client... */
  93.     Remove(c);
  94.     FreeMem(c,sizeof(CYCLE));
  95.     c = c2;
  96.   }
  97. }
  98.  
  99. restart_cycles(list)
  100. LIST *list;
  101. {
  102.   register CYCLE *c,*c2;
  103.  
  104.   c = (CYCLE *)list->lh_Head;
  105.  
  106.   while(c2 = (CYCLE *)c->node.ln_Succ) {
  107.     if (c->status == STATUS_AWAITING) {
  108.       c->x           = rand() % (X_SIZE - 10) + 5;
  109.       c->y           = rand() % (Y_SIZE - 10) + 5;
  110.       c->dir         = DIR_RIGHT;
  111.       c->status      = STATUS_NEED_NEW;
  112.       c->msg->x      = c->x;
  113.       c->msg->y      = c->y;
  114.       c->msg->status = c->status;
  115.       c->msg->dir    = c->dir;
  116.       wpix(c->colour,c->x,c->y,c->dir);
  117.  
  118.       ReplyMsg(c->msg);
  119.       c->msg = NULL;
  120.     }
  121.     c = c2;
  122.   }
  123.   num_waiting = 0;
  124.   num_alive   = num_players;
  125. }
  126.