khanhdu

CSCA_LightEffects

May 26th, 2017
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 11.61 KB | None | 0 0
  1. =begin
  2. CSCA Light Effects
  3. version: 1.0.0 (Released: November 21, 2012)
  4. Created by: Casper Gaming (http://www.caspergaming.com/)
  5.  
  6. Compatibility:
  7. Made for RPGVXAce
  8. IMPORTANT: ALL CSCA Scripts should be compatible with each other unless
  9. otherwise noted.
  10.  
  11. FFEATURES
  12. Easily customize and create light effects. 12 preset light effects.
  13. Turn lights on/off in game.
  14.  
  15. SETUP
  16. Set up required. Instructions below.
  17.  
  18. CREDIT:
  19. Free to use in noncommercial games if credit is given to:
  20. Casper Gaming (http://www.caspergaming.com/)
  21.  
  22. To use in a commercial game, please purchase a license here:
  23. http://www.caspergaming.com/licenses.html
  24.  
  25. TERMS:
  26. http://www.caspergaming.com/terms_of_use.html
  27. =end
  28. module CSCA
  29.   module LIGHTS
  30.     EFFECTS = [] # Don't Touch
  31.     #
  32.     #Set up your EFFECTS like this:
  33.     #EFFECTS[x] = ["NAME", graphic, zoom_x, zoom_y, opacity, blend_type, tone,
  34.     #              switch, rand_opacity, adjust_x, adjust_y]
  35.     #
  36.     # "NAME" is the type of Light that you type into the comment of your event.
  37.     # If the light has a name of "FIRE" your event comment will be: "LIGHT: FIRE"
  38.     #
  39.     # Graphic is the graphic to be used. Located in the Graphics/Pictures folder.
  40.     #
  41.     # zoom_x and zoom_y are the sprite's x and y-axis zoom levels. 1 is normal.
  42.     #
  43.     # opacity is how transparent the sprite is. (0-255)
  44.     # blend type is how the sprite blends(0: normal, 1: addition, 2: subtraction)
  45.     #
  46.     # Tone is the color tone. For no tone change, use "Tone.new". Optional 4th
  47.     # value can be added, this is the gray value.
  48.     #
  49.     # switch is a switch ID. When this switch is ON, lights of this type will
  50.     # turn on. When the switch is OFF, lights of this type will turn off.
  51.     #
  52.     # rand_opacity is used to create a flicker. The opacity will randomize
  53.     # itself from the original opacity by the numebr entered. Higher numbers
  54.     # have more noticable flicker. Set to 0 for no effect(a steady light).
  55.     #
  56.     # adjust_x and adjust_y are values added to the x and y values to fine tune
  57.     # how each light displays. In pixels. Set to 0 for no effect.
  58.     #
  59.     # Effects have already been set up for you to be similar to Thomas Edison
  60.     # VX. You can customize them or create new effects yourself, too!
  61.     # The preset light effects are:
  62.     # GROUND1 - Medium steady white light.
  63.     # GROUND2 - Medium white light with slight flicker.
  64.     # GROUND3 - Small steady red light.
  65.     # GROUND4 - Medium steady green light.
  66.     # GROUND5 - Medium steady blu light.
  67.     # FIRE - Large red light with a slight flicker.
  68.     # LIGHT1 - Small steady white light.
  69.     # LIGHT2 - X-Large steady white light.
  70.     # LIGHT3 - Small white light with slight flicker.
  71.     # TORCH1 - X-Large red light with a heavy flicker.
  72.     # TORCH2 - X-Large red light with a slight flicker.
  73.     # TORCH3 - Large white light with a slight flicker.
  74.     #
  75.     EFFECTS[0] = ["FIRE", "Light", 3, 3, 100, 1, Tone.new(255,-100,-255), 1, 10, 0, 0]
  76.     EFFECTS[1] = ["LIGHT1", "Light", 1, 1, 150, 1, Tone.new, 2, 0, 0, 0]
  77.     EFFECTS[2] = ["LIGHT2", "Light", 6, 6, 150, 1, Tone.new, 3, 0, 0, 0]
  78.     EFFECTS[3] = ["LIGHT3", "Light", 1, 1, 150, 1, Tone.new, 4, 10, 0, 0]
  79.     EFFECTS[4] = ["TORCH1", "Light", 6, 6, 150, 1, Tone.new(255,-100,-255), 5, 30, 0, 0]
  80.     EFFECTS[5] = ["TORCH2", "Light", 6, 6, 150, 1, Tone.new(255,-100,-255), 6, 10, 0, 0]
  81.     EFFECTS[6] = ["TORCH3", "Light", 3, 3, 100, 1, Tone.new, 7, 10, 0, 0]
  82.     EFFECTS[7] = ["GROUND1", "Light", 2, 2, 100, 1, Tone.new, 8, 0, 0, 0]
  83.     EFFECTS[8] = ["GROUND2", "Light", 2, 2, 100, 1, Tone.new, 9, 10, 0, 0]
  84.     EFFECTS[9] = ["GROUND3", "Light", 2, 2, 100, 1, Tone.new(255,-255,-255,255), 10, 0, 0, 0]
  85.     EFFECTS[10] = ["GROUND4", "Light", 2, 2, 100, 1, Tone.new(-255,255,-255,100), 11, 0, 0, 0]
  86.     EFFECTS[11] = ["GROUND5", "Light", 2, 2, 100, 1, Tone.new(-255,255,255,100), 12, 0, 0, 0]
  87.     #
  88.     # Script Calls:
  89.     #
  90.     # To refresh lights(if an event was erased or changed pages and should no
  91.     # longer be lit up), make the following script call:
  92.     # $game_map.csca_light_need_refresh = true
  93.     #
  94.     # To dispose specific lights, use the following script call:
  95.     # $game_map.csca_dispose_lights = [x,y,z,etc]
  96.     # where x, y, and z would be the event id's of events showing light effects.
  97.     #
  98.   end
  99. end
  100. #----------------------------------End Setup----------------------------------#
  101. $imported = {} if $imported.nil?
  102. $imported["CSCA-LightEffects"] = true
  103. #==============================================================================
  104. # ** Game_Map
  105. #------------------------------------------------------------------------------
  106. # Handles Light Effects
  107. #Aliases: initialize
  108. #==============================================================================
  109. class Game_Map
  110.   attr_accessor :csca_light_need_refresh
  111.   attr_accessor :csca_dispose_lights
  112.   #--------------------------------------------------------------------------#
  113.   # Alias Method; initialize                                                 #
  114.   #--------------------------------------------------------------------------#
  115.   alias :csca_le_init :initialize
  116.   def initialize
  117.     csca_le_init
  118.     @csca_light_need_refresh = false
  119.     @csca_dispose_lights = nil
  120.   end
  121. end
  122. #==============================================================================
  123. # ** Spriteset_Map
  124. #------------------------------------------------------------------------------
  125. # Displays Lights on the map screen.
  126. #Aliases: initialize, dispose, update
  127. #==============================================================================
  128. class Spriteset_Map
  129.   #--------------------------------------------------------------------------#
  130.   # Alias Method; initialize                                                 #
  131.   #--------------------------------------------------------------------------#
  132.   alias :csca_le_init :initialize
  133.   def initialize
  134.     csca_init_light_effects
  135.     csca_le_init
  136.   end
  137.   #--------------------------------------------------------------------------#
  138.   # Alias Method; dispose                                                    #
  139.   #--------------------------------------------------------------------------#
  140.   alias :csca_le_dispose :dispose
  141.   def dispose
  142.     csca_dispose_light_effects
  143.     csca_le_dispose
  144.   end
  145.   #--------------------------------------------------------------------------#
  146.   # Alias Method; update                                                     #
  147.   #--------------------------------------------------------------------------#
  148.   alias :csca_le_update :update
  149.   def update
  150.     csca_update_light_effects
  151.     csca_le_update
  152.   end
  153.   #--------------------------------------------------------------------------#
  154.   # Dispose light effects                                                    #
  155.   #--------------------------------------------------------------------------#
  156.   def csca_dispose_light_effects
  157.     for effect in @lights
  158.       effect.light.dispose
  159.     end
  160.     @lights = nil
  161.   end
  162.   #--------------------------------------------------------------------------#
  163.   # Determine type of effect                                                 #
  164.   #--------------------------------------------------------------------------#
  165.   def get_effect(type)
  166.     CSCA::LIGHTS::EFFECTS.each do |effect|
  167.       if effect[0] == type
  168.         return effect
  169.       end
  170.     end
  171.   end
  172.   #--------------------------------------------------------------------------#
  173.   # Initialize Light Effects                                                 #
  174.   #--------------------------------------------------------------------------#
  175.   def csca_init_light_effects
  176.     @lights = []
  177.     $game_map.events.values.each do |event|
  178.       next if event.list.nil?
  179.       for i in 0...event.list.size
  180.         list = event.list[i]
  181.         if list.code == 108 && list.parameters[0].include?("LIGHT: ")
  182.           param = list.parameters[0]
  183.           type = param[7, param.length]
  184.           light = get_effect(type)
  185.           light_effect = CSCA_Light.new(event, type, light[1])
  186.           @lights.push(light_effect)
  187.           next
  188.         end
  189.       end
  190.     end
  191.     csca_setup_light_effects
  192.   end
  193.   #--------------------------------------------------------------------------#
  194.   # Setup Light Effect Properties                                            #
  195.   #--------------------------------------------------------------------------#
  196.   def csca_setup_light_effects
  197.     for effect in @lights
  198.       le = get_effect(effect.type)
  199.       effect.light.zoom_x = le[2]
  200.       effect.light.zoom_y = le[3]
  201.       effect.light.opacity = le[4]
  202.       effect.light.blend_type = le[5]
  203.       effect.light.tone = le[6]
  204.       effect.save_effect = le
  205.       width = (effect.light.width/2)*effect.light.zoom_x
  206.       height = (effect.light.height/2)*effect.light.zoom_y
  207.       effect.light.x = effect.event.screen_x - width + le[9]
  208.       effect.light.y = effect.event.screen_y - height + le[10]
  209.     end
  210.   end
  211.   #--------------------------------------------------------------------------#
  212.   # Update Light Effects                                                     #
  213.   #--------------------------------------------------------------------------#
  214.   def csca_update_light_effects
  215.     for effect in @lights
  216.       next if effect.light.disposed?
  217.       le = effect.save_effect
  218.       effect.light.visible = $game_switches[le[7]]
  219.       width = (effect.light.width/2)*effect.light.zoom_x
  220.       height = (effect.light.height/2)*effect.light.zoom_y
  221.       effect.light.x = effect.event.screen_x - width + le[9]
  222.       effect.light.y = effect.event.screen_y - height + le[10]
  223.       effect.light.opacity = rand(le[8]) + (le[4] - le[8])
  224.     end
  225.     csca_refresh_light_effects if @map_id != $game_map.map_id
  226.     if $game_map.csca_light_need_refresh
  227.       $game_map.csca_light_need_refresh = false
  228.       csca_refresh_light_effects
  229.     end
  230.     if !$game_map.csca_dispose_lights.nil?
  231.       csca_dispose_select_lights($game_map.csca_dispose_lights)
  232.     end
  233.   end
  234.   #--------------------------------------------------------------------------#
  235.   # Refresh Lights                                                           #
  236.   #--------------------------------------------------------------------------#
  237.   def csca_refresh_light_effects
  238.     csca_dispose_light_effects
  239.     csca_init_light_effects
  240.   end
  241.   #--------------------------------------------------------------------------#
  242.   # Dispose Select Lights                                                    #
  243.   #--------------------------------------------------------------------------#
  244.   def csca_dispose_select_lights(ids)
  245.     ids.each do |id|
  246.       for effect in @lights
  247.         if effect.event.id == id
  248.           le = effect
  249.           break
  250.         end
  251.       end
  252.       le.light.dispose
  253.     end
  254.     $game_map.csca_dispose_lights = nil
  255.   end
  256. end
  257. #==============================================================================
  258. # ** CSCA_Light
  259. #------------------------------------------------------------------------------
  260. # Light class. Handles lights.
  261. #==============================================================================
  262. class CSCA_Light
  263.   attr_accessor :light
  264.   attr_accessor :event
  265.   attr_accessor :type
  266.   attr_accessor :save_effect
  267.   #--------------------------------------------------------------------------#
  268.   # Object Initialization                                                    #
  269.   #--------------------------------------------------------------------------#
  270.   def initialize(event, type, graphic = "Light")
  271.     @light = Sprite.new
  272.     @light.bitmap = Cache.picture(graphic)
  273.     @light.visible = true
  274.     @light.z = 1000
  275.     @event = event
  276.     @type = type
  277.     @save_effect = []
  278.   end
  279. end
Advertisement
Add Comment
Please, Sign In to add comment