#使用方法:不透明的物体在光源旁边会产生一个阴影。
#所以,在光源的事件里面(例如火),请在第一页加上一个注释“s”(请不要带引号)
#然后将此脚本命名为“人物阴影”插入到main上方即可。
#==============================================================================
# ■ 阴影精灵 (渐变精灵 )
# 以 Genzai Kawakami的阴影脚本为基础,
# Rataime为其重写和更新,
# Boushy 为其添加附属功能
# 精灵使者汉化
#==============================================================================
CATERPILLAR_COMPATIBLE = true
class Game_Party
attr_reader :characters
end
class Sprite_Shadow < RPG::Sprite
attr_accessor :character
def initialize(viewport, character = nil,source = nil,anglemin=0,anglemax=0,distancemax=0)
super(viewport)
@anglemin=anglemin.to_f
@anglemax=anglemax.to_f
@distancemax=distancemax.to_f
@character = character
@source = source
update
end
def update
super
if (@tile_id != @character.tile_id or
@character_name != @character.character_name or
@character_hue != @character.character_hue)# and ( @character.screen_x >= 0 and @character.screen_x <=640 and @character.screen_y>=0 and @character.screen_y <= 480)
@tile_id = @character.tile_id
@character_name = @character.character_name
@character_hue = @character.character_hue
if @character_name.include?("AC") and not @character_name.include?("=4")
if @character.direction == 4
self.mirror = false
else
self.mirror = true
end
else
if @character.direction == 4
self.mirror = true
else
self.mirror = false
end
end
if @tile_id >= 384
self.bitmap = RPG::Cache.tile($game_map.tileset_name,
@tile_id, @character.character_hue)
self.src_rect.set(0, 0, 32, 32)
self.ox = 16
self.oy = 32
else
self.bitmap = RPG::Cache.character(@character.character_name,
@character.character_hue)
@cw = bitmap.width / 4
@cw = bitmap.width / 4
if not @character_name.include?("=4")
@ch = bitmap.height / 4
else
@ch = bitmap.height / 4
end
self.ox = @cw / 2
self.oy = @ch
end
end
self.visible = (not @character.transparent)
#self.visible = [email protected] && @character.screen_x.between?(0, 640) && @character.screen_y.between?(0,480) # 大致坐标,并不精确
if @tile_id == 0
# 设置传送目标的矩形
if not @character_name.include?("=4")
if @character.pattern >= 4
sx = (@character.pattern - 4) * @cw
else
sx = @character.pattern * @cw
end
if @character.pattern >= 4
sy = (4 - 2) / 2 * @ch
else
sy = (2 - 2) / 2 * @ch
end
self.src_rect.set(sx, sy, @cw, @ch)
else
sx = @character.pattern * @cw
sy = (@character.direction - 2) / 2 * @ch
self.src_rect.set(sx, sy, @cw, @ch)
end
end
self.x = @character.screen_x
self.y = @character.screen_y-5
self.z = @character.screen_z(@ch)-1
self.opacity = @character.opacity
self.blend_type = @character.blend_type
self.bush_depth = @character.bush_depth
#if @character.animation_id != 0
#animation = $data_animations[@character.animation_id]
# animation(animation, true)
# @character.animation_id = 0
#end
@deltax=@source.x-self.x
@deltay= @source.y-self.y
self.angle = 57.3*Math.atan2(@deltax, @deltay )
@angle_trigo=self.angle+90
if @angle_trigo<0
@angle_trigo=360+@angle_trigo
end
self.color = Color.new(0, 0, 0)
@distance = ((@deltax ** 2) + (@deltay ** 2))
if$game_map.shadows==-1
self.opacity = 0
else
self.opacity = 1200000/(@distance+6000)
end
if @character.screen_x >= 640 or @character.screen_x <= 0 or @character.screen_y >= 480 or @character.screen_y <= 0
self.opacity = 0
end
@distance = @distance ** 0.5
if @distancemax !=0 and @distance>=@distancemax
self.opacity=0
end
if @anglemin !=0 or @anglemax !=0
if (@angle_trigo<@anglemin or @angle_trigo>@anglemax) and @anglemin<@anglemax
self.opacity=0
end
if (@angle_trigo<@anglemin and @angle_trigo>@anglemax) and @anglemin>@anglemax
self.opacity=0
end
end
end
end
#===================================================
# ■ 重定义 Sprite_Character
#===================================================
class Sprite_Character < RPG::Sprite
alias shadow_initialize initialize
def initialize(viewport, character = nil)
@character = character
# @character = nil
super(viewport)
@ombrelist=[]
if (character.is_a?(Game_Event) and character.list!=nil and character.list[0].code == 108 and character.list[0].parameters == ["s"])
if (character.list[1]!=nil and character.list[1].code == 108)
@anglemin=character.list[1].parameters[0]
end
if (character.list[2]!=nil and character.list[2].code == 108)
@anglemax=character.list[2].parameters[0]
end
if (character.list[3]!=nil and character.list[3].code == 108)
@distancemax=character.list[3].parameters[0]
end
for i in $game_map.events.keys.sort
if $game_map.events[i].arpg_hp <=0 and ($game_map.events[i].is_a?(Game_Event) and not ($game_map.events[i].list[0].code == 108 && ($game_map.events[i].list[0].parameters == ["NotShadow"]) or $game_map.events[i].list[0].parameters == ["s"]) ) and (not $game_map.events[i].name.include?("NotShadow") ) #$game_map.events[i].list!=nil and $game_map.events[i].list[0].code == 108 and $game_map.events[i].list[0].parameters == ["o"])
@ombrelist[i+1] = Sprite_Shadow.new(viewport, $game_map.events[i],self,@anglemin,@anglemax,@distancemax)
end
end
@ombrelist[1] = Sprite_Shadow.new(viewport, $game_player,self,@anglemin,@anglemax,@distancemax)
#===================================================
# ● 原装人物跟随兼容脚本
#===================================================
if CATERPILLAR_COMPATIBLE and $game_party.characters!=nil
for member in $game_party.characters
@ombrelist.push(Sprite_Shadow.new(viewport, member,self,@anglemin,@anglemax,@distancemax))
end
end
#===================================================
# ● 兼容脚本结束
#===================================================
end
shadow_initialize(viewport, @character)
end
alias shadow_update update
def update
shadow_update
if @ombrelist!=[]
for i in [email]1..@ombrelist.size[/email]
# if @character.x >= 7 # character.x = @x -1
if @ombrelist[i]!=nil
@ombrelist[i].update
end
# end
end
end
end
end
#===================================================
# ■ 新定义类Scene_Save
#===================================================
class Scene_Save < Scene_File
alias shadows_write_save_data write_save_data
def write_save_data(file)
$game_map.shadows = nil
shadows_write_save_data(file)
end
end
#===================================================
# ■ 新定义类 Game_Map
#===================================================
class Game_Map
attr_accessor :shadows
end