Advertisement
Guest User

Approach

a guest
Oct 21st, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// @description Approach(a, b, amount);
  2. /// @function Approach
  3. /// @param a
  4. /// @param b
  5. /// @param amount
  6.  
  7. // Moves "a" towards "b" by "amount" and returns the result
  8. // Very usefull because it won't overshoot "b", and works in both directions
  9. // Examples:
  10. //          speed = Approach(speed, max_speed, acceleration);
  11. //          hp = Approach(hp, 0, damage);
  12. //          hp = Approach(hp, max_hp, heal);
  13. //          exp = Approach(exp, levelUP, monsterXP);;
  14.  
  15. if (argument0 < argument1){ // Example(Approach(hp, max_hp, heal(20))): If hp < max_hp
  16.    
  17.     argument0 += argument2; // Add heal to hp
  18.     if(argument0 > argument1) return argument1; // If hp is now over max hp, return max hp instead(to no overshoot)
  19.  
  20. } else { // Another Example: If hp > 0hp and the player suffers damage
  21.    
  22.     argument0 -= argument2; // Remove from hp the damage value
  23.     if(argument0 < argument1) return argument1; // If the new HP is less then 0, returns 0 instead(to no overshoot)
  24.  
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement