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

Project1

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

[已经解决] 求影子系统

 关闭 [复制链接]

Lv3.寻梦者

梦石
3
星屑
50
在线时间
762 小时
注册时间
2010-8-17
帖子
681
跳转到指定楼层
1
发表于 2011-8-18 10:25:05 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 嚴子 于 2011-8-22 10:09 编辑

算起来已经是第三次发这样的帖子了,前两次都没有得到想要的脚本。要求是只需一个脚本,不要再搞注释什么的,就可以在每个角色及NPC下方加上一个与原人物形状相同的影子。求教。阿门。

点评

弄注释很麻烦么  发表于 2011-8-18 11:22

Lv2.观梦者

梦石
0
星屑
365
在线时间
142 小时
注册时间
2008-11-20
帖子
231
2
发表于 2011-8-18 13:42:44 | 只看该作者
最简单的做法是在美工上下功夫,比脚本来得实在

点评

不怕你笑,鄙人对美工实在一窍不通,还是求脚本吧。  发表于 2011-8-18 14:43
  
【RPGXP视频教学】脚本不是高手的专利 (正在更新...)
http://rpg.blue/thread-238457-1-1.html



回复

使用道具 举报

Lv2.观梦者

梦石
0
星屑
280
在线时间
1374 小时
注册时间
2005-10-16
帖子
5113

贵宾

3
发表于 2011-8-18 16:40:51 | 只看该作者
想用脚本就得学会如何用,人家脚本的使用方法就是通过注释来调用的,你还嫌麻烦……

点评

赞  发表于 2011-8-18 17:24
我只个搬答案的
叔叔我已经当爹了~
婚后闪人了……
回复

使用道具 举报

Lv2.观梦者

梦石
0
星屑
365
在线时间
142 小时
注册时间
2008-11-20
帖子
231
4
发表于 2011-8-19 10:49:39 | 只看该作者
个人建议在每个角色的脚下加一个半透明的黑圈,也不麻烦,效果也还可以,特别是你对脚本认知不好,这是最简单有效的办法了
  
【RPGXP视频教学】脚本不是高手的专利 (正在更新...)
http://rpg.blue/thread-238457-1-1.html



回复

使用道具 举报

Lv2.观梦者

虚構歪曲

梦石
0
星屑
364
在线时间
1198 小时
注册时间
2010-12-18
帖子
3928

贵宾

5
发表于 2011-8-19 12:22:17 | 只看该作者
不加注释你的意思是房子里面的人也有影子?
晚上的时候也有影子?
……
而且如果给空事件也建立精灵会浪费效率……
回复

使用道具 举报

Lv3.寻梦者

梦石
3
星屑
50
在线时间
762 小时
注册时间
2010-8-17
帖子
681
6
 楼主| 发表于 2011-8-19 16:07:38 | 只看该作者
说白了我就是想要《仙剑时空传二》里的影子系统,那里面怎么没有注释呢?
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
212
在线时间
292 小时
注册时间
2009-1-1
帖子
97
7
发表于 2011-8-20 00:22:48 | 只看该作者
本帖最后由 as8987000 于 2011-8-20 01:14 编辑

设置一个光源事件注视为:s  (其实很简单你创建个事件里面有个注释输入注释:s   ,想要有影子的事件注视:o 就可以了)ps:影子沿着光源呈散射状............

下面是脚本:
  1. #==============================================================================
  2. # ** Dynamic Shadows
  3. #------------------------------------------------------------------------------
  4. # Rataime
  5. # Version 4.0
  6. # 06/05/2007 (2007-05-06)
  7. # Version 1.0 was based on Genzai Kawakami's shadows, extra features Boushy
  8. #==============================================================================

  9. #==============================================================================
  10. # Here's the brand new free configuration feature
  11. # The comments will be compared to the pattern using Regexp, except that I did
  12. # the entire work for you, so you don't have to know regexps at all.
  13. # Just choose the trigger ('s', 'begin shadow' or whatever), and the pattern
  14. # The pattern can be one line or a list to use multiple comment lines.
  15. # arg1 is the minimum angle
  16. # arg2 is the maximum angle
  17. # arg3 is the maximum distance
  18. # The only thing you must do is using 'trigger' before the arguments
  19. # Examples :
  20. #
  21. # SHADOWS_SOURCE_COMMENT_TRIGGER = 's'
  22. # SHADOWS_SOURCE_COMMENT_PATTERN = ['trigger','arg1','arg2','arg3']
  23. # SHADOWS_CHAR_COMMENT_TRIGGER = 'o'
  24. # SHADOWS_CHAR_COMMENT_PATTERN = 'trigger'
  25. # is the old way to use shadows, with a single 's' in the first line, and the
  26. # arguments in following lines
  27. #
  28. # SHADOWS_SOURCE_COMMENT_TRIGGER = 'begin shadow source'
  29. # SHADOWS_SOURCE_COMMENT_PATTERN =
  30. # ['trigger','anglemin arg1','anglemax arg2','distancemax arg3']
  31. # SHADOWS_CHAR_COMMENT_TRIGGER = 'begin shadow'
  32. # SHADOWS_CHAR_COMMENT_PATTERN = 'trigger'
  33. # will work with :
  34. # Comment "begin shadow source"
  35. # Comment "anglemin 0"
  36. # Comment "anglemax 0"
  37. # Comment "distancemax 250"
  38. #
  39. # Take the time to choose something you like, and something compatible with other
  40. # scripts.
  41. # Note that the comments will be detected even if they aren't in the beginning
  42. # of the event's action list. Ah, and you can switch the arguments if you like
  43. #==============================================================================

  44. #==============================================================================
  45. # Here is the method I like best, because of its compatibility with other
  46. # scripts. But don't hesitate to change it.
  47. # It will react to something like Shadow|0|0|250
  48. #==============================================================================

  49. SHADOWS_SOURCE_COMMENT_TRIGGER = 's'
  50. SHADOWS_SOURCE_COMMENT_PATTERN = 'trigger|arg1|arg2|arg3'
  51. SHADOWS_CHAR_COMMENT_TRIGGER = 'o'
  52. SHADOWS_CHAR_COMMENT_PATTERN = 'trigger'

  53. #==============================================================================
  54. # An important option : if you set it to true, the shadows will get longer if
  55. # you are far from the source. Nice, but induces lag : it will eat your CPU,
  56. # and quite possibly your first born if you try that on a big map.
  57. #==============================================================================

  58. SHADOW_GETS_LONGER = true

  59. #==============================================================================
  60. # Misc options
  61. # If an event has its opacity below SHADOWS_OPACITY_THRESHOLD, no shadow will
  62. # be displayed.
  63. # Set SHADOWS_CATERPILLAR_COMPATIBLE to true if you uses the caterpillar script
  64. #==============================================================================

  65. SHADOWS_OPACITY_THRESHOLD = 254
  66. SHADOWS_CATERPILLAR_COMPATIBLE = true

  67. #==============================================================================
  68. # You probably won't need to touch this : it's the 'map' of how to display the
  69. # shadow depending on the event's direction and his relative position to the
  70. # source. a minus means the shadow is mirrored. It seems complex, and it is.
  71. # Complain to Enterbrain (why didn't they use something clockwise or counter-
  72. # clockwise ? I suspect it's because of the rm2k legacy. More explanations
  73. # below.
  74. #==============================================================================

  75. SHADOWS_DIRECTION_ARRAY = Array.new
  76. SHADOWS_DIRECTION_ARRAY[2] = [ -3, 4, -2, 1 ]
  77. SHADOWS_DIRECTION_ARRAY[4] = [ 4, -2, 1, -3 ]
  78. SHADOWS_DIRECTION_ARRAY[6] = [ 1, -3, 4, -2 ]
  79. SHADOWS_DIRECTION_ARRAY[8] = [ -2, 1, -3, 4 ]


  80. #==============================================================================
  81. # ** Game_Party, for compatibility with the caterpillar script.
  82. #==============================================================================

  83. class Game_Party
  84.   attr_reader :characters
  85. end

  86. #==============================================================================
  87. # ** Sprite_Shadow, the meat of this script
  88. #==============================================================================

  89. class Sprite_Shadow < RPG::Sprite

  90.   attr_accessor :character
  91.   
  92.   #--------------------------------------------------------------------------
  93.   # * Initialize
  94.   #--------------------------------------------------------------------------
  95.   def initialize(viewport, character = nil,source = nil,anglemin=0, \
  96.                  anglemax=0,distancemax=700)
  97.     super(viewport)
  98.     @anglemin=anglemin.to_f
  99.     @anglemax=anglemax.to_f
  100.     @distancemax=distancemax.to_f
  101.     @character = character
  102.     @source = source
  103.     self.color = Color.new(0, 0, 0)
  104.     update
  105.   end
  106.   
  107.   #--------------------------------------------------------------------------
  108.   # * Update
  109.   #--------------------------------------------------------------------------
  110.   def update
  111.     if @character.transparent or @character.opacity <= SHADOWS_OPACITY_THRESHOLD
  112.       self.visible = false
  113.       return
  114.     end
  115.     @deltax=(@[email protected]_x)/4
  116.     @deltay= (@[email protected]_y)/4
  117.     @distance = (((@deltax ** 2) + (@deltay ** 2))** 0.5)
  118.     if @distancemax !=0 and @distance>@distancemax
  119.       self.visible = false
  120.       return
  121.     end
  122.     self.angle = 57.3*Math.atan2(@deltax, @deltay )
  123.     @angle_trigo= (self.angle+90) % 360
  124.     if @anglemin !=0 or @anglemax !=0
  125.       if (@angle_trigo<@anglemin or @angle_trigo>@anglemax) and \
  126.           @anglemin<@anglemax
  127.         self.visible = false
  128.         return
  129.       elsif (@angle_trigo<@anglemin and @angle_trigo>@anglemax) and \
  130.              @anglemin>@anglemax
  131.         self.visible = false
  132.         return
  133.       end     
  134.     end
  135.     super
  136.     if @tile_id != @character.tile_id or
  137.        @character_name != @character.character_name or
  138.        @character_hue != @character.character_hue
  139.        @tile_id = @character.tile_id
  140.       @character_name = @character.character_name
  141.       @character_hue = @character.character_hue
  142.       if @tile_id >= 384
  143.         self.bitmap = RPG::Cache.tile($game_map.tileset_name,
  144.         @tile_id, @character.character_hue)
  145.         self.src_rect.set(0, 0, 32, 32)
  146.         self.ox = 16
  147.         self.oy = 32
  148.       else
  149.         self.bitmap = RPG::Cache.character(@character.character_name,
  150.           @character.character_hue)
  151.         @cw = bitmap.width / 4
  152.         @ch = bitmap.height / 4
  153.         self.ox = @cw / 2
  154.         self.oy = @ch
  155.       end
  156.     end
  157.     self.visible = true
  158.     self.x = @character.screen_x
  159.     self.y = @character.screen_y-8
  160.     self.z = @character.screen_z(@ch)-1
  161.     if @character.animation_id != 0
  162.       animation = $data_animations[@character.animation_id]
  163.       animation(animation, true)
  164.       @character.animation_id = 0
  165.     end
  166.     if @tile_id == 0
  167.       sx = @character.pattern * @cw
  168.       quarter = ((@angle_trigo/90+0.5).floor)%4
  169.       # The quarter is the position of the event relative to the source.
  170.       # Imagine the source is the o point (0,0). Trace the 2 lines
  171.       # y=x and y=-x : you get something like a big X
  172.       # On the right, quarter=0. Up, quarter = 1, and so on
  173.       # Take the @character.direction row (2,4,6,8), and the quarter
  174.       # column (0,1,2,3) (remember, it starts at 0), and you'll get
  175.       # a number between 1 and 4. It correspond to the row of the charset
  176.       # the shadow will be, and mirrored if negative.
  177.       # Yes, it isn't obvious, but I didn't find any simple operation to
  178.       # get those.
  179.       magic = SHADOWS_DIRECTION_ARRAY[@character.direction][quarter]
  180.       magic = -magic
  181.       if magic < 0
  182.         self.mirror = true
  183.         magic = -magic
  184.       else
  185.         self.mirror = false
  186.       end
  187.       sy = (magic-1)*@ch
  188.       self.src_rect.set(sx, sy, @cw, @ch)
  189.     end
  190.     # This is the formula of the opacity in function of the distance
  191.     # ** 2 means square
  192.     self.opacity = 1200/((@distance ** 2)/ 1000 + 6)
  193.     # This is the formula of the size in function of the distance
  194.     # The 0.75 is here so you have a size of 1:1 when next to the source.
  195.     self.zoom_y=0.75 + @distance / 256 if SHADOW_GETS_LONGER
  196.   end
  197.   
  198. end

  199. #======================================================================
  200. # ** Sprite_Character EDIT
  201. #======================================================================
  202. #    All those things could go somewhere else, but they
  203. #    work quite well here.
  204. #======================================================================

  205. class Sprite_Character < RPG::Sprite
  206.   
  207.   @@regexp_source = nil
  208.   @@regexp_source_short = nil
  209.   @@regexp_char = nil
  210.   @@regexp_char_short = nil
  211.   
  212.   alias rataime_shadow_initialize initialize
  213.   
  214.   #--------------------------------------------------------------------------
  215.   # * Initialize
  216.   #--------------------------------------------------------------------------
  217.   def initialize(viewport, character = nil)
  218.    
  219.     if @@regexp_source == nil
  220.       regexp_initialize
  221.     end
  222.     @character = character
  223.     super(viewport)
  224.     @ombrelist=[]
  225.     if (character.is_a?(Game_Event) and character.list!=nil)
  226.       # Let's check the comments in our event list
  227.       for j_list in 0..character.list.size-1
  228.         #p [@@regexp_source_short, character.list[j_list].parameters[0]]
  229.         if (character.list[j_list].code == 108 and \
  230.             @@regexp_source_short.match(character.list[j_list].parameters[0])!= nil)
  231.           # Haha ! We found a trigger tag ! Time to retrieve the parameters !
  232.           parameter_string = character.list[j_list].parameters[0]
  233.           j_list += 1
  234.           while j_list < character.list.size and \
  235.                 (character.list[j_list].code == 108 or \
  236.                  character.list[j_list].code == 408)
  237.             parameter_string = parameter_string + "\n" + \
  238.                                character.list[j_list].parameters[0]
  239.             j_list += 1
  240.           end
  241.           # The following line is a nifty piece of code. Really.
  242.           @anglemin,@anglemax,@distancemax = \
  243.           (regexp_get_parameters(parameter_string, true)+[nil]*3)[0..2]
  244.           # We have our source parameters. Let's find which events we should
  245.           # make have a shadow
  246.           for i in $game_map.events.keys.sort
  247.             if ($game_map.events[i].is_a?(Game_Event) and \
  248.                 $game_map.events[i].list!=nil)
  249.               for i_list in 0..$game_map.events[i].list.size-1  
  250.                 if (($game_map.events[i].list[i_list].code == 108 or \
  251.                      $game_map.events[i].list[i_list].code == 408 )and \
  252.                     @@regexp_char_short.match( \
  253.                       $game_map.events[i].list[i_list].parameters[0])!= nil)
  254.                   @ombrelist[i+1] = Sprite_Shadow.new(viewport, $game_map.events[i],\
  255.                                               self,@anglemin,@anglemax,@distancemax)
  256.                   break # no need to add more than one shadow per source per event
  257.                 end
  258.               end # end for                                
  259.             end                                 
  260.           end # end for
  261.           @ombrelist[1] = Sprite_Shadow.new(viewport, $game_player,self,@anglemin,\
  262.                                              @anglemax,@distancemax)
  263.           #===================================================
  264.           # Compatibility with fukuyama's caterpillar script
  265.           #===================================================
  266.           if SHADOWS_CATERPILLAR_COMPATIBLE and $game_party.characters!=nil
  267.          
  268.             for member in $game_party.characters
  269.               @ombrelist.push(Sprite_Shadow.new(viewport, member,self,@anglemin,\
  270.                                                 @anglemax,@distancemax))
  271.             end
  272.          
  273.           end
  274.           #===================================================
  275.           # End of the compatibility
  276.           #===================================================
  277.         end
  278.         break # We don't need to go further in the source's list
  279.       end # end for
  280.     end
  281.     rataime_shadow_initialize(viewport, @character)
  282.   end
  283.   
  284.   alias rataime_shadow_update update
  285.   #--------------------------------------------------------------------------
  286.   # * Update
  287.   #--------------------------------------------------------------------------
  288.   def update
  289.     rataime_shadow_update
  290.     if @ombrelist!=[]
  291.       for i in [email protected]
  292.         if @ombrelist[i]!=nil
  293.           @ombrelist[i].update
  294.         end
  295.       end
  296.     end
  297.   end  
  298.   
  299.   #--------------------------------------------------------------------------
  300.   # * Real_x : it just returns the character's real_x
  301.   #--------------------------------------------------------------------------
  302.   def real_x
  303.     return @character.real_x
  304.   end
  305.   
  306.   #--------------------------------------------------------------------------
  307.   # * Real_y : it just returns the character's real_y
  308.   #--------------------------------------------------------------------------
  309.   def real_y
  310.     return @character.real_y
  311.   end
  312.   
  313.   #--------------------------------------------------------------------------
  314.   # * regexp_initialize : the brand new configuration function
  315.   #   This function generate the regexps based on the configuration
  316.   #--------------------------------------------------------------------------
  317.   def regexp_initialize
  318.     @@regexp_source = regexp_generate(true)
  319.     @@regexp_char = regexp_generate(false)
  320.     @@regexp_source_short = @@regexp_source
  321.     @@regexp_char_short = @@regexp_char
  322.     if SHADOWS_SOURCE_COMMENT_PATTERN.is_a?(Array)
  323.       @@regexp_source_short = regexp_generate_short(@@regexp_source)
  324.     end
  325.     if SHADOWS_CHAR_COMMENT_PATTERN.is_a?(Array)
  326.       @@regexp_char_short = regexp_generate_short(@@regexp_char)
  327.     end
  328.   end
  329.   #--------------------------------------------------------------------------
  330.   # * regexp_generate generate a full length regexp including the arguments
  331.   #   detection.
  332.   #--------------------------------------------------------------------------
  333.   def regexp_generate(source = false)
  334.     if source
  335.       pattern = SHADOWS_SOURCE_COMMENT_PATTERN
  336.       trigger = SHADOWS_SOURCE_COMMENT_TRIGGER
  337.       @@argument_indexes_source = []
  338.       indexes = @@argument_indexes_source
  339.     else
  340.       pattern = SHADOWS_CHAR_COMMENT_PATTERN
  341.       trigger = SHADOWS_CHAR_COMMENT_TRIGGER
  342.       @@argument_indexes_char = []
  343.       indexes = @@argument_indexes_char
  344.     end
  345.     if pattern.is_a?(Array)
  346.       string = Regexp.escape(pattern.join("\n"))
  347.     else
  348.       string = Regexp.escape(pattern)
  349.     end
  350.     string = string.gsub('trigger',')('+trigger+')(')
  351.     splitted = string.split('arg')
  352.     regexp = '\A(' + splitted[0] + '(\d+)){0,1}'
  353.     for i in 1..splitted.size-1
  354.       if splitted[i][0..0].to_i == 0
  355.         p 'Error : You probably forgot a digit after an arg'
  356.         raise
  357.       else
  358.         indexes.push(splitted[i][0..0].to_i)
  359.         regexp = regexp + '(' + splitted[i][1..splitted[i].size-1] + '(\d+)){0,1}'
  360.       end
  361.     end
  362.     return Regexp.new(regexp.chomp('(\d+)){0,1}') + ')')
  363.   end
  364.   #--------------------------------------------------------------------------
  365.   # * Will return a shorter regexp, but still able to identify the trigger
  366.   #--------------------------------------------------------------------------
  367.   def regexp_generate_short(regexp)
  368.     string = regexp.inspect
  369.     string = string.split('\n')[0]
  370.     string = string[1..string.size-2]
  371.     return Regexp.new(string)
  372.   end
  373.   #--------------------------------------------------------------------------
  374.   # * regexp_get_parameters is called whenever a trigger has been identify,
  375.   #   and the script wants to know the arguments. It returns an array in the
  376.   #   right orger [arg1,arg2,arg3]
  377.   #--------------------------------------------------------------------------
  378.   def regexp_get_parameters(string, source = false)
  379.     if source
  380.       regexp = @@regexp_source
  381.       indexes = @@argument_indexes_source.dup
  382.     else
  383.       regexp = @@regexp_char
  384.       indexes = @@argument_indexes_char.dup
  385.     end
  386.     indexes = indexes.reverse!
  387.     match_array = regexp.match(string).captures
  388.     return_array = Array.new
  389.     if match_array.size > 3
  390.       for i in 2..match_array.size-1
  391.         if ((i.to_f/2).ceil)*2 != i and match_array[i]!=nil
  392.           return_array[indexes.pop-1] = match_array[i]
  393.         end
  394.       end
  395.     end
  396.     return return_array
  397.   end
  398.   
  399. end
复制代码
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
155
在线时间
0 小时
注册时间
2011-8-19
帖子
2
8
发表于 2011-8-20 00:46:24 | 只看该作者
我以为你说的是电脑程序影子系统
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
81 小时
注册时间
2011-8-5
帖子
22
9
发表于 2011-8-21 14:55:22 | 只看该作者
本帖最后由 via1314 于 2011-8-21 14:57 编辑

不知道楼主是否需要的就是这样的效果呢?`
如果是的话`shadow和default文件放入Graphics\Characters里,把脚本插入mian前面即可`

111.jpg (15.18 KB, 下载次数: 10)

111.jpg

脚本及阴影.rar

2.93 KB, 下载次数: 79

(_↘誰芣肻塮募``誰怺遠仩湮瀿澕◆ ‘▕
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
69
在线时间
592 小时
注册时间
2010-10-31
帖子
194

开拓者

10
发表于 2011-8-22 09:38:31 | 只看该作者
如果实在不想要注释,那就在原有的脚本中做点手脚吧,把脚本改成不用注释,任何事件都可以有影子的脚本,或者是有注释的事件没有影子~

好了,我撤~
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

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

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

GMT+8, 2024-11-23 05:38

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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