查看: 2209|回复: 1

[已经解决] 求帮忙把佣兵界面的战斗图变成动态行走图

[复制链接]
梦石
0
星屑
1748
在线时间
485 小时
注册时间
2006-1-7
回帖
996
发表于 2015-6-4 15:38:09 | 显示全部楼层 |阅读模式

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

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

×
Data.zip (172.23 KB, 下载次数: 76)

我不知道怎么做好
把原来定义的 draw 换成 refresh 就不会更新角色了,做出之后,只有一个人,光标切换到别人身上还是不更新。

求帮忙

@RyanBern

下面是我自己修改的结果

点击展开/收起

  1. module Mercenaries
  2. class Window_Help < ::Window_Base
  3.   def initialize
  4.     super(0, 0, 196, 276)
  5.     self.contents = Bitmap.new(width - 32, height - 32)
  6.     self.contents.font.size = 18
  7.     @actor = nil
  8.     self.z += 10
  9.     @o_count = @count = 0
  10.   end
  11.   def refresh#(actor)#draw_actor(actor)
  12. #    if @actor != actor
  13.       self.contents.clear
  14.       
  15.       bitmap = RPG::Cache.character(@actor.character_name, @actor.character_hue)
  16.       bx = (158 - bitmap.width / 4)/ 2
  17.       by = 96 - bitmap.height / 8
  18.       cw = bitmap.width / 4
  19.       ch = bitmap.height / 4
  20.       src_rect = Rect.new(@o_count*cw, 0, cw, ch)
  21.       self.contents.blt(bx, by, bitmap, src_rect)
  22.       
  23.       self.contents.draw_text(4, 4 + 0, 196, 18, "佣金:" + @actor.price.to_s)
  24.       self.contents.draw_text(4, 4 + 20, 196, 18, "姓名:" + @actor.name)
  25.       self.contents.draw_text(4, 160, 196, 18, "物攻:#{@actor.atk}")
  26.       self.contents.draw_text(4, 180, 196, 18, "物防:#{@actor.pdef}")
  27.       self.contents.draw_text(4, 200, 196, 18, "魔攻:#{@actor.int}")
  28.       self.contents.draw_text(4, 220, 196, 18, "魔防:#{@actor.mdef}")
  29. #      @actor = actor
  30. #    end
  31.   end
  32.   
  33.   def update(actor)
  34.     super
  35.     if @actor != actor
  36.       @actor = actor
  37.     end
  38.     @count += 1
  39.     @count = 0 if @count == 40
  40.     if @o_count != @count / 10
  41.       @o_count = @count / 10
  42.       refresh
  43.     end
  44.   end
  45. end

  46. class Window_ShopCommand < Window_Selectable
  47. #--------------------------------------------------------------------------
  48. # ● 初始化对像
  49. #--------------------------------------------------------------------------
  50.   def initialize
  51.     super(80, 90 - 64, 480, 64)
  52.     self.contents = Bitmap.new(width - 32, height - 32)
  53.     @item_max = 3
  54.     @column_max = 3
  55.     @commands = ["雇佣", "解雇", "取消"]
  56.     refresh
  57.     self.index = 0
  58.   end
  59. #--------------------------------------------------------------------------
  60. # ● 刷新
  61. #--------------------------------------------------------------------------
  62.   def refresh
  63.     self.contents.clear
  64.     for i in 0...@item_max
  65.       draw_item(i)
  66.     end
  67.   end
  68. #--------------------------------------------------------------------------
  69. # ● 描绘项目
  70. # index : 项目编号
  71. #--------------------------------------------------------------------------
  72.   def draw_item(index)
  73.     x = 4 + index * 160
  74.     self.contents.draw_text(x, 0, 128, 32, @commands[index])
  75.   end
  76. end

  77. #--------------------------------------------------------------------------
  78. #--------------------------------------------------------------------------
  79. #--------------------------------------------------------------------------

  80. class Window_Mercenaries < ::Window_Selectable
  81.   attr_reader :column_max
  82.   attr_reader :item_max
  83.   attr_reader :mercenaries
  84.   def initialize(mercenaries)
  85.     super(80, 90, 480, 320)
  86.     @mercenaries = mercenaries
  87.     @column_max = 7
  88.     refresh
  89.     self.index = 0
  90.   end
  91.   def set_mercenaries(mercenaries)
  92.     @mercenaries = mercenaries
  93.     refresh
  94.   end
  95.   def id
  96.     return @mercenaries[self.index]
  97.   end
  98.   def refresh
  99.     if self.contents != nil
  100.       self.contents.dispose
  101.       self.contents = nil
  102.     end
  103.     @item_max = @mercenaries.size
  104.     if @item_max > 0
  105.       self.contents = Bitmap.new(width - 32, row_max * 80)
  106.       for i in 0...@item_max
  107.         draw_actor(i) if @mercenaries[i] != nil#凌冰
  108.       end
  109.     end
  110.   end
  111.   def draw_actor(index)
  112.     x = 4 + (index % @column_max * 64)
  113.     y = 4 + (index / @column_max * 80)
  114.     actor = $game_actors[@mercenaries[index]]
  115.     bitmap = RPG::Cache.character(actor.character_name,actor.character_hue)
  116.     rect = bitmap.rect
  117.     rect.width /= 4
  118.     rect.height /= 4
  119.     self.contents.blt(x, y, bitmap, rect)
  120.     self.contents.font.size = 12
  121.     self.contents.draw_text(x, y + 64 - 8, 64, 16, actor.name)
  122.     self.contents.font.size = 9
  123.     self.contents.draw_text(x + 4, y + 64 - 16, 64, 9, "Lv."+sprintf("%02d", actor.level))
  124.   end
  125. #--------------------------------------------------------------------------
  126. # ● 更新光标举行
  127. #--------------------------------------------------------------------------
  128.   def update_cursor_rect
  129.     # 光标位置不满 0 的情况下
  130.     if @index < 0
  131.       self.cursor_rect.empty
  132.       return
  133.     end
  134.     # 获取当前的行
  135.     row = @index / @column_max
  136.     # 当前行被显示开头行前面的情况下
  137.     if row < self.top_row
  138.       # 从当前行向开头行滚动
  139.       self.top_row = row
  140.     end
  141.     # 当前行被显示末尾行之后的情况下
  142.     if row > self.top_row + (self.page_row_max - 1)
  143.       # 从当前行向末尾滚动
  144.       self.top_row = row - (self.page_row_max - 1)
  145.     end
  146.     # 计算光标的宽
  147.     cursor_width = self.width / @column_max - 32
  148.     # 计算光标坐标
  149.     x = @index % @column_max * 64
  150.     y = @index / @column_max * 80 - self.oy
  151.     # 更新国标矩形
  152.     self.cursor_rect.set(x, y, 64, 80)
  153.   end
  154. end


  155. #--------------------------------------------------------------------------
  156. #--------------------------------------------------------------------------
  157. #--------------------------------------------------------------------------
  158. class Scene_Mercenaries
  159.   def initialize(mercenaries)
  160.     @mercenaries = mercenaries
  161.     for actor in $game_party.actors
  162.       if @mercenaries.include?(actor.id)
  163.         @mercenaries.delete(actor.id)
  164.       end
  165.     end
  166.     @windows = []
  167.     @temp = @mercenaries.dup
  168.     @type = -1
  169.   end
  170.   
  171.   def main_start
  172.     make_window
  173.     @spriteset = Spriteset_Map.new
  174.   end
  175.   
  176.   def main_loop
  177.     while $scene == self
  178.       rm_update
  179.       input_update
  180.       update_window
  181.     end
  182.   end
  183.   def main_end
  184.     dispose_window
  185.     @spriteset.dispose
  186.   end
  187.   def main
  188.     main_start
  189.     Graphics.transition
  190.     main_loop
  191.     Graphics.freeze
  192.     main_end
  193.   end
  194.   def make_window
  195.     @window_shopcommand = Window_ShopCommand.new
  196.     @window_help = Window_Help.new
  197.     @window_mercenaries = Window_Mercenaries.new(@mercenaries)
  198.     @window_mercenaries.active = false
  199.     @window_mercenaries.index = -1
  200.     wx = (@window_mercenaries.index % @window_mercenaries.column_max * 64)
  201.     wy = (@window_mercenaries.index / @window_mercenaries.column_max * 80)
  202.     @window_help.x = wx + @window_mercenaries.x + 64
  203.     @window_help.y = wy + @window_mercenaries.y + 80
  204.     @window_gold = Window_Gold.new
  205.     @window_gold.x = 640 - @window_gold.width - 32
  206.     @window_gold.y = 480 - @window_gold.height - 32
  207.     @windows << @window_gold << @window_shopcommand << @window_mercenaries << @window_help
  208.     @window_help.visible = false
  209.   end
  210.   def update_window
  211.     @windows.each{ |window|window.update }
  212.     help_update
  213.   end
  214.   def dispose_window
  215.     @windows.each{ |window|window.dispose }
  216.   end
  217.   def help_update
  218.     if @window_mercenaries.active and @window_mercenaries.id != nil#凌冰
  219.       @window_help.visible = true
  220.       wx = (@window_mercenaries.index % @window_mercenaries.column_max * 64)
  221.       wy = (@window_mercenaries.index / @window_mercenaries.column_max * 80)
  222.       @window_help.x = wx + @window_mercenaries.x + 64 #动态调整介绍窗口的坐标
  223.       @window_help.y = wy + @window_mercenaries.y + 80
  224.       if @window_help.x + @window_help.width > 640
  225.         @window_help.x = 640 - @window_help.width
  226.       end
  227.       if @window_help.y + @window_help.height > 480
  228.         @window_help.y = 480 - @window_help.height
  229.       end
  230.       @window_help.update($game_actors[@window_mercenaries.id]) #byakki
  231.     else
  232.       @window_help.visible = false
  233.     end
  234.   end
  235.   def input_update
  236.     if Input.trigger?(Input::B)
  237.       @type = -1
  238.       @window_shopcommand.active = true
  239.       @window_mercenaries.active = false
  240.       @window_mercenaries.index = -1
  241.       return
  242.     end
  243.     if Input.trigger?(Input::C)
  244.       if @window_shopcommand.active
  245.         case @window_shopcommand.index
  246.         when 0
  247.           @window_mercenaries.set_mercenaries(@temp)
  248.           @type = 0
  249.           @window_shopcommand.active = false
  250.           @window_mercenaries.active = true
  251.           @window_mercenaries.index = 0
  252.           return
  253.           when 1
  254.             actors = []
  255.             for actor in $game_party.actors
  256.               actors << actor.id and actors -= [1]
  257.             end
  258.             @window_mercenaries.set_mercenaries(actors)
  259.             @type = 1
  260.             @window_shopcommand.active = false
  261.             @window_mercenaries.active = true
  262.             @window_mercenaries.index = 0
  263.             return
  264.           when 2
  265.             $scene = Scene_Map.new
  266.             return
  267.           end
  268.         end
  269.         case @type
  270.         when 0
  271.           if @window_mercenaries.id != nil and $game_party.gold >= $game_actors[@window_mercenaries.id].price
  272.             if $game_party.actors.size < 4
  273.               $game_party.lose_gold($game_actors[@window_mercenaries.id].price)
  274.               $game_party.add_actor(@window_mercenaries.id)
  275.               @window_mercenaries.mercenaries.delete(@window_mercenaries.id)
  276.               @window_mercenaries.refresh
  277.               if @window_mercenaries.index > @window_mercenaries.mercenaries.size-1
  278.                 @window_mercenaries.index = @window_mercenaries.mercenaries.size-1
  279.               end
  280.             end
  281.           end
  282.         when 1
  283.           if @window_mercenaries.id != nil and $game_party.gain_gold($game_actors[@window_mercenaries.id].price / 2)
  284.             $game_party.remove_actor(@window_mercenaries.id)
  285.             @temp << @window_mercenaries.id
  286.             @window_mercenaries.mercenaries.delete(@window_mercenaries.id)
  287.             @window_mercenaries.refresh
  288.             if @window_mercenaries.index > @window_mercenaries.mercenaries.size-1
  289.               @window_mercenaries.index = @window_mercenaries.mercenaries.size-1
  290.             end
  291.           end
  292.         end
  293.         @window_gold.refresh
  294.       end
  295.     end
  296.     def rm_update
  297.       Graphics.update
  298.       Input.update
  299.     end
  300.   end
  301. end
  302. ############################################################
  303. class Game_Actor
  304.   def price
  305.     price = @name.split(/,/)[1].nil? ? 0 : @name.split(/,/)[1].to_i
  306.     return price * self.level
  307.   end
  308.   def name
  309.     return @name.split(/,/)[0]
  310.   end
  311. end
  312.    
  313. class Game_System
  314.   attr_reader :mercenaries
  315.   alias old_initialize initialize
  316.   def initialize
  317.     old_initialize
  318.     @mercenaries = {}
  319.   end
  320. end
复制代码

评分

参与人数 1星屑 +35 收起 理由
RyanBern + 35 手动认可奖励

查看全部评分

初从文,三年不中;后习武,校场发一矢,中鼓吏,逐之出;遂学医,有所成。自撰一良方,服之,卒。
梦石
0
星屑
34511
在线时间
5096 小时
注册时间
2012-11-19
回帖
4715

开拓者

发表于 2015-6-4 22:46:16 | 显示全部楼层
一个简单的只是显示队伍角色行走图动态的窗口
  1. class Window_Actor_Act < Sprite
  2.   #--------------------------------------------------------------------------
  3.   def initialize
  4.     super()
  5.     self.bitmap = Bitmap.new(640, 480)
  6.     @count = 0
  7.   end
  8.   #--------------------------------------------------------------------------
  9.   def dispose
  10.     self.bitmap.dispose
  11.     super
  12.   end
  13.   #--------------------------------------------------------------------------
  14.   def refresh
  15.     self.bitmap.clear
  16.     x = 320 - (100 * $game_party.actors.size / 2)
  17.     y = 140
  18.     for i in 0...$game_party.actors.size
  19.       ax = i * 100 + x
  20.       actor = $game_party.actors[i]
  21.       bitmap = RPG::Cache.character(actor.character_name, actor.character_hue)
  22.       cw = bitmap.width / 4 ; ch = bitmap.height / 4
  23.       self.bitmap.blt(ax, y, bitmap, Rect.new(@count / 10 * cw, 0, cw, ch))
  24.     end
  25.   end
  26.   #--------------------------------------------------------------------------
  27.   def update
  28.     super
  29.     @count = (@count + 1) % 40
  30.     if @data_count != (@count / 10)
  31.       @data_count = (@count / 10)
  32.       refresh
  33.     end
  34.   end
  35. end
复制代码

点评

瞬间我就开窍了。以前是在draw的位置(actor),的。现在在初始化的时候就(actor),然后就都明白了。不管怎样,多谢了~!  发表于 2015-6-6 19:15
我从未试过~~~我还是先去试一下吧。  发表于 2015-6-5 20:50
多谢芯。不过让它动起来我还是会的。只是这个佣兵的信息窗口是跟其他的东西关联的。一关联我就不明白了。  发表于 2015-6-5 20:48

评分

参与人数 1星屑 +200 收起 理由
RyanBern + 200 认可答案

查看全部评分

xp vx va mv  va mz 各类型脚本/插件定制
回复

使用道具 举报

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

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部