Guest User

Untitled

a guest
May 22nd, 2013
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.58 KB | None | 0 0
  1. =begin
  2.                               Thomas Edison VX
  3.  
  4. Version: 0.1
  5. Author: BulletXt ([email protected])
  6. Date: 12/06/2009
  7. Script based upon Kylock's (http://www.rpgmakervx.net/index.php?showtopic=2432)
  8.  
  9.  
  10. Description:
  11. To make an event glow, put a Comment inside event with the name of one of the
  12. light modes in the table below.
  13. When importing this script to a new project, be sure to copy
  14. Graphics/Pictures/le.png to your project.
  15.  
  16. You can make a specific light type turn off/on by turning
  17. one of the following switches id ON/off. By default, the switches are off so
  18. the lights will show. Of course, turning all switches to ON will make all
  19. light types go off.
  20.  
  21. The parameters you can modify for each light type are as follows:
  22. Name:    What you put in the comment for the event.
  23. Switch:  The switch that deactivates this type of light.
  24. Zoom:    The radius of the light in units of 32 pixels.
  25. Opacity: The opacity of the light.
  26. Vert:    The upwards offset for the light, use in case you want torches, etc.
  27. Flicker: The random offset of the position when flickering, in pixels.
  28.          0 creates a steady light source.
  29.         -1 will hold the position, but flicker the opacity.
  30. RGBK:    The tone values for the source. Work like the Tint Picture command.
  31.  
  32. You can also make custom effects if you know a bit of Ruby.
  33.  
  34. =end
  35. module BLXT
  36.   #id switch that if ON turns off FIRE mode lights
  37.   FIRE = 87
  38.   #id switch that if ON turns off LIGHT mode lights
  39.   LIGHT = 86
  40.   #id switch that if ON turns off GROUND mode lights
  41.   GROUND = 85
  42.   #id switch that if ON turns off TORCH mode lights
  43.   TORCH = 84
  44.  
  45.   LIGHT_TYPES = {
  46. #  Name            Switch Zoom  Opacity   Vert  Flicker    R    G    B    K
  47.   "DORMANT"    => [     0,   1,       0,     0,       0,   0,   0,   0,   0 ],
  48.   #Use this for things that can be "off" when the player saves.
  49.  
  50.   "FIRE"       => [  FIRE,   3,     100,     0,       3, 255,-100,-255,   0 ],  
  51.    
  52.   "LIGHT"      => [ LIGHT,   1,     150,     0,       0,   0,   0,   0,   0 ],
  53.   "LIGHT2"     => [ LIGHT,   6,     150,    20,       0,   0,   0,   0,   0 ],
  54.   "LIGHT3"     => [ LIGHT,   1,     150,    20,      -1,   0,   0,   0,   0 ],
  55.    
  56.   "TORCH"      => [ TORCH,   6,     150,    20,      10, 255,-100,-255,   0 ],
  57.   "TORCH2"     => [ TORCH,   6,     150,    20,      -1, 255,-100,-255,   0 ],
  58.   "TORCH3"     => [ TORCH,   3,     100,     0,       3, 255,-100,-255,   0 ],
  59.    
  60.   "GROUND"     => [GROUND,   2,     100,     0,       0,   0,   0,   0,   0 ],
  61.   "GROUND2"    => [GROUND,   2,     100,     0,      -1,   0,   0,   0,   0 ],
  62.   "GROUND3"    => [GROUND,   2,     100,     0,       0, 255,-255,-255, 255 ],
  63.   "GROUND4"    => [GROUND,   2,     100,     0,       0,-255, 255,-255, 100 ],
  64.   "GROUND5"    => [GROUND,   2,     100,     0,       0,-255, 255, 255, 100 ],
  65.   }
  66.  
  67.  
  68. # this value can be true or false. If true, it enables compatibility with
  69. # KGC_DayNight script. When it's night, lights will automatically go on, when
  70. # morning comes back lights will go off. If you set this to true, be sure to
  71. # place this script below KGC_DayNight script in the Scripting Editor of VX.
  72.   ENABLE_KGC_DAY_NIGHT_SCRIPT = true
  73.  
  74. =begin
  75. This value must be exactly the same of "PHASE_VARIABLE" setting in KGC_DayNight
  76. script. By default the script sets it to 11.
  77. To make the event light go on/off with DayNight system, set the event page
  78. to be triggered with this variable id and set it to be 1 or above.
  79. =end
  80.   KGC_DAY_NIGHT_SCRIPT_VARIABLE = 11
  81. end
  82.  
  83. =begin
  84. You can make custom effects here.
  85. Some values you can use:
  86.  
  87. @light.
  88.   opacity
  89.   x
  90.   y
  91.   zoom_x
  92.   zoom_y
  93.   tone
  94.  
  95. @phase (value from 0 to 120 for use in pulsing lights)
  96. $cm_light_ticker (goes from 0 to 600 over a period of 10 seconds)
  97.  
  98. =end
  99. class Light_Effect
  100.   def custom_effects
  101.     case @key
  102.     when "TORCH"
  103.       @light.opacity = rand(30) + 70
  104.     when "CRYSTAL"
  105.       @light.opacity = 100 + Math.cos(($cm_light_ticker - 300 + @phase) / (Math::PI*15))*15
  106.     end
  107.   end
  108. end
  109.  
  110. #=============================================================================#
  111. # Things may break if code is modified beyond this point.                     #
  112. #=============================================================================#
  113.  
  114. $bulletxt_day_check = 0
  115. $cm_light_ticker = 0
  116.  
  117. class Spriteset_Map
  118.    
  119.   alias bulletxt_spriteset_map_initalize initialize
  120.     def initialize
  121.         @light_effects = []
  122.         initialize_lights
  123.         bulletxt_spriteset_map_initalize
  124.         update
  125.     end
  126.  
  127.   alias bulletxt_spriteset_map_dispose dispose
  128.     def dispose
  129.         bulletxt_spriteset_map_dispose
  130.         for effect in @light_effects
  131.             effect.light.dispose
  132.         end
  133.         @light_effects = []
  134.     end
  135.    
  136.   alias bulletxt_spriteset_map_update update
  137.     def update
  138.         bulletxt_spriteset_map_update
  139.     check_day_night if BLXT::ENABLE_KGC_DAY_NIGHT_SCRIPT
  140.         update_light_effects
  141.    
  142.     end
  143.  
  144.  
  145.   def check_day_night
  146.     #if night
  147.    if $bulletxt_day_check == 0
  148.     if $game_variables[BLXT::KGC_DAY_NIGHT_SCRIPT_VARIABLE] == 1
  149.       $bulletxt_day_check = 1
  150.  
  151.     end
  152.    
  153.   else
  154.     #if morning
  155.     if $game_variables[BLXT::KGC_DAY_NIGHT_SCRIPT_VARIABLE] == 3
  156.       $game_variables[BLXT::KGC_DAY_NIGHT_SCRIPT_VARIABLE] = -1
  157.       $bulletxt_day_check = 0
  158.     end
  159.   end
  160.  
  161.    
  162.    
  163.   end
  164.  
  165.  
  166.     def initialize_lights
  167.         for event in $game_map.events.values
  168.             next if event.list == nil
  169.       for i in 0...event.list.size
  170.         if event.list[i].code == 108
  171.             for k in BLXT::LIGHT_TYPES.keys
  172.               p_array = [k]
  173.               if event.list[i].parameters == p_array
  174.                 effect = Light_Effect.new(event, k)
  175.                 event.set_light_effect(effect)
  176.                 @light_effects.push(effect)
  177.               end
  178.             end
  179.         end
  180.       end
  181.     end
  182.   end
  183.  
  184.   def update_light_effects
  185.  
  186.     for effect in @light_effects
  187.       if !effect.event.has_light_effect?
  188.         effect.event.set_light_effect(effect)
  189.         effect.reset
  190.       end
  191.       effect.update_light_effects
  192.     end
  193.    
  194.     $cm_light_ticker = ($cm_light_ticker + 1) % 600
  195.    
  196.   #close def
  197.   end
  198. #close class    
  199. end
  200.  
  201. class Light_Effect
  202.     attr_accessor :light
  203.     attr_accessor :event
  204.     attr_reader   :key
  205.    
  206.     def initialize(event, key)
  207.         @light = Sprite.new
  208.         @light.bitmap = Cache.picture("le.png")
  209.         @light.visible = true
  210.         @light.z = 1000
  211.     @phase = rand(120)
  212.         @event = event
  213.     @lightswitch = 0
  214.     @available = true
  215.     setup(key)
  216.     end
  217.  
  218.   def setup(key)
  219.     @key = key
  220.     light_params = BLXT::LIGHT_TYPES[key]
  221.     @lightswitch = light_params[0]
  222.     @light.zoom_y = light_params[1]
  223.     @light.zoom_x = light_params[1]
  224.    
  225.     @light.opacity = light_params[2]
  226.     @offset = (@light.width/2)*light_params[1]*8
  227.     @vertical = light_params[3]
  228.     @flicker = light_params[4]
  229.     @light.blend_type = 1
  230.     @light.tone = Tone.new(light_params[5], light_params[6], light_params[7],
  231.     light_params[8])
  232.   end
  233.  
  234.   def update_light_effects
  235.     pos_flicker = @flicker > 0 ? @flicker : 0
  236.     @light.x = (@event.real_x - @offset - $game_map.display_x) / 8 + 16 + rand(pos_flicker*2) - pos_flicker
  237.     @light.y = (@event.real_y - @offset - $game_map.display_y) / 8 + 16 + rand(pos_flicker*2) - @vertical - pos_flicker
  238.    
  239.     @light.opacity = rand(10) + 90 if @flicker != 0
  240.     if $game_switches[@lightswitch] == true or !@available or @event.erased?
  241.       @light.visible = false
  242.     else
  243.       @light.visible = true
  244.     end
  245.     custom_effects
  246.    
  247.   end
  248.  
  249.   def reset
  250.     @available = false
  251.     return if @event.list == nil
  252.     for i in 0...@event.list.size
  253.       if @event.list[i].code == 108
  254.         for k in BLXT::LIGHT_TYPES.keys
  255.           p_array = [k]
  256.           if @event.list[i].parameters == p_array
  257.             setup(k)
  258.             @available = true
  259.           end
  260.         end
  261.       end
  262.     end
  263.   end
  264.  
  265. end
  266.  
  267. class Game_Event < Game_Character
  268.  
  269.   def set_light_effect(light_effect)
  270.     @light_effect = light_effect
  271.   end
  272.  
  273.   def has_light_effect?
  274.     return @light_effect != nil
  275.   end
  276.  
  277.   def erased?
  278.     return @erased
  279.   end
  280.  
  281.   alias setup_cm setup
  282.   def setup(new_page)
  283.     setup_cm(new_page)
  284.     if has_light_effect?
  285.       @light_effect.reset
  286.     end
  287.   end
  288. end
  289.  
  290. class Scene_File < Scene_Base
  291.   def do_save
  292.     for event in $game_map.events.values
  293.       event.set_light_effect(nil)
  294.     end
  295.     file = File.open(@savefile_windows[@index].filename, "wb")
  296.     write_save_data(file)
  297.     file.close
  298.     return_scene
  299.   end
  300. end
Advertisement
Add Comment
Please, Sign In to add comment