Advertisement
Dekita

FoG

Jan 15th, 2013
1,704
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.96 KB | None | 0 0
  1. =begin =========================================================================
  2. Dekita's v1.2
  3. ★ FOG™ ★
  4.  
  5. ================================================================================
  6. Script Information:
  7. ====================
  8. This script allows for upto 3 different fogs to be displayed on the map and in
  9. battle.
  10. I have limited it to 3 for game performance sake, also 3 is more than
  11. enough imo...
  12.  
  13. Features :~
  14. Upto 3 seperate fogs,(per map)
  15. multiple options for each fog,
  16. e.g color / scroll speed / opacity / z value (importance)
  17.  
  18. Note : if z value is lower than 0 it will be shown under the map like a parallax
  19.  
  20. ================================================================================
  21. ★☆★☆★☆★☆★☆★☆★☆★ TERMS AND CONDITIONS: ☆★☆★☆★☆★☆★☆★☆★☆★☆
  22. ================================================================================
  23. 1. You must give credit to "Dekita"
  24. 2. You are NOT allowed to repost this script.(or modified versions)
  25. 3. You are NOT allowed to convert this script.(into other game engines e.g RGSS2)
  26. 4. You are NOT allowed to use this script for Commercial games.
  27. 5. ENJOY!
  28.  
  29. "FINE PRINT"
  30. By using this script you hereby agree to the above terms and conditions,
  31. if any violation of the above terms occurs "legal action" may be taken.
  32. Not understanding the above terms and conditions does NOT mean that
  33. they do not apply to you.
  34. If you wish to discuss the terms and conditions in further detail you can
  35. contact me at http://dekitarpg.wordpress.com/ or DekitaRPG@gmail.com
  36.  
  37. ================================================================================
  38. History:
  39. =========
  40. D /M /Y
  41. 14/o1/2o13 - improved efficiency,
  42. 13/o1/2o13 - fixed bug with $BTEST,
  43. 12/o1/2o13 - finished,
  44. ??/o1/2o13 - started,
  45.  
  46. ================================================================================
  47. Known Bugs:
  48. ============
  49. N/A
  50.  
  51. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  52. If a new bug is found please contact me at
  53. http://dekitarpg.wordpress.com/
  54.  
  55. ================================================================================
  56. INSTRUCTIONS:
  57. ==============
  58. Place this script UNDER "▼ Materials" and ABOVE "▼ Main" in your script editor.
  59.  
  60. ================================================================================
  61. Credit and Thanks to :
  62. =======================
  63. Hyde - for asking me to write this ^_^
  64.  
  65. ================================================================================
  66. NOTETAGS: (map noteboxes)
  67. ==========
  68.  
  69. <fog id: NAME>
  70. NAME = the name of the fog file (must be in parallax folder)
  71.  
  72. <id move: x, y>
  73. x / y = how mych the fog moves per frame update
  74.  
  75. <id opac: opacity>
  76. opacity = the transparency of the graphic
  77.  
  78. <id col: red,green,blue,alpha>
  79. reg / green / blue / aplha = the color / visibility values
  80.  
  81. <id z: z_value>
  82. z_value = the importance of the fog. below 0 will show the image behind the map.
  83.  
  84. id can be : a / b / c
  85. e.g
  86. <fog a: FOG_NAME>
  87. <a move: 1, 1>
  88. <a opac: 150>
  89. <a z: 50>
  90.  
  91. =end #=========================================================================#
  92. module FOG_By_Dekita
  93.  
  94. Default_Fog_A_z = 51
  95. Default_Fog_B_z = 52
  96. Default_Fog_C_z = 53
  97.  
  98. Show_In_Battle = true
  99. #####################
  100. # CUSTOMISATION END #
  101. end #####################
  102. #☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★#
  103. # #
  104. # http://dekitarpg.wordpress.com/ #
  105. # #
  106. #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆#
  107. #===============================================================================#
  108. # ARE YOU MODIFYING BEYOND THIS POINT? \.\. #
  109. # YES?\.\. #
  110. # OMG, REALLY? \| #
  111. # WELL SLAP MY FACE AND CALL ME A DRAGONITE.\..\.. #
  112. # I REALLY DIDN'T THINK YOU HAD IT IN YOU.\..\.. #
  113. #===============================================================================#
  114.  
  115. $imported = {} if $imported.nil?
  116. $imported[:Dekita_FOG] = true
  117.  
  118. #===============================================================================#
  119. class RPG::Map
  120. #===============================================================================#
  121.  
  122. attr_reader(:can_fog)
  123. attr_reader(:fog_a_name)
  124. attr_reader(:fog_a_move)
  125. attr_reader(:fog_a_opac)
  126. attr_reader(:fog_a_z)
  127. attr_reader(:fog_a_color)
  128. attr_reader(:fog_b_name)
  129. attr_reader(:fog_b_move)
  130. attr_reader(:fog_b_opac)
  131. attr_reader(:fog_b_z)
  132. attr_reader(:fog_b_color)
  133. attr_reader(:fog_c_name)
  134. attr_reader(:fog_c_move)
  135. attr_reader(:fog_c_opac)
  136. attr_reader(:fog_c_z)
  137. attr_reader(:fog_c_color)
  138.  
  139. def get_fog_info
  140. @can_fog = false
  141. @fog_a_name = ""
  142. @fog_a_move = [0, 0]
  143. @fog_a_opac = 255
  144. @fog_a_z = FOG_By_Dekita::Default_Fog_A_z
  145. @fog_a_color = nil
  146. @fog_b_name = ""
  147. @fog_b_move = [0, 0]
  148. @fog_b_opac = 255
  149. @fog_b_z = FOG_By_Dekita::Default_Fog_B_z
  150. @fog_b_color = nil
  151. @fog_c_name = ""
  152. @fog_c_move = [0, 0]
  153. @fog_c_opac = 255
  154. @fog_c_z = FOG_By_Dekita::Default_Fog_C_z
  155. @fog_c_color = nil
  156. self.note.split(/[\r\n]+/).each { |line| case line
  157. when /<fog a: (.*)/i ; @can_fog = true ; @fog_a_name = $1.to_s
  158. when /<a move: (.*), (.*)>/i ; @fog_a_move = [$1.to_i, $2.to_i]
  159. when /<a opac: (.*)/i ; @fog_a_opac = $1.to_i
  160. when /<a z: (.*)/i ; @fog_a_z = $1.to_i
  161. when /<a col: (.*),(.*),(.*),(.*)>/im
  162. @fog_a_color = Color.new($1.to_i,$2.to_i,$3.to_i,$4.to_i)
  163. when /<fog b: (.*)/i ; @can_fog = true ; @fog_b_name = $1.to_s
  164. when /<b move: (.*), (.*)>/i ; @fog_b_move = [$1.to_i, $2.to_i]
  165. when /<b opac: (.*)/i ; @fog_b_opac = $1.to_i
  166. when /<b z: (.*)/i ; @fog_b_z = $1.to_i
  167. when /<b col: (.*),(.*),(.*),(.*)>/im
  168. @fog_b_color = Color.new($1.to_i,$2.to_i,$3.to_i,$4.to_i)
  169. when /<fog c: (.*)/i ; @can_fog = true ; @fog_c_name = $1.to_s
  170. when /<c move: (.*), (.*)>/i ; @fog_c_move = [$1.to_i, $2.to_i]
  171. when /<c opac: (.*)/i ; @fog_c_opac = $1.to_i
  172. when /<c z: (.*)/i ; @fog_c_z = $1.to_i
  173. when /<c col: (.*),(.*),(.*),(.*)>/im
  174. @fog_c_color = Color.new($1.to_i,$2.to_i,$3.to_i,$4.to_i)
  175. end ; } # self.note.split
  176. end
  177.  
  178. end
  179.  
  180. #===============================================================================#
  181. class Game_Map
  182. #===============================================================================#
  183.  
  184. alias :fogsys :setup
  185. alias :sdp_for_fog :set_display_pos
  186. alias :s_d_for_fog :scroll_down
  187. alias :s_l_for_fog :scroll_left
  188. alias :s_r_for_fog :scroll_right
  189. alias :s_u_for_fog :scroll_up
  190. alias :update_for_fog :update_parallax
  191.  
  192. attr_reader(:has_fog)
  193. attr_reader(:fog_a_name)
  194. attr_reader(:fog_a_move)
  195. attr_reader(:fog_a_opacity)
  196. attr_reader(:fog_a_z)
  197. attr_reader(:fog_a_color)
  198. attr_reader(:fog_b_name)
  199. attr_reader(:fog_b_move)
  200. attr_reader(:fog_b_opacity)
  201. attr_reader(:fog_b_z)
  202. attr_reader(:fog_b_color)
  203. attr_reader(:fog_c_name)
  204. attr_reader(:fog_c_move)
  205. attr_reader(:fog_c_opacity)
  206. attr_reader(:fog_c_z)
  207. attr_reader(:fog_c_color)
  208.  
  209. def setup(map_id)
  210. fogsys(map_id)
  211. @map.get_fog_info
  212. @has_fog = @map.can_fog
  213. setup_fog_a
  214. setup_fog_b
  215. setup_fog_c
  216. end
  217.  
  218. def setup_fog_a
  219. @fog_a_name = @map.fog_a_name
  220. @fog_a_move = @map.fog_a_move
  221. @fog_a_opacity = @map.fog_a_opac
  222. @fog_a_z = @map.fog_a_z
  223. @fog_a_color = @map.fog_a_color
  224. @fog_a_loop_x = @fog_a_move[0] != 0 ? true : false
  225. @fog_a_loop_y = @fog_a_move[1] != 0 ? true : false
  226. @fog_a_sx = @fog_a_move[0]
  227. @fog_a_sy = @fog_a_move[1]
  228. @fog_a_x = 0
  229. @fog_a_y = 0
  230. end
  231.  
  232. def setup_fog_b
  233. @fog_b_name = @map.fog_b_name
  234. @fog_b_move = @map.fog_b_move
  235. @fog_b_opacity = @map.fog_b_opac
  236. @fog_b_z = @map.fog_b_z
  237. @fog_b_color = @map.fog_b_color
  238. @fog_b_loop_x = @fog_b_move[0] != 0 ? true : false
  239. @fog_b_loop_y = @fog_b_move[1] != 0 ? true : false
  240. @fog_b_sx = @fog_b_move[0]
  241. @fog_b_sy = @fog_b_move[1]
  242. @fog_b_x = 0
  243. @fog_b_y = 0
  244. end
  245.  
  246. def setup_fog_c
  247. @fog_c_name = @map.fog_c_name
  248. @fog_c_move = @map.fog_c_move
  249. @fog_c_opacity = @map.fog_c_opac
  250. @fog_c_z = @map.fog_c_z
  251. @fog_c_color = @map.fog_c_color
  252. @fog_c_loop_x = @fog_c_move[0] != 0 ? true : false
  253. @fog_c_loop_y = @fog_c_move[1] != 0 ? true : false
  254. @fog_c_sx = @fog_c_move[0]
  255. @fog_c_sy = @fog_c_move[1]
  256. @fog_c_x = 0
  257. @fog_c_y = 0
  258. end
  259.  
  260. def set_display_pos(x, y)
  261. sdp_for_fog(x, y)
  262. @fog_a_x = x
  263. @fog_a_y = y
  264. @fog_b_x = x
  265. @fog_b_y = y
  266. @fog_c_x = x
  267. @fog_c_y = y
  268. end
  269.  
  270. def scroll_down(distance)
  271. last_y = @display_y
  272. s_d_for_fog(distance)
  273. fog_scroll_down(distance, last_y)
  274. end
  275.  
  276. def fog_scroll_down(distance, last_y)
  277. value = loop_vertical? ? distance : @display_y - last_y
  278. @fog_a_y += value ; @fog_b_y += value ; @fog_c_y += value
  279. end
  280.  
  281. def scroll_left(distance)
  282. last_x = @display_x
  283. s_l_for_fog(distance)
  284. fog_scroll_left(distance, last_x)
  285. end
  286.  
  287. def fog_scroll_left(distance, last_x)
  288. value = loop_horizontal? ? -distance : @display_x - last_x
  289. @fog_a_x += value ; @fog_b_x += value ; @fog_c_x += value
  290. end
  291.  
  292. def scroll_right(distance)
  293. last_x = @display_x
  294. s_r_for_fog(distance)
  295. fog_scroll_right(distance, last_x)
  296. end
  297.  
  298. def fog_scroll_right(distance, last_x)
  299. value = loop_horizontal? ? distance : @display_x - last_x
  300. @fog_a_x += value ; @fog_b_x += value ; @fog_c_x += value
  301. end
  302.  
  303. def scroll_up(distance)
  304. last_y = @display_y
  305. s_u_for_fog(distance)
  306. fog_scroll_down(distance, last_y)
  307. end
  308.  
  309. def fog_scroll_down(distance, last_y)
  310. value = loop_vertical? ? -distance : @display_y - last_y
  311. @fog_a_y += value ; @fog_b_y += value ; @fog_c_y += value
  312. end
  313.  
  314. def update_parallax
  315. update_for_fog
  316. update_fog
  317. end
  318.  
  319. def update_fog
  320. @fog_a_x += @fog_a_sx / 128.0 if @fog_a_loop_x
  321. @fog_a_y += @fog_a_sy / 128.0 if @fog_a_loop_y
  322. @fog_b_x += @fog_b_sx / 128.0 if @fog_b_loop_x
  323. @fog_b_y += @fog_b_sy / 128.0 if @fog_b_loop_y
  324. @fog_c_x += @fog_c_sx / 128.0 if @fog_c_loop_x
  325. @fog_c_y += @fog_c_sy / 128.0 if @fog_c_loop_y
  326. end
  327.  
  328. def fog_a_x
  329. @fog_a_x
  330. end
  331.  
  332. def fog_a_y
  333. @fog_a_y
  334. end
  335.  
  336. def fog_b_x
  337. @fog_b_x
  338. end
  339.  
  340. def fog_b_y
  341. @fog_b_y
  342. end
  343.  
  344. def fog_c_x
  345. @fog_c_x
  346. end
  347.  
  348. def fog_c_y
  349. @fog_c_y
  350. end
  351.  
  352. end
  353.  
  354. #==============================================================================
  355. class Plane_FOG < Plane
  356. #==============================================================================
  357.  
  358. def initialize(fog_id = "", fog_type)
  359. return unless fog_id != ""
  360. return if $BTEST
  361. super(nil)
  362. self.bitmap = Cache.parallax(fog_id)
  363. @fog_type = fog_type
  364. initialize_values
  365. update
  366. end
  367.  
  368. def initialize_values
  369. case @fog_type
  370. when :type_a
  371. self.z = $game_map.fog_a_z
  372. self.opacity = $game_map.fog_a_opacity
  373. self.color = $game_map.fog_a_color if $game_map.fog_a_color != nil
  374. when :type_b
  375. self.z = $game_map.fog_b_z
  376. self.opacity = $game_map.fog_b_opacity
  377. self.color = $game_map.fog_b_color if $game_map.fog_b_color != nil
  378. when :type_c
  379. self.z = $game_map.fog_c_z
  380. self.opacity = $game_map.fog_c_opacity
  381. self.color = $game_map.fog_c_color if $game_map.fog_c_color != nil
  382. end
  383. end
  384.  
  385. def get_position_update
  386. case @fog_type
  387. when :type_a
  388. self.ox = $game_map.fog_a_x * 32 + $game_map.fog_a_move[0]
  389. self.oy = $game_map.fog_a_y * 32 + $game_map.fog_a_move[1]
  390. when :type_b
  391. self.ox = $game_map.fog_b_x * 32 + $game_map.fog_b_move[0]
  392. self.oy = $game_map.fog_b_y * 32 + $game_map.fog_b_move[1]
  393. when :type_c
  394. self.ox = $game_map.fog_c_x * 32 + $game_map.fog_c_move[0]
  395. self.oy = $game_map.fog_c_y * 32 + $game_map.fog_c_move[1]
  396. end
  397. end
  398.  
  399. def update
  400. return if self.disposed?
  401. get_position_update
  402. case @fog_type
  403. when :type_a
  404. self.opacity = $game_map.fog_a_opacity if self.opacity != $game_map.fog_a_opacity
  405. when :type_b
  406. self.opacity = $game_map.fog_b_opacity if self.opacity != $game_map.fog_b_opacity
  407. when :type_c
  408. self.opacity = $game_map.fog_c_opacity if self.opacity != $game_map.fog_c_opacity
  409. end
  410. end
  411.  
  412. # def dispose
  413. # super
  414. # end
  415.  
  416. end
  417.  
  418. #==============================================================================
  419. module Planeset_FOG
  420. #==============================================================================
  421.  
  422. def create_fog
  423. gm = $game_map
  424. create_fog_a(gm)
  425. create_fog_b(gm)
  426. create_fog_c(gm)
  427. end
  428.  
  429. def create_fog_a(gm)
  430. @fogg_a = Plane_FOG.new(gm.fog_a_name,:type_a)
  431. @fogg_a_name = gm.fog_a_name
  432. end
  433.  
  434. def create_fog_b(gm)
  435. @fogg_b = Plane_FOG.new(gm.fog_b_name,:type_b)
  436. @fogg_b_name = gm.fog_b_name
  437. end
  438.  
  439. def create_fog_c(gm)
  440. @fogg_c = Plane_FOG.new(gm.fog_c_name,:type_c)
  441. @fogg_c_name = gm.fog_c_name
  442. end
  443.  
  444. def dispose_fog
  445. @fogg_a.dispose if @fogg_a != nil
  446. @fogg_b.dispose if @fogg_b != nil
  447. @fogg_c.dispose if @fogg_c != nil
  448. end
  449.  
  450. def update_fog
  451. if @fogg_a_name != $game_map.fog_a_name
  452. @fogg_a.dispose if @fogg_a != nil
  453. create_fog_a($game_map)
  454. end
  455. if @fogg_b_name != $game_map.fog_b_name
  456. @fogg_b.dispose if @fogg_b != nil
  457. create_fog_b($game_map)
  458. end
  459. if @fogg_c_name != $game_map.fog_c_name
  460. @fogg_c.dispose if @fogg_c != nil
  461. create_fog_c($game_map)
  462. end
  463. @fogg_a.update if @fogg_a != nil
  464. @fogg_b.update if @fogg_b != nil
  465. @fogg_c.update if @fogg_c != nil
  466. end
  467.  
  468. end
  469.  
  470. #==============================================================================
  471. class Spriteset_Map
  472. #==============================================================================
  473.  
  474. include Planeset_FOG
  475. alias :initializefogg :initialize
  476. alias :disposefogg :dispose
  477. alias :updatefogg :update
  478.  
  479. def initialize
  480. create_fog
  481. initializefogg
  482. end
  483.  
  484. def dispose
  485. disposefogg
  486. dispose_fog
  487. end
  488.  
  489. def update
  490. updatefogg
  491. update_fog
  492. end
  493.  
  494. end
  495.  
  496. #==============================================================================
  497. class Spriteset_Battle
  498. #==============================================================================
  499.  
  500. include Planeset_FOG
  501. alias :initializefogg :initialize
  502. alias :disposefogg :dispose
  503. alias :updatefogg :update
  504.  
  505. def initialize
  506. create_fog
  507. initializefogg if FOG_By_Dekita::Show_In_Battle
  508. end
  509.  
  510. def dispose
  511. disposefogg
  512. dispose_fog
  513. end
  514.  
  515. def update
  516. updatefogg
  517. update_battle_fog
  518. end
  519.  
  520. def update_battle_fog
  521. return unless FOG_By_Dekita::Show_In_Battle
  522. $game_map.update_fog
  523. update_fog
  524. end
  525.  
  526. end
  527.  
  528. #===============================================================================#
  529. # - SCRIPT END - #
  530. #===============================================================================#
  531. # http://dekitarpg.wordpress.com/ #
  532. #===============================================================================#
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement