SHARE
TWEET

ai

a guest Nov 27th, 2017 106 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. unsigned char ai( unsigned char turn )
  2. {
  3.     int status;
  4.     unsigned char position;                         /* pac-mans current position */
  5.     unsigned char level = ram_[0x4E13];   /* current game level */
  6.  
  7.  
  8.     /* AI cannot start in middle of a level */
  9.     if( turn > 200)
  10.     {
  11.         rb->splash(HZ/2, "AI will engage at next level start");
  12.         return 0;
  13.     }
  14.     if( turn == 0)
  15.     {
  16.         if( ram_[0x4E0E] == 0)
  17.         {
  18.             turn++;
  19.         }
  20.     }
  21.  
  22.  
  23.     if(turn != 0)
  24.     {
  25.         /* set which axis to look for pac-man along */
  26.         position = ram_[0x4D3A];
  27.         if( ai_direction[level][turn-1] < 2)
  28.         {
  29.             position = ram_[0x4D39];
  30.         }
  31.  
  32.  
  33.  
  34.         /*move joystick if necessary */
  35.         if( position == ai_location[level][turn] )
  36.         {
  37.             switch(ai_direction[level][turn])
  38.             {
  39.                 case 0:
  40.                     clear_joystick();
  41.                     setDeviceMode( Joy1_Up, DeviceOn);
  42.                     break;
  43.                 case 1:
  44.                     clear_joystick();
  45.                     setDeviceMode( Joy1_Down, DeviceOn);
  46.                     break;
  47.                 case 2:
  48.                     clear_joystick();
  49.                     setDeviceMode( Joy1_Right, DeviceOn);
  50.                     break;
  51.                 case 3:
  52.                     clear_joystick();
  53.                     setDeviceMode( Joy1_Left, DeviceOn);
  54.                     break;
  55.             }
  56.             turn++;
  57.         }
  58.     }
  59.  
  60.     /* reset turn counter on level end */
  61.     if(ram_[0x4E0E] == 254)
  62.     {
  63.         return 1;
  64.     }
  65.  
  66.  
  67.     /* Check the button status */
  68.     status = rb->button_status();
  69.     rb->button_clear_queue();
  70.     /*handle buttons if AI is off */
  71.     if(!turn || (turn == 1))
  72.     {
  73. #ifdef PACMAN_HAS_REMOTE
  74.         setDeviceMode( Joy1_Left, (status & PACMAN_LEFT || status == PACMAN_RC_LEFT) ? DeviceOn : DeviceOff);
  75.         setDeviceMode( Joy1_Right, (status & PACMAN_RIGHT || status == PACMAN_RC_RIGHT) ? DeviceOn : DeviceOff);
  76.         setDeviceMode( Joy1_Up, (status & PACMAN_UP || status == PACMAN_RC_UP) ? DeviceOn : DeviceOff);
  77.         setDeviceMode( Joy1_Down, (status & PACMAN_DOWN || status == PACMAN_RC_DOWN) ? DeviceOn : DeviceOff);
  78.         setDeviceMode( CoinSlot_1, (status & PACMAN_COIN || status == PACMAN_RC_COIN) ? DeviceOn : DeviceOff);
  79.         setDeviceMode( Key_OnePlayer, (status & PACMAN_1UP || status == PACMAN_RC_1UP) ? DeviceOn : DeviceOff);
  80.         setDeviceMode( Key_TwoPlayers, (status & PACMAN_2UP || status == PACMAN_RC_2UP) ? DeviceOn : DeviceOff);
  81. #else
  82.         setDeviceMode( Joy1_Left, (status & PACMAN_LEFT) ? DeviceOn : DeviceOff);
  83.         setDeviceMode( Joy1_Right, (status & PACMAN_RIGHT) ? DeviceOn : DeviceOff);
  84.         setDeviceMode( Joy1_Up, (status & PACMAN_UP) ? DeviceOn : DeviceOff);
  85.         setDeviceMode( Joy1_Down, (status & PACMAN_DOWN) ? DeviceOn : DeviceOff);
  86.         setDeviceMode( CoinSlot_1, (status & PACMAN_COIN) ? DeviceOn : DeviceOff);
  87.         setDeviceMode( Key_OnePlayer, (status & PACMAN_1UP) ? DeviceOn : DeviceOff);
  88. #ifdef PACMAN_2UP
  89.         setDeviceMode( Key_TwoPlayers, (status & PACMAN_2UP) ? DeviceOn : DeviceOff);
  90. #endif
  91. #endif
  92.     }//else
  93.         //hack();
  94.  
  95. /*    rb->logf("level = %d", level);*/
  96. /*    rb->logf("turn point = %d",ai_location[level][turn]);*/
  97. /*    rb->logf("turn = %d",turn);*/
  98. /*    rb->logf("x = %d",ram_[0x4D3A]);*/
  99. /*    rb->logf("y = %d",ram_[0x4D39]);*/
  100.     return turn;
  101. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top