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

Project1

 找回密码
 注册会员
搜索
12
返回列表 发新帖
楼主: 阿尔卑斯
打印 上一主题 下一主题

[已经解决] 怎么做环条式血条

[复制链接]

Lv4.逐梦者

梦石
0
星屑
6483
在线时间
119 小时
注册时间
2020-1-8
帖子
234
11
发表于 2021-3-11 17:41:25 | 只看该作者
脚本绘制的图……还是用其他软件画出来的好看
横截线无论blt还是sprite.src_rect 动态环形血条 估计都不算卡

脚本是纯脚本绘制环形血条(感谢8楼,没试真不知道,真的不卡)
横截线就是简单 注释的那部分就实现了
  1. class Window_BattleStates < Window_Base
  2.   #--------------------------------------------------------------------------
  3.   # ● 刷新
  4.   #--------------------------------------------------------------------------
  5.   def refresh
  6.     self.contents.clear
  7.     @item_max = $game_party.actors.size
  8.     for i in 0...$game_party.actors.size
  9.       actor = $game_party.actors[i]
  10.       actor_x = i * 160 + 4
  11.       draw_actor_name(actor, actor_x, 0)
  12.       draw_actor_hp(actor, actor_x, 32, 120)
  13.       draw_actor_sp(actor, actor_x, 64, 120)
  14.       
  15.       #参数
  16.       c1, c2 = Color.new(255, 0, 0), Color.new(0, 0, 255)
  17.       out_r, in_r = 50, 40
  18.       cx, cy = actor_x + 70, 64
  19.       #高度版
  20. =begin      
  21.       #hp
  22.       hpy = cy + out_r - 2 * out_r * actor.hp / actor.maxhp
  23.       hpy.upto(cy + out_r) {|y|
  24.         x1 = cx - Math.sqrt(out_r ** 2 - [(y - cy).abs, out_r].min ** 2)
  25.         x2 = cx - Math.sqrt(in_r ** 2 - [(y - cy).abs, in_r].min ** 2)
  26.         self.contents.fill_rect(x1.round, y, (x1 - x2).abs.round, 1, c1)
  27.       }  
  28.       #sp
  29.       spy = cy + out_r - 2 * out_r * actor.sp / actor.maxsp
  30.       spy.upto(cy + out_r) {|y|
  31.         x1 = cx + Math.sqrt(out_r ** 2 - [(y - cy).abs, out_r].min ** 2)
  32.         x2 = cx + Math.sqrt(in_r ** 2 - [(y - cy).abs, in_r].min ** 2)
  33.         w = (x1 - x2).abs.round
  34.         self.contents.fill_rect(x2.round, y, w, 1, c2)
  35.       }
  36. =end      
  37.       #角度版
  38.       #hp
  39.       rad = Math::PI * (270 - actor.hp * 180.0 / actor.maxhp) / 180      
  40.       yy, line_x = nil,{}
  41.       in_r.upto(out_r) {|r|
  42.         x = (cx + r * Math.cos(rad)).round
  43.         y = (cy - r * Math.sin(rad)).round
  44.         if yy != y
  45.           line_x[y] = x
  46.           yy = y
  47.         end
  48.       }
  49.       out_y = (cy - out_r * Math.sin(rad)).round
  50.       in_y = (cy - in_r * Math.sin(rad)).round
  51.       [out_y, in_y].min.upto(cy + out_r) {|y|
  52.         x1 = cx - Math.sqrt(out_r ** 2 - [(y - cy).abs, out_r].min ** 2)
  53.         x2 = cx - Math.sqrt(in_r ** 2 - [(y - cy).abs, in_r].min ** 2)
  54.         if (lx = line_x[y]) != nil
  55.           w = out_y <= in_y ? (x1 - lx).abs : (lx - x2).abs
  56.         else
  57.           w = (x1 - x2).abs
  58.         end  
  59.         sx = out_y <= in_y ? x1.round : x2.round - w  
  60.         self.contents.fill_rect(sx, y, w, 1, c1)
  61.       }
  62.       #sp
  63.       rad = Math::PI * (270 + actor.sp * 180.0 / actor.maxsp) / 180      
  64.       yy, line_x = nil,{}
  65.       in_r.upto(out_r) {|r|
  66.         x = (cx + r * Math.cos(rad)).round
  67.         y = (cy - r * Math.sin(rad)).round
  68.         if yy != y
  69.           line_x[y] = x
  70.           yy = y
  71.         end
  72.       }
  73.       out_y = (cy - out_r * Math.sin(rad)).round
  74.       in_y = (cy - in_r * Math.sin(rad)).round
  75.       [out_y, in_y].min.upto(cy + out_r) {|y|
  76.         x1 = cx + Math.sqrt(out_r ** 2 - [(y - cy).abs, out_r].min ** 2)
  77.         x2 = cx + Math.sqrt(in_r ** 2 - [(y - cy).abs, in_r].min ** 2)
  78.         if (lx = line_x[y]) != nil
  79.           w = out_y <= in_y ? (x1 - lx).abs : (lx - x2).abs
  80.         else
  81.           w = (x1 - x2).abs
  82.         end  
  83.         sx = out_y <= in_y ? x1.round - w : x2
  84.         self.contents.fill_rect(sx, y, w, 1, c2)
  85.       }

  86.       
  87.       if @level_up_flags[i]
  88.         self.contents.font.color = normal_color
  89.         self.contents.draw_text(actor_x, 96, 120, 32, "LEVEL UP!")
  90.       else
  91.         draw_actor_state(actor, actor_x, 96)
  92.       end
  93.     end
  94.   end
  95. end
复制代码

点评

gradient_fill_rect的核心思路就是按1绘制,渐变色根本没难度好吧  发表于 2021-3-12 12:26
理想中的血条起码要渐变色……这才是惨不忍睹的原因,如果再加上动态血条那会更悲催。  发表于 2021-3-11 20:40
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
6483
在线时间
119 小时
注册时间
2020-1-8
帖子
234
12
发表于 2021-3-12 08:33:15 | 只看该作者
重新换种算法,写起来很简单,总的效率差不多,但牺牲了些精度,不太适合渐变色
11楼的方法,逐行描绘,颜色数值与行数建立关系,上下渐变色不要太简单……具体效率没测试不知有多大的影响
  1. class Window_BattleStatus < Window_Base
  2.   #--------------------------------------------------------------------------
  3.   # ● 刷新
  4.   #--------------------------------------------------------------------------
  5.   def refresh
  6.     self.contents.clear
  7.     @item_max = $game_party.actors.size
  8.     for i in 0...$game_party.actors.size
  9.       actor = $game_party.actors[i]
  10.       actor_x = i * 160 + 4
  11.       draw_actor_name(actor, actor_x, 0)
  12.       draw_actor_hp(actor, actor_x, 32, 120)
  13.       draw_actor_sp(actor, actor_x, 64, 120)
  14.       
  15.       #参数
  16.       c1, c2 = Color.new(255, 0, 0), Color.new(0, 0, 255)
  17.       out_r, in_r = 50, 40
  18.       cx, cy = actor_x + 70, 64
  19.       #角度版
  20.       xx, yy = nil, nil
  21.       a1 = (270 - actor.hp * 180.0 / actor.maxhp).to_i
  22.       a2 = (270 + actor.sp * 180.0 / actor.maxsp).to_i
  23.       aa, rr = 1, 3 #2个精度
  24.       a1.step(a2, aa) {|a|
  25.         rad = Math::PI * a / 180
  26.         color = a > 270 ? c2 : c1
  27.         in_r.step(out_r, rr) {|r|
  28.           x = (cx + r * Math.cos(rad)).ceil
  29.           y = (cy - r * Math.sin(rad)).ceil
  30.           next if xx == x && yy == y
  31.           self.contents.fill_rect(x, y, rr, rr, color)
  32.           xx, yy = x, y
  33.         }
  34.       }
  35.          
  36.       if @level_up_flags[i]
  37.         self.contents.font.color = normal_color
  38.         self.contents.draw_text(actor_x, 96, 120, 32, "LEVEL UP!")
  39.       else
  40.         draw_actor_state(actor, actor_x, 96)
  41.       end
  42.     end
  43.   end
  44. end  
复制代码

回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
2373
在线时间
463 小时
注册时间
2012-6-17
帖子
422
13
 楼主| 发表于 2021-3-15 20:38:59 | 只看该作者
RPGzh500223 发表于 2021-3-12 08:33
重新换种算法,写起来很简单,总的效率差不多,但牺牲了些精度,不太适合渐变色
11楼的方法,逐行描绘,颜 ...

非常精彩。这就是乐趣啊!!!

问渠那得清如许为有源头活水来点击这里了解《都市天师》
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-9-20 20:29

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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