Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- # Dynamic Time and Light System
- # Version: 2.05
- # Author: TimeKeeper
- # Date: 2014-10-05
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- #
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- # Introduction
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- #
- # Formally: Advanced Dynamic Light System
- #
- # This system add dynamic light circle including a time system which vary the tint
- # of the night. The light circle can also be animated using a random pattern,
- # a wave pattern or a combination of both.
- #
- # The script is really fast. I found a 2 to 3 FPS drop with about 115 animated
- # light circle in a 50x50 map.
- #
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- # Features
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- #
- # - Really fast
- # - Dynamic light circle for the events
- # - Dynamic light circle for the player
- # - All light circle can be turn off on on with switch
- # - Time system which vary the night tint
- # - Night tinting color base on time of year
- # - Multiple night and time setting (climate)
- #
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- # Instructions
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- #
- #--------------------------------------------------------------------------
- # System activtion configuration
- #--------------------------------------------------------------------------
- #
- # To activate a function of this script you can set the part to activate in the
- # configuration or you one os the fallowing command with the script command of
- # the event:
- #
- # DTLS.Activate(value): Activate or deactivate the entire script
- # DTLS.ActivateTime(value): Activate or deactivate the time part
- # DTLS.ActivateTimeWindow(value): Activate or deactivate the time window
- # DTLS.ActivateNight(value): Activate or deactivate the night (dark
- # screen and light)
- # DTLS.ActivateLight(value): Activate or deactivate the light only
- #
- #--------------------------------------------------------------------------
- # Light circle basic configuration
- #--------------------------------------------------------------------------
- #
- # To create a light circle the first comment must start with either of the
- # following comment (The filename is optional):
- # light_event filename
- # light_player filename
- #
- # You can also add the following comment to modify to the light circle:
- # follow value
- # zoom value
- # opacity value
- # switch value
- #
- # The effect of the parameter:
- # - follow: The light will be in the direction of the event or player. It
- # require 4 picture with "_D", "_L", "_R" and "_U" after the
- # filename. The default value is false
- # - zoom: Change the size of the light. The default value if 1.0
- # - opacity: Change the opacity of the light. The default value if 255
- # - switch: Set a switch to turn of the light of that event or the player.
- # The default value if 0
- #
- # Those parameter will activate the light circle depending on the time of day.
- # Note: Adding both parameter will make the light always active.
- # night_only
- # day_only
- #
- # The effect of the parameter:
- # - night_only: Will activate the light circle when it's the night.
- # - day_only: Will activate the light circle when it's the day.
- #
- #--------------------------------------------------------------------------
- # Light circle animation configuration
- #--------------------------------------------------------------------------
- #
- # Those parameter add a random effect:
- # rand_zoom_frame value
- # rand_zoom value
- # rand_opacity_frame value
- # rand_opacity value
- #
- # The effect of the parameter:
- # - rand_zoom_frame and rand_opacity_frame:
- # The set the number of frame between the random update of
- # either the random zoom or opacity animation. I recommend not
- # updating every frame because it can cause weird graphical
- # glitch. The default value is 5.
- # - rand_zoom: The maximum value that the zoom can change. The default
- # value is 5
- # - rand_opacity: The maximum value that the opacity can change. The default
- # value is 5
- #
- # Those parameter add wave effect:
- # wave_zoom_frame value
- # wave_zoom value step
- # wave_opacity_frame value
- # wave_opacity value step
- #
- # The effect of the parameter:
- # - rand_zoom_frame and rand_opacity_frame:
- # The set the number of frame between the random update of
- # either the random zoom or opacity animation. I recommend not
- # updeting every frame because it can cause weird graphical
- # glitch. The default value is 5.
- # - wave_zoom: The maximum value that the zoom can change. And also set the
- # step the zoom will change every frame (the step is optional).
- # The default value is 0 and the default step is 0.01.
- # - wave_opacity: The maximum value that the opacity can change. And also set
- # the step the opacity will change every frame (the step is
- # optional). The default value is 0 and the default step is 0.01.
- #
- #--------------------------------------------------------------------------
- # Map setting
- #--------------------------------------------------------------------------
- #
- # To modify the setting of the map the first comment must start with the
- # following comment:
- # set_map
- #
- # To change the climate of a map you must use the following comment after
- # 'set_map':
- # climate value
- #
- # To create permanent night tint you must use the following comment after
- # 'set_map':
- # night red green blue alpha transition
- # - Transtion: This parameter will set the time for the transition
- # between the current color and the new color. This
- # parameter is optionnal.
- #
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- # Compatibility
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- #
- # Should be compatible with everything
- #
- # NOTE: Some change to improve the animation of the light circle make this
- # version of the script incompatible with previous configuration
- #
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- # Credits and Thanks
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- #
- # TimeKeeper
- # Fabien and kellessdee for the inspiration
- # ArcaneAlchemy for the idea of a Day and night system
- # schmoggi for the night transition idea
- #
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- module DTLS
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- # Start of the configuration
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- # * Activation configuration
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- Activate = true
- ActivateTime = false
- ActivateTimeWindow = false
- ActivateNight = true
- ActivateLight = true
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- # * Time system configuration
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- #--------------------------------------------------------------------------
- # * Day and night switch
- #--------------------------------------------------------------------------
- IsNightSwitch = 1
- IsDaySwitch = 2
- #--------------------------------------------------------------------------
- # * Time variable
- #--------------------------------------------------------------------------
- MinuteVariable = 1
- HourVariable = 2
- DayVariable = 3
- MonthVariable = 4
- YearVariable = 5
- #--------------------------------------------------------------------------
- # * Initial time
- #--------------------------------------------------------------------------
- # Set the initial time = [minute, hour, day, month, year]
- # The initial time will ajust to the maximum time value if the time set is
- # invalid.
- InitialTime = [1023, 12, 27, 12, 0]
- #--------------------------------------------------------------------------
- # * Time setup
- #--------------------------------------------------------------------------
- # Set the maximum of the number of hour in a day and minute in a hour
- DaySetup = [24, 60]
- # Set the name and the number of day for each month. The number of month in a
- # year will be set by the size of the array.
- MonthSetup = [['January', 31], ['February', 28], ['March', 31], ['April', 30],
- ['May', 31], ['June', 30], ['July', 31], ['August', 31], ['September', 30],
- ['October', 31], ['November', 30], ['December', 31]]
- #--------------------------------------------------------------------------
- # * Time length
- #--------------------------------------------------------------------------
- # Set the number of minute between each update of the time window.
- CountLength = 5
- # Set the number of minute add each update.
- CountMinute = 1
- #--------------------------------------------------------------------------
- # * Set the parameter of the season
- #--------------------------------------------------------------------------
- # Set the the setting for each season. The 'season_name' is use to get the
- # color of the night.
- #
- # Season = { 'climate_name' => [ first month, first day, 'season_name',
- # day_hour, day_minure, night_hour, night_minute ], ... ], ... }
- Season = {
- 'desert' => [[0, 0, 'summer', 5, 0, 19, 0]],
- 'snow' => [[3, 21, 'snow_springfall', 9, 0, 15, 0],
- [6, 21, 'snow_summer', 6, 0, 18, 0],
- [9, 21, 'snow_springfall', 9, 0, 15, 0],
- [12, 21, 'snow_winter', 10, 0, 14, 0]]
- }
- # Set the default season when no climate are specified
- Season.default = [[3, 21, 'spring_fall', 6, 0, 18, 0],
- [6, 21, 'summer', 5, 0, 19, 0],
- [9, 21, 'spring_fall', 6, 0, 18, 0],
- [12, 21, 'winter', 7, 0, 17, 0]]
- #--------------------------------------------------------------------------
- # * Set the time of the day and night
- #--------------------------------------------------------------------------
- # Set the color of the night at specific time of day.
- #
- # NightColor = { 'season_name' => [ [ hour, minute, red, green, blue,
- # alpha], ...], ... }
- NightColor = {
- # Normal climate and deset climat (summe only)
- 'winter' => [[0, 0, 230, 230, 230, 255], # Night
- [6, 0, 210, 210, 210, 255], # Sunrise
- [8, 0, 20, 20, 20, 255], # Dawn
- [12, 0, 0, 0, 0, 255], # Day
- [18, 0, 20, 20, 20, 255], # Sundown
- [20, 0, 210, 210, 210, 255]], # Dusk
- 'spring_fall' => [[0, 0, 200, 200, 200, 255], # Night
- [5, 0, 180, 180, 180, 255], # Sunrise
- [7, 0, 20, 20, 20, 255], # Dawn
- [12, 0, 0, 0, 0, 255], # Day
- [17, 0, 20, 20, 20, 255], # Sundown
- [19, 0, 180, 180, 180, 255]], # Dusk
- 'summer' => [[0, 0, 175, 175, 175, 255], # Night
- [4, 0, 155, 155, 155, 255], # Sunrise
- [6, 0, 20, 20, 20, 255], # Dawn
- [12, 0, 0, 0, 0, 255], # Day
- [16, 0, 20, 20, 20, 255], # Sundown
- [18, 0, 155, 155, 155, 255]], # Dusk
- # Snow climate
- 'snow_winter' => [[0, 0, 240, 240, 240, 255], # Night
- [9, 0, 220, 220, 220, 255], # Sunrise
- [11, 0, 20, 20, 20, 255], # Dawn
- [12, 0, 0, 0, 0, 255], # Day
- [13, 0, 20, 20, 20, 255], # Sundown
- [15, 0, 220, 220, 220, 255]], # Dusk
- 'snow_springfall' => [[0, 0, 230, 230, 230, 255], # Night
- [5, 0, 210, 210, 210, 255], # Sunrise
- [7, 0, 20, 20, 20, 255], # Dawn
- [12, 0, 0, 0, 0, 255], # Day
- [17, 0, 20, 20, 20, 255], # Sundown
- [19, 0, 210, 210, 210, 255]], # Dusk
- 'snow_summer' => [[0, 0, 200, 200, 200, 255], # Night
- [4, 0, 180, 180, 180, 255], # Sunrise
- [6, 0, 20, 20, 20, 255], # Dawn
- [12, 0, 0, 0, 0, 255], # Day
- [16, 0, 20, 20, 20, 255], # Sundown
- [18, 0, 180, 180, 180, 255]], # Dusk
- }
- # Set the default night color when no season are specified.
- NightColor.default = [[0, 0, 175, 175, 175, 255], # Night
- [4, 0, 155, 155, 155, 255], # Sunrise
- [6, 0, 20, 20, 20, 255], # Dawn
- [12, 0, 0, 0, 0, 255], # Day
- [16, 0, 20, 20, 20, 255], # Sundown
- [18, 0, 155, 155, 155, 255]] # Dusk
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- # Configuration of the default value
- #-----------------------------------------------------------------------------
- # WARNING : Be carful when modifing those value, changing the default value
- # can cause weird graphical glitch. I chose the default value to have the
- # best looking animation.
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- #--------------------------------------------------------------------------
- # * Default value of the basic parameter
- #--------------------------------------------------------------------------
- DefaultPicture = 'light'
- DefaultFollow = false
- DefaultZoom = 1.0
- DefaultOpacity = 255
- DefaultSwitch = 0
- #--------------------------------------------------------------------------
- # * Default value of the random animation
- #--------------------------------------------------------------------------
- DefaultRandZoomFrame = 5
- DefaultRandZoom = 0.0
- DefaultRandOpacityFrame = 5
- DefaultRandOpacity = 0.0
- #--------------------------------------------------------------------------
- # * Default value of the wave animation
- #--------------------------------------------------------------------------
- DefaultWaveZoomFrame = 1
- DefaultWaveZoomMax = 0.0
- DefaultWaveZoomStep = 0.001
- DefaultWaveOpacityFrame = 5
- DefaultWaveOpacityMax = 0.0
- DefaultWaveOpacityStep = 1
- #--------------------------------------------------------------------------
- # * Default value of the night only and day only switch
- #--------------------------------------------------------------------------
- DefaultNightOnly = false
- DefaultDayOnly = false
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- # End of the configuration
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- # Shortcut for the Time system
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- #--------------------------------------------------------------------------
- # * Shortcut for $game_map.ActivateTime
- #--------------------------------------------------------------------------
- def self.ActivateTime(bool)
- $game_system.activate_time = bool
- end
- #--------------------------------------------------------------------------
- # * Shortcut for $game_map.activate_time_window
- #--------------------------------------------------------------------------
- def self.ActivateTimeWindow(bool)
- $game_system.activate_time_window = bool
- end
- #--------------------------------------------------------------------------
- # * Shortcut for changing the climate
- #--------------------------------------------------------------------------
- def self.ChangeClimate(name)
- $game_system.time.change_climate(name)
- end
- #--------------------------------------------------------------------------
- # * Shortcut for setting the time to a specific date
- #--------------------------------------------------------------------------
- def self.SetTime(minute, hour, day, month, year)
- $game_system.time.set_time(minute, hour, day, month, year)
- end
- #--------------------------------------------------------------------------
- # * Shortcut for $game_system.activate_dtls
- #--------------------------------------------------------------------------
- def self.Activate(bool)
- $game_system.activate_dtls = bool
- end
- #--------------------------------------------------------------------------
- # * Shortcut for $game_map.activate_night
- #--------------------------------------------------------------------------
- def self.ActivateNight(bool)
- $game_system.activate_night = bool
- end
- #--------------------------------------------------------------------------
- # * Shortcut for $game_map.activate_light
- #--------------------------------------------------------------------------
- def self.ActivateLight(bool)
- $game_system.activate_light = bool
- end
- #--------------------------------------------------------------------------
- # * Shortcut for adding minute
- #--------------------------------------------------------------------------
- def self.AddMinute(minute)
- $game_system.time.add_minute(minute)
- end
- #--------------------------------------------------------------------------
- # * Shortcut for adding hour
- #--------------------------------------------------------------------------
- def self.AddHour(hour)
- $game_system.time.add_hour(hour)
- end
- #--------------------------------------------------------------------------
- # * Shortcut for adding day
- #--------------------------------------------------------------------------
- def self.AddDay(day)
- $game_system.time.add_day(day)
- end
- #--------------------------------------------------------------------------
- # * Shortcut for adding month
- #--------------------------------------------------------------------------
- def self.AddMonth(month)
- $game_system.time.add_month(month)
- end
- #--------------------------------------------------------------------------
- # * Shortcut for adding year
- #--------------------------------------------------------------------------
- def self.AddYear(year)
- $game_system.time.add_year(year)
- end
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- # Shortcut for the Night system
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- #--------------------------------------------------------------------------
- # * Shortcut for $game_map.remove_light_player
- #--------------------------------------------------------------------------
- def self.ChangeNightColor(r, g, b, a, time = 0)
- $game_map.night_color = [r, g, b, a]
- $game_map.night_tansition = time
- end
- #--------------------------------------------------------------------------
- # * Shortcut for $game_map.remove_light_player
- #--------------------------------------------------------------------------
- def self.RemoveNightColor()
- $game_map.night_color = []
- $game_map.night_tansition = 0
- end
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- # Shortcut for the Light system
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- #--------------------------------------------------------------------------
- # * Shortcut for $game_map.change_light_event
- #--------------------------------------------------------------------------
- def self.ChangeEvent(event_id, filename = nil, follow = nil, zoom = nil,
- opacity = nil, switch = nil, rand = [], wave = [], sin = [], time = [])
- $game_map.change_light_event(event_id, filename, follow, zoom, opacity,
- switch, rand, wave, sin, time)
- end
- #--------------------------------------------------------------------------
- # * Shortcut for $game_map.remove_light_event
- #--------------------------------------------------------------------------
- def self.RemoveEvent(event_id)
- $game_map.remove_light_event(event_id)
- end
- #--------------------------------------------------------------------------
- # * Shortcut for $game_map.change_light_player
- #--------------------------------------------------------------------------
- def self.ChangePlayer(filename = nil, follow = nil, zoom = nil,
- opacity = nil, switch = nil, rand = [], wave = [], sin = [], time = [])
- $game_map.change_light_player(event_id, filename, follow, zoom, opacity,
- switch, rand, wave, sin, time)
- end
- #--------------------------------------------------------------------------
- # * Shortcut for $game_map.remove_light_player
- #--------------------------------------------------------------------------
- def self.RemovePlayer
- $game_map.remove_light_player
- end
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- # End of Shortcut
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- end
- #==============================================================================
- # ** Time_System
- #------------------------------------------------------------------------------
- # This class handles data the time system.
- #==============================================================================
- class Time_System
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_reader :climate
- attr_accessor :minute
- attr_accessor :hour
- attr_accessor :day
- attr_accessor :month
- attr_accessor :year
- attr_reader :night_color
- attr_accessor :last_map
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize
- # Initialize the season and climate
- @season = 0
- @climate = nil
- # Set the initial night color
- @night_color = DTLS::NightColor[DTLS::Season[@climate][@season][2]]
- # Set the initial day time and night time
- @time_day = DTLS::Season[@climate][@season][3] * 60 + DTLS::Season[@climate][@season][4]
- @time_night = DTLS::Season[@climate][@season][5] * 60 + DTLS::Season[@climate][@season][6]
- # Set the initial minute
- @minute = [(DTLS::InitialTime[4] - DTLS::InitialTime[4] % DTLS::CountMinute), 0].max
- # Set the initial hour
- @hour = [DTLS::InitialTime[3], 0].max
- # Set the initial day with a minimum of 1
- @day = [DTLS::InitialTime[2], 1].max
- # Set the initial month with a minimum of 1
- @month = [DTLS::InitialTime[1], 1].max
- # Set the initial year
- @year = [DTLS::InitialTime[0], 0].max
- # Update the time data
- check_time
- # Update the season data
- update_season
- end
- #--------------------------------------------------------------------------
- # * Get New Climate
- #--------------------------------------------------------------------------
- def change_climate(name)
- # Check if the new climate is diferent for the curent one
- if @climate != name
- # Change the climate name
- @climate = name
- # Update the season data
- update_season
- end
- end
- #--------------------------------------------------------------------------
- # * Get Date
- #--------------------------------------------------------------------------
- def get_date(month, day)
- # Set the number of day to the current date
- day_month = day
- # If its not the first month
- if @month > 1
- # Cycle from the first month to the current month
- (1..(month)).each { |i|
- # Add the nimber of day in the month to the current date
- day_month += DTLS::MonthSetup[i - 1][1]
- }
- end
- # Return the current date
- return day_month
- end
- #--------------------------------------------------------------------------
- # * Set Time
- #--------------------------------------------------------------------------
- def set_time(minute, hour, day, month, year)
- # Set the new minute with a minimum of 0
- @minute = [(minute - minute % DTLS::CountMinute), 0].max
- # Set the new hour with a minimum of 0
- @hour = [hour, 0].max
- # Set the new day with a minimum of 1
- @day = [day, 1].max
- # Set the new month with a minimum of 1
- @month = [month, 1].max
- # Set the new year with a minimum of 0
- @year = [year, 0].max
- # Check the time to put it in the right format
- check_time
- end
- #--------------------------------------------------------------------------
- # * Add minute
- #--------------------------------------------------------------------------
- def add_minute(minute)
- # Set the new minute with a minimum of 0
- @minute = [((@minute + minute) - (@minute + minute) % DTLS::CountMinute), 0].max
- # Check the time to put it in the right format
- check_time
- end
- #--------------------------------------------------------------------------
- # * Set Time
- #--------------------------------------------------------------------------
- def add_hour(hour)
- # Set the new hour with a minimum of 0
- @hour = [(@hour + hour), 0].max
- # Check the time to put it in the right format
- check_time
- end
- #--------------------------------------------------------------------------
- # * Set Time
- #--------------------------------------------------------------------------
- def sdd_day(day)
- # Set the new day with a minimum of 1
- @day = [(@day + day), 1].max
- # Check the time to put it in the right format
- check_time
- end
- #--------------------------------------------------------------------------
- # * Set Time
- #--------------------------------------------------------------------------
- def add_month(month)
- # Set the new month with a minimum of 1
- @month = [(@month + month), 1].max
- # Check the time to put it in the right format
- check_time
- end
- #--------------------------------------------------------------------------
- # * Set Time
- #--------------------------------------------------------------------------
- def add_year(year)
- # Set the new year with a minimum of 0
- @year = [(@year + year), 0].max
- # Check the time to put it in the right format
- check_time
- end
- #--------------------------------------------------------------------------
- # * Check Time
- #--------------------------------------------------------------------------
- def check_time
- # Check if the minutes are greater than the maximum value
- if @minute >= DTLS::DaySetup[1]
- # Increase the number of hour with the extra minutes
- @hour += (@minute / DTLS::DaySetup[1]).floor
- # Remove the extra minutes
- @minute %= DTLS::DaySetup[1]
- # Check if the hours are greater than the maximum value
- if @hour >= DTLS::DaySetup[0]
- # Increase the number of hour with the extra hours
- @day += (@hour / DTLS::DaySetup[0]).floor
- # Remove the extra hours
- @hour %= DTLS::DaySetup[0]
- # Check if the days are greater than the maximum value
- if @day > DTLS::MonthSetup[@month - 1][1]
- # Cylcle thought the extra month
- while @day > DTLS::MonthSetup[@month - 1][1] do
- # Remove the number of day in the month to the day
- @day -= DTLS::MonthSetup[@month - 1][1]
- # Increase the nunber of month by one
- @month += 1
- # Check if the month are greater than the maximum value
- if @month > DTLS::MonthSetup.size
- # Increase the number of year by one
- @year += 1
- # Remove the extra month
- @month %= DTLS::MonthSetup.size
- end
- end
- # Update the season data if the number of month change
- update_season
- end
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Update Season
- #--------------------------------------------------------------------------
- def update_season
- # Check if the number of season is biger than 1
- if DTLS::Season[@climate].size > 1
- # Get the curent date
- current_date = get_date(@month, @day)
- # Sort the season by date
- season_data = DTLS::Season[@climate].sort { |x, y| get_date(x[0], x[1]) <=> get_date(y[0], y[1]) }
- # Cycle thought the season
- season_data.each_index { |s|
- # Get the next season id
- ns = (s + 1) % DTLS::Season[@climate].size
- # Get the date of the start and the end of the season
- season_start = get_date(season_data[s][0], season_data[s][1])
- season_end = get_date(season_data[ns][0], season_data[ns][1])
- # Check if the current date between the start and the end of the season
- if current_date >= season_start && current_date < season_end
- # Set the season id
- @season = s
- # Get the two ration for the linear interpolation
- ratio_start = (season_end - current_date).to_f / (season_end - season_start)
- ratio_end = (current_date - season_start).to_f / (season_end - season_start)
- # Get the night time color value
- night_time_start = DTLS::NightColor[DTLS::Season[@climate][s][2]]
- night_time_start.sort { |x,y| x[0] <=> y[0] }
- night_time_end = DTLS::NightColor[DTLS::Season[@climate][ns][2]]
- night_time_end.sort { |x,y| x[0] <=> y[0] }
- # Cycle throught the night color value
- night_time_start.each_index { |i|
- night_time_start[i].each_index { |j|
- @night_color[i][j] = night_time_start[i][j] * ratio_start + night_time_end[i][j] * ratio_end
- }
- }
- # Get the current season day and night time
- time_day_start = DTLS::Season[@climate][s][3] * 60 + DTLS::Season[@climate][s][4]
- time_night_start = DTLS::Season[@climate][s][5] * 60 + DTLS::Season[@climate][s][6]
- # Get the next season day and night time
- time_day_end = DTLS::Season[@climate][ns][3] * 60 + DTLS::Season[@climate][ns][4]
- time_night_end = DTLS::Season[@climate][ns][5] * 60 + DTLS::Season[@climate][ns][6]
- # Calculate the time of day and night
- @time_day = time_day_start * ratio_start + time_day_end * ratio_end
- @time_night = time_night_start * ratio_start + time_night_end * ratio_end
- end
- }
- else
- # Set the season id to 0
- @season = 0
- # Get the night color for the only season
- @night_color = DTLS::NightColor[DTLS::Season[@climate][0][2]]
- # Get the day time for the only season
- @time_day = DTLS::Season[@climate][0][3] * 60 + DTLS::Season[@climate][0][4]
- # Get the night time for the only season
- @time_night = DTLS::Season[@climate][0][5] * 60 + DTLS::Season[@climate][0][6]
- end
- end
- #--------------------------------------------------------------------------
- # * Day?
- #--------------------------------------------------------------------------
- def day?
- # Check if its the day
- return (@hour * 60 + @minute) <= @time_night && (@hour * 60 + @minute) >= @time_day
- end
- #--------------------------------------------------------------------------
- # * Day?
- #--------------------------------------------------------------------------
- def night?
- # Check if it's not the day
- return !day?
- end
- #--------------------------------------------------------------------------
- # * Season
- #--------------------------------------------------------------------------
- def season?
- # Return the season name
- return DTLS::Season[@climate][@season][2]
- end
- #--------------------------------------------------------------------------
- # * Frame Update
- #--------------------------------------------------------------------------
- def update
- # Check if the system and the time are activated
- if $game_system.activate_dtls && $game_system.activate_time
- # Increase the minute count
- @minute += DTLS::CountMinute
- # Update the time data
- check_time
- if day?
- $game_switches[DTLS::IsNightSwitch] = false
- $game_switches[DTLS::IsDaySwitch] = true
- else
- $game_switches[DTLS::IsNightSwitch] = true
- $game_switches[DTLS::IsDaySwitch] = false
- end
- $game_variables[DTLS::MinuteVariable] = @minute
- $game_variables[DTLS::HourVariable] = @hour
- $game_variables[DTLS::DayVariable] = @day
- $game_variables[DTLS::MonthVariable] = @month
- $game_variables[DTLS::YearVariable] = @year
- $game_map.need_refresh = true
- end
- end
- end
- #==============================================================================
- # ** Game_System
- #------------------------------------------------------------------------------
- # This class handles data surrounding the system. Backround music, etc.
- # is managed here as well. Refer to "$game_system" for the instance of
- # this class.
- #==============================================================================
- class Game_System
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_reader :time
- attr_accessor :activate_dtls
- attr_accessor :activate_time
- attr_accessor :activate_night
- attr_accessor :activate_light
- attr_accessor :activate_time_window
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- alias dtls_initialize initialize
- def initialize
- dtls_initialize
- # Set the activation parameter
- @activate_dtls = DTLS::Activate
- @activate_time = DTLS::ActivateTime
- @activate_night = DTLS::ActivateNight
- @activate_light = DTLS::ActivateLight
- @activate_time_window = DTLS::ActivateTimeWindow
- # Set the time system
- @time = Time_System.new
- end
- end
- #==============================================================================
- # ** Game_Map
- #------------------------------------------------------------------------------
- # This class handles the map. It includes scrolling and passable determining
- # functions. Refer to "$game_map" for the instance of this class.
- #==============================================================================
- class Game_Map
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_accessor :light_event
- attr_accessor :light_player
- attr_accessor :night_color
- attr_accessor :night_tansition
- #--------------------------------------------------------------------------
- # * Setup
- # map_id : map ID
- #--------------------------------------------------------------------------
- alias dtls_setup setup
- def setup(map_id)
- dtls_setup (map_id)
- # Create the light event list
- @light_event = {}
- # Create the light player list
- @light_player = []
- # Create the night color
- @night_color = []
- # Night time transition
- @night_tansition = 0
- # Set all the light data list
- create_light_list
- end
- #--------------------------------------------------------------------------
- # * Create light list
- #--------------------------------------------------------------------------
- def create_light_list
- climate = nil
- # Verify all event on the map for light comment
- if @events != {} && @events != nil
- @events.each_value { |event|
- # Nest event if empty
- next if event.list == nil
- # Create light a light around the event if the first comment is
- # 'light_event'
- if event.list[0].code == 108
- # Add the light to the event light list
- if event.list[0].parameters[0].split[0] == 'light_event'
- # Add the light data to the light event list
- @light_event[event.id] = get_light_data(event)
- # Set the player list
- elsif event.list[0].parameters[0].split[0] == 'light_player'
- # Get the filename after the creation comment on the first comment.
- # If their is no filename get the default name.
- filename = [DTLS::DefaultPicture, '']
- if event.list[0].parameters[0].split[1] != nil
- filename[0] = event.list[0].parameters[0].split[1]
- end
- # Add the light data to the light player list
- @light_player = get_light_data(event)
- # Get constant night color
- elsif event.list[0].parameters[0].split[0] == 'set_map'
- # Cycle thought the other line of the event to see if their is other
- # configuration in comment
- (1..event.list.size).each { |i|
- # Check if the line is a comment
- if event.list[i] != nil && event.list[i].code == 108
- # Fix the value of the night to the specicied color
- if event.list[i].parameters[0].split[0] == 'night'
- @night_color = [event.list[i].parameters[0].split[1].to_i,
- event.list[i].parameters[0].split[2].to_i,
- event.list[i].parameters[0].split[3].to_i,
- event.list[i].parameters[0].split[4].to_i]
- if event.list[i].parameters[0].split[5] != nil
- @night_tansition = event.list[i].parameters[0].split[5].to_i
- end
- # Set the climate the the specified value
- elsif event.list[i].parameters[0].split[0] == 'climate'
- climate = event.list[0].parameters[0].split[1]
- end
- end
- }
- # Change the climate in the time system
- # $game_system.time.change_climate(climate)
- end
- end
- }
- end
- end
- #--------------------------------------------------------------------------
- # * Get Light Data
- #--------------------------------------------------------------------------
- def get_light_data(event)
- # Get the filename after the creation comment on the first comment.
- # If their is no filename get the default name.
- filename = DTLS::DefaultPicture
- if event.list[0].parameters[0].split[1] != nil
- filename = event.list[0].parameters[0].split[1]
- end
- # Set the default tag
- follow = DTLS::DefaultFollow
- # Set the default zoom
- zoom = DTLS::DefaultZoom
- # Set the default opacity
- opacity = DTLS::DefaultOpacity
- # Set the default switch
- switch = DTLS::DefaultSwitch
- # Set the default random animation variable
- rand = [DTLS::DefaultRandZoomFrame, DTLS::DefaultRandZoom, 0.0,
- DTLS::DefaultRandOpacityFrame, DTLS::DefaultRandOpacity, 0.0]
- # Set the default wave animation variable
- wave = [DTLS::DefaultWaveZoomFrame, DTLS::DefaultWaveZoomMax,
- DTLS::DefaultWaveZoomStep, 0.0, DTLS::DefaultWaveOpacityFrame,
- DTLS::DefaultWaveOpacityMax, DTLS::DefaultWaveOpacityStep, 0.0]
- # Set the day and night only tag
- time = [DTLS::DefaultNightOnly, DTLS::DefaultDayOnly]
- # Cycle thought the other line of the event to see if their is other
- # configuration in comment
- (1..event.list.size).each { |i|
- # Check if the line is a comment
- if event.list[i] != nil && event.list[i].code == 108
- # Get the tag to see if the light will follow the direction of the
- # event
- if event.list[i].parameters[0].split[0] == 'follow'
- follow = true
- # Get the value of the zoom on the light image
- elsif event.list[i].parameters[0].split[0] == 'zoom'
- zoom = event.list[i].parameters[0].split[1].to_f
- # Get the opacity of the light image
- elsif event.list[i].parameters[0].split[0] == 'opacity'
- opacity = event.list[i].parameters[0].split[1].to_i
- # Get the switch id that will turn on or off this particuliar light
- elsif event.list[i].parameters[0].split[0] == 'switch'
- switch = event.list[i].parameters[0].split[1].to_i
- # Get the number of frame beetween each random animation update
- elsif event.list[i].parameters[0].split[0] == 'rand_zoom_frame'
- rand[0] = event.list[i].parameters[0].split[1].to_i
- # Get the maximum value of the zoom for random animation
- elsif event.list[i].parameters[0].split[0] == 'rand_zoom'
- rand[1] = event.list[i].parameters[0].split[1].to_f
- # Get the number of frame beetween each random animation update
- elsif event.list[i].parameters[0].split[0] == 'rand_opacity_frame'
- rand[3] = event.list[i].parameters[0].split[1].to_i
- # Get the maximum value of the opacity for random animation
- elsif event.list[i].parameters[0].split[0] == 'rand_opacity'
- rand[4] = event.list[i].parameters[0].split[1].to_f
- # Get the number of frame beetween each wave zoom animation update
- elsif event.list[i].parameters[0].split[0] == 'wave_zoom_frame'
- wave[0] = event.list[i].parameters[0].split[1].to_i
- # Get the amplitude of zoom and the value increase between each
- # update.
- elsif event.list[i].parameters[0].split[0] == 'wave_zoom'
- wave[1] = event.list[i].parameters[0].split[1].to_f
- if event.list[i].parameters[0].split[2] != nil
- wave[2] = event.list[i].parameters[0].split[1].to_f
- end
- # Get the number of frame beetween each wave opacity animation
- # update
- elsif event.list[i].parameters[0].split[0] == 'wave_opacity_frame'
- wave[4] = event.list[i].parameters[0].split[1].to_i
- # Get the amplitude of opacity and the value increase between each
- # update.
- elsif event.list[i].parameters[0].split[0] == 'wave_opacity'
- wave[5] = event.list[i].parameters[0].split[1].to_f
- if event.list[i].parameters[0].split[2] != nil
- wave[6] = event.list[i].parameters[0].split[1].to_f
- end
- # Get the tag for the light that are only active during the night
- elsif event.list[i].parameters[0].split[0] == 'night_only'
- time[0] = true
- # Get the tag for the light that are only active during the day
- elsif event.list[i].parameters[0].split[0] == 'day_only'
- time[1] = true
- end
- end
- }
- # Add the light to the event light list
- return [filename, follow, zoom, opacity, switch, rand, wave, time]
- end
- #--------------------------------------------------------------------------
- # * Change Light Event
- #--------------------------------------------------------------------------
- def change_light_event(event_id, filename = nil, follow = nil, zoom = nil,
- opacity = nil, switch = nil, rand = [], wave = [], sin = [], time = [])
- # Get new filename
- filename = filename != nil ? filename : DTLS::DefaultPicture
- # Get new follow flag
- follow = follow != nil ? follow : DTLS::DefaultFollow
- # Get new zoom
- zoom = zoom != nil ? zoom : DTLS::DefaultZoom
- # Get new opacity
- opacity = opacity != nil ? opacity : DTLS::DefaultOpacity
- # Get new switch
- switch = switch != nil ? switch : DTLS::DefaultSwitch
- # Set the default random animation variable
- rand = [DTLS::DefaultRandZoomFrame, DTLS::DefaultRandZoom, 0.0,
- DTLS::DefaultRandOpacityFrame, DTLS::DefaultRandOpacity, 0.0]
- if rand != []
- # Get new random animation frame
- rand[0] = rand[0] != nil ? rand[0] : DTLS::DefaultRandZoomFrame
- # Get new random zoom animation
- rand[1] = rand[1] != nil ? rand[1] : DTLS::DefaultRandZoom
- # Set the random variable
- rand[2] = 0.0
- # Get new random animation frame
- rand[3] = rand[3] != nil ? rand[3] : DTLS::DefaultRandOpacityFrame
- # Get new random opacity animation
- rand[4] = rand[4] != nil ? rand[4] : DTLS::DefaultRandOpacity
- # Set the random variable
- rand[5] = 0.0
- end
- # Set the default wave animation variable
- wave = [DTLS::DefaultWaveZoomFrame, DTLS::DefaultWaveZoomMax,
- DTLS::DefaultWaveZoomStep, 0.0, DTLS::DefaultWaveOpacityFrame,
- DTLS::DefaultWaveOpacityMax, DTLS::DefaultWaveOpacityStep, 0.0]
- if wave != []
- # Get new wave zoom animation frame
- wave[0] = wave[0] != nil ? wave[0] : DTLS::DefaultWaveZoomFrame
- # Get new wave zoom animation
- wave[1] = wave[1] != nil ? wave[1] : DTLS::DefaultWaveZoomMax
- wave[2] = wave[2] != nil ? wave[2] : DTLS::DefaultWaveZoomStep
- # Set the wave zoom variable
- wave[3] = 0.0
- # Get new wave zoom animation frame
- wave[4] = wave[4] != nil ? wave[4] : DTLS::DefaultWaveOpacityFrame
- # Get new wave opacity animation
- wave[5] = wave[5] != nil ? wave[5] : DTLS::DefaultWaveOpacityMax
- wave[6] = wave[6] != nil ? wave[6] : DTLS::DefaultWaveOpacityStep
- # Set the wave opacity variable
- wave[7] = 0.0
- end
- # Set the day and night only tag
- time = [DTLS::DefaultNightOnly, DTLS::DefaultDayOnly]
- if time != []
- # Get the day only and night only tag
- time[0] = time[0] != nil ? time[0] : DTLS::DefaultNightOnly
- time[1] = time[1] != nil ? time[1] : DTLS::DefaultDayOnly
- end
- # Modified light event list
- @light_event[event_id] = [filename, follow, zoom, opacity, switch, rand,
- wave, time]
- end
- #--------------------------------------------------------------------------
- # * Remove Light Event
- #--------------------------------------------------------------------------
- def remove_light_event(event_id)
- @light_event.delete(event_id)
- end
- #--------------------------------------------------------------------------
- # * Change Light Player
- #--------------------------------------------------------------------------
- def change_light_player(filename = nil, follow = nil, zoom = nil,
- opacity = nil, switch = nil, rand = [], wave = [], sin = [], time = [])
- # Get new filename
- filename = filename != nil ? filename : DTLS::DefaultPicture
- # Get new follow flag
- follow = follow != nil ? follow : DTLS::DefaultFollow
- # Get new zoom
- zoom = zoom != nil ? zoom : DTLS::DefaultZoom
- # Get new opacity
- opacity = opacity != nil ? opacity : DTLS::DefaultOpacity
- # Get new switch
- switch = switch != nil ? switch : DTLS::DefaultSwitch
- # Set the default random animation variable
- rand = [DTLS::DefaultRandZoomFrame, DTLS::DefaultRandZoom, 0.0,
- DTLS::DefaultRandOpacityFrame, DTLS::DefaultRandOpacity, 0.0]
- if rand != []
- # Get new random animation frame
- rand[0] = rand[0] != nil ? rand[0] : DTLS::DefaultRandZoomFrame
- # Get new random zoom animation
- rand[1] = rand[1] != nil ? rand[1] : DTLS::DefaultRandZoom
- # Set the random variable
- rand[2] = 0.0
- # Get new random animation frame
- rand[3] = rand[3] != nil ? rand[3] : DTLS::DefaultRandOpacityFrame
- # Get new random opacity animation
- rand[4] = rand[4] != nil ? rand[4] : DTLS::DefaultRandOpacity
- # Set the random variable
- rand[5] = 0.0
- end
- # Set the default wave animation variable
- wave = [DTLS::DefaultWaveZoomFrame, DTLS::DefaultWaveZoomMax,
- DTLS::DefaultWaveZoomStep, 0.0, DTLS::DefaultWaveOpacityFrame,
- DTLS::DefaultWaveOpacityMax, DTLS::DefaultWaveOpacityStep, 0.0]
- if wave != []
- # Get new wave zoom animation frame
- wave[0] = wave[0] != nil ? wave[0] : DTLS::DefaultWaveZoomFrame
- # Get new wave zoom animation
- wave[1] = wave[1] != nil ? wave[1] : DTLS::DefaultWaveZoomMax
- wave[2] = wave[2] != nil ? wave[2] : DTLS::DefaultWaveZoomStep
- # Set the wave zoom variable
- wave[3] = 0.0
- # Get new wave zoom animation frame
- wave[4] = wave[4] != nil ? wave[4] : DTLS::DefaultWaveOpacityFrame
- # Get new wave opacity animation
- wave[5] = wave[5] != nil ? wave[5] : DTLS::DefaultWaveOpacityMax
- wave[6] = wave[6] != nil ? wave[6] : DTLS::DefaultWaveOpacityStep
- # Set the wave opacity variable
- wave[7] = 0.0
- end
- # Set the day and night only tag
- time = [DTLS::DefaultNightOnly, DTLS::DefaultDayOnly]
- if time != []
- # Get the day only and night only tag
- time[0] = time[0] != nil ? time[0] : DTLS::DefaultNightOnly
- time[1] = time[1] != nil ? time[1] : DTLS::DefaultDayOnly
- end
- # Modified light event list
- @light_player = [filename, follow, zoom, opacity, switch, rand, wave,
- time]
- end
- #--------------------------------------------------------------------------
- # * Remove Light Player
- #--------------------------------------------------------------------------
- def remove_light_player
- @light_player = []
- end
- end
- #==============================================================================
- # ** Spriteset_Map
- #------------------------------------------------------------------------------
- # This class brings together map screen sprites, tilemaps, etc.
- # It's used within the Scene_Map class.
- #==============================================================================
- class Spriteset_Map
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- alias dtls_initialize initialize
- def initialize
- # Set the frame count for the animation
- @frame = 0
- # Get the color of the night sprite for the current time
- @current_color = [0, 0, 0, 0]
- # Get the time for the fixed night color transition
- @night_tansition = $game_map.night_tansition
- # Create the night and light sprite
- @light = Sprite.new
- @light.bitmap = Bitmap.new(640,480)
- # Set the sprite blend type to substract
- @light.blend_type = 2
- # Set the other sprite parameter
- @light.z = 100
- @light.opacity = 255
- # Original initialize
- dtls_initialize
- end
- #--------------------------------------------------------------------------
- # * Dispose
- #--------------------------------------------------------------------------
- alias dtls_dispose dispose
- def dispose
- # Original dispose
- dtls_dispose
- # Dispose of the light sprite
- @light.dispose
- # Reset the event and player light list
- @light_list = {}
- @player_light = []
- end
- #--------------------------------------------------------------------------
- # * Frame Update
- #--------------------------------------------------------------------------
- alias dtls_update update
- def update
- # Original update
- dtls_update
- # Display light and night when night switch is off
- if $game_system.activate_dtls && $game_system.activate_night
- # Display the night
- if $game_map.night_color != []
- if @night_tansition > 0
- night_color_corr = []
- ratio_start = @night_tansition.to_f / $game_map.night_tansition
- ratio_end = ($game_map.night_tansition - @night_tansition).to_f / $game_map.night_tansition
- $game_map.night_color.each_index { |i|
- night_color_corr[i] = @current_color[i] * ratio_start + $game_map.night_color[i] * ratio_end
- }
- # Draw the night with a fixe color
- @light.bitmap.fill_rect(@light.bitmap.rect, Color.new(night_color_corr[0], night_color_corr[1], night_color_corr[2], night_color_corr[3]))
- else
- # Draw the night with a fixe color
- @light.bitmap.fill_rect(@light.bitmap.rect, Color.new($game_map.night_color[0], $game_map.night_color[1], $game_map.night_color[2], $game_map.night_color[3]))
- end
- @night_tansition -= 1
- else
- # Get the night color value base on the time of day
- update_night
- # Draw the night for the correct time
- @light.bitmap.fill_rect(@light.bitmap.rect, Color.new(@current_color[0], @current_color[1], @current_color[2], @current_color[3]))
- end
- # Display the light when the light switch is off
- if $game_system.activate_light
- # Update the light of the event
- update_light_event
- # Update the light of the player
- update_light_player
- end
- else
- # Draw an empty night when the switch is on
- @light.bitmap.fill_rect(@light.bitmap.rect, Color.new(0,0,0,0))
- end
- # Increase the frame count for the animation
- @frame += 1
- end
- #--------------------------------------------------------------------------
- # * Frame Update (Night)
- #--------------------------------------------------------------------------
- def update_night
- # Get the current time in minute
- current_time = $game_system.time.hour * 60 + $game_system.time.minute
- # Cycle throught
- $game_system.time.night_color.each_index { |i|
- j = (i + 1) % $game_system.time.night_color.size
- time_last = $game_system.time.night_color[i][0] * 60 + $game_system.time.night_color[i][1]
- time_next = $game_system.time.night_color[j][0] * 60 + $game_system.time.night_color[i][1]
- # Check if the next time is smaller then the last time
- if time_next < time_last
- # Add a day because the next time is the first color value
- time_next += 24 * 60
- end
- # Check if the current time is smaller then the last time
- if current_time < time_last
- current_time += 24 * 60
- end
- # Check if the current time is in between the last and the next time
- if current_time >= time_last && current_time <= time_next
- color_last = $game_system.time.night_color[i]
- color_next = $game_system.time.night_color[j]
- ratio_last = (time_next - current_time).to_f / (time_next - time_last)
- ratio_next = (current_time - time_last).to_f / (time_next - time_last)
- (0..3).each{ |c|
- @current_color[c] = color_last[c + 2] * ratio_last + color_next[c + 2] * ratio_next
- }
- end
- }
- end
- #--------------------------------------------------------------------------
- # * Frame Update (Light event)
- #--------------------------------------------------------------------------
- def update_light_event
- # Display the ligth when one or more light were created
- if $game_map.light_event != {}
- # Cycle through the light list
- $game_map.light_event.each { |i, light|
- # Display one light if it's switch is off
- if (light[4] == 0 || (light[4] > 0 && !$game_switches[light[4]])) &&
- (!light[7][0] || (light[7][0] && $game_system.time.night?)) &&
- (!light[7][1] || (light[7][1] && $game_system.time.day?))
- # Get the filename of the light
- filename = light[0]
- if light[1]
- filename += '_D' if $game_map.events[i].direction == 2
- filename += '_L' if $game_map.events[i].direction == 4
- filename += '_R' if $game_map.events[i].direction == 6
- filename += '_U' if $game_map.events[i].direction == 8
- end
- img = RPG::Cache.picture(filename)
- # Get the random zoom effect modifier for the light
- if @frame % light[5][0] == 0
- if light[5][1] > 0
- $game_map.light_event[i][5][2] = (rand(2) - 1) * light[5][1]
- end
- end
- # Get the random opacity effect modifier for the light
- if @frame % light[5][3] == 0
- if light[5][4]
- $game_map.light_event[i][5][5] = (rand(2) - 1) * light[5][5]
- end
- end
- # Get the wave zoom effect modifier for the light
- if @frame % light[6][0] == 0
- if light[6][1] > 0
- $game_map.light_event[i][6][3] += light[6][2]
- if $game_map.light_event[i][6][3] > light[6][1]
- $game_map.light_event[i][6][3] = light[6][1]
- $game_map.light_event[i][6][2] *= -1
- elsif $game_map.light_event[i][6][3] < -1 * light[6][1]
- $game_map.light_event[i][6][3] = -1 * light[6][1]
- $game_map.light_event[i][6][2] *= -1
- end
- end
- end
- # Get the wave opacity effect modifier for the light
- if @frame % light[6][4] == 0
- if light[6][5] > 0
- $game_map.light_event[i][6][7] += light[6][6]
- if $game_map.light_event[i][6][7] > light[6][5]
- $game_map.light_event[i][6][7] = light[6][5]
- $game_map.light_event[i][6][6] *= -1
- elsif $game_map.light_event[i][6][7] < -1 * light[6][5]
- $game_map.light_event[i][6][7] = -1 * light[6][5]
- $game_map.light_event[i][6][6] *= -1
- end
- end
- end
- # Get the width and the height of the modified image
- tx = img.width * (light[2] + $game_map.light_event[i][5][2] + $game_map.light_event[i][6][3])
- ty = img.height * (light[2] + $game_map.light_event[i][5][2] + $game_map.light_event[i][6][3])
- # Get the position of the light base on the position of the event
- x = ($game_map.events[i].real_x - $game_map.display_x) / 4 - tx / 2 + 16
- y = ($game_map.events[i].real_y - $game_map.display_y) / 4 - ty / 2 + 16
- # Get the opacity of the light
- op = [light[3] + $game_map.light_event[i][5][5] + $game_map.light_event[i][6][7], 255].min
- # Draw the light on the light sprite
- @light.bitmap.stretch_blt(Rect.new(x, y, tx, ty), img, img.rect, op)
- end
- }
- end
- end
- #--------------------------------------------------------------------------
- # * Frame Update (Light player)
- #--------------------------------------------------------------------------
- def update_light_player
- # Display player light if it's switch is off
- if $game_map.light_player != [] && ($game_map.light_player[4] == 0 ||
- ($game_map.light_player[4] > 0 &&
- !$game_switches[$game_map.light_player[4]])) &&
- (!$game_map.light_player[7][0] || ($game_map.light_player[7][0] &&
- $game_system.time.night?)) && (!$game_map.light_player[7][1] ||
- ($game_map.light_player[7][1] && $game_system.time.day?))
- # Get the filename of the light
- filename = $game_map.light_player[0]
- if $game_map.light_player[1]
- filename += '_D' if $game_player.direction == 2
- filename += '_L' if $game_player.direction == 4
- filename += '_R' if $game_player.direction == 6
- filename += '_U' if $game_player.direction == 8
- end
- img = RPG::Cache.picture(filename)
- # Get the random zoom effect modifier for the light
- if @frame % $game_map.light_player[5][0] == 0
- if $game_map.light_player[5][1] > 0
- $game_map.light_player[5][2] = (rand(2) - 1) * $game_map.light_player[5][1]
- end
- end
- # Get the random opacity effect modifier for the light
- if @frame % $game_map.light_player[5][3] == 0
- if $game_map.light_player[5][4]
- $game_map.light_player[5][5] = (rand(2) - 1) * $game_map.light_player[5][4]
- end
- end
- # Get the wave zoom effect modifier for the light
- if @frame % $game_map.light_player[6][0] == 0
- if $game_map.light_player[6][1] > 0
- $game_map.light_player[6][3] += $game_map.light_player[6][2]
- if $game_map.light_player[6][3] > $game_map.light_player[6][1]
- $game_map.light_player[6][3] = $game_map.light_player[6][1]
- $game_map.light_player[6][2] *= -1
- elsif $game_map.light_player[6][3] < -1 * $game_map.light_player[6][1]
- $game_map.light_player[6][3] = -1 * $game_map.light_player[6][1]
- $game_map.light_player[6][2] *= -1
- end
- end
- end
- # Get the wave opacity effect modifier for the light
- if @frame % $game_map.light_player[6][4] == 0
- if $game_map.light_player[6][5] > 0
- $game_map.light_player[6][7] += $game_map.light_player[6][6]
- if $game_map.light_player[6][7] > $game_map.light_player[6][5]
- $game_map.light_player[6][7] = $game_map.light_player[6][5]
- $game_map.light_player[6][6] *= -1
- elsif $game_map.light_player[6][7] < -1 * $game_map.light_player[6][5]
- $game_map.light_player[6][7] = -1 * $game_map.light_player[6][5]
- $game_map.light_player[6][6] *= -1
- end
- end
- end
- # Get the width and the height of the modified image
- tx = img.width * ($game_map.light_player[2] + $game_map.light_player[5][2] + $game_map.light_player[6][3])
- ty = img.height * ($game_map.light_player[2] + $game_map.light_player[5][2] + $game_map.light_player[6][3])
- # Get the position of the light base on the position of the event
- x = ($game_player.real_x - $game_map.display_x) / 4 - tx / 2 + 16
- y = ($game_player.real_y - $game_map.display_y) / 4 - ty / 2 + 16
- # Get the opacity of the light
- op = [$game_map.light_player[3] + $game_map.light_player[5][5] + $game_map.light_player[6][7], 255].min
- # Draw the light on the light sprite
- @light.bitmap.stretch_blt(Rect.new(x, y, tx, ty), img, img.rect, op)
- end
- end
- end
- #==============================================================================
- # ** Scene_Map
- #------------------------------------------------------------------------------
- # This class performs map screen processing.
- #==============================================================================
- class Scene_Map
- #--------------------------------------------------------------------------
- # * Main Processing
- #--------------------------------------------------------------------------
- alias dtls_main main
- def main
- #@time_window = Window_Time.new
- #if !$game_system.activate_time_window || !$game_system.activate_time
- #@time_window.visible = false
- #end
- dtls_main
- #@time_window.dispose
- end
- #--------------------------------------------------------------------------
- # * Frame Update
- #--------------------------------------------------------------------------
- alias dtls_update update
- def update
- #$game_system.time.update
- #if $game_system.activate_time_window && $game_system.activate_time
- #@time_window.visible = true
- #@time_window.refresh
- #else
- #@time_window.visible = false
- #end
- dtls_update
- end
- end
Add Comment
Please, Sign In to add comment