Advertisement
Guest User

Untitled

a guest
May 27th, 2015
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.23 KB | None | 0 0
  1. =begin
  2. #===============================================================================
  3. Title: Camera Target
  4. Author: Tsukihime
  5. Date: Nov 24, 2014
  6. --------------------------------------------------------------------------------
  7. ** Change log
  8. Nov 24, 2014
  9. - fixed bug where followers weren't being targeted at all
  10. Jun 23, 2014
  11. - fixed bug where using events to set event positions incorrectly moved
  12. the camera to another event
  13. Feb 22, 2014
  14. - added support for setting party followers as the camera target
  15. Apr 16, 2013
  16. - initial release
  17. --------------------------------------------------------------------------------
  18. ** Terms of Use
  19. * Free to use in commercial/non-commercial projects
  20. * No real support. The script is provided as-is
  21. * Will do bug fixes, but no compatibility patches
  22. * Features may be requested but no guarantees, especially if it is non-trivial
  23. * Credits to Tsukihime in your project
  24. * Preserve this header
  25. --------------------------------------------------------------------------------
  26. ** Description
  27.  
  28. This script allows you to set the camera to follow a particular character
  29. on the map using script calls. By default, the camera follows the leader
  30. of the party.
  31.  
  32. --------------------------------------------------------------------------------
  33. ** Installation
  34.  
  35. Place this script below Materials and above Main
  36.  
  37. --------------------------------------------------------------------------------
  38. ** Usage
  39.  
  40. To set the camera's target, make a script call in the event or move route
  41.  
  42. set_camera_target(char_id)
  43.  
  44. If char_id is negative, then it is the corresponding member of the party.
  45. For example, -1 is the leader of the party, -2 is the second member, -3
  46. is the third member.
  47.  
  48. If char_id is 0, then it is the current event that is executing the call.
  49.  
  50. if char_id is 1 or higher, then it is the specified event. For example, char_id
  51. 5 refers to event 5 on the current map.
  52. #===============================================================================
  53. =end
  54. $imported = {} if $imported.nil?
  55. $imported[:TH_CameraTarget] = true
  56. #===============================================================================
  57. # ** Configuration
  58. #===============================================================================
  59. module TH
  60. module Camera_Target
  61. end
  62. end
  63. #===============================================================================
  64. # ** Rest of script
  65. #===============================================================================
  66. module DataManager
  67. class << self
  68. alias :th_camera_target_create_game_objects :create_game_objects
  69. end
  70. def self.create_game_objects
  71. th_camera_target_create_game_objects
  72. $game_system.camera_target = $game_player
  73. end
  74. end
  75.  
  76. #-------------------------------------------------------------------------------
  77. # For convenient script call
  78. #-------------------------------------------------------------------------------
  79. class Game_Interpreter
  80.  
  81. #-----------------------------------------------------------------------------
  82. # Set the camera target. Update mode is how the camera will update its target
  83. # Not implemented yet
  84. #-----------------------------------------------------------------------------
  85. def set_camera_target(event_id, update_mode=0)
  86. $game_system.camera_target = get_character(event_id)
  87. $game_map.refresh_camera_target(update_mode)
  88. end
  89.  
  90. alias :th_camera_target_get_character :get_character
  91. def get_character(param)
  92. return nil if $game_party.in_battle
  93. return $game_player.followers[-(param+2)] if param < -1
  94. th_camera_target_get_character(param)
  95. end
  96. end
  97.  
  98. #-------------------------------------------------------------------------------
  99. # Camera target stored with the system
  100. #-------------------------------------------------------------------------------
  101. class Game_System
  102. attr_reader :camera_target
  103.  
  104. alias :th_camera_target_initialize :initialize
  105. def initialize
  106. th_camera_target_initialize
  107. @camera_target = nil
  108. end
  109.  
  110. def camera_target=(target)
  111. @camera_target = target
  112. end
  113. end
  114.  
  115. #-------------------------------------------------------------------------------
  116. # When the camera target changes, decide whether to update the camera position
  117. # to the current target, and how it should be done
  118. #-------------------------------------------------------------------------------
  119. class Game_Map
  120. def refresh_camera_target(update_mode)
  121. char = $game_system.camera_target
  122. $game_system.camera_target.center(char.x, char.y)
  123. end
  124. end
  125.  
  126. #-------------------------------------------------------------------------------
  127. # Add scrolling logic to all characters
  128. #-------------------------------------------------------------------------------
  129. class Game_Character < Game_CharacterBase
  130.  
  131. #-----------------------------------------------------------------------------
  132. # X Coordinate of Screen Center
  133. #-----------------------------------------------------------------------------
  134. def center_x
  135. (Graphics.width / 32 - 1) / 2.0
  136. end
  137. #-----------------------------------------------------------------------------
  138. # Y Coordinate of Screen Center
  139. #-----------------------------------------------------------------------------
  140. def center_y
  141. (Graphics.height / 32 - 1) / 2.0
  142. end
  143. #-----------------------------------------------------------------------------
  144. # Set Map Display Position to Center of Screen
  145. #-----------------------------------------------------------------------------
  146. def center(x, y)
  147. $game_map.set_display_pos(x - center_x, y - center_y)
  148. end
  149.  
  150. #-----------------------------------------------------------------------------
  151. # Scroll map depending on character location
  152. #-----------------------------------------------------------------------------
  153. def update_scroll(last_real_x, last_real_y)
  154. return unless $game_system.camera_target == self
  155. ax1 = $game_map.adjust_x(last_real_x)
  156. ay1 = $game_map.adjust_y(last_real_y)
  157. ax2 = $game_map.adjust_x(@real_x)
  158. ay2 = $game_map.adjust_y(@real_y)
  159. $game_map.scroll_down (ay2 - ay1) if ay2 > ay1 && ay2 > center_y
  160. $game_map.scroll_left (ax1 - ax2) if ax2 < ax1 && ax2 < center_x
  161. $game_map.scroll_right(ax2 - ax1) if ax2 > ax1 && ax2 > center_x
  162. $game_map.scroll_up (ay1 - ay2) if ay2 < ay1 && ay2 < center_y
  163. end
  164.  
  165. #-----------------------------------------------------------------------------
  166. # Return the specified character by ID
  167. #-----------------------------------------------------------------------------
  168. def get_character(param)
  169. if $game_party.in_battle
  170. nil
  171. elsif param == -1
  172. $game_player
  173. elsif param < -1
  174. $game_player.followers[param.abs-2]
  175. else
  176. $game_map.events[param]
  177. end
  178. end
  179.  
  180. #-----------------------------------------------------------------------------
  181. # Set the camera target. Used in move route interpreter
  182. #-----------------------------------------------------------------------------
  183. def set_camera_target(event_id, update_mode=0)
  184. $game_system.camera_target = get_character(event_id)
  185. $game_map.refresh_camera_target(update_mode)
  186. end
  187.  
  188. alias :th_camera_target_update :update
  189. def update
  190. last_real_x = @real_x
  191. last_real_y = @real_y
  192. th_camera_target_update
  193. update_scroll(last_real_x, last_real_y)
  194. end
  195.  
  196. alias :th_camera_target_moveto :moveto
  197. def moveto(x, y)
  198. th_camera_target_moveto(x, y)
  199. center(x, y) if $game_system.camera_target == self
  200. end
  201. end
  202.  
  203. #-------------------------------------------------------------------------------
  204. # Only update scroll if player is the camera target
  205. #-------------------------------------------------------------------------------
  206. class Game_Player < Game_Character
  207.  
  208. alias :th_camera_target_update_scroll :update_scroll
  209. def update_scroll(last_real_x, last_real_y)
  210. return unless $game_system.camera_target == self
  211. th_camera_target_update_scroll(last_real_x, last_real_y)
  212. end
  213. end
  214.  
  215. class Game_Event < Game_Character
  216.  
  217. alias :th_camera_target_get_character :get_character
  218. def get_character(param)
  219. if param == 0
  220. return $game_map.events[@id]
  221. end
  222. th_camera_target_get_character(param)
  223. end
  224. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement