设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 1848|回复: 0
打印 上一主题 下一主题

[已经过期] 烛光系统和阴影精灵脚本无法一起使用

[复制链接]

Lv4.逐梦者

梦石
0
星屑
13566
在线时间
3845 小时
注册时间
2013-7-18
帖子
2307
跳转到指定楼层
1
发表于 2015-12-29 20:24:19 | 只看该作者 回帖奖励 |正序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
本帖最后由 y967 于 2015-12-29 20:26 编辑

烛光系统

RUBY 代码复制
  1. =begin
  2.   HN_Light version 1.0.1.0 for VX Ace
  3.         by 半生
  4.  
  5.  
  6.   要HN_RG_BITMAP(ver 0.1.2.1以降)
  7.  
  8. 2012/01/08 ver 1.0.1.2
  9.  队列歩行の仲间に対応
  10.  
  11. 2015/04/25 Xp移植
  12.   By RyanBern
  13.  
  14. =end
  15.  
  16. # ----- 在这里设定-----
  17. module HN_Light
  18.   # 简略化0:(精细)~2:(粗暴,负荷轻)
  19.   SIMPLIFY = 1
  20.  
  21.   # 表示黑暗处的不透明度,数值为0-255,越大则不可见度越高
  22.   DARK_OPACITY = 190
  23.  
  24.   # 玩家的烛光类型使用的变量号码
  25.   PLAYER_LIGHT_TYPE = 13
  26.  
  27.   # 黑暗判断上使用的开关
  28.   DARK_SWITCH = 73
  29.  
  30.   # 烛光事件识别用的正规表达式
  31.   REGEX_LIGHT = /@LIGHT(\d+)/
  32.  
  33.   # 烛光图像的目录
  34.   LIGHT_IMG_DIR = "Graphics/Pictures/"
  35.  
  36.   # 烛光Bitmap设定
  37.   LIGHTS = [
  38.   # [文件名  ,格栅数, 放大率,  Y偏移值, 色相]
  39.     ["light6",     1,    5.0,        0,    0],
  40.     ["light6",     1,    7.5,        0,    0],
  41.     ["light6",     1,    10.0,        0,    0],
  42.     ["light5",     1,    12.0,      -16,    0],
  43.     ["light5",     1,    5.0,        0,    0],
  44.     ["light5",     1,    15.0,        0,    0],
  45.     ["light7",     1,    3.0,      -16,    0],
  46.     ["light8",     1,    0.5,        0,    0],
  47.     ["light9",     1,    2.0,        0,    0],
  48.   ]
  49. end
  50. #  ----- 在这里设定 -----
  51.  
  52. module HN_Light
  53.   # 事件mix-in用
  54.   module LightEvent
  55.     attr_reader :light_type
  56.     def initialize
  57.       super()
  58.       @light_type = 0
  59.     end
  60.  
  61.     def check_light
  62.       @light_type = 0
  63.       return if @list.nil?
  64.       @list.each do |command|
  65.         break if @light_type > 0
  66.         if command.code == 108 or command.code == 408
  67.           command.parameters.each do |line|
  68.             if line =~ REGEX_LIGHT
  69.               @light_type = $1.to_i
  70.               break
  71.             end
  72.           end
  73.         end
  74.       end # END @list.each
  75.     end
  76.  
  77.   end # END module LightEvent
  78.  
  79.  
  80.   class Light
  81.     attr_reader :bitmap
  82.     attr_reader :cells
  83.     attr_reader :width
  84.     attr_reader :height
  85.     attr_reader :ox
  86.     attr_reader :oy
  87.     def initialize(light_type, s_zoom = 1)
  88.       light = LIGHTS[light_type - 1]
  89.       if light.nil?
  90.         # 本来不应该来这里
  91.         @bitmap = Bitmap.new(32, 32)
  92.         @cels = 1
  93.         @zoom = 1.0
  94.         @oy = 16
  95.         @ox = 16
  96.         @width  = 32
  97.         @height = 32
  98.       else
  99.         @bitmap = Bitmap.new(LIGHT_IMG_DIR + light[0])
  100.         @bitmap.invert()
  101.         @cells = light[1].to_i
  102.         @cells = 1 if (@cells < 1 or @cells > @bitmap.width)
  103.         @zoom = light[2].to_f
  104.         @zoom = 1.0 if @zoom <= 0.0
  105.         @zoom /= s_zoom
  106.         @width  = @bitmap.width / @cells
  107.         @height = @bitmap.height
  108.  
  109.         # 缩放处理
  110.         if @zoom != 1.0
  111.           new_width  = (@width * @zoom).round
  112.           new_height = (@height * @zoom).round
  113.           if new_width * new_height < 1
  114.             @zoom = 1.0
  115.           else
  116.             @width = new_width
  117.             @height = new_height
  118.             new_bitmap = Bitmap.new(@width * @cells, @height)
  119.             new_bitmap.stretch_blt(new_bitmap.rect,@bitmap, @bitmap.rect)
  120.             @bitmap.dispose
  121.             @bitmap = new_bitmap
  122.           end
  123.         end
  124.         @ox = @width / 2
  125.         @oy = @height / 2 - light[3].to_i / s_zoom
  126.  
  127.         # 色相変换
  128.         if ( (hue = light[4].to_i) != 0)
  129.           @bitmap.hue_change(hue)
  130.         end
  131.       end
  132.     end # End def initialize
  133.  
  134.     # 色调转换
  135.     def dispose
  136.       @bitmap.dispose
  137.       @bitmap = nil
  138.     end
  139.   end
  140.  
  141. end
  142.  
  143. class Game_Event
  144.   include HN_Light::LightEvent
  145.   alias :_hn_light__setup :refresh unless method_defined?(:_hn_light__setup)
  146.   def refresh
  147.     _hn_light__setup
  148.     check_light()
  149.   end
  150. end
  151.  
  152. class Game_Player
  153.   def light_type
  154.     return $game_variables[HN_Light::PLAYER_LIGHT_TYPE]
  155.   end
  156. end
  157.  
  158. class Game_Map
  159.   attr_reader :light_events
  160.  
  161.   # 更新烛光事件列表
  162.   def refresh_lights
  163.     @light_events = []
  164.     @events.values.each do |event|
  165.       if (event.light_type > 0)
  166.         @light_events.push(event)
  167.       end
  168.     end
  169.   end
  170.  
  171.   alias :_hn_light__setup_events :setup unless method_defined?(:_hn_light__setup_events)
  172.   def setup(map_id)
  173.     _hn_light__setup_events(map_id)
  174.     refresh_lights()
  175.   end
  176.  
  177.   alias :_hn_light__refresh :refresh unless method_defined?(:_hn_light__refresh)
  178.   def refresh
  179.     _hn_light__refresh()
  180.     refresh_lights()
  181.   end
  182. end
  183.  
  184. class Sprite_Dark < Sprite
  185.   @@base_color = Color.new(255,255,255,HN_Light::DARK_OPACITY)
  186.  
  187.   def initialize(viewport = nil)
  188.     super(viewport)
  189.     @width = 640
  190.     @height = 480
  191.  
  192.     case HN_Light::SIMPLIFY
  193.     when 1
  194.       @zoom = 2
  195.     when 2
  196.       @zoom = 4
  197.     else
  198.       @zoom = 1
  199.     end
  200.     @width /= @zoom
  201.     @height /= @zoom
  202.     self.zoom_x = @zoom.to_f
  203.     self.zoom_y = @zoom.to_f
  204.  
  205.     self.bitmap = Bitmap.new(@width, @height)
  206.     self.bitmap.fill_rect(self.bitmap.rect, @@base_color)
  207.     self.blend_type = 2 # 混合型(减算)
  208.     self.z = 800
  209.     self.visible = false
  210.     @light_cache = {}
  211.   end
  212.  
  213.   # 追加烛光
  214.   def add_light(charactor)
  215.     return if charactor.nil?
  216.     light_type = charactor.light_type
  217.     return if (light_type < 1 or light_type > HN_Light::LIGHTS.size)
  218.     unless @light_cache.key?(light_type)
  219.       @light_cache[light_type] = HN_Light::Light.new(light_type, @zoom)
  220.     end
  221.     light = @light_cache[light_type]
  222.  
  223.     # 画面外什麽都不做
  224.     if @zoom == 1
  225.       return if (charactor.screen_x < 0  - light.width + light.ox)
  226.       return if (charactor.screen_x > @width + light.ox)
  227.       return if (charactor.screen_y < 0 - light.height + light.oy)
  228.       return if (charactor.screen_y > @height + light.oy)
  229.     else
  230.       return if (charactor.screen_x < 0  - (light.width + light.ox) * @zoom)
  231.       return if (charactor.screen_x > (@width + light.ox)  * @zoom)
  232.       return if (charactor.screen_y < 0 - (light.height + light.oy) * @zoom)
  233.       return if (charactor.screen_y > (@height + light.oy) * @zoom)
  234.     end
  235.  
  236.     # 动画判定
  237.     if light.cells > 1
  238.       index = (Graphics.frame_count / 4) % light.cells
  239.       rect = Rect.new(index * light.width , 0, light.width, light.height)
  240.     else
  241.       rect = light.bitmap.rect
  242.     end
  243.     if @zoom != 1
  244.       p_x = charactor.screen_x / @zoom - light.ox
  245.       p_y = (charactor.screen_y - 16) / @zoom - light.oy
  246.     else
  247.       p_x = charactor.screen_x - light.ox
  248.       p_y = charactor.screen_y - 16 - light.oy
  249.     end
  250.  
  251.     # 乗算合成(3)
  252.     self.bitmap.blend_blt(p_x, p_y, light.bitmap, rect, 3)
  253.   end
  254.  
  255.  
  256.   def refresh
  257.     self.bitmap.fill_rect(self.bitmap.rect, @@base_color)
  258.     $game_map.light_events.each do |event|
  259.       next if HN_Light::LIGHTS[event.light_type - 1].nil?
  260.       add_light(event)
  261.     end
  262.     add_light($game_player)
  263.   end
  264.  
  265.   # 更新
  266.   def update
  267.     super
  268.     refresh()
  269.   end
  270.  
  271.   #--------------------------------------------------------------------------
  272.   # ● 解放
  273.   #--------------------------------------------------------------------------
  274.   def dispose
  275.     self.bitmap.dispose
  276.     @light_cache.values.each do |light|
  277.       light.dispose
  278.     end
  279.     super
  280.   end
  281. end
  282.  
  283.  
  284. class Spriteset_Map  
  285.   # 动画判定
  286.   def create_dark
  287.     @dark_sprite = Sprite_Dark.new(@viewport1)
  288.   end
  289.  
  290.   # 更新黑暗Sprite
  291.   def update_dark
  292.     if (@dark_sprite.visible = $game_switches[HN_Light::DARK_SWITCH])
  293.       @dark_sprite.update
  294.     end
  295.   end
  296.  
  297.   # 破弃黑暗Sprite
  298.   def dispose_dark
  299.     @dark_sprite.dispose
  300.   end
  301.  
  302.   # 初期化
  303.   alias :_dark__initialize :initialize unless private_method_defined?(:_dark__initialize)
  304.   def initialize
  305.     _dark__initialize()
  306.     create_dark()
  307.     update_dark()
  308.   end
  309.  
  310.   # 更新
  311.   alias :_dark__update :update unless method_defined?(:_dark__update)
  312.   def update
  313.     _dark__update()
  314.     update_dark() if !@dark_sprite.nil? and !@dark_sprite.disposed?
  315.   end
  316.  
  317.   # 结束处理
  318.   alias :_dark__dispose :dispose unless method_defined?(:_dark__dispose)
  319.   def dispose
  320.     dispose_dark()
  321.     _dark__dispose()
  322.   end
  323. end



阴影精灵

RUBY 代码复制
  1. #使用方法:不透明的物体在光源旁边会产生一个阴影。
  2.  
  3. #所以,在光源的事件里面(例如火),请在第一页加上一个注释“s”(请不要带引号)
  4.  
  5. #然后将此脚本命名为“人物阴影”插入到main上方即可。
  6.  
  7.  
  8. #==============================================================================
  9.  
  10. # ■ 阴影精灵 (渐变精灵 )
  11.  
  12. # 以 Genzai Kawakami的阴影脚本为基础,
  13. #  Rataime为其重写和更新,
  14. #  Boushy 为其添加附属功能
  15.  
  16. #  精灵使者汉化
  17.  
  18. #==============================================================================
  19.  
  20.  
  21. CATERPILLAR_COMPATIBLE = true
  22.  
  23.  
  24. class Game_Party
  25.  
  26. attr_reader :characters
  27.  
  28. end
  29.  
  30.  
  31. class Sprite_Shadow < RPG::Sprite
  32.  
  33.  
  34. attr_accessor :character
  35.  
  36.  
  37. def initialize(viewport, character = nil,source = nil,anglemin=0,anglemax=0,distancemax=0)
  38.  
  39.    super(viewport)
  40.  
  41.    @anglemin=anglemin.to_f
  42.  
  43.    @anglemax=anglemax.to_f
  44.  
  45.    @distancemax=distancemax.to_f
  46.  
  47.    @character = character
  48.  
  49.    @source = source
  50.  
  51.    update
  52.  
  53. end
  54.  
  55.  
  56. def update
  57.  
  58.    super
  59.  
  60.  
  61.    if (@tile_id != @character.tile_id or
  62.  
  63.       @character_name != @character.character_name or
  64.  
  65.       @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)
  66.  
  67.      @tile_id = @character.tile_id
  68.  
  69.      @character_name = @character.character_name
  70.  
  71.      @character_hue = @character.character_hue
  72.      if   @character_name.include?("AC") and  not   @character_name.include?("=4")
  73.             if @character.direction == 4
  74.       self.mirror = false
  75.     else
  76.        self.mirror = true
  77.      end
  78.      else
  79.             if @character.direction == 4
  80.       self.mirror = true
  81.     else
  82.        self.mirror = false
  83.      end
  84.      end
  85.      if @tile_id >= 384
  86.  
  87.        self.bitmap = RPG::Cache.tile($game_map.tileset_name,
  88.  
  89.          @tile_id, @character.character_hue)
  90.  
  91.        self.src_rect.set(0, 0, 32, 32)
  92.  
  93.        self.ox = 16
  94.  
  95.        self.oy = 32
  96.  
  97.      else
  98.  
  99.        self.bitmap = RPG::Cache.character(@character.character_name,
  100.  
  101.          @character.character_hue)
  102.  
  103.        @cw = bitmap.width / 4
  104.  
  105.        @cw = bitmap.width / 4
  106.     if not   @character_name.include?("=4")
  107.        @ch = bitmap.height / 4
  108.      else
  109.        @ch = bitmap.height / 4
  110.        end
  111.  
  112.  
  113.        self.ox = @cw / 2
  114.  
  115.        self.oy = @ch
  116.  
  117.      end
  118.  
  119.    end
  120.  
  121.    self.visible = (not @character.transparent)
  122.  
  123.     if @tile_id == 0
  124.       # 设置传送目标的矩形
  125.     if not   @character_name.include?("=4")
  126.       if @character.pattern >= 4
  127.       sx = (@character.pattern - 4) * @cw
  128.         else
  129.       sx = @character.pattern * @cw
  130.     end
  131.       if @character.pattern >= 4
  132.         sy = (4 - 2) / 2 * @ch  
  133.        else
  134.       sy = (2 - 2) / 2 * @ch
  135.       end
  136.       self.src_rect.set(sx, sy, @cw, @ch)
  137.     else
  138.             sx = @character.pattern * @cw
  139.       sy = (@character.direction - 2) / 2 * @ch
  140.       self.src_rect.set(sx, sy, @cw, @ch)
  141.       end
  142.     end
  143.  
  144.    self.x = @character.screen_x
  145.  
  146.    self.y = @character.screen_y-5
  147.  
  148.    self.z = @character.screen_z(@ch)-1
  149.  
  150.    self.opacity = @character.opacity
  151.  
  152.    self.blend_type = @character.blend_type
  153.  
  154.    self.bush_depth = @character.bush_depth
  155.  
  156.    #if @character.animation_id != 0
  157.  
  158.      #animation = $data_animations[@character.animation_id]
  159.  
  160.     # animation(animation, true)
  161.  
  162.     # @character.animation_id = 0
  163.  
  164.    #end
  165.  
  166.    @deltax=@source.x-self.x
  167.  
  168.    @deltay= @source.y-self.y
  169.  
  170.    self.angle = 57.3*Math.atan2(@deltax, @deltay )
  171.  
  172.    @angle_trigo=self.angle+90
  173.  
  174.    if @angle_trigo<0
  175.  
  176.      @angle_trigo=360+@angle_trigo
  177.  
  178.    end
  179.  
  180.    self.color = Color.new(0, 0, 0)
  181.  
  182.    @distance = ((@deltax ** 2) + (@deltay ** 2))
  183.  
  184.    if$game_map.shadows==-1
  185.  
  186.      self.opacity = 0
  187.    else
  188.  
  189.      self.opacity = 1200000/(@distance+6000)   
  190.    end
  191.  
  192.    if @character.screen_x >= 640 or @character.screen_x <= 0 or @character.screen_y >= 480 or @character.screen_y <= 0
  193.    self.opacity = 0
  194.      end   
  195.  
  196.    @distance = @distance ** 0.5
  197.  
  198.    if @distancemax !=0 and @distance>=@distancemax
  199.  
  200.      self.opacity=0
  201.  
  202.    end
  203.  
  204.    if @anglemin !=0 or @anglemax !=0
  205.  
  206.       if (@angle_trigo<@anglemin or @angle_trigo>@anglemax) and @anglemin<@anglemax
  207.  
  208.         self.opacity=0
  209.  
  210.       end
  211.  
  212.       if (@angle_trigo<@anglemin and @angle_trigo>@anglemax) and @anglemin>@anglemax
  213.  
  214.         self.opacity=0
  215.  
  216.       end     
  217.  
  218.    end
  219.  
  220. end
  221.  
  222. end
  223.  
  224.  
  225. #===================================================
  226.  
  227. # ■ 重定义 Sprite_Character
  228.  
  229. #===================================================
  230.  
  231.  
  232. class Sprite_Character < RPG::Sprite
  233.  
  234. alias shadow_initialize initialize
  235.  
  236.  
  237. def initialize(viewport, character = nil)
  238.  
  239.    @character = character
  240.   # @character = nil
  241.    super(viewport)
  242.  
  243.    @ombrelist=[]
  244.  
  245.    if (character.is_a?(Game_Event) and character.list!=nil and character.list[0].code == 108 and character.list[0].parameters == ["s"])
  246.  
  247.      if (character.list[1]!=nil and character.list[1].code == 108)
  248.  
  249.        @anglemin=character.list[1].parameters[0]
  250.  
  251.      end
  252.  
  253.      if (character.list[2]!=nil and character.list[2].code == 108)
  254.  
  255.        @anglemax=character.list[2].parameters[0]
  256.  
  257.      end
  258.  
  259.      if (character.list[3]!=nil and character.list[3].code == 108)
  260.  
  261.        @distancemax=character.list[3].parameters[0]
  262.  
  263.      end  
  264.  
  265.     for i in $game_map.events.keys.sort
  266.  
  267.      if ($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"]) ) #$game_map.events[i].list!=nil and $game_map.events[i].list[0].code == 108 and $game_map.events[i].list[0].parameters == ["o"])
  268.  
  269.        @ombrelist[i+1] = Sprite_Shadow.new(viewport, $game_map.events[i],self,@anglemin,@anglemax,@distancemax)
  270.  
  271.      end
  272.  
  273.     end
  274.  
  275.     @ombrelist[1] = Sprite_Shadow.new(viewport, $game_player,self,@anglemin,@anglemax,@distancemax)
  276.  
  277. #===================================================
  278.  
  279. # ● 原装人物跟随兼容脚本
  280.  
  281. #===================================================
  282.  
  283. if CATERPILLAR_COMPATIBLE and $game_party.characters!=nil
  284.  
  285.  
  286. for member in $game_party.characters
  287.  
  288.    @ombrelist.push(Sprite_Shadow.new(viewport, member,self,@anglemin,@anglemax,@distancemax))
  289.  
  290. end
  291.  
  292.  
  293. end
  294.  
  295. #===================================================
  296.  
  297. # ● 兼容脚本结束
  298.  
  299. #===================================================
  300.  
  301.    end
  302.  
  303.    shadow_initialize(viewport, @character)
  304.  
  305. end
  306.  
  307.  
  308. alias shadow_update update
  309.  
  310.  
  311. def update
  312.    shadow_update
  313.    if @ombrelist!=[]
  314.  
  315.      for i in [email]1..@ombrelist.size[/email]
  316.   # if @character.x >= 7 # character.x = @x -1
  317.        if @ombrelist[i]!=nil
  318.  
  319.          @ombrelist[i].update
  320.  
  321.        end
  322.   # end
  323.      end
  324.  
  325.    end
  326.  
  327. end  
  328.  
  329.  
  330. end
  331.  
  332.  
  333. #===================================================
  334.  
  335. # ■ 新定义类Scene_Save
  336.  
  337. #===================================================
  338.  
  339. class Scene_Save < Scene_File
  340.  
  341.  
  342. alias shadows_write_save_data write_save_data
  343.  
  344.  
  345. def write_save_data(file)
  346.  
  347.    $game_map.shadows = nil
  348.  
  349.    shadows_write_save_data(file)
  350.  
  351. end
  352.  
  353. end
  354.  
  355.  
  356. #===================================================
  357.  
  358. # ■ 新定义类 Game_Map
  359.  
  360. #===================================================
  361.  
  362. class Game_Map
  363.  
  364. attr_accessor :shadows
  365.  
  366. end



问题:两个脚本都是用注释作为识别的,无法同时起作用,如何解决,要是可以,那就完美了

单独显示烛光和影子是可以的,但不能在烛光周围显示影子....




  
山岚野人,快人快语,礼数不周,还望海涵....
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-9-22 21:14

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表