From 4c1dda76f63bf9ed2cdfd7fa6d9560ad84c25983 Mon Sep 17 00:00:00 2001 From: Mathew Velasquez Date: Sun, 22 Nov 2015 18:44:06 -0500 Subject: [PATCH] Re-implemented ambient light and bulb glow --- scripts/Game_Map.rb | 3 +++ scripts/RPG.rb | 10 ++++++++++ scripts/Scene_Map.rb | 9 --------- scripts/Script.rb | 21 ++++++++++++--------- scripts/Spriteset_Map.rb | 18 +++++++++++++----- 5 files changed, 38 insertions(+), 23 deletions(-) diff --git a/scripts/Game_Map.rb b/scripts/Game_Map.rb index fe24411..fe0cb92 100644 --- a/scripts/Game_Map.rb +++ b/scripts/Game_Map.rb @@ -28,6 +28,7 @@ class Game_Map attr_accessor :particles_type # particles name attr_accessor :clamped_panorama # panorama is clamped? attr_accessor :wrapping # map is wrapping? + attr_accessor :ambient # ambient light attr_reader :passages # passage table attr_reader :priorities # prioroty table attr_reader :terrain_tags # terrain tag table @@ -109,6 +110,8 @@ class Game_Map @clamped_panorama = false # Unwrap map @wrapping = false + # Full bright ambient light + @ambient = Tone.new(0, 0, 0, 0) # Construct map name path mapinfo = load_data("Data/MapInfos.rxdata") diff --git a/scripts/RPG.rb b/scripts/RPG.rb index a15ca60..faa2bdc 100644 --- a/scripts/RPG.rb +++ b/scripts/RPG.rb @@ -16,3 +16,13 @@ module RPG end end end + +class Tone + def +(o) + Tone.new(self.red + o.red, self.green + o.green, self.blue + o.blue, self.gray + o.gray) + end + + def *(s) + Tone.new(self.red * s, self.green * s, self.blue * s, self.gray * s) + end +end diff --git a/scripts/Scene_Map.rb b/scripts/Scene_Map.rb index fddecbc..fced8a9 100644 --- a/scripts/Scene_Map.rb +++ b/scripts/Scene_Map.rb @@ -341,12 +341,6 @@ class Scene_Map #-------------------------------------------------------------------------- # * Lighting operations #-------------------------------------------------------------------------- - def ambient - @spriteset.ambient - end - def ambient=(val) - @spriteset.ambient = val - end def add_light(id, filename, intensity, x, y) @spriteset.add_light(id, filename, intensity, x, y) end @@ -356,9 +350,6 @@ class Scene_Map def clear_lights @spriteset.clear_lights end - def fade_in_bulb - @spriteset.fade_in_bulb - end #-------------------------------------------------------------------------- # * Particle operations #-------------------------------------------------------------------------- diff --git a/scripts/Script.rb b/scripts/Script.rb index c90663d..2468932 100644 --- a/scripts/Script.rb +++ b/scripts/Script.rb @@ -46,6 +46,10 @@ module Script end end +def has_lightbulb? + $game_party.item_number(1) > 0 +end + def enter_name $game_temp.name_calling = true end @@ -76,14 +80,12 @@ def particles(type) $game_map.particles_type = type end -def ambient(r, g = -1, b = -1) - g = r if g < 0 - b = r if b < 0 - #$scene.ambient = Color.new(r, g, b) +def ambient(r, g, b, gray = 0) + $game_map.ambient.set(r, g, b, gray) end def clear_ambient - #$scene.ambient = Color.new(255, 255, 255) + $game_map.ambient.set(0, 0, 0, 0) end def add_light(id, file, intensity, x, y) @@ -98,10 +100,6 @@ def clear_lights #$scene.clear_lights end -def fade_in_bulb - #$scene.fade_in_bulb -end - def clamp_panorama $game_map.clamped_panorama = true end @@ -109,3 +107,8 @@ end def wrap_map $game_map.wrapping = true end + +# Map specific settings +def green_ambient + ambient -50, -50, -50 +end diff --git a/scripts/Spriteset_Map.rb b/scripts/Spriteset_Map.rb index b9f530c..84b8362 100644 --- a/scripts/Spriteset_Map.rb +++ b/scripts/Spriteset_Map.rb @@ -62,6 +62,10 @@ class Spriteset_Map end # Make timer sprite @timer_sprite = Sprite_Timer.new + # Make lightbulb sprite + @bulb = Sprite.new(@viewport_lights) + @bulb.bitmap = RPG::Cache.light('bulb') + @bulb.opacity = has_lightbulb? ? 255 : 0 # Frame update update end @@ -223,10 +227,14 @@ class Spriteset_Map sprite.update end # Update bulb if fading in - if @bulb && @bulb.intensity < @bulb_intensity - @bulb.intensity += 0.005 - if @bulb.intensity > @bulb_intensity - @bulb.intensity = @bulb_intensity + @bulb.tone = $game_map.ambient + if has_lightbulb? + if @bulb.opacity < 255 + @bulb.opacity += 2.125 + end + else + if @bulb.opacity > 0 + @bulb.opacity -= 2.125 end end # Update particles @@ -234,7 +242,7 @@ class Spriteset_Map # Update timer sprite @timer_sprite.update # Set screen color tone and shake position - @viewport.tone = $game_screen.tone + @viewport.tone = $game_screen.tone + $game_map.ambient * (1.0 - @bulb.opacity / 255.0) @viewport.ox = $game_screen.shake # Set screen flash color @viewport_flash.color = $game_screen.flash_color