Project1

标题: 血槽计算公式求教 [打印本页]

作者: jiushiainilip19    时间: 2016-10-8 17:55
标题: 血槽计算公式求教
如图 血槽采用四张图片来设定

每一张图片只计算角色25%的血量

这个公式应该怎么去计算呢!

就像一些网络游戏一样   血条有好几层一样


RUBY 代码复制
  1. def draw_actor_hp1_bar(actor, x, y,height=60)
  2.  
  3.     bitmap3=Bitmap.new("Graphics/Pictures/xue4")
  4.     w4 = 1.0 * actor.hp / actor.maxhp * height
  5.     src_rect3 = Rect.new(0, 0, 60,w4)
  6.     self.contents.blt(x+300, y, bitmap3, src_rect3)
  7.  
  8.     bitmap2=Bitmap.new("Graphics/Pictures/xue3") # 60  60
  9.     w3 = 1.0 * actor.hp / actor.maxhp * height
  10.     src_rect2 = Rect.new(0, 0, 60,w3)
  11.     self.contents.blt(x+200, y, bitmap2, src_rect2)
  12.  
  13.     bitmap1=Bitmap.new("Graphics/Pictures/xue2")
  14.     w2 = 1.0 * actor.hp / actor.maxhp * height
  15.     src_rect1 = Rect.new(0, 0, 60,w2)
  16.     self.contents.blt(x+100, y, bitmap1, src_rect1)
  17.  
  18.     bitmap=Bitmap.new("Graphics/Pictures/xue1") # 60  60
  19.     w1 = 1.0 * actor.hp / actor.maxhp * height
  20.     src_rect = Rect.new(0, 0, 60,w1)
  21.     self.contents.blt(x, y, bitmap, src_rect)
  22.  
  23.   end

血槽图片.png (39.01 KB, 下载次数: 5)

血槽图片.png

作者: 芯☆淡茹水    时间: 2016-10-9 18:56
随手瞎写的

  1. def draw_actor_hp1_bar(actor, x, y,height=60)
  2.     ar = []
  3.     data = actor.hp
  4.     names = ["xue4","xue3","xue2","xue1"]
  5.     n = actor.maxhp / 4
  6.     4.times do
  7.       nhp = [[n, data].min, 0].max
  8.       data -= nhp
  9.       ar << nhp
  10.     end
  11.     for i in 0..3
  12.       next if i != 3 and ar[i+1] == n
  13.       bitmap = Bitmap.new("Graphics/Pictures/#{names[i]}")
  14.       w = 1.0 * ar[i] / n * height
  15.       src_rect = Rect.new(0, 0, 60, w)
  16.       self.contents.blt(x, y, bitmap, src_rect)
  17.     end
  18.   end
复制代码





欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1