Advertisement
M3rein

Better Fast-forward Mode

Oct 21st, 2017
4,768
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.29 KB | None | 0 0
  1. #==============================================================================#
  2. #                         Better Fast-forward Mode                             #
  3. #                                   v1.0                                       #
  4. #                                                                              #
  5. #                                 by Marin                                     #
  6. #==============================================================================#
  7. #                                   Usage                                      #
  8. #                                                                              #
  9. # SPEEDUP_STAGES are the speed stages the game will pick from. If you click F, #
  10. # it'll choose the next number in that array. It goes back to the first number #
  11. #                                 afterward.                                   #
  12. #                                                                              #
  13. #             $GameSpeed is the current index in the speed up array.           #
  14. #   Should you want to change that manually, you can do, say, $GameSpeed = 0   #
  15. #                                                                              #
  16. # If you don't want the user to be able to speed up at certain points, you can #
  17. #                use "pbDisallowSpeedup" and "pbAllowSpeedup".                 #
  18. #==============================================================================#
  19.  
  20. # When the user clicks F, it'll pick the next number in this array.
  21. SPEEDUP_STAGES = [1,2,3]
  22.  
  23.  
  24. def pbAllowSpeedup
  25.   $CanToggle = true
  26. end
  27.  
  28. def pbDisallowSpeedup
  29.   $CanToggle = false
  30. end
  31.  
  32. # Default game speed.
  33. $GameSpeed = 0
  34.  
  35. $frame = 0
  36. $CanToggle = true
  37. module Graphics
  38.   class << Graphics
  39.     alias fast_forward_update update
  40.   end
  41.  
  42.   def self.update
  43.     if $CanToggle && Input.trigger?(Input::F)
  44.       $GameSpeed += 1
  45.       $GameSpeed = 0 if $GameSpeed >= SPEEDUP_STAGES.size
  46.     end
  47.     $frame += 1
  48.     return unless $frame % SPEEDUP_STAGES[$GameSpeed] == 0
  49.     fast_forward_update
  50.     $frame = 0
  51.   end
  52. end
  53.  
  54. module Input
  55.   class << Input
  56.     alias fast_forward_button_to_key buttonToKey
  57.   end
  58.  
  59.   F = 50
  60.  
  61.   def self.buttonToKey(btn)
  62.     return [0x46] if btn == Input::F
  63.     fast_forward_button_to_key(btn)
  64.   end
  65. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement