Advertisement
ZoriaRPG

RPG.zh Dragon Quest Style Walking v2

Sep 2nd, 2018
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.81 KB | None | 0 0
  1. //Dragon Quest Walking
  2.  
  3. int GetTerrainWalkFactor(int dir)
  4. {
  5.     int x; int y;
  6.     //types
  7.     const int WLK_PLAINS = 0;
  8.     const int WLK_FOREST = 5;
  9.     const int WLK_HILLS = 10;
  10.     const int WLK_BARRIER = 5;
  11.     const int WLK_SWAMP = 5;
  12.    
  13.     //combo inherent flags
  14.     const int CF_PLAINS = 0;
  15.     const int CF_FOREST = 150;
  16.     const int CF_HILLS = 151;
  17.     const int CF_BARRIER = 152;
  18.     const int CF_SWAMP = 153;
  19.    
  20.     switch(dir)
  21.     {
  22.         case DIR_UP:
  23.         {
  24.             x = 0; y = -16;
  25.             break;
  26.         }
  27.         case DIR_DOWN:
  28.         {
  29.             x = 0; y = 16;
  30.             break;
  31.         }
  32.         case DIR_LEFT:
  33.         {
  34.             x = -16; y = 0;
  35.             break;
  36.         }      
  37.         case DIR_RIGHT:
  38.         {
  39.             x = 16; y = 0;
  40.             break;
  41.         }
  42.     }
  43.     switch(Screen->ComboI[ComboAt(Link->X+x, Link->Y+y)])
  44.     {
  45.         case CF_PLAINS: return WLK_PLAINS;
  46.         case CF_FOREST: return WLK_FOREST;
  47.         case CF_HILLS: return WLK_HILLS;
  48.         case CF_BARRIER: return WLK_BARRIER;
  49.         case CF_SWAMP: return WLK_SWAMP;
  50.            
  51.         default: return 0;
  52.        
  53.     }
  54.     return 0;
  55.    
  56. }
  57.  
  58. ragon Quest Walking
  59.  
  60. int GetTerrainDamage(bool flash)
  61. {
  62.     int x; int y;
  63.     //types
  64.     const int DAMAGE_PLAINS = 0;
  65.     const int DAMAGE_FOREST = 5;
  66.     const int DAMAGE_HILLS = 10;
  67.     const int DAMAGE_BARRIER = 10;
  68.     const int DAMAGE_SWAMP = 1;
  69.    
  70.     //combo inherent flags
  71.     const int CF_PLAINS = 0;
  72.     const int CF_FOREST = 150;
  73.     const int CF_HILLS = 151;
  74.     const int CF_BARRIER = 152;
  75.     const int CF_SWAMP = 153;
  76.    
  77.     int damage;
  78.    
  79.     switch(Screen->ComboI[ComboAt(Link->X, Link->Y)])
  80.     {
  81.         case CF_PLAINS: damage = DAMAGE_PLAINS;
  82.         case CF_FOREST: damage = DAMAGE_FOREST;
  83.         case CF_HILLS: damage = DAMAGE_HILLS;
  84.         case CF_BARRIER: damage = DAMAGE_BARRIER;
  85.         case CF_SWAMP: damage = DAMAGE_SWAMP;
  86.            
  87.         default: return 0;
  88.        
  89.     }
  90.    
  91.     if ( flash )
  92.     {
  93.         if ( damage > 0 )
  94.         {
  95.             //FlashRed();
  96.         }
  97.     }
  98.        
  99.     return damage;
  100.    
  101. }
  102.  
  103. const int WALK_STEP_DUR = 20; //frames;
  104. void Walk()
  105. {
  106.     int temp_frame; int temp_hold;
  107.     switch(Link->Dir)
  108.     {
  109.         case DIR_UP:
  110.         {
  111.             if ( Input->Press[CB_UP] )
  112.             {
  113.                 if ( Screen->isSolid(Link->X, Link->Y-16) )
  114.                 {
  115.                     Audio->PlaySound(SFX_CANTWALK);
  116.                     break;
  117.                 }
  118.                 else
  119.                 {
  120.                     while ( (frame < (GetTerrainWalkFactor(dir)) ) { ++temp_frame; Waitframe(); }
  121.                    
  122.                     do
  123.                     {
  124.                         --Link->Y;
  125.                     } while ( Link->Y%16 );
  126.                     temp_frame = 0;
  127.                     //damage Link if he walked into a damage terrain type.
  128.                     //and flash the screen.
  129.                     Link->HP -= GetTerrainDamage(true);
  130.                     break;
  131.                    
  132.                 }
  133.                
  134.             }
  135.             else if ( Input->Hold[CB_UP] )
  136.             {
  137.                 while( frame < (WALK_STEP_DUR) ) { ++temp_frame; Waitframe(); }
  138.                 Input->Hold[CB_UP] = false; //force it back to press by unsetting both/
  139.                 Input->Press[CB_UP] = false; //on the next frame, it should register as a new press.
  140.                 //Waitframe();
  141.                 //temp_frame = 0;
  142.                 //damage Link if he walked into a damage terrain type.
  143.                 //and flash the screen.
  144.                 break;
  145.             }
  146.             else break;
  147.         }
  148.         case DIR_DOWN:
  149.         {
  150.             if ( Input->Press[CB_DOWN] )
  151.             {
  152.                 if ( Screen->isSolid(Link->X, Link->Y+16) )
  153.                 {
  154.                     Audio->PlaySound(SFX_CANTWALK);
  155.                     break;
  156.                 }
  157.                 else
  158.                 {
  159.                     while ( (frame < GetTerrainWalkFactor(dir)) ) { ++temp_frame; Waitframe(); }
  160.                    
  161.                     do
  162.                     {
  163.                         ++Link->Y;
  164.                     } while ( Link->Y%16 );
  165.                     temp_frame = 0;
  166.                     //damage Link if he walked into a damage terrain type.
  167.                     //and flash the screen.
  168.                     Link->HP -= GetTerrainDamage(true);
  169.                     break;
  170.                    
  171.                 }
  172.                
  173.             }
  174.             else if ( Input->Hold[CB_DOWN] )
  175.             {
  176.  
  177.                 while( frame<(WALK_STEP_DUR+GetTerrainWalkFactor(dir)) ) { ++temp_frame; Waitframe(); }
  178.                 Input->Hold[CB_DOWN] = false; //force it back to press by unsetting both/
  179.                 Input->Press[CB_DOWN] = false; //on the next frame, it should register as a new press.
  180.                 //Waitframe();
  181.                 //temp_frame = 0;
  182.                 //damage Link if he walked into a damage terrain type.
  183.                 //and flash the screen.
  184.                 //Link->HP -= GetTerrainDamage(true);
  185.                
  186.                 break;
  187.             }
  188.             else break;
  189.         }
  190.         case DIR_LEFT:
  191.         {
  192.             if ( Input->Press[CB_LEFT] )
  193.             {
  194.                 if ( Screen->isSolid(Link->X-16, Link->Y) )
  195.                 {
  196.                     Audio->PlaySound(SFX_CANTWALK);
  197.                     break;
  198.                 }
  199.                 else
  200.                 {
  201.                     while ( (frame<(GetTerrainWalkFactor(dir)) ) { ++temp_frame; Waitframe(); }
  202.                    
  203.                     do
  204.                     {
  205.                         --Link->X;
  206.                     } while ( Link->X%16 );
  207.                     temp_frame = 0;
  208.                     //damage Link if he walked into a damage terrain type.
  209.                     //and flash the screen.
  210.                     Link->HP -= GetTerrainDamage(true);
  211.                     break;
  212.                    
  213.                 }
  214.                
  215.             }
  216.             else if ( Input->Hold[CB_LEFT] )
  217.             {
  218.                 Input->Hold[CB_LEFT] = false; //force it back to press by unsetting both/
  219.                 Input->Press[CB_LEFT] = false; //on the next frame, it should register as a new press.
  220.                 //Waitframe();
  221.                 //temp_frame = 0;
  222.                 //damage Link if he walked into a damage terrain type.
  223.                 //and flash the screen.
  224.                 //Link->HP -= GetTerrainDamage(true);
  225.                 break;
  226.             }
  227.             else break;
  228.         }
  229.         case DIR_RIGHT:
  230.         {
  231.             if ( Input->Press[CB_RIGHT] )
  232.             {
  233.                 if ( Screen->isSolid(Link->X+16, Link->Y) )
  234.                 {
  235.                     Audio->PlaySound(SFX_CANTWALK);
  236.                     break;
  237.                 }
  238.                 else
  239.                 {
  240.                    
  241.                     while ( (frame<(GetTerrainWalkFactor(dir)) ) { ++temp_frame; Waitframe(); }
  242.                    
  243.                     do
  244.                     {
  245.                         ++Link->X;
  246.                     } while ( Link->X%16 );
  247.                     temp_frame = 0;
  248.                     //damage Link if he walked into a damage terrain type.
  249.                     //and flash the screen.
  250.                     Link->HP -= GetTerrainDamage(true);
  251.                     break;
  252.                    
  253.                 }
  254.                
  255.             }
  256.             else if ( Input->Hold[CB_RIGHT] )
  257.             {
  258.                 Input->Hold[CB_RIGHT] = false; //force it back to press by unsetting both/
  259.                 Input->Press[CB_RIGHT] = false; //on the next frame, it should register as a new press.
  260.                 //Waitframe();
  261.                    
  262.                 //temp_frame = 0;
  263.                 //damage Link if he walked into a damage terrain type.
  264.                 //and flash the screen.
  265.                 //Link->HP -= GetTerrainDamage(true);
  266.                 break;
  267.             }
  268.             else break;
  269.         }
  270.     }
  271. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement