Advertisement
MakerSystems

RPG Maker VX Ace - Enhanced Camera

Dec 8th, 2014
2,989
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 49.60 KB | None | 0 0
  1. %Q(
  2. ╔════╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═════╗
  3. ║ ╔══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╗ ║
  4. ╠─╣ Enhanced Camera ╠─╣
  5. ╠─╣ by RPG Maker Source. ╠─╣
  6. ╠─╣ www.rpgmakersource.com ╠─╣
  7. ║ ╚══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╝ ║
  8. ╠════╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═════╣
  9. ║ ┌────┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴─────┐ ║
  10. ╠─┤ Version 1.0.2 07/03/15 DD/MM/YY ├─╣
  11. ║ └────┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬─────┘ ║
  12. ╠══════╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══════╣
  13. ║ ║
  14. ║ This work is protected by the following license: ║
  15. ║ ╔══════════════════════════════════════════════════════════════════╗ ║
  16. ║ │ │ ║
  17. ║ │ Copyright © 2014 Maker Systems. │ ║
  18. ║ │ │ ║
  19. ║ │ This software is provided 'as-is', without any kind of │ ║
  20. ║ │ warranty. Under no circumstances will the author be held │ ║
  21. ║ │ liable for any damages arising from the use of this software. │ ║
  22. ║ │ │ ║
  23. ║ │ Permission is granted to anyone to use this software on their │ ║
  24. ║ │ free or commercial games made with a legal copy of RPG Maker │ ║
  25. ║ │ VX Ace, as long as Maker Systems - RPG Maker Source is │ ║
  26. ║ │ credited within the game. │ ║
  27. ║ │ │ ║
  28. ║ │ Selling this code or any portions of it 'as-is' or as part of │ ║
  29. ║ │ another code, is not allowed. │ ║
  30. ║ │ │ ║
  31. ║ │ The original header, which includes this copyright notice, │ ║
  32. ║ │ must not be edited or removed from any verbatim copy of the │ ║
  33. ║ │ sotware nor from any edited version. │ ║
  34. ║ │ │ ║
  35. ║ ╚══════════════════════════════════════════════════════════════════╝ ║
  36. ║ ║
  37. ║ ║
  38. ╠══════════════════════════════════════════════════════════════════════════════╣
  39. ║ 1. VERSION HISTORY. ▼ ║
  40. ╠══════════════════════════════════════════════════════════════════════════════╣
  41. ║ ║
  42. ║ • Version 1.0.0, 08/12/14 - (DD/MM/YY). ║
  43. ║ ║
  44. ║ • Version 1.0.1, 13/12/14 - (DD/MM/YY). ║
  45. ║ ║
  46. ║ • Version 1.0.2, 07/03/15 - (DD/MM/YY). ║
  47. ║ - Camera will now behave like default when strength is set to 1. ║
  48. ║ ║
  49. ╠══════════════════════════════════════════════════════════════════════════════╣
  50. ╠══════════════════════════════════════════════════════════════════════════════╣
  51. ║ 2. USER MANUAL. ▼ ║
  52. ╠══════════════════════════════════════════════════════════════════════════════╣
  53. ║ ║
  54. ║ ┌──────────────────────────────────────────────────────────────────────────┐ ║
  55. ║ │ ■ Introduction. │ ║
  56. ║ └┬┬┬┬──────────────────────────────────────────────────────────────────┬┬┬┬┘ ║
  57. ║ ║
  58. ║ Hello there! This script is "plug and play", you can simply insert it into ║
  59. ║ your project and it will perform flawlessly. ║
  60. ║ ║
  61. ║ This script greatly improves the appearence of your games. Once you see it ║
  62. ║ in action, you will love it. ║
  63. ║ ║
  64. ║ It makes the camera smoothly follow the player with a nice deceleration ║
  65. ║ effect, and provides new functions that makes it more versatile. ║
  66. ║ ║
  67. ║ Although it will work as soon as you insert it, we included some ║
  68. ║ instructions in the next section for you to take advantage of some of the ║
  69. ║ new features provided and to create awesome scenes and mechanics. ║
  70. ║ ║
  71. ║ We hope you enjoy it. ║
  72. ║ ║
  73. ║ Thanks for choosing our products. ║
  74. ║ ║
  75. ║ ┌──────────────────────────────────────────────────────────────────────────┐ ║
  76. ║ │ ■ Configuration. │ ║
  77. ║ └┬┬┬┬──────────────────────────────────────────────────────────────────┬┬┬┬┘ ║
  78. ║ ║
  79. ║ "How do I change the strength of the deceleration effect?" ║
  80. ║ Right click anywhere in the script editor and select "Find" (or CTRL + F) ║
  81. ║ search for "DECELERATION_VALUE" (without quotation marks). ║
  82. ║ ║
  83. ║ You will see something like "DECELERATION_VALUE = 22" ║
  84. ║ ║
  85. ║ Set the number after the equality sign to any numer you like, bigger or ║
  86. ║ equal than 1. The bigger the number, the stronger the deceleration effect ║
  87. ║ and thus the slower the camera movement when following the player. Small ║
  88. ║ numbers result in a faster deceleration, default value is 22. ║
  89. ║ ║
  90. ║ ┌──────────────────────────────────────────────────────────────────────────┐ ║
  91. ║ │ ■ Feature Documentation. │ ║
  92. ║ └┬┬┬┬──────────────────────────────────────────────────────────────────┬┬┬┬┘ ║
  93. ║ ║
  94. ║ There are several commands that you can use inside a Script Call (Event ║
  95. ║ Command) to create awesome scenes and mechanics. Although they are easy to ║
  96. ║ use and understand, it is useful to have a reference to check in case you ║
  97. ║ forget something about them. ║
  98. ║ ║
  99. ║ The script commands that you can use inside a Script Call (Event Command) ║
  100. ║ are displayed inside the following chart, followed by their description ║
  101. ║ and, if needed, usage details and examples. ║
  102. ║ ║
  103. ║ ┌───────────────────────────────┐ ║
  104. ║ │ ms_pro_cam_wait_for_scrolling │ ║
  105. ║ ├───────────────────────────────┴────────────────────────────────────────┐ ║
  106. ║ │ Waits until screen scrolling is completed before executing the next │ ║
  107. ║ │ event command. This works for both the event command default scrolling │ ║
  108. ║ │ and for the new "scroll to position" (ms_pro_cam_center_at) function │ ║
  109. ║ │ of Enhanced Camera. │ ║
  110. ║ └────────────────────────────────────────────────────────────────────────┘ ║
  111. ║ ┌────────────────────────────────────┐ ║
  112. ║ │ ms_pro_cam_center_at(x, y, frames) │ ║
  113. ║ ├────────────────────────────────────┴───────────────────────────────────┐ ║
  114. ║ │ Smoothly centers the camera at the desired coordinates in the exact │ ║
  115. ║ │ desired number of frames. │ ║
  116. ║ │ │ ║
  117. ║ │ In other words, this command allows you to tell the camera to move to │ ║
  118. ║ │ a point, center the view on that point, and do so exactly in the time │ ║
  119. ║ │ you desire. │ ║
  120. ║ │ │ ║
  121. ║ │ The speed of the camera movement is automatically adjusted to arrive │ ║
  122. ║ │ at its destination exactly when its time is up. │ ║
  123. ║ │ │ ║
  124. ║ │ NOTE: Compatible with looped maps. Normally, if the camera is at the │ ║
  125. ║ │ upper left corner of the map and you use this command to move it to │ ║
  126. ║ │ ther lower right corner, the camera will go through the map center. │ ║
  127. ║ │ But when you have horizontal, vertical or both loops in your maps, it │ ║
  128. ║ │ will go through the shortest path, which in the case of the above │ ║
  129. ║ │ example, is a short movement in the upper left direction (to just │ ║
  130. ║ │ cross the map border). When you call ms_pro_cam_center_at, you have to │ ║
  131. ║ │ add three "parameters" to it, those parameters are x (target x │ ║
  132. ║ │ position) y (target y position) and frames (time that the movement │ ║
  133. ║ │ must take) │ ║
  134. ║ │ │ ║
  135. ║ │ As an example, if you want the camera to center at x44 y44 and to do │ ║
  136. ║ │ so in 6 seconds (360 frames at normal 60FPS rate), you should use: │ ║
  137. ║ │ │ ║
  138. ║ │ ms_pro_cam_center_at(44, 44, 360) │ ║
  139. ║ └────────────────────────────────────────────────────────────────────────┘ ║
  140. ║ ┌───────────────────────────────────────┐ ║
  141. ║ │ ms_pro_cam_center_at_char(id, frames) │ ║
  142. ║ ├───────────────────────────────────────┴────────────────────────────────┐ ║
  143. ║ │ Similar as ms_pro_cam_center_at but instead of using an X and Y value, │ ║
  144. ║ │ uses an id of the character whose position is the target. │ ║
  145. ║ │ │ ║
  146. ║ │ (*) What is "id"? │ ║
  147. ║ │ id is a number representing the character, -1 is for player, 0 for the │ ║
  148. ║ │ calling event and 1 and up for event id. │ ║
  149. ║ └────────────────────────────────────────────────────────────────────────┘ ║
  150. ║ ┌──────────────────────────────────────────┐ ║
  151. ║ │ ms_pro_cam_focus_on(id, can_cancel, key) │ ║
  152. ║ ├──────────────────────────────────────────┴─────────────────────────────┐ ║
  153. ║ │ Tells the camera to follow the desired character as if it would │ ║
  154. ║ │ normally do for the player. In other words, tells the system to stop │ ║
  155. ║ │ following the player and start following the desired character │ ║
  156. ║ │ (determined by the parameter "id") │ ║
  157. ║ │ │ ║
  158. ║ │ (*) What is "id"? │ ║
  159. ║ │ id is a number representing the character, -1 is for player, 0 for the │ ║
  160. ║ │ calling event and 1 and up for event id. │ ║
  161. ║ │ │ ║
  162. ║ │ As an example, if you want to focus the camera on an event and its ID │ ║
  163. ║ │ is 22, use: ms_pro_cam_focus_on(22) │ ║
  164. ║ │ │ ║
  165. ║ │ And if you later want to center it back to the player: │ ║
  166. ║ │ ms_pro_cam_focus_on(-1) │ ║
  167. ║ │ │ ║
  168. ║ │ (*) What is "can_cancel"? │ ║
  169. ║ │ can_cancel is either true or false and it is not necessary to include │ ║
  170. ║ │ it in the command call unless you want the player to be able to focus │ ║
  171. ║ │ the camera back on the playing character by pressing a key. Default is │ ║
  172. ║ │ false. │ ║
  173. ║ │ │ ║
  174. ║ │ (*) What is "key"? │ ║
  175. ║ │ key is the symbol that represents the aforementioned key. It is not │ ║
  176. ║ │ necessary to include it. Check RPG Maker Ace's help file for all the │ ║
  177. ║ │ Input keys supported by the program. Keep in mind that if you use a │ ║
  178. ║ │ custom or expanded input module (script) you can use more keys. │ ║
  179. ║ │ Default is :CTRL (CONTROL) key (always put a double colon before the │ ║
  180. ║ │ name of the key). │ ║
  181. ║ │ │ ║
  182. ║ │ This are the keys supported by default in Ace: │ ║
  183. ║ │ │ ║
  184. ║ │ :DOWN :LEFT :RIGHT :UP (Arrow Keys) │ ║
  185. ║ │ :A :B :C :X :Y :Z :L :R (These do no represent keyboard letters) │ ║
  186. ║ │ :SHIFT :CTRL :ALT │ ║
  187. ║ │ :F5 :F6 :F7 :F8 :F9 │ ║
  188. ║ └────────────────────────────────────────────────────────────────────────┘ ║
  189. ║ ┌─────────────────────────────────────┐ ║
  190. ║ │ ms_pro_cam_character_on_screen?(id) │ ║
  191. ║ ├─────────────────────────────────────┴──────────────────────────────────┐ ║
  192. ║ │ Checks if character is visible on screen. │ ║
  193. ║ │ │ ║
  194. ║ │ This one is a slightly different than the others, since it will return │ ║
  195. ║ │ either true or false, you could use it in an Event Conditional Branch │ ║
  196. ║ │ Command, fourth tab, last option (Script). You simply insert the │ ║
  197. ║ │ command with the desired id that represents the character to check, │ ║
  198. ║ │ and it will act as a normal conditional branch. │ ║
  199. ║ │ │ ║
  200. ║ │ Why would you want to use something like that? Imagine the player has │ ║
  201. ║ │ to chase a thief down the street, you could center the camera at the │ ║
  202. ║ │ running thief and tell the player to chase it closely or otherwise the │ ║
  203. ║ │ thief will run away. You can use this command to check if the player │ ║
  204. ║ │ is "keeping up", if the player is not visible on screen, the thief │ ║
  205. ║ │ escaped. │ ║
  206. ║ │ │ ║
  207. ║ │ This is just one example, you can use it for any mechanic that you can │ ║
  208. ║ │ think of. │ ║
  209. ║ │ │ ║
  210. ║ │ The "id" parameter works exactly like described above. │ ║
  211. ║ └────────────────────────────────────────────────────────────────────────┘ ║
  212. ║ ┌──────────────────────┐ ║
  213. ║ │ ms_pro_cam_reset_str │ ║
  214. ║ ├──────────────────────┴─────────────────────────────────────────────────┐ ║
  215. ║ │ Sets the deceleration strength to the number defined in │ ║
  216. ║ │ DECELERATION_VALUE. │ ║
  217. ║ │ │ ║
  218. ║ │ You can use this command to set back the deceleration strength to its │ ║
  219. ║ │ default value. This affects only the "following" feature of the │ ║
  220. ║ │ camera, like normal player focus/following and event focus/following. │ ║
  221. ║ └────────────────────────────────────────────────────────────────────────┘ ║
  222. ║ ┌───────────────────────┐ ║
  223. ║ │ ms_pro_cam_str(value) │ ║
  224. ║ ├───────────────────────┴────────────────────────────────────────────────┐ ║
  225. ║ │ Sets the deceleration strength to the desired value. │ ║
  226. ║ │ │ ║
  227. ║ │ This command sets the deceleration strength of the focus/following │ ║
  228. ║ │ feature of the camera to any number you insert as the "value" │ ║
  229. ║ │ parameter. │ ║
  230. ║ │ │ ║
  231. ║ │ Keep in mind that the lower the number, the faster the camera will │ ║
  232. ║ │ focus/follow (1 will result in something similar to RPG Maker Ace's │ ║
  233. ║ │ default) and the bigger the number, the stronger the deceleration and │ ║
  234. ║ │ thus the slower the speed. │ ║
  235. ║ │ │ ║
  236. ║ │ You can use ms_pro_cam_reset_str, described above, to reset back the │ ║
  237. ║ │ strength to its default setting. │ ║
  238. ║ └────────────────────────────────────────────────────────────────────────┘ ║
  239. ║ ┌──────────────────────────────────────┐ ║
  240. ║ │ ms_pro_cam_ignore_player(true/false) │ ║
  241. ║ ├──────────────────────────────────────┴─────────────────────────────────┐ ║
  242. ║ │ If set to true, it won't follow the player, but it will scroll as │ ║
  243. ║ │ usual when using scroll event commands or when using │ ║
  244. ║ │ ms_pro_cam_center_at. │ ║
  245. ║ │ If set to false, it will follow the player as usual when neeeded. │ ║
  246. ║ │ │ ║
  247. ║ │ Why would you want to use it? │ ║
  248. ║ │ In case you want to make some camera movement across the map without │ ║
  249. ║ │ focusing on any particular character, and you don't want the camera to │ ║
  250. ║ │ jump back to the player as soon as the scrolling is finished and the │ ║
  251. ║ │ player moves. │ ║
  252. ║ │ │ ║
  253. ║ │ By having this set to true (and thus "ignoring" the player) the camera │ ║
  254. ║ │ can be set still (it can be moving too) to any map location and it │ ║
  255. ║ │ won't focus back on the player even if the player is moving. │ ║
  256. ║ │ │ ║
  257. ║ │ Use true to ignore the player and false to acknowledge it back. │ ║
  258. ║ └────────────────────────────────────────────────────────────────────────┘ ║
  259. ║ ┌────────────────────────┐ ║
  260. ║ │ ms_pro_cam_lock_camera │ ║
  261. ║ ├────────────────────────┴───────────────────────────────────────────────┐ ║
  262. ║ │ Prevents the camera movement until ms_pro_cam_unlock_camera is called. │ ║
  263. ║ │ │ ║
  264. ║ │ This one is pretty simple, when you call it, the camera won't move │ ║
  265. ║ │ anymore until you "unlock" it again. Nothing will move it, not even │ ║
  266. ║ │ zombie vampires. │ ║
  267. ║ │ │ ║
  268. ║ │ Keep in mind that the player can still move freely and everything will │ ║
  269. ║ │ work as usual. │ ║
  270. ║ └────────────────────────────────────────────────────────────────────────┘ ║
  271. ║ ┌──────────────────────────┐ ║
  272. ║ │ ms_pro_cam_unlock_camera │ ║
  273. ║ ├──────────────────────────┴─────────────────────────────────────────────┐ ║
  274. ║ │ Allows normal camera movement. │ ║
  275. ║ │ │ ║
  276. ║ │ This one is to reverse the locking caused by the above command. The │ ║
  277. ║ │ camera will "go back to life" and perform as usual. │ ║
  278. ║ └────────────────────────────────────────────────────────────────────────┘ ║
  279. ║ ║
  280. ╠══════════════════════════════════════════════════════════════════════════════╣
  281. ╠══════════════════════════════════════════════════════════════════════════════╣
  282. ║ 3. NOTES. ▼ ║
  283. ╠══════════════════════════════════════════════════════════════════════════════╣
  284. ║ ║
  285. ║ Have fun and enjoy! ║
  286. ║ ║
  287. ╠══════════════════════════════════════════════════════════════════════════════╣
  288. ╠══════════════════════════════════════════════════════════════════════════════╣
  289. ║ 4. CONTACT. ▼ ║
  290. ╠══════════════════════════════════════════════════════════════════════════════╣
  291. ║ ║
  292. ║ Keep in touch with us and be the first to know about new releases: ║
  293. ║ ║
  294. ║ www.rpgmakersource.com ║
  295. ║ www.facebook.com/RPGMakerSource ║
  296. ║ www.twitter.com/RPGMakerSource ║
  297. ║ www.youtube.com/user/RPGMakerSource ║
  298. ║ ║
  299. ║ Get involved! Have an idea for a system? Let us know. ║
  300. ║ ║
  301. ║ Spread the word and help us reach more people so we can continue creating ║
  302. ║ awesome resources for you! ║
  303. ║ ║
  304. ╚══════════════════════════════════════════════════════════════════════════════╝)
  305.  
  306. #==============================================================================
  307. # ** Maker Systems
  308. #------------------------------------------------------------------------------
  309. # Module for our Systems.
  310. #==============================================================================
  311.  
  312. module MakerSystems
  313.  
  314. #============================================================================
  315. # ** Enhanced Camera
  316. #----------------------------------------------------------------------------
  317. # Contains configurable values for the camera systems.
  318. #============================================================================
  319.  
  320. module EnhancedCamera
  321.  
  322. #------------------------------------------------------------------------
  323. # * Scrolling Deceleration Strength. [OPT]
  324. #------------------------------------------------------------------------
  325. DECELERATION_VALUE = 38
  326.  
  327. end
  328.  
  329. end
  330.  
  331. #==============================================================================
  332. # ** Game_Interpreter
  333. #------------------------------------------------------------------------------
  334. # Added methods to use in Script Call Event Command.
  335. #==============================================================================
  336.  
  337. class Game_Interpreter
  338.  
  339. #--------------------------------------------------------------------------
  340. # * Reset Deceleration Strength. [NEW]
  341. #--------------------------------------------------------------------------
  342. def ms_pro_cam_reset_str
  343. # Set camera deceleration strength back to default.
  344. $game_map.ms_ecam_str =
  345. MakerSystems::EnhancedCamera::DECELERATION_VALUE.to_f
  346. end
  347.  
  348. #--------------------------------------------------------------------------
  349. # * Deceleration Strength. [NEW]
  350. #--------------------------------------------------------------------------
  351. def ms_pro_cam_str(value)
  352. # Set camera deceleration strength.
  353. $game_map.ms_ecam_str = value.to_f
  354. end
  355.  
  356. #--------------------------------------------------------------------------
  357. # * Ignore Player Toggle. [NEW]
  358. #--------------------------------------------------------------------------
  359. def ms_pro_cam_ignore_player(value)
  360. # Set ignore player flag.
  361. $game_map.ms_ecam_ignore_player = value
  362. end
  363.  
  364. #--------------------------------------------------------------------------
  365. # * Lock Camera. [NEW]
  366. #--------------------------------------------------------------------------
  367. def ms_pro_cam_lock_camera
  368. # Turns on camera lock flag.
  369. $game_map.ms_ecam_locked = true
  370. end
  371.  
  372. #--------------------------------------------------------------------------
  373. # * Unlock Camera. [NEW]
  374. #--------------------------------------------------------------------------
  375. def ms_pro_cam_unlock_camera
  376. # Turns off camera lock flag.
  377. $game_map.ms_ecam_locked = false
  378. end
  379.  
  380. #--------------------------------------------------------------------------
  381. # * Character on Screen? [NEW]
  382. #--------------------------------------------------------------------------
  383. def ms_pro_cam_character_on_screen?(id)
  384. # Get character based on provided number (id).
  385. character = get_character(id)
  386. # Inside screen boundaries?
  387. character.screen_x > 0 && character.screen_x < Graphics.width &&
  388. character.screen_y > 0 && character.screen_y < Graphics.height
  389. end
  390.  
  391. #--------------------------------------------------------------------------
  392. # * Focus on Character. [NEW]
  393. #--------------------------------------------------------------------------
  394. def ms_pro_cam_focus_on(id, can_cancel = false, key = :CTRL)
  395. # Get character based on provided number (id).
  396. character = get_character(id)
  397. # Special handling if Player is the target.
  398. if character.is_a?(Game_Player)
  399. # Clears special character focus variable.
  400. $game_map.ms_ecam_target = nil
  401. # Turns off ignore player flag.
  402. $game_map.ms_ecam_ignore_player = false
  403. # Moves camera back to player.
  404. $game_map.ms_ecam_center(character.real_x, character.real_y)
  405. else
  406. # Sets camera target to its new target character.
  407. $game_map.ms_ecam_target = character
  408. # Sets cancel focus flag.
  409. $game_map.ms_ecam_cancel = can_cancel
  410. # Sets cancel focus key.
  411. $game_map.ms_ecam_cancel_key = key
  412. end
  413. end
  414.  
  415. #--------------------------------------------------------------------------
  416. # * Wait for Scrolling. [NEW]
  417. #--------------------------------------------------------------------------
  418. def ms_pro_cam_wait_for_scrolling
  419. # Yield until scrolling is completed.
  420. Fiber.yield while $game_map.scrolling? || $game_map.ms_ecam_iterations
  421. end
  422.  
  423. #--------------------------------------------------------------------------
  424. # * Center Camera at Position. [NEW]
  425. #--------------------------------------------------------------------------
  426. def ms_pro_cam_center_at(x, y, frames)
  427. # Set camera location target.
  428. $game_map.ms_ecam_go_to(x, y, frames)
  429. end
  430.  
  431. #--------------------------------------------------------------------------
  432. # * Center Camera at Character. [NEW]
  433. #--------------------------------------------------------------------------
  434. def ms_pro_cam_center_at_char(id, frames)
  435. # Get character based on provided number (id).
  436. character = get_character(id)
  437. # Set camera location target.
  438. $game_map.ms_ecam_go_to(character.x, character.y, frames)
  439. end
  440.  
  441. end
  442.  
  443. #==============================================================================
  444. # ** Game_Map
  445. #------------------------------------------------------------------------------
  446. # Edited update_scroll and initialize.
  447. #==============================================================================
  448.  
  449. class Game_Map
  450.  
  451. #--------------------------------------------------------------------------
  452. # * Public Instance Variables. [NEW]
  453. #--------------------------------------------------------------------------
  454. attr_accessor :ms_ecam_target, :ms_ecam_iterations, :ms_ecam_str,
  455. :ms_ecam_ignore_player, :ms_ecam_locked, :ms_ecam_cancel,
  456. :ms_ecam_cancel_key, :ms_ecam_active
  457.  
  458. #--------------------------------------------------------------------------
  459. # * Alias Initialize. [NEW]
  460. #--------------------------------------------------------------------------
  461. alias_method(:ms_ecam_original_initialize, :initialize)
  462.  
  463. #--------------------------------------------------------------------------
  464. # * Initialize. [MOD]
  465. #--------------------------------------------------------------------------
  466. def initialize
  467. # Original method.
  468. ms_ecam_original_initialize
  469. # Initializes deceleration strength.
  470. @ms_ecam_str = MakerSystems::EnhancedCamera::DECELERATION_VALUE.to_f
  471. end
  472.  
  473. #--------------------------------------------------------------------------
  474. # * Center Position. [NEW]
  475. #--------------------------------------------------------------------------
  476. def ms_ecam_center(target_real_x, target_real_y, hard = false)
  477. # Target position, centered.
  478. @ms_ecam_real_x = target_real_x - screen_tile_x / 2
  479. @ms_ecam_real_y = target_real_y - screen_tile_y / 2
  480. # Position correction for no horizontally looped maps.
  481. unless loop_horizontal?
  482. # Limit for the X axis.
  483. limit_x = width - screen_tile_x
  484. limit_x = 0 if limit_x < 0
  485. # Keeps target position inside correct boundaries.
  486. @ms_ecam_real_x = 0 if @ms_ecam_real_x < 0
  487. @ms_ecam_real_x = limit_x if @ms_ecam_real_x > limit_x
  488. end
  489. # Position correction for no vertically looped maps.
  490. unless loop_vertical?
  491. # Limit for the Y axis.
  492. limit_y = height - screen_tile_y
  493. limit_y = 0 if limit_y < 0
  494. # Keeps target position inside correct boundaries.
  495. @ms_ecam_real_y = 0 if @ms_ecam_real_y < 0
  496. @ms_ecam_real_y = limit_y if @ms_ecam_real_y > limit_y
  497. end
  498. # Ensures correct target values in case of looping any axis.
  499. @ms_ecam_real_x %= width
  500. @ms_ecam_real_y %= height
  501. # No smooth movement?
  502. if hard
  503. # Sets display position now, without any smooth deceleration effect.
  504. @display_x = @ms_ecam_real_x
  505. @display_y = @ms_ecam_real_y
  506. end
  507. end
  508.  
  509. #--------------------------------------------------------------------------
  510. # * Prepares Camera Target. [NEW]
  511. #--------------------------------------------------------------------------
  512. def ms_ecam_go_to(target_x, target_y, period = 60.0)
  513. # Prevents execution of any kind of camera movement if locked flag is on.
  514. return if @ms_ecam_locked
  515. # Sets correct target positions.
  516. ms_ecam_center(target_x, target_y)
  517. # Gets correct X distance.
  518. @ms_ecam_x_amplitude = ms_ecam_correct_amplitude(@display_x,
  519. @ms_ecam_real_x, width, loop_horizontal?)
  520. # Gets correct Y distance.
  521. @ms_ecam_y_amplitude = ms_ecam_correct_amplitude(@display_y,
  522. @ms_ecam_real_y, height, loop_vertical?)
  523. # Initializes iteration counter.
  524. @ms_ecam_iterations = 0.0
  525. # Saves the original, starting position.
  526. @ms_ecam_x_original = @display_x
  527. @ms_ecam_y_original = @display_y
  528. # Sets period (time).
  529. @ms_ecam_period = period.to_f
  530. end
  531.  
  532. #--------------------------------------------------------------------------
  533. # * Correct Amplitude. [NEW]
  534. #--------------------------------------------------------------------------
  535. def ms_ecam_correct_amplitude(current, target, limit, condition)
  536. # Checks if looping in the desired axis.
  537. if condition
  538. # Returns shortest distance, crossing map borders if needed.
  539. if ((target - current) % limit) < ((current - target) % limit)
  540. (target - current) % limit
  541. else
  542. -((current - target) % limit)
  543. end
  544. else
  545. # Returns normal distance.
  546. target - current
  547. end
  548. end
  549.  
  550. #--------------------------------------------------------------------------
  551. # * Alias Update Scroll. [NEW]
  552. #--------------------------------------------------------------------------
  553. alias_method(:ms_ecam_original_update_scroll, :update_scroll)
  554.  
  555. #--------------------------------------------------------------------------
  556. # * Update Scroll. [MOD]
  557. #--------------------------------------------------------------------------
  558. def update_scroll
  559. # Default method only unless Enhanced Camera is active.
  560. return ms_ecam_original_update_scroll unless @ms_ecam_str > 1
  561. # Prevents execution of any kind of camera movement if locked flag is on.
  562. return if @ms_ecam_locked
  563. # If non player target for camera.
  564. if @ms_ecam_target
  565. # If can be cancelled by player input and the key is triggered.
  566. if @ms_ecam_cancel && Input.trigger?(@ms_ecam_cancel_key)
  567. # Clears target flag.
  568. @ms_ecam_target = nil
  569. # Moves camera back to player.
  570. ms_ecam_center($game_player.real_x, $game_player.real_y)
  571. else
  572. # Centers camera on target.
  573. ms_ecam_center(@ms_ecam_target.real_x, @ms_ecam_target.real_y, false)
  574. end
  575. end
  576. # Iterations pending?
  577. if @ms_ecam_iterations
  578. # Calculates period.
  579. period = (@ms_ecam_iterations / @ms_ecam_period) * 1.57
  580. # Sets new display positions.
  581. @display_x = @ms_ecam_x_original + @ms_ecam_x_amplitude * Math.sin(period)
  582. @display_y = @ms_ecam_y_original + @ms_ecam_y_amplitude * Math.sin(period)
  583. # Ensures correct display values.
  584. @display_x %= $game_map.width
  585. @display_y %= $game_map.height
  586. # If target positions were reached.
  587. if period == 1.57
  588. # Sets target position flag off.
  589. @ms_ecam_iterations = nil
  590. # Updates target positions.
  591. @ms_ecam_real_x = @display_x
  592. @ms_ecam_real_y = @display_y
  593. else
  594. # Updates iteration count.
  595. @ms_ecam_iterations += 1.0
  596. end
  597. else
  598. # Camera being moved by event commands?
  599. if scrolling?
  600. # Target position is actual display position.
  601. @ms_ecam_real_x = @display_x
  602. @ms_ecam_real_y = @display_y
  603. else
  604. # Moves camera. Correct step value with deceleration effect. X Axis.
  605. @display_x += ms_ecam_correct_amplitude(@display_x,
  606. @ms_ecam_real_x, width, loop_horizontal?) / @ms_ecam_str
  607. # Moves camera. Correct step value with deceleration effect. Y Axis.
  608. @display_y += ms_ecam_correct_amplitude(@display_y,
  609. @ms_ecam_real_y, height, loop_vertical?) / @ms_ecam_str
  610. # Keeps map display values inside correct boundaries.
  611. @display_x %= width
  612. @display_y %= height
  613. end
  614. end
  615. # Original method.
  616. ms_ecam_original_update_scroll
  617. end
  618.  
  619. end
  620.  
  621. #==============================================================================
  622. # ** Game_Player
  623. #------------------------------------------------------------------------------
  624. # Replaced update_scroll and center.
  625. #==============================================================================
  626.  
  627. class Game_Player < Game_Character
  628.  
  629. #--------------------------------------------------------------------------
  630. # * Alias Update Scroll. [NEW]
  631. #--------------------------------------------------------------------------
  632. alias_method(:ms_ecam_original_update_scroll, :update_scroll)
  633.  
  634. #--------------------------------------------------------------------------
  635. # * Update Scroll. [MOD]
  636. #--------------------------------------------------------------------------
  637. def update_scroll(last_real_x, last_real_y)
  638. # Check if Enhanced Camera is active.
  639. if $game_map.ms_ecam_str > 1
  640. # Check if it is good to go.
  641. unless $game_map.ms_ecam_target || $game_map.ms_ecam_iterations ||
  642. $game_map.ms_ecam_ignore_player || !moving?
  643. # Updates the camera centering.
  644. $game_map.ms_ecam_center(@real_x, @real_y)
  645. end
  646. else
  647. # Not active? Then default method only.
  648. ms_ecam_original_update_scroll(last_real_x, last_real_y)
  649. end
  650. end
  651.  
  652. #--------------------------------------------------------------------------
  653. # * Alias Center. [NEW]
  654. #--------------------------------------------------------------------------
  655. alias_method(:ms_ecam_original_center, :center)
  656.  
  657. #--------------------------------------------------------------------------
  658. # * Center. [MOD]
  659. #--------------------------------------------------------------------------
  660. def center(x, y)
  661. # Check if Enhanced Camera is active.
  662. if $game_map.ms_ecam_str > 1
  663. # Don't center if the camera is anchored to its position.
  664. return if $game_map.ms_ecam_locked
  665. # Center camera display position at once.
  666. $game_map.ms_ecam_center(x.to_f, y.to_f, true)
  667. else
  668. # Not active? Then default method only.
  669. ms_ecam_original_center(x, y)
  670. end
  671. end
  672.  
  673. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement