Advertisement
Guest User

Untitled

a guest
Mar 31st, 2015
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.35 KB | None | 0 0
  1. #-------------------------------------------------------------------------------
  2. # * [ACE] Khas Awesome Light Effects
  3. #-------------------------------------------------------------------------------
  4. # * By Khas Arcthunder - arcthunder.site40.net
  5. # * Version: 1.0 EN
  6. # * Released on: 17/01/2012
  7. #
  8. #-------------------------------------------------------------------------------
  9. # * Terms of Use
  10. #-------------------------------------------------------------------------------
  11. # Terms of Use I - Free scripts
  12. # Last updated: January 24, 2015
  13. #
  14. # The Terms of Use I apply to the following scripts: Arc Engine (VX Ace),
  15. # Awesome Light Effects (VX Ace), Pathfinder (VX Ace),
  16. # Pixel Movement (VX - VX Ace), Sapphire Action System (VX Ace),
  17. # Self Switches (VX Ace) and Smooth Sliding (VX Ace).
  18. #
  19. # If a script is not listed above, these terms do not apply and it may
  20. # require the user to purchase a license to use. Please check that
  21. # script for it's own terms of use.
  22. #
  23. # When using any of the listed scripts, you agree with the following
  24. # terms:
  25. #
  26. # 1. You must give credit to Khas (you may provide a link to
  27. # (http://arcthunder.blogspot.ca/p/terms-of-use.html if you want);
  28. # 2. You can use the listed scripts for free in both non-commercial
  29. # and commercial projects;
  30. # 4. You can use or edit the listed scripts for using in your
  31. # own project. However, you are not allowed to distribute any
  32. # modified version;
  33. # 5. You can’t give credit to yourself for posting any Khas script;
  34. # 6. If you want to share a Khas script, don’t post the direct
  35. # download link - redirect the user
  36. # [http://arcthunder.blogspot.ca/p/terms-of-use.html] instead.
  37. #
  38. #-------------------------------------------------------------------------------
  39. # * Features
  40. #-------------------------------------------------------------------------------
  41. # - Realistic Light
  42. # - Light does not pass over walls, blocks and roofs
  43. # - Static Light Sources
  44. # - Dynamic Light Sources (like a player's lantern)
  45. # - Multiple effects
  46. # - Easy to use (comments)
  47. #
  48. #-------------------------------------------------------------------------------
  49. # * WARNING - Performance
  50. #-------------------------------------------------------------------------------
  51. # This script may be too heavy to old processors! The Awesome Light Effects was
  52. # tested on a Core 2 Duo E4500 and on a Core i5, without any lag. However,
  53. # there's other factors that may influence the script performance:
  54. #
  55. # 1. Map size
  56. # This script searches surfaces on the map, in order to cut the light pictures.
  57. # In a huge map, the number of surfaces may increase a lot, affecting the
  58. # DYNAMIC LIGHT SOURCE only. Map size does not influence the static sources.
  59. #
  60. # 2. Number of effects
  61. # This script draws the effects on the screen, but before drawing, it checks
  62. # if the effect is out of screen (in this case, the script will skip the
  63. # light drawing). Too much effects may cause lag, but this is just a prevision.
  64. #
  65. # 3. Effect's picture size
  66. # The picture size of the DYNAMIC LIGHT SOURCE influences directly on your
  67. # game's performace. The bigger is the picture, the slower it will be to
  68. # draw it dynamically. The recommended maximum size is 200x200 pixels
  69. #
  70. #-------------------------------------------------------------------------------
  71. # * WARNING - Light pictures
  72. #-------------------------------------------------------------------------------
  73. # In order to run this script correctly, the light pictures MUST obey the
  74. # following conditions:
  75. # 1. The picture's size MUST be multiple of 2. Example: 150x150
  76. # 2. The picture's width MUST be equal to it's height. Example: 156x156
  77. # 3. The picture's colors MUST be inverted! This is necessary because
  78. # the script inverts the colors to draw the effect. The black color
  79. # will be transparent!
  80. #
  81. #-------------------------------------------------------------------------------
  82. # * Instructions - 1. Setup your effects!
  83. #-------------------------------------------------------------------------------
  84. # In order to setup your static effects, go to the setup part and define your
  85. # effects inside the Effects hash. Do as the following mode:
  86. #
  87. # X => [picture,opacity,variation,cut], <= Remember to put a comma here!
  88. #
  89. # Where:
  90. # picture => Picture's name, inside the Graphics/Lights folder;
  91. # opacity => Effect's opacity;
  92. # variation => Effect's opacity variation;
  93. # cut => Put true to cut the effect or false to don't;
  94. # X => The effect's ID, it will be used on events.
  95. #
  96. # Check the default effects to understand how they work.
  97. #
  98. #-------------------------------------------------------------------------------
  99. # * Instructions - 2. Use your effects!
  100. #-------------------------------------------------------------------------------
  101. # In order to use a effect, put the following comment on a event:
  102. #
  103. # [light x]
  104. #
  105. # Where x must be the Effect's ID.
  106. #
  107. #-------------------------------------------------------------------------------
  108. # * Instructions - 3. Use an awesome lantern!
  109. #-------------------------------------------------------------------------------
  110. # The dynamic light source (lantern) is initialized invisible by default.
  111. # You may call the following commands:
  112. #
  113. # l = $game_map.lantern
  114. # Gets the lantern into a variable
  115.  
  116. # l.set_graphic(i)
  117. # Sets the lantern's graphic to i, where i must be the picture's file name on
  118. # Graphics/Lights folder.
  119. #
  120. # l.set_multiple_graphics(h)
  121. # Sets the lantern's graphics to h, where h must be a hash with the following
  122. # structure:
  123. #
  124. # h = {2=>"ld",4=>"ll",6=>"lr",8=>"lu"}
  125. #
  126. # Where:
  127. # "ld" is the name of the picture when the lantern's owner is looking down;
  128. # "ll" is the name of the picture when the lantern's owner is looking left;
  129. # "lr" is the name of the picture when the lantern's owner is looking right;
  130. # "lu" is the name of the picture when the lantern's owner is looking up.
  131. #
  132. # l.change_owner(char)
  133. # Sets the lantern's owner to char. Char must be ONE of the following commands:
  134. # $game_player <= The player itself;
  135. # self_event <= The event where the command was called;
  136. # $game_map.events[x] <= The event ID x.
  137. #
  138. # l.set_opacity(o,p)
  139. # Sets the lantern's opacity, where:
  140. # o is the opacity itself;
  141. # p is the opacity variation.
  142. #
  143. # l.show
  144. # After setting the lantern with the commands above, you may set it to visible
  145. # using this command.
  146. #
  147. # l.hide
  148. # Use this command to set the lantern as invisible.
  149. #
  150. #-------------------------------------------------------------------------------
  151. # * Instructions - 4. Use the effect's surface!
  152. #-------------------------------------------------------------------------------
  153. # The Awesome Light Effects draws the effects on a surface. In order to make
  154. # the effects visible, the effect's surface MUST be visible. The Effect's
  155. # Surface is initialized with it's opacity set to zero. You can call the
  156. # following commands:
  157. #
  158. # s = $game_map.effect_surface
  159. # Gets the Effect's Surface into a variable
  160. #
  161. # s.set_color(r,g,b)
  162. # Changes the Effect's Surface color instantly, where:
  163. # r => red level;
  164. # g => green level;
  165. # b => blue level;
  166. #
  167. # s.set_alpha(a)
  168. # Changes the Effect's Surface opacity instantly to a.
  169. #
  170. # s.change_color(time,r,g,b)
  171. # Changes the Effect's Surface color ONLY in a certain time, where:
  172. # time => The change's time (frames);
  173. # r => red level;
  174. # g => green level;
  175. # b => blue level;
  176. #
  177. # s.change_color(time,r,g,b,a)
  178. # Changes the Effect's Surface color and it's opacity in a certain time, where:
  179. # time => The change's time (frames);
  180. # r => red level;
  181. # g => green level;
  182. # b => blue level;
  183. # a => opacity
  184. #
  185. # s.change_alpha(time,a)
  186. # Changes the Effect's Surface opacity in a certain time, where:
  187. # time => The change's time (frames);
  188. # a => opacity
  189. #
  190. #-------------------------------------------------------------------------------
  191. # * Instructions - 5. Use the effect's surface with Tone command!
  192. #-------------------------------------------------------------------------------
  193. # You can access the Effect's Surface with the "Screen Tone" command. In order
  194. # to turn this feature on, set the "Surface_UE" constant to true.
  195. #
  196. # If you decided to use this feature, please note some details:
  197. # 1. The colors values must be between 0 and 255;
  198. # 2. The time is in frames;
  199. # 3. The "gray" value will be sent as the opacity value
  200. #
  201. #-------------------------------------------------------------------------------
  202. # * Instructions - 6. Setup your Tileset Tags!
  203. #-------------------------------------------------------------------------------
  204. # In order to cut the effect's picture correctly, there's 3 types of behavior
  205. # for a tile: wall, block and roof. Walls will make shadows as real walls,
  206. # blocks as blocks and roofs as roofs. So, the tileset tags MUST be configured.
  207. # Check the demo to understand how this system works. If the tilesets aren't
  208. # configured correctly, the script won't cut the effects correctly.
  209. #
  210. #-------------------------------------------------------------------------------
  211. # * Setup Part
  212. #-------------------------------------------------------------------------------
  213. module Light_Core
  214. Effects = { # <= DON'T change this!
  215. #-------------------------------------------------------------------------------
  216. # PUT YOUR EFFECTS HERE!
  217. #-------------------------------------------------------------------------------
  218. 0 => ["light",255,0,true],
  219. 1 => ["torch",200,20,true],
  220. 2 => ["torch_m",180,30,true],
  221. 3 => ["light_s",255,0,true],
  222.  
  223. #-------------------------------------------------------------------------------
  224. # End of effecs configuration
  225. #-------------------------------------------------------------------------------
  226. } # <= DON'T change this!
  227.  
  228. # Z coordinate of the Effect's Surface
  229. Surface_Z = 180
  230.  
  231. # Enable Effect's Surface control by "Screen Tone" command?
  232. Surface_UE = true
  233.  
  234. # Roof behavior tag
  235. Roof_Tag = 5
  236. # Wall behavior tag
  237. Wall_Tag = 6
  238. # Block behavior tag
  239. Block_Tag = 7
  240.  
  241. # Don't change this!
  242. ACC = Math.tan(Math::PI/26)
  243. end
  244. #-------------------------------------------------------------------------------
  245. # Script
  246. #-------------------------------------------------------------------------------
  247. module Cache
  248. def self.light(filename)
  249. load_bitmap("Graphics/Lights/", filename)
  250. end
  251. end
  252. module Light_Bitcore
  253. include Light_Core
  254. def self.initialize
  255. @@buffer = {}
  256. Effects.values.each { |effect| Light_Bitcore.push(effect[0])}
  257. end
  258. def self::[](key)
  259. return @@buffer[key]
  260. end
  261. def self.push(key)
  262. return if @@buffer.keys.include?(key)
  263. @@buffer[key] = Cache.light(key)
  264. end
  265. end
  266. Light_Bitcore.initialize
  267. class Light_SSource
  268. attr_reader :real_x
  269. attr_reader :real_y
  270. attr_reader :range
  271. attr_accessor :bitmap
  272. attr_reader :w
  273. attr_reader :h
  274. attr_reader :hs
  275. def initialize(char,bitmap,opacity,plus,hs)
  276. sync(char)
  277. @key = bitmap
  278. @bitmap = Light_Bitcore[@key].clone
  279. @range = @bitmap.width/2
  280. @w = @bitmap.width
  281. @h = @bitmap.height
  282. @mr = @range - 16
  283. @opacity = opacity
  284. @plus = plus
  285. @hs = hs
  286. render if @hs
  287. end
  288. def render
  289. tx = x
  290. ty = y
  291. tsx = x + @range
  292. tsy = y + @range
  293. dr = @range*2
  294. for s in $game_map.surfaces
  295. next if !s.visible?(tsx,tsy) || !s.within?(tx,tx+dr,ty,ty+dr)
  296. s.render_shadow(tx,ty,tsx,tsy,@range,@bitmap)
  297. end
  298. end
  299. def restore
  300. return unless @bitmap.nil?
  301. @bitmap = Light_Bitcore[@key].clone
  302. render if @hs
  303. end
  304. def opacity
  305. @plus == 0 ? @opacity : (@opacity + rand(@plus))
  306. end
  307. def sx
  308. return $game_map.adjust_x(@real_x)*32-@mr
  309. end
  310. def sy
  311. return $game_map.adjust_y(@real_y)*32-@mr
  312. end
  313. def sync(char)
  314. @real_x = char.real_x
  315. @real_y = char.real_y
  316. end
  317. def x
  318. return (@real_x*32 - @mr).to_f
  319. end
  320. def y
  321. return (@real_y*32 - @mr).to_f
  322. end
  323. def dispose
  324. return if @bitmap.nil?
  325. @bitmap.dispose
  326. @bitmap = nil
  327. end
  328. end
  329. class Light_DSource < Light_SSource
  330. attr_reader :bitmap
  331. attr_reader :visible
  332. def initialize
  333. @key = nil
  334. @bitmap = nil
  335. @opacity = 255
  336. @plus = 0
  337. @char = $game_player
  338. @visible = false
  339. end
  340. def set_opacity(o,p)
  341. @opacity = o
  342. @plus = p
  343. end
  344. def set_graphic(sb)
  345. dispose
  346. @key = {2=>sb,4=>sb,6=>sb,8=>sb}
  347. Light_Bitcore.push(sb)
  348. @bitmap = {2=>Light_Bitcore[@key[2]].clone,4=>Light_Bitcore[@key[4]].clone,6=>Light_Bitcore[@key[6]].clone,8=>Light_Bitcore[@key[8]].clone}
  349. @range = @bitmap[2].width/2
  350. @w = @bitmap[2].width
  351. @h = @bitmap[2].height
  352. @mr = @range - 16
  353. end
  354. def set_multiple_graphics(ba)
  355. dispose
  356. @key = ba
  357. @key.values.each {|key| Light_Bitcore.push(key)}
  358. @bitmap = {2=>Light_Bitcore[@key[2]].clone,4=>Light_Bitcore[@key[4]].clone,6=>Light_Bitcore[@key[6]].clone,8=>Light_Bitcore[@key[8]].clone}
  359. @range = @bitmap[2].width/2
  360. @w = @bitmap[2].width
  361. @h = @bitmap[2].height
  362. @mr = @range - 16
  363. end
  364. def get_graphic
  365. return @bitmap[@char.direction].clone
  366. end
  367. def show
  368. return if @bitmap.nil?
  369. @visible = true
  370. end
  371. def hide
  372. @visible = false
  373. end
  374. def restore
  375. return if @key.nil?
  376. @key.values.each {|key| Light_Bitcore.push(key)}
  377. @bitmap = {2=>Light_Bitcore[@key[2]].clone,4=>Light_Bitcore[@key[4]].clone,6=>Light_Bitcore[@key[6]].clone,8=>Light_Bitcore[@key[8]].clone}
  378. end
  379. def dispose
  380. return if @bitmap.nil?
  381. @bitmap.values.each { |b| b.dispose }
  382. @bitmap = nil
  383. end
  384. def change_owner(char)
  385. @char = char
  386. end
  387. def render
  388. end
  389. def sx
  390. return $game_map.adjust_x(@char.real_x)*32-@mr
  391. end
  392. def sy
  393. return $game_map.adjust_y(@char.real_y)*32-@mr
  394. end
  395. def x
  396. return (@char.real_x*32 - @mr).to_f
  397. end
  398. def y
  399. return (@char.real_y*32 - @mr).to_f
  400. end
  401. end
  402. class Light_Surface
  403. def initialize
  404. @ta = @a = 0
  405. @tr = @r = 255
  406. @tg = @g = 255
  407. @tb = @b = 255
  408. @va = @vr = @vg = @vb = 0.0
  409. @timer = 0
  410. end
  411. def refresh
  412. return if @timer == 0
  413. @a += @va
  414. @r += @vr
  415. @g += @vg
  416. @b += @vb
  417. $game_map.light_surface.opacity = @a
  418. @timer -= 1
  419. end
  420. def change_color(time,r,g,b,a=nil)
  421. r = 0 if r < 0; r = 255 if r > 255
  422. g = 0 if g < 0; g = 255 if g > 255
  423. b = 0 if b < 0; b = 255 if b > 255
  424. unless a.nil?
  425. a = 0 if a < 0; a = 255 if a > 255
  426. end
  427. @timer = time
  428. @tr = 255-r
  429. @tg = 255-g
  430. @tb = 255-b
  431. @va = (a.nil? ? 0 : (a-@a).to_f/@timer)
  432. @vr = (@tr - @r).to_f/@timer
  433. @vg = (@tg - @g).to_f/@timer
  434. @vb = (@tb - @b).to_f/@timer
  435. end
  436. def change_alpha(time,a)
  437. a = 0 if a < 0; a = 255 if a > 255
  438. @timer = time
  439. @ta = a
  440. @vr = @vg = @vb = 0.0
  441. @va = (a-@a).to_f/@timer
  442. end
  443. def set_color(r,g,b)
  444. r = 0 if r < 0; r = 255 if r > 255
  445. g = 0 if g < 0; g = 255 if g > 255
  446. b = 0 if b < 0; b = 255 if b > 255
  447. @tr = @r = 255-r
  448. @tg = @g = 255-g
  449. @tb = @b = 255-b
  450. @va = @vr = @vg = @vb = 0.0
  451. @timer = 0
  452. end
  453. def set_alpha(a)
  454. a = 0 if a < 0; a = 255 if a > 255
  455. @ta = @a = a
  456. $game_map.light_surface.opacity = @a
  457. @va = @vr = @vg = @vb = 0.0
  458. @timer = 0
  459. end
  460. def alpha
  461. return @a
  462. end
  463. def color
  464. return Color.new(@r,@g,@b)
  465. end
  466. end
  467. class Game_Map
  468. include Light_Core
  469. attr_accessor :light_surface
  470. attr_accessor :light_sources
  471. attr_accessor :surfaces
  472. attr_accessor :effect_surface
  473. attr_accessor :lantern
  474. alias kbl_setup_events setup_events
  475. alias kbl_initialize initialize
  476. alias kbl_update update
  477. def initialize
  478. kbl_initialize
  479. @effect_surface = Light_Surface.new
  480. @lantern = Light_DSource.new
  481. end
  482. def update(arg)
  483. @effect_surface.refresh if arg
  484. kbl_update(arg)
  485. end
  486. def first_tag(x,y)
  487. tag = tileset.flags[tile_id(x,y,0)] >> 12
  488. return tag > 0 ? tag : 0
  489. end
  490. def setup_events
  491. @light_sources.nil? ? @light_sources = [] : @light_sources.clear
  492. setup_surfaces
  493. merge_surfaces
  494. kbl_setup_events
  495. end
  496. def setup_surfaces
  497. @surfaces = []
  498. for x in 0..(width-1)
  499. for y in 0..(height-1)
  500. tag = first_tag(x,y)
  501. if tag == Wall_Tag
  502. i = tile_id(x,y,0)
  503. if i & 0x02 == 0x02
  504. @surfaces << Block_SD.new(x*32,y*32,x*32+32,y*32)
  505. end
  506. if i & 0x04 == 0x04
  507. @surfaces << Block_WR.new(x*32+31,y*32,x*32+31,y*32+32)
  508. @surfaces << Block_IL.new(x*32+32,y*32,x*32+32,y*32+32)
  509. end
  510. if i & 0x01 == 0x01
  511. @surfaces << Block_IR.new(x*32-1,y*32,x*32-1,y*32+32)
  512. @surfaces << Block_WL.new(x*32,y*32,x*32,y*32+32)
  513. end
  514. elsif tag == Roof_Tag
  515. i = tile_id(x,y,0)
  516. @surfaces << Block_SU.new(x*32,y*32,x*32+32,y*32) if i & 0x02 == 0x02
  517. @surfaces << Block_SR.new(x*32+31,y*32,x*32+31,y*32+32) if i & 0x04 == 0x04
  518. @surfaces << Block_SL.new(x*32,y*32,x*32,y*32+32) if i & 0x01 == 0x01
  519. elsif tag == Block_Tag
  520. f = tileset.flags[tile_id(x,y,0)]
  521. @surfaces << Block_SL.new(x*32,y*32,x*32,y*32+32) if f & 0x02 == 0x02
  522. @surfaces << Block_SR.new(x*32+31,y*32,x*32+31,y*32+32) if f & 0x04 == 0x04
  523. @surfaces << Block_SU.new(x*32,y*32,x*32+32,y*32) if f & 0x08 == 0x08
  524. end
  525. end
  526. end
  527. end
  528. def merge_surfaces
  529. new_surfaces = []
  530. hs = []; vs = []
  531. ws = []; is = []
  532. for surface in @surfaces
  533. if surface.type & 0x05 == 0
  534. hs << surface
  535. else
  536. if surface.type & 0x010 == 0
  537. vs << surface
  538. else
  539. if surface.type & 0x08 == 0
  540. ws << surface
  541. else
  542. is << surface
  543. end
  544. end
  545. end
  546. end
  547. for surface in hs
  548. surface.ready ? next : surface.ready = true
  549. for s in hs
  550. next if s.ready || s.y1 != surface.y1 || surface.type != s.type
  551. if s.x2 == surface.x1
  552. surface.x1 = s.x1
  553. s.trash = true
  554. s.ready = true
  555. surface.ready = false
  556. elsif s.x1 == surface.x2
  557. surface.x2 = s.x2
  558. s.trash = true
  559. s.ready = true
  560. surface.ready = false
  561. end
  562. end
  563. end
  564. hs.each { |s| @surfaces.delete(s) if s.trash}
  565. for surface in vs
  566. surface.ready ? next : surface.ready
  567. for s in vs
  568. next if s.ready || s.x1 != surface.x1
  569. if s.y2 == surface.y1
  570. surface.y1 = s.y1
  571. s.trash = true
  572. s.ready = true
  573. surface.ready = false
  574. elsif s.y1 == surface.y2
  575. surface.y2 = s.y2
  576. s.trash = true
  577. s.ready = true
  578. surface.ready = false
  579. end
  580. end
  581. end
  582. vs.each { |s| @surfaces.delete(s) if s.trash}
  583. for surface in ws
  584. surface.ready ? next : surface.ready
  585. for s in ws
  586. next if s.ready || s.x1 != surface.x1
  587. if s.y2 == surface.y1
  588. surface.y1 = s.y1
  589. s.trash = true
  590. s.ready = true
  591. surface.ready = false
  592. elsif s.y1 == surface.y2
  593. surface.y2 = s.y2
  594. s.trash = true
  595. s.ready = true
  596. surface.ready = false
  597. end
  598. end
  599. end
  600. ws.each { |s| @surfaces.delete(s) if s.trash}
  601. for surface in is
  602. surface.ready ? next : surface.ready
  603. for s in is
  604. next if s.ready || s.x1 != surface.x1
  605. if s.y2 == surface.y1
  606. surface.y1 = s.y1
  607. s.trash = true
  608. s.ready = true
  609. surface.ready = false
  610. elsif s.y1 == surface.y2
  611. surface.y2 = s.y2
  612. s.trash = true
  613. s.ready = true
  614. surface.ready = false
  615. end
  616. end
  617. end
  618. is.each { |s| @surfaces.delete(s) if s.trash}
  619. end
  620. end
  621. class Game_Event < Game_Character
  622. alias kbl_initialize initialize
  623. alias kbl_setup_page setup_page
  624. def initialize(m,e)
  625. @light = nil
  626. kbl_initialize(m,e)
  627. end
  628. def setup_page(np)
  629. kbl_setup_page(np)
  630. setup_light(np.nil?)
  631. end
  632. def setup_light(dispose)
  633. unless @light.nil?
  634. $game_map.light_sources.delete(self)
  635. @light.dispose
  636. @light = nil
  637. end
  638. unless dispose && @list.nil?
  639. for command in @list
  640. if command.code == 108 && command.parameters[0].include?("[light")
  641. command.parameters[0].scan(/\[light ([0.0-9.9]+)\]/)
  642. effect = Light_Core::Effects[$1.to_i]
  643. @light = Light_SSource.new(self,effect[0],effect[1],effect[2],effect[3])
  644. $game_map.light_sources << self
  645. return
  646. end
  647. end
  648. end
  649. end
  650. def draw_light
  651. sx = @light.sx
  652. sy = @light.sy
  653. w = @light.w
  654. h = @light.h
  655. return if sx > 544 && sy > 416 && sx + w < 0 && sy + h < 0
  656. $game_map.light_surface.bitmap.blt(sx,sy,@light.bitmap,Rect.new(0,0,w,h),@light.opacity)
  657. end
  658. def dispose_light
  659. @light.dispose
  660. end
  661. def restore_light
  662. @light.restore
  663. end
  664. end
  665. if Light_Core::Surface_UE
  666. class Game_Interpreter
  667. def command_223
  668. $game_map.effect_surface.change_color(@params[1],@params[0].red,@params[0].green,@params[0].blue,@params[0].gray)
  669. wait(@params[1]) if @params[2]
  670. end
  671. end
  672. end
  673. class Game_Interpreter
  674. def self_event
  675. return $game_map.events[@event_id]
  676. end
  677. end
  678. class Block_Surface
  679. include Light_Core
  680. attr_accessor :x1
  681. attr_accessor :y1
  682. attr_accessor :x2
  683. attr_accessor :y2
  684. attr_accessor :ready
  685. attr_accessor :trash
  686. def initialize(x1,y1,x2,y2)
  687. @x1 = x1
  688. @y1 = y1
  689. @x2 = x2
  690. @y2 = y2
  691. @ready = false
  692. @trash = false
  693. end
  694. def within?(min_x,max_x,min_y,max_y)
  695. return @x2 > min_x && @x1 < max_x && @y2 > min_y && @y1 < max_y
  696. end
  697. end
  698. class Block_SL < Block_Surface
  699. attr_reader :type
  700. def initialize(x1,y1,x2,y2)
  701. super(x1,y1,x2,y2)
  702. @type = 0x01
  703. end
  704. def visible?(sx,sy)
  705. return sx < @x1
  706. end
  707. def render_shadow(phx,phy,sx,sy,range,bitmap)
  708. @m1 = (@y1-sy)/(@x1-sx)
  709. @n1 = sy - @m1*sx
  710. @m2 = (@y2-sy)/(@x2-sx)
  711. @n2 = sy - @m2*sx
  712. for x in @x1..(sx+range)
  713. init = shadow_iy(x)
  714. bitmap.clear_rect(x-phx,init-phy,1,shadow_fy(x)-init+3)
  715. end
  716. end
  717. def shadow_iy(x)
  718. return @m1*x+@n1
  719. end
  720. def shadow_fy(x)
  721. return @m2*x+@n2
  722. end
  723. end
  724. class Block_SR < Block_Surface
  725. attr_reader :type
  726. def initialize(x1,y1,x2,y2)
  727. super(x1,y1,x2,y2)
  728. @type = 0x04
  729. end
  730. def visible?(sx,sy)
  731. return sx > @x1
  732. end
  733. def render_shadow(phx,phy,sx,sy,range,bitmap)
  734. @m1 = (@y1-sy)/(@x1-sx)
  735. @n1 = sy - @m1*sx
  736. @m2 = (@y2-sy)/(@x2-sx)
  737. @n2 = sy - @m2*sx
  738. for x in (sx-range).to_i..@x1
  739. init = shadow_iy(x)
  740. bitmap.clear_rect(x-phx,init-phy,1,shadow_fy(x)-init+3)
  741. end
  742. end
  743. def shadow_iy(x)
  744. return @m1*x+@n1
  745. end
  746. def shadow_fy(x)
  747. return @m2*x+@n2
  748. end
  749. end
  750. class Block_IL < Block_Surface
  751. attr_reader :type
  752. def initialize(x1,y1,x2,y2)
  753. super(x1,y1,x2,y2)
  754. @type = 0x019
  755. end
  756. def visible?(sx,sy)
  757. return sx < @x1 && sy > @y1
  758. end
  759. def render_shadow(phx,phy,sx,sy,range,bitmap)
  760. @m1 = (@y1-sy)/(@x1-sx)
  761. @n1 = @y1 - @m1*@x1
  762. @m2 = (@y2-sy)/(@x2-sx)
  763. @m2 = 0 if @m2 > 0
  764. @n2 = @y2 - @m2*@x2
  765. for x in @x1..(sx+range)
  766. init = shadow_iy(x).floor
  767. bitmap.clear_rect(x-phx,init-3-phy,1,shadow_fy(x)-init+3)
  768. end
  769. end
  770. def shadow_iy(x)
  771. return @m1*x+@n1
  772. end
  773. def shadow_fy(x)
  774. return @m2*x+@n2
  775. end
  776. end
  777. class Block_IR < Block_Surface
  778. attr_reader :type
  779. def initialize(x1,y1,x2,y2)
  780. super(x1,y1,x2,y2)
  781. @type = 0x01c
  782. end
  783. def visible?(sx,sy)
  784. return sx > @x1 && sy > @y1
  785. end
  786. def render_shadow(phx,phy,sx,sy,range,bitmap)
  787. @m1 = (@y1-sy)/(@x1-sx)
  788. @n1 = @y1 - @m1*@x1
  789. @m2 = (@y2-sy)/(@x2-sx)
  790. @m2 = 0 if @m2 < 0
  791. @n2 = @y2 - @m2*@x2
  792. for x in (sx-range).to_i..@x1
  793. init = shadow_iy(x).floor
  794. bitmap.clear_rect(x-phx,init-3-phy,1,shadow_fy(x)-init+3)
  795. end
  796. end
  797. def shadow_iy(x)
  798. return @m1*x+@n1
  799. end
  800. def shadow_fy(x)
  801. return @m2*x+@n2
  802. end
  803. end
  804. class Block_WL < Block_Surface
  805. attr_reader :type
  806. def initialize(x1,y1,x2,y2)
  807. super(x1,y1,x2,y2)
  808. @type = 0x011
  809. end
  810. def visible?(sx,sy)
  811. return sx < @x1 && sy < @y2
  812. end
  813. def render_shadow(phx,phy,sx,sy,range,bitmap)
  814. @m1 = (@y1-sy)/(@x1-sx)
  815. @n1 = sy - @m1*sx
  816. @m2 = (@y2-sy)/(@x2-sx)
  817. @n2 = sy - @m2*sx
  818. for x in @x1..(sx+range)
  819. init = shadow_iy(x)
  820. bitmap.clear_rect(x-phx,init-phy,1,shadow_fy(x)-init+2)
  821. end
  822. end
  823. def shadow_iy(x)
  824. return @m1*x+@n1
  825. end
  826. def shadow_fy(x)
  827. return @m2*x+@n2
  828. end
  829. end
  830. class Block_WR < Block_Surface
  831. attr_reader :type
  832. def initialize(x1,y1,x2,y2)
  833. super(x1,y1,x2,y2)
  834. @type = 0x014
  835. end
  836. def visible?(sx,sy)
  837. return sx > @x1 && sy < @y2
  838. end
  839. def render_shadow(phx,phy,sx,sy,range,bitmap)
  840. @m1 = (@y1-sy)/(@x1-sx)
  841. @n1 = sy - @m1*sx
  842. @m2 = (@y2-sy)/(@x2-sx)
  843. @n2 = sy - @m2*sx
  844. for x in (sx-range).to_i..@x1
  845. init = shadow_iy(x)
  846. bitmap.clear_rect(x-phx,init-phy,1,shadow_fy(x)-init+2)
  847. end
  848. end
  849. def shadow_iy(x)
  850. return @m1*x+@n1
  851. end
  852. def shadow_fy(x)
  853. return @m2*x+@n2
  854. end
  855. end
  856. class Block_SU < Block_Surface
  857. attr_reader :type
  858. def initialize(x1,y1,x2,y2)
  859. super(x1,y1,x2,y2)
  860. @type = 0x02
  861. end
  862. def visible?(sx,sy)
  863. return sy < @y1
  864. end
  865. def render_shadow(phx,phy,sx,sy,range,bitmap)
  866. if @x1 == sx
  867. @m1 = nil
  868. else
  869. @m1 = (@y1-sy)/(@x1-sx)
  870. @m1 += ACC if @m1 < -ACC
  871. @n1 = @y1 - @m1*@x1
  872. end
  873. if @x2 == sx
  874. @m2 = nil
  875. else
  876. @m2 = (@y2-sy)/(@x2-sx)
  877. @n2 = sy - @m2*sx
  878. end
  879. for y in @y1..(sy+range)
  880. init = shadow_ix(y)
  881. bitmap.clear_rect(init-phx,y-phy,shadow_fx(y)-init+1,1)
  882. end
  883. end
  884. def shadow_ix(y)
  885. return @m1.nil? ? @x1 : (y-@n1)/@m1
  886. end
  887. def shadow_fx(y)
  888. return @m2.nil? ? @x2 : (y-@n2)/@m2
  889. end
  890. end
  891. class Block_SD < Block_Surface
  892. attr_reader :type
  893. def initialize(x1,y1,x2,y2)
  894. super(x1,y1,x2,y2)
  895. @type = 0x08
  896. end
  897. def visible?(sx,sy)
  898. return sy > @y1
  899. end
  900. def render_shadow(phx,phy,sx,sy,range,bitmap)
  901. if @x1 == sx
  902. @m1 = nil
  903. else
  904. @m1 = (@y1-sy)/(@x1-sx)
  905. @m1 -= ACC if @m1 > ACC
  906. @n1 = sy - @m1*sx
  907. end
  908. if x2 == sx
  909. @m2 = nil
  910. else
  911. @m2 = (@y2-sy)/(@x2-sx)
  912. @n2 = sy - @m2*sx
  913. end
  914. for y in (sy-range).to_i..@y1
  915. init = shadow_ix(y)
  916. bitmap.clear_rect(init-phx,y-phy,shadow_fx(y)-init+1,1)
  917. end
  918. end
  919. def shadow_ix(y)
  920. return @m1.nil? ? @x1 : (y-@n1)/@m1
  921. end
  922. def shadow_fx(y)
  923. return @m2.nil? ? @x2 : (y-@n2)/@m2
  924. end
  925. end
  926. class Spriteset_Map
  927. include Light_Core
  928. alias kbl_initialize initialize
  929. alias kbl_update update
  930. alias kbl_dispose dispose
  931. def initialize
  932. setup_lights
  933. kbl_initialize
  934. end
  935. def update
  936. kbl_update
  937. update_lights
  938. end
  939. def dispose
  940. kbl_dispose
  941. dispose_lights
  942. end
  943. def dispose_lights
  944. $game_map.lantern.dispose
  945. $game_map.light_sources.each { |source| source.dispose_light }
  946. $game_map.light_surface.bitmap.dispose
  947. $game_map.light_surface.dispose
  948. $game_map.light_surface = nil
  949. end
  950. def update_lights
  951. $game_map.light_surface.bitmap.clear
  952. $game_map.light_surface.bitmap.fill_rect(0,0,544,416,$game_map.effect_surface.color)
  953. $game_map.light_sources.each { |source| source.draw_light }
  954. return unless $game_map.lantern.visible
  955. @btr = $game_map.lantern.get_graphic
  956. x = $game_map.lantern.x
  957. y = $game_map.lantern.y
  958. r = $game_map.lantern.range
  959. sx = x + r
  960. sy = y + r
  961. dr = r*2
  962. $game_map.surfaces.each { |s| s.render_shadow(x,y,sx,sy,r,@btr) if s.visible?(sx,sy) && s.within?(x,x+dr,y,y+dr) }
  963. $game_map.light_surface.bitmap.blt($game_map.lantern.sx,$game_map.lantern.sy,@btr,Rect.new(0,0,dr,dr),$game_map.lantern.opacity)
  964. end
  965. def setup_lights
  966. @btr = nil
  967. $game_map.lantern.restore
  968. $game_map.light_sources.each { |source| source.restore_light }
  969. $game_map.light_surface = Sprite.new
  970. $game_map.light_surface.bitmap = Bitmap.new(544,416)
  971. $game_map.light_surface.bitmap.fill_rect(0,0,544,416,$game_map.effect_surface.color)
  972. $game_map.light_surface.blend_type = 2
  973. $game_map.light_surface.opacity = $game_map.effect_surface.alpha
  974. $game_map.light_surface.z = Surface_Z
  975. end
  976. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement