Project1

标题: 关于变量槽得绘制? [打印本页]

作者: 纳尔德    时间: 2012-8-4 08:54
标题: 关于变量槽得绘制?
我想制作一个赋予变量1得变量槽,例如我在脚本先绘制一个矩形,接着,随着变量1得数值改变变量条得宽度。和血槽得绘制方法差不多,但是不懂的怎么计算变量槽得算法。求教大大,事件脚本都可以哦!记得是赋予变量得。dsu_plus_rewardpost_czw
作者: 极地小鸥    时间: 2012-8-4 09:03
本帖最后由 Kimu 于 2012-8-4 10:01 编辑






参照使用方法
  1. # -----------------------------------------------------------------------------
  2. # 值槽脚本随机生成系统(SLOTCR) By.Clov
  3. # 通用版本:RMXP(RGSS1) RMVX(RGSS2) RMVX ACE(RGSS3)
  4. # 使用方法:在全部窗口类插入即可 例:draw_cr(0,0,变量1,变量2,'开心值',100,10)
  5. # 参数说明:x x坐标,y y坐标,current 当前值,max 最大值,txt 显示的文字
  6. # width 值槽的宽,height 值槽的高
  7. # 背景与边框没有随机的必要,请自行到脚本里设置
  8. # -----------------------------------------------------------------------------
  9. class Window_Base
  10.    def draw_cr(x,y,current,max,txt='',width=128,height=15)
  11.     #颜色1、颜色2
  12.     c1=[59, 191, 119];c2=[253, 94, 1]
  13.     #边框色颜色
  14.     bk_color = Color.new(255,255,255,255)
  15.     #数值是否显示
  16.     num = true
  17.     #显示数值的对齐方式 0:向左对齐 1:向中间对齐 2:向右边对齐
  18.     num_align = 1
  19.     #计算比率
  20.     bl = current.to_f / max
  21.     #计算实际宽
  22.     w = (width*bl).round
  23.     #描绘值槽
  24.     r = c1[0];g = c1[1];b = c1[2]
  25.     plus_r = (c2[0]-c1[0])/((width-1)*bl)
  26.     plus_g = (c2[1]-c1[1])/((width-1)*bl)
  27.     plus_b = (c2[2]-c1[2])/((width-1)*bl)
  28.     w.times {|k|
  29.     contents.fill_rect(x+k, y, 1, height, Color.new(r,g,b,255))
  30.     r+=plus_r;g+=plus_g;b+=plus_b}
  31.     contents.fill_rect(x-1, y-1, width+2, 1, bk_color)
  32.     contents.fill_rect(x-1, y+height, width+2, 1, bk_color)
  33.     contents.fill_rect(x-1, y, 1, height, bk_color)
  34.     contents.fill_rect(x+width, y, 1, height, bk_color)
  35.     #描绘文字
  36.     txt_w = contents.text_size(txt).width + 2
  37.     contents.draw_text(x-txt_w,y+height/2-12, width, 24, txt)
  38.     contents.draw_text(x,y+height/2-12, width, 24,
  39.     current.to_s+'/'+max.to_s,num_align) if num
  40.   end
  41. end
复制代码

作者: 945127391    时间: 2012-8-5 00:45
算法么……
大概是:
  1. 变量1/上限*槽宽度
复制代码

作者: 沙漠点灰    时间: 2012-8-5 12:50
本帖最后由 hcm 于 2012-8-10 09:16 编辑
  1. x = 0
  2. y = 0
  3. hgt  = 10   # 高度
  4. max = 100 # 100%时,变量1的值
  5. wid = 100 # 100%时的宽度
  6. tmp = $game_variables[1] # 带入变量1
  7. rect = Rect.new(x,y,(tmp/max.to_f*wid).to_i,hgt) # 生成矩形
复制代码
rect就是你想要的矩形




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