Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
- # Map Shaded Areas
- # Author: ForeverZer0
- # Version: 1.0
- # Date: 6.26.2012
- #+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
- #
- # Introduction:
- # This is simple script to display "shaded" areas on the map. Characters that
- # pass underneath will also be shaded.
- #
- # Instructions:
- # - See configuration below for detailed instructions on setup
- # - Use "$game_map.shade_color = COLOR" to change the color of the shade.
- # COLOR should be instance of a Color object.
- #
- # Example:
- # $game_map.shade_color = Color.new(0, 0, 80, 60) # Red, Green, Blue, Alpha
- #
- #+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
- #===============================================================================
- # ** Shade
- #-------------------------------------------------------------------------------
- # Class that represents a shaded area on the map.
- #===============================================================================
- class Shade < RPG::Sprite
- #-----------------------------------------------------------------------------
- # * Configuration
- #
- # For each map that you want to display a shaded area in, add a new "when"
- # statement with the ID of the map as the condition. Within that block, create
- # an array of Rect objects as in the example below. These Rects represent the
- # display coordinates of the shaded areas:
- #
- # ex.
- # when 45 # Map with ID:45
- # [Rect.new(3, 7, 10, 4), Rect.new(18, 34, 2, 1)]
- #
- # This will display two shaded areas in map 45. The first area will be as map
- # coordinate (3, 7), and will be 10 tiles wide, and 4 tiles high. The second
- # area will be at map coordinate (19, 34), and will be 2 tiles high, and only
- # one tile wide.
- #
- # Rect.new(MAP_X, MAP_Y, TILE_WIDTH, TILE_HEIGHT)
- #
- # You can add as many areas you like to each map, or none at all. If you you
- # run out of space and need to break to a new line while configuring, do so
- # after a commma to prevent errors. Make sure that each block for the maps
- # begins and ends with an opening and closing bracket: [ ].
- #-----------------------------------------------------------------------------
- def self.areas(map_id)
- return case map_id
- when 1
- [Rect.new(2, 2, 4, 6), Rect.new(5, 5, 3, 3)]
- when 2
- []
- when 3
- []
- else
- []
- end
- end
- #-----------------------------------------------------------------------------
- # * Public Instance Variables
- #-----------------------------------------------------------------------------
- attr_reader :rect
- #-----------------------------------------------------------------------------
- # * Object Initialization
- #-----------------------------------------------------------------------------
- def initialize(viewport = nil, rect = nil, color = nil)
- super(viewport)
- @color = color
- self.rect = rect
- end
- #-----------------------------------------------------------------------------
- # * Set Rectangle
- # rectangle : The display rectangle. X and Y values are map coordinates and
- # width and height values are the number of tiles it covers.
- #-----------------------------------------------------------------------------
- def rect=(rectangle)
- @rect = rectangle
- if self.bitmap != nil && !self.bitmap.disposed?
- self.bitmap = self.bitmap.dispose
- end
- self.x = @rect.x * 32
- self.y = @rect.y * 32
- self.bitmap = Bitmap.new(@rect.width * 32, @rect.height * 32)
- unless @color.nil?
- self.bitmap.fill_rect(self.bitmap.rect, @color)
- end
- end
- #-----------------------------------------------------------------------------
- # * Set Display Area
- # x : Map x-coordinate the shade is displayed at
- # y : Map y-coordinate the shade is displayed at
- # width : Width in tiles the shade covers on the horizontal axis
- # height : Height in tiles the shade covers on the vertical axis
- #-----------------------------------------------------------------------------
- def area=(x, y, width, height)
- self.rect = Rect.new(x, y, width, height)
- end
- def color=(color)
- if @color != color
- @color = color
- self.bitmap.fill_rect(self.bitmap.rect, @color)
- end
- end
- end
- #===============================================================================
- # ** Spriteset_Map
- #===============================================================================
- class Spriteset_Map
- #-----------------------------------------------------------------------------
- # * Object Initialization (alias)
- #-----------------------------------------------------------------------------
- alias shade_sprite_init initialize
- def initialize
- @shade_sprites = []
- shade_sprite_init
- areas = Shade.areas($game_map.map_id)
- areas.each {|rect|
- shade = Shade.new(@viewport2, rect, $game_map.shade_color)
- shade.ox = $game_map.display_x / 4
- shade.oy = $game_map.display_y / 4
- @shade_sprites.push(shade)
- }
- end
- #-----------------------------------------------------------------------------
- # * Frame Update (alias)
- #-----------------------------------------------------------------------------
- alias shade_sprite_update update
- def update
- shade_sprite_update
- _ox = $game_map.display_x / 4
- _oy = $game_map.display_y / 4
- @shade_sprites.each {|shade|
- shade.color = $game_map.shade_color
- shade.ox, shade.oy = _ox, _oy
- }
- end
- #-----------------------------------------------------------------------------
- # * Dispose Sprites (alias)
- #-----------------------------------------------------------------------------
- alias shade_sprite_dispose dispose
- def dispose
- shade_sprite_dispose
- @shade_sprites.each {|shade| shade.dispose }
- end
- end
- #===============================================================================
- # ** Game_Map
- #===============================================================================
- class Game_Map
- #-----------------------------------------------------------------------------
- # * Public Instance Variables
- #-----------------------------------------------------------------------------
- attr_accessor :shade_color
- #-----------------------------------------------------------------------------
- # * Object Initialization
- #-----------------------------------------------------------------------------
- alias shade_color_init initialize
- def initialize
- @shade_color = Color.new(0, 0, 0, 60)
- shade_color_init
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement