khanhdu

Galv's Encounter Pointer

Jun 13th, 2017
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.21 KB | None | 0 0
  1. #------------------------------------------------------------------------------#
  2. #  Galv's Encounter Pointer
  3. #------------------------------------------------------------------------------#
  4. #  For: RPGMAKER VX ACE
  5. #  Version 1.1
  6. #------------------------------------------------------------------------------#
  7. #  2013-02-18 - Version 1.1 - fixed bug with changing number of frames
  8. #  2013-02-18 - Version 1.0 - release
  9. #------------------------------------------------------------------------------#
  10. #  This script displays a pointer above the player's head that changes
  11. #  depending on how many steps until the next random encounter will happen.
  12. #  This is based off of the feature in the psone game 'Legend of Dragoon'.
  13. #------------------------------------------------------------------------------#
  14. #  INSTRUCTIONS
  15. #------------------------------------------------------------------------------#
  16. #  Get image from demo.
  17. #  Put script under Materials and above Main
  18. #  Check settings to see if you want to change anything.
  19. #  Start a new game.
  20. #------------------------------------------------------------------------------#
  21.  
  22. ($imported ||= {})["Galv_Encounter_Pointer"] = true
  23. module Galv_Enc
  24.  
  25. #------------------------------------------------------------------------------#  
  26. #  SETUP OPTIONS
  27. #------------------------------------------------------------------------------#
  28.   #---------------------#
  29.   #  Gameplay Options:  #
  30.   #---------------------#
  31.  
  32.   DISABLE_BUTTON = :Y  # Button for player to turn it on and off :Y is "s" key
  33.   DISABLE_SWITCH = 1   # Turn ON to turn pointer OFF.
  34.  
  35.   WARNING_LEVEL = 0.5  # When pointer turns yellow
  36.   DANGER_LEVEL = 0.2   # When pointer turns red
  37.  
  38.   # The above levels are based on how many steps until encounter and the
  39.   # encounter rate of the area. 0.5 means when steps until encounter has reached
  40.   # 50% of the encounter rate. (So 15 steps in a 30 step zone).
  41.  
  42.   #---------------------#
  43.   #  Graphic Options:   #
  44.   #---------------------#
  45.  
  46.   IMAGE = "encounter_pointer"   # The image to use in /Graphics/System/
  47.  
  48.   FRAMES = 5           # Amount of frames the pointer animation uses
  49.   SPEED = 5            # Speed of animation (higher is slower)
  50.   Z_LEVEL = 100        # Make higher to display above things if it doesn't.
  51.   Y_POSITION = -50     # Y position relevant to the player.
  52.  
  53. #------------------------------------------------------------------------------#  
  54. #  END SETUP OPTIONS
  55. #------------------------------------------------------------------------------#
  56. end
  57.  
  58.  
  59. class Spriteset_Map
  60.   alias galv_enc_point_smap_initialize initialize
  61.   def initialize
  62.     create_enc_symbol
  63.     galv_enc_point_smap_initialize
  64.   end
  65.  
  66.   def create_enc_symbol
  67.     @enc_symbol = Sprite_EncSymbol.new(@viewport1, $game_player)
  68.   end
  69.  
  70.   alias galv_enc_point_smap_update update
  71.   def update
  72.     galv_enc_point_smap_update
  73.     @enc_symbol.update
  74.   end
  75.  
  76.   alias galv_enc_point_smap_dispose dispose
  77.   def dispose
  78.     galv_enc_point_smap_dispose
  79.     dispose_enc_symbol
  80.   end
  81.  
  82.   def dispose_enc_symbol
  83.     @enc_symbol.dispose if @enc_symbol
  84.   end
  85. end # Spriteset_Map
  86.  
  87.  
  88. class Sprite_EncSymbol < Sprite_Character
  89.   def initialize(viewport, character = nil)
  90.     super(viewport, character)
  91.     @character = character
  92.     update
  93.   end
  94.  
  95.   def defaults
  96.     @speed_timer = 0
  97.     @enc_pattern = 1
  98.     @enc_rate = $game_map.encounter_step
  99.     @enc_status = $game_player.encounter_count
  100.   end
  101.  
  102.   def update
  103.     update_enc_status
  104.     set_enc_bitmap if @enc_pattern.nil?
  105.     update_src_rect
  106.     update_position
  107.     update_other
  108.   end
  109.  
  110.   def update_enc_status
  111.     steps_left = $game_player.encounter_count.to_f / $game_map.encounter_step.to_f
  112.     if steps_left <= Galv_Enc::DANGER_LEVEL
  113.       @enc_status = 2
  114.     elsif steps_left <= Galv_Enc::WARNING_LEVEL
  115.       @enc_status = 1
  116.     else
  117.       @enc_status = 0
  118.     end
  119.   end
  120.  
  121.   def set_enc_bitmap
  122.     @enc_pattern ||= 1
  123.     @speed_timer ||= 0
  124.     self.bitmap = Cache.system(Galv_Enc::IMAGE)
  125.     @cw = bitmap.width / Galv_Enc::FRAMES
  126.     @ch = bitmap.height / 3
  127.     self.ox = @cw / 2
  128.     self.oy = @ch
  129.   end
  130.  
  131.   def update_src_rect
  132.     if @enc_pattern < Galv_Enc::FRAMES
  133.       pattern = @enc_pattern
  134.     else
  135.       @enc_pattern = 1
  136.       pattern = 1
  137.     end
  138.     sx = pattern * @cw
  139.     sy = @enc_status * @ch
  140.     self.src_rect.set(sx, sy, @cw, @ch)
  141.   end
  142.  
  143.   def update_position    
  144.     self.x = @character.screen_x
  145.     self.y = @character.screen_y + Galv_Enc::Y_POSITION
  146.     self.z = Galv_Enc::Z_LEVEL
  147.   end
  148.  
  149.   def update_other
  150.     @speed_timer += 1
  151.     if @speed_timer > Galv_Enc::SPEED
  152.       @enc_pattern += 1
  153.       @speed_timer = 0
  154.     end
  155.     if !$game_switches[Galv_Enc::DISABLE_SWITCH]
  156.       self.opacity = 255
  157.     else
  158.       self.opacity = 0
  159.     end
  160.     self.visible = !@character.transparent
  161.   end
  162.  
  163. end # Sprite_EncSymbol < Sprite_Character
  164.  
  165.  
  166. class Game_Player < Game_Character
  167.   attr_reader :encounter_count
  168.  
  169.   alias galv_enc_point_player_move_by_input move_by_input
  170.   def move_by_input
  171.     if Input.trigger?(Galv_Enc::DISABLE_BUTTON)
  172.       $game_switches[1] ^= true
  173.     end
  174.     galv_enc_point_player_move_by_input
  175.   end
  176. end # Game_Player < Game_Character
Advertisement
Add Comment
Please, Sign In to add comment