Re-implemented lights as another viewport layer

This commit is contained in:
Mathew Velasquez 2015-11-22 17:35:08 -05:00
parent 52ad0e9f3e
commit afbcc3b6a3
2 changed files with 119 additions and 22 deletions

View File

@ -5,7 +5,7 @@
# class and automatically changes sprite conditions. # class and automatically changes sprite conditions.
#============================================================================== #==============================================================================
class Sprite_Character < RPG::Sprite class Sprite_Character
#-------------------------------------------------------------------------- #--------------------------------------------------------------------------
# * Public Instance Variables # * Public Instance Variables
#-------------------------------------------------------------------------- #--------------------------------------------------------------------------
@ -13,10 +13,13 @@ class Sprite_Character < RPG::Sprite
#-------------------------------------------------------------------------- #--------------------------------------------------------------------------
# * Object Initialization # * Object Initialization
# viewport : viewport # viewport : viewport
# light_viewport : light viewport
# character : character (Game_Character) # character : character (Game_Character)
#-------------------------------------------------------------------------- #--------------------------------------------------------------------------
def initialize(viewport, character = nil) def initialize(viewport, light_viewport, character = nil)
super(viewport) @sprite = Sprite.new(viewport)
@light_sprite = Sprite.new(light_viewport)
@light_sprite.blend_type = 1
@character = character @character = character
update update
end end
@ -24,7 +27,9 @@ class Sprite_Character < RPG::Sprite
# * Frame Update # * Frame Update
#-------------------------------------------------------------------------- #--------------------------------------------------------------------------
def update def update
super # Update sprites
@sprite.update
@light_sprite.update
# If tile ID, file name, or hue are different from current ones # If tile ID, file name, or hue are different from current ones
if @tile_id != @character.tile_id or if @tile_id != @character.tile_id or
@character_name != @character.character_name or @character_name != @character.character_name or
@ -35,22 +40,26 @@ class Sprite_Character < RPG::Sprite
@character_hue = @character.character_hue @character_hue = @character.character_hue
# If tile ID value is valid # If tile ID value is valid
if @tile_id >= 384 if @tile_id >= 384
self.bitmap = RPG::Cache.tile($game_map.tileset_name, @sprite.bitmap = RPG::Cache.tile($game_map.tileset_name,
@tile_id, @character.character_hue) @tile_id, @character.character_hue)
self.src_rect.set(0, 0, 32, 32) @light_sprite.visible = false
@sprite.src_rect.set(0, 0, 32, 32)
@light_sprite.src_rect.set(0, 0, 32, 32)
self.ox = 16 self.ox = 16
self.oy = 32 self.oy = 32
# If tile ID value is invalid # If tile ID value is invalid
else else
self.bitmap = RPG::Cache.character(@character.character_name, @sprite.bitmap = RPG::Cache.character(@character.character_name,
@character.character_hue) @character.character_hue)
#begin begin
# self.lightmap = RPG::Cache.lightmap(@character.character_name) @light_sprite.bitmap = RPG::Cache.lightmap(@character.character_name)
#rescue @light_sprite.visible = true
# self.lightmap = nil rescue
#end @light_sprite.bitmap = nil
@cw = bitmap.width / 4 @light_sprite.visible = false
@ch = bitmap.height / 4 end
@cw = @sprite.bitmap.width / 4
@ch = @sprite.bitmap.height / 4
self.ox = @cw / 2 self.ox = @cw / 2
self.oy = @ch self.oy = @ch
end end
@ -62,7 +71,8 @@ class Sprite_Character < RPG::Sprite
# Set rectangular transfer # Set rectangular transfer
sx = @character.pattern * @cw sx = @character.pattern * @cw
sy = (@character.direction - 2) / 2 * @ch sy = (@character.direction - 2) / 2 * @ch
self.src_rect.set(sx, sy, @cw, @ch) @sprite.src_rect.set(sx, sy, @cw, @ch)
@light_sprite.src_rect.set(sx, sy, @cw, @ch)
end end
# Set sprite coordinates # Set sprite coordinates
self.x = @character.screen_x self.x = @character.screen_x
@ -79,4 +89,91 @@ class Sprite_Character < RPG::Sprite
@character.animation_id = 0 @character.animation_id = 0
end end
end end
#--------------------------------------------------------------------------
# * Sprite attribute wrapper
#--------------------------------------------------------------------------
def self.sprite_attr(*args)
args.each do |arg|
class_eval("def #{arg};@sprite.#{arg};end")
class_eval("def #{arg}=(val);@sprite.#{arg}=val;@light_sprite.#{arg}=val;end")
end
end
#--------------------------------------------------------------------------
# * RPG::Sprite methods
#--------------------------------------------------------------------------
def whiten
@sprite.whiten
@light_sprite.whiten
end
def appear
@sprite.appear
@light_sprite.appear
end
def escape
@sprite.escape
@light_sprite.escape
end
def collapse
@sprite.collapse
@light_sprite.collapse
end
def damage(value, critical)
@sprite.damage(value, critical)
end
def animation(animation, hit)
@sprite.animation(animation, hit)
end
def loop_animation(animation, hit)
@sprite.loop_animation(animation)
end
def blink_on
@sprite.blink_on
@light_sprite.blink_on
end
def blink_off
@sprite.blink_off
@light_sprite.blink_off
end
def blink?
@sprite.blink?
end
def effect?
@sprite.effect?
end
#--------------------------------------------------------------------------
# * Sprite methods
#--------------------------------------------------------------------------
def dispose
@sprite.dispose
@light_sprite.dispose
@sprite = nil
@light_sprite = nil
end
def disposed?
@sprite == nil
end
def flash(color, duration)
@sprite.flash(color, duration)
@light_sprite.flash(color, duration)
end
#--------------------------------------------------------------------------
# * Sprite properties
#--------------------------------------------------------------------------
sprite_attr :src_rect
sprite_attr :visible
sprite_attr :x, :y, :z
sprite_attr :ox, :oy
sprite_attr :zoom_x, :zoom_y
sprite_attr :angle
sprite_attr :mirror
sprite_attr :bush_depth
sprite_attr :opacity
sprite_attr :color
sprite_attr :tone
def blend_type
@sprite.blend_type
end
def blend_type=(val)
@sprite.blend_type = val
end
end end

View File

@ -45,13 +45,13 @@ class Spriteset_Map
# Make character sprites # Make character sprites
@character_sprites = [] @character_sprites = []
for i in $game_map.events.keys.sort for i in $game_map.events.keys.sort
sprite = Sprite_Character.new(@viewport, $game_map.events[i]) sprite = Sprite_Character.new(@viewport, @viewport_lights, $game_map.events[i])
@character_sprites.push(sprite) @character_sprites.push(sprite)
end end
$game_followers.each do |follower| $game_followers.each do |follower|
@character_sprites.push(Sprite_Character.new(@viewport, follower)) @character_sprites.push(Sprite_Character.new(@viewport, @viewport_lights, follower))
end end
@character_sprites.push(Sprite_Character.new(@viewport, $game_player)) @character_sprites.push(Sprite_Character.new(@viewport, @viewport_lights, $game_player))
# Make weather # Make weather
@weather = RPG::Weather.new(@viewport) @weather = RPG::Weather.new(@viewport)
# Make picture sprites # Make picture sprites
@ -108,8 +108,8 @@ class Spriteset_Map
#-------------------------------------------------------------------------- #--------------------------------------------------------------------------
def add_follower(follower) def add_follower(follower)
@character_sprites.pop.dispose @character_sprites.pop.dispose
@character_sprites.push(Sprite_Character.new(@viewport, follower)) @character_sprites.push(Sprite_Character.new(@viewport, @viewport_lights, follower))
@character_sprites.push(Sprite_Character.new(@viewport, $game_player)) @character_sprites.push(Sprite_Character.new(@viewport, @viewport_lights, $game_player))
end end
def remove_follower(follower) def remove_follower(follower)
@character_sprites.reverse_each do |spr| @character_sprites.reverse_each do |spr|