Advertisement
ZoriaRPG

RPG.zh Dragon Quest Style Walking, Terrain Types and Damage

Sep 2nd, 2018
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.23 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.                 if ( Screen->isSolid(Link->X, Link->Y-16) )
  138.                 {
  139.                     Audio->PlaySound(SFX_CANTWALK);
  140.                     break;
  141.                 }
  142.                 else
  143.                 {
  144.                     while( frame < (WALK_STEP_DUR+GetTerrainWalkFactor(dir)) ) { ++temp_frame; Waitframe(); }
  145.                     do
  146.                     {
  147.                        
  148.                         --Link->Y;
  149.                     } while ( Link->Y%16 );
  150.                        
  151.                     temp_frame = 0;
  152.                     //damage Link if he walked into a damage terrain type.
  153.                     //and flash the screen.
  154.                     Link->HP -= GetTerrainDamage(true);
  155.                     break;
  156.                        
  157.                    
  158.                 }
  159.             }
  160.             else break;
  161.         }
  162.         case DIR_DOWN:
  163.         {
  164.             if ( Input->Press[CB_DOWN] )
  165.             {
  166.                 if ( Screen->isSolid(Link->X, Link->Y+16) )
  167.                 {
  168.                     Audio->PlaySound(SFX_CANTWALK);
  169.                     break;
  170.                 }
  171.                 else
  172.                 {
  173.                     while ( (frame < GetTerrainWalkFactor(dir)) ) { ++temp_frame; Waitframe(); }
  174.                    
  175.                     do
  176.                     {
  177.                         ++Link->Y;
  178.                     } while ( Link->Y%16 );
  179.                     temp_frame = 0;
  180.                     //damage Link if he walked into a damage terrain type.
  181.                     //and flash the screen.
  182.                     Link->HP -= GetTerrainDamage(true);
  183.                     break;
  184.                    
  185.                 }
  186.                
  187.             }
  188.             else if ( Input->Hold[CB_DOWN] )
  189.             {
  190.                 if ( Screen->isSolid(Link->X, Link->Y+16) )
  191.                 {
  192.                     Audio->PlaySound(SFX_CANTWALK);
  193.                     break;
  194.                 }
  195.                 else
  196.                 {
  197.                     while( frame<(WALK_STEP_DUR+GetTerrainWalkFactor(dir)) ) { ++temp_frame; Waitframe(); }
  198.                     do
  199.                     {
  200.                        
  201.                         ++Link->Y;
  202.                     } while ( Link->Y%16 );
  203.                        
  204.                     temp_frame = 0;
  205.                     //damage Link if he walked into a damage terrain type.
  206.                     //and flash the screen.
  207.                     Link->HP -= GetTerrainDamage(true);
  208.                    
  209.                     break;
  210.                        
  211.                    
  212.                 }
  213.             }
  214.             else break;
  215.         }
  216.         case DIR_LEFT:
  217.         {
  218.             if ( Input->Press[CB_LEFT] )
  219.             {
  220.                 if ( Screen->isSolid(Link->X-16, Link->Y) )
  221.                 {
  222.                     Audio->PlaySound(SFX_CANTWALK);
  223.                     break;
  224.                 }
  225.                 else
  226.                 {
  227.                     while ( (frame<(GetTerrainWalkFactor(dir)) ) { ++temp_frame; Waitframe(); }
  228.                    
  229.                     do
  230.                     {
  231.                         --Link->X;
  232.                     } while ( Link->X%16 );
  233.                     temp_frame = 0;
  234.                     //damage Link if he walked into a damage terrain type.
  235.                     //and flash the screen.
  236.                     Link->HP -= GetTerrainDamage(true);
  237.                     break;
  238.                    
  239.                 }
  240.                
  241.             }
  242.             else if ( Input->Hold[CB_LEFT] )
  243.             {
  244.                 if ( Screen->isSolid(Link->X-16, Link->Y) )
  245.                 {
  246.                     Audio->PlaySound(SFX_CANTWALK);
  247.                     break;
  248.                 }
  249.                 else
  250.                 {
  251.                    
  252.                     while( frame<(WALK_STEP_DUR+GetTerrainWalkFactor(dir)) ) { ++temp_frame; Waitframe(); }
  253.                     do
  254.                     {
  255.                        
  256.                         --Link->X;
  257.                     } while ( Link->X%16 );
  258.                        
  259.                     temp_frame = 0;
  260.                     //damage Link if he walked into a damage terrain type.
  261.                     //and flash the screen.
  262.                     Link->HP -= GetTerrainDamage(true);
  263.                     break;
  264.                        
  265.                    
  266.                 }
  267.             }
  268.             else break;
  269.         }
  270.         case DIR_RIGHT:
  271.         {
  272.             if ( Input->Press[CB_RIGHT] )
  273.             {
  274.                 if ( Screen->isSolid(Link->X+16, Link->Y) )
  275.                 {
  276.                     Audio->PlaySound(SFX_CANTWALK);
  277.                     break;
  278.                 }
  279.                 else
  280.                 {
  281.                    
  282.                     while ( (frame<(GetTerrainWalkFactor(dir)) ) { ++temp_frame; Waitframe(); }
  283.                    
  284.                     do
  285.                     {
  286.                         ++Link->X;
  287.                     } while ( Link->X%16 );
  288.                     temp_frame = 0;
  289.                     //damage Link if he walked into a damage terrain type.
  290.                     //and flash the screen.
  291.                     Link->HP -= GetTerrainDamage(true);
  292.                     break;
  293.                    
  294.                 }
  295.                
  296.             }
  297.             else if ( Input->Hold[CB_RIGHT] )
  298.             {
  299.                 if ( Screen->isSolid(Link->X+16, Link->Y) )
  300.                 {
  301.                     Audio->PlaySound(SFX_CANTWALK);
  302.                     break;
  303.                 }
  304.                 else
  305.                 {
  306.                     while( frame<(WALK_STEP_DUR+GetTerrainWalkFactor(dir)) ) { ++temp_frame; Waitframe(); }
  307.                     do
  308.                     {
  309.                        
  310.                         ++Link->X;
  311.                     } while ( Link->X%16 );
  312.                        
  313.                     temp_frame = 0;
  314.                     //damage Link if he walked into a damage terrain type.
  315.                     //and flash the screen.
  316.                     Link->HP -= GetTerrainDamage(true);
  317.                     break;
  318.                        
  319.                    
  320.                 }
  321.             }
  322.             else break;
  323.         }
  324.     }
  325. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement