查看: 2605|回复: 2

[已经解决] 血槽计算公式求教

[复制链接]
梦石
0
星屑
606
在线时间
797 小时
注册时间
2014-7-1
回帖
501

开拓者

发表于 2016-10-8 17:55:15 | 显示全部楼层 |阅读模式

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

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

×
如图 血槽采用四张图片来设定

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

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

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


[pre lang="ruby"]  
def draw_actor_hp1_bar(actor, x, y,height=60)
   
    bitmap3=Bitmap.new("Graphics/Pictures/xue4")
    w4 = 1.0 * actor.hp / actor.maxhp * height
    src_rect3 = Rect.new(0, 0, 60,w4)
    self.contents.blt(x+300, y, bitmap3, src_rect3)
   
    bitmap2=Bitmap.new("Graphics/Pictures/xue3") # 60  60
    w3 = 1.0 * actor.hp / actor.maxhp * height
    src_rect2 = Rect.new(0, 0, 60,w3)
    self.contents.blt(x+200, y, bitmap2, src_rect2)
   
    bitmap1=Bitmap.new("Graphics/Pictures/xue2")
    w2 = 1.0 * actor.hp / actor.maxhp * height
    src_rect1 = Rect.new(0, 0, 60,w2)
    self.contents.blt(x+100, y, bitmap1, src_rect1)
   
    bitmap=Bitmap.new("Graphics/Pictures/xue1") # 60  60
    w1 = 1.0 * actor.hp / actor.maxhp * height
    src_rect = Rect.new(0, 0, 60,w1)
    self.contents.blt(x, y, bitmap, src_rect)
   
  end
[/pre]
血槽图片.png
学习使我疲劳,打工使我疲惫,恋爱使我伤身,吸烟伤我肺腑,饮酒损我形象,旅游使我破费,月底不见铜板,只有在论坛里面看看各种大佬才能使我进去
梦石
0
星屑
34459
在线时间
5096 小时
注册时间
2012-11-19
回帖
4715

开拓者

发表于 2016-10-9 18:56:33 | 显示全部楼层
随手瞎写的

  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
复制代码

点评

谢谢芯大!!!!  发表于 2016-10-10 08:04

评分

参与人数 2星屑 +220 收起 理由
RyanBern + 200 认可答案
jiushiainilip19 + 20 认可答案

查看全部评分

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

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部