From afbcc3b6a33458da41076218e44db4643520e2e0 Mon Sep 17 00:00:00 2001 From: Mathew Velasquez Date: Sun, 22 Nov 2015 17:35:08 -0500 Subject: [PATCH] Re-implemented lights as another viewport layer --- scripts/Sprite_Character.rb | 131 +++++++++++++++++++++++++++++++----- scripts/Spriteset_Map.rb | 10 +-- 2 files changed, 119 insertions(+), 22 deletions(-) diff --git a/scripts/Sprite_Character.rb b/scripts/Sprite_Character.rb index 9d73c74..74ff6b2 100644 --- a/scripts/Sprite_Character.rb +++ b/scripts/Sprite_Character.rb @@ -5,18 +5,21 @@ # class and automatically changes sprite conditions. #============================================================================== -class Sprite_Character < RPG::Sprite +class Sprite_Character #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_accessor :character # character #-------------------------------------------------------------------------- # * Object Initialization - # viewport : viewport - # character : character (Game_Character) + # viewport : viewport + # light_viewport : light viewport + # character : character (Game_Character) #-------------------------------------------------------------------------- - def initialize(viewport, character = nil) - super(viewport) + def initialize(viewport, light_viewport, character = nil) + @sprite = Sprite.new(viewport) + @light_sprite = Sprite.new(light_viewport) + @light_sprite.blend_type = 1 @character = character update end @@ -24,7 +27,9 @@ class Sprite_Character < RPG::Sprite # * Frame 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 != @character.tile_id or @character_name != @character.character_name or @@ -35,22 +40,26 @@ class Sprite_Character < RPG::Sprite @character_hue = @character.character_hue # If tile ID value is valid 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) - 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.oy = 32 # If tile ID value is invalid else - self.bitmap = RPG::Cache.character(@character.character_name, + @sprite.bitmap = RPG::Cache.character(@character.character_name, @character.character_hue) - #begin - # self.lightmap = RPG::Cache.lightmap(@character.character_name) - #rescue - # self.lightmap = nil - #end - @cw = bitmap.width / 4 - @ch = bitmap.height / 4 + begin + @light_sprite.bitmap = RPG::Cache.lightmap(@character.character_name) + @light_sprite.visible = true + rescue + @light_sprite.bitmap = nil + @light_sprite.visible = false + end + @cw = @sprite.bitmap.width / 4 + @ch = @sprite.bitmap.height / 4 self.ox = @cw / 2 self.oy = @ch end @@ -62,7 +71,8 @@ class Sprite_Character < RPG::Sprite # Set rectangular transfer sx = @character.pattern * @cw 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 # Set sprite coordinates self.x = @character.screen_x @@ -79,4 +89,91 @@ class Sprite_Character < RPG::Sprite @character.animation_id = 0 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 diff --git a/scripts/Spriteset_Map.rb b/scripts/Spriteset_Map.rb index fdea81c..b9f530c 100644 --- a/scripts/Spriteset_Map.rb +++ b/scripts/Spriteset_Map.rb @@ -45,13 +45,13 @@ class Spriteset_Map # Make character sprites @character_sprites = [] 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) end $game_followers.each do |follower| - @character_sprites.push(Sprite_Character.new(@viewport, follower)) + @character_sprites.push(Sprite_Character.new(@viewport, @viewport_lights, follower)) end - @character_sprites.push(Sprite_Character.new(@viewport, $game_player)) + @character_sprites.push(Sprite_Character.new(@viewport, @viewport_lights, $game_player)) # Make weather @weather = RPG::Weather.new(@viewport) # Make picture sprites @@ -108,8 +108,8 @@ class Spriteset_Map #-------------------------------------------------------------------------- def add_follower(follower) @character_sprites.pop.dispose - @character_sprites.push(Sprite_Character.new(@viewport, follower)) - @character_sprites.push(Sprite_Character.new(@viewport, $game_player)) + @character_sprites.push(Sprite_Character.new(@viewport, @viewport_lights, follower)) + @character_sprites.push(Sprite_Character.new(@viewport, @viewport_lights, $game_player)) end def remove_follower(follower) @character_sprites.reverse_each do |spr|