home *** CD-ROM | disk | FTP | other *** search
/ Unreal Tournament Game Programming for Teens / UnrealTournamentGameProgrammingForTeens.iso / Chapter Files / Chapter06 / UT2004 / Ch04Area / Classes / Math.uc < prev    next >
Encoding:
Text File  |  2006-10-28  |  1.2 KB  |  53 lines

  1. //========================================================
  2. // Math.
  3. //see Math.txt
  4. //========================================================
  5. class Math extends Actor placeable;
  6.  
  7.  
  8. // #1 Takes two arguments of the type float
  9. //  and returns a value of the type float
  10. public function float Add(float NumA, float Numb){
  11.    return NumA + NumB;
  12. }
  13.  
  14. public function float Subtract(float NumA, float NumB){
  15.    return NumA - NumB;
  16. }
  17.  
  18. public function float Multiply(float NumA, float Numb){
  19.     
  20.    return NumA * NumB;
  21. }
  22.  
  23. public function float DivideAbyB(float NumA, float Numb){
  24.  
  25.    // #2 Declare a variable that is not 
  26.    // visible to other functions
  27.    local float Result;
  28.    Result = 0; 
  29.    if(NumA != 0){
  30.      Result = NumA/NumB;   
  31.    }
  32.    return Result;
  33. }
  34.  
  35.  
  36. public function float AverageTwoNumbers(float First, float Second){
  37.  
  38.     local float ResultingNumber;
  39.  
  40.  
  41.     //#3 Call add from within the class
  42.     //Assign the returned value of Add()
  43.     ResultingNumber = Add(First, Second);
  44.     
  45.     //#4 When you assign a new value, you clear the old
  46.     ResultingNumber = DivideAbyB(ResultingNumber, 2.0);
  47.     return ResultingNumber;
  48. }
  49.  
  50. defaultproperties
  51. {
  52. }
  53.