Project1

标题: 如何绘制六边形【已经解决】 [打印本页]

作者: 清远    时间: 2017-5-8 19:46
标题: 如何绘制六边形【已经解决】
本帖最后由 清远 于 2017-5-9 22:52 编辑

ace的能力共6个,刚好组成一个六边形
我记得以前有高手做过在状态栏显示六边形
但是找不到了,不知道哪位高人给指点下

QQ图片20170509125027.png (115.99 KB, 下载次数: 41)

QQ图片20170509125027.png

作者: 魔法丶小肉包    时间: 2017-5-9 00:39
用了个比较笨的方法....肯定是需要修改的....
RUBY 代码复制
  1. def draw_six_status(actor,x,y)
  2.     line_color = Color.new(255,0,0)
  3.     gauge_back_color = Color.new(255,255,255)
  4.     contents.fill_rect(x-50, y-50, 100, 2, gauge_back_color)
  5.     50.times {|i|contents.fill_rect(x-50-i, y-50+i, 2, 1, gauge_back_color)}
  6.     50.times {|i|contents.fill_rect(x-100+i, y+i, 2, 1, gauge_back_color)}
  7.     contents.fill_rect(x-50, y+50, 100, 2, gauge_back_color)
  8.     50.times {|i|contents.fill_rect(x+50+i, y+50-i, 2, 1, gauge_back_color)}
  9.     50.times {|i|contents.fill_rect(x+100-i, y-i, 2, 1, gauge_back_color)}
  10.     actor.atk.times {|i| contents.fill_rect(x+i, y-i, 2, 1, line_color)}
  11.     (actor.def*2).times {|i| contents.fill_rect(x+i, y, 2, 1, line_color)}
  12.     actor.mat.times {|i| contents.fill_rect(x+i, y+i, 2, 1, line_color)}
  13.     actor.mdf.times {|i| contents.fill_rect(x-i, y+i, 2, 1, line_color)}
  14.     (actor.agi*2).times {|i| contents.fill_rect(x-i, y, 2, 1, line_color)}
  15.     actor.luk.times {|i| contents.fill_rect(x-i, y-i, 2, 1, line_color)}
  16.     draw_triangle(x,y,x+actor.atk,y-actor.atk,x+actor.def*2,y)
  17.     draw_triangle(x,y,x+actor.mat,y+actor.mat,x+actor.def*2,y)
  18.     draw_triangle(x-actor.mdf,y+actor.mdf,x,y,x+actor.mat,y+actor.mat)
  19.     draw_triangle(x-actor.agi*2,y,x-actor.mdf,y+actor.mdf,x,y)
  20.     draw_triangle(x-actor.agi*2,y,x-actor.luk,y-actor.luk,x,y)
  21.     draw_triangle(x-actor.luk,y-actor.luk,x+actor.atk,y-actor.atk,x,y)
  22.   end
  23.   def draw_triangle(x1,y1,x2,y2,x3,y3,color=Color.new(255,0,0,255))
  24.   x=0
  25.   k1=(y2-y1)*1.0/(x2-x1)
  26.   k2=(y3-y1)*1.0/(x3-x1)
  27.   k3=(y3-y2)*1.0/(x3-x2)
  28.   height=1
  29.   for x in x1..x2
  30.       y = (x-x1)*k1+y1
  31.       height = (x-x1)*k2+y1-y
  32.       if height < 0
  33.         y+=height
  34.         height = 0 - height
  35.       end
  36.       contents.fill_rect(x, y, 1, height, color)
  37.     end
  38.     for x in x2..x3
  39.       y = (x-x2)*k3+y2
  40.       height = (x-x1)*k2+y1-y
  41.       if height < 0
  42.         y+=height
  43.         height = 0 - height
  44.       end
  45.       contents.fill_rect(x, y, 1, height, color)
  46.     end
  47. end



作者: 清远    时间: 2017-5-9 12:03
魔法丶小肉包 发表于 2017-5-9 00:39
用了个比较笨的方法....肯定是需要修改的....
  def draw_six_status(actor,x,y)
    line_color = Color.n ...


大师,你这个六边形怎么是扁的呀,
能不能做成正六边形。
另外,里面那个图形怎么感觉怪怪的

最好数字能显示在图形的旁边
作者: 清远    时间: 2017-5-9 12:52
魔法丶小肉包 发表于 2017-5-9 00:39
用了个比较笨的方法....肯定是需要修改的....
  def draw_six_status(actor,x,y)
    line_color = Color.n ...

增加了图片
作者: 清远    时间: 2017-5-9 18:41
清远 发表于 2017-5-9 12:52
增加了图片

能有就行了,不敢催大神
作者: 魔法丶小肉包    时间: 2017-5-9 21:39


方法需要楼主自己调用,可自由定义六边形的边长。
方法:
draw_six(actor,a,x,y,c,s)
draw_six_status(actor,x,y,c,s,bl)
注意:上面两个方法调用缺一不可,并且设置的x,y必须相同
draw_six(actor,a,x,y,c,s)参数:
actor:角色
a:边长
x:六边形中心点的x坐标
y:六边形中心点的y坐标
c:六边形的线条颜色
s:六边形线条的直径
draw_six_status(actor,x,y,c,s,bl)参数
actor:角色
x:能力值不规则图形中心点的x坐标
y:能力值不规则图形中心点的y坐标
c:能力值不规则图形的线条颜色
s:能力值不规则图形的线条直径
bl:能力值图形比率(比如10,就是能力值/10来显示,具体效果可自己尝试)
  1. class Bitmap
  2.     def draw_line(x, y, dx, dy, color,size)
  3.        return unless x
  4.        mx = x < dx ? 1 : -1
  5.        my = y < dy ? 1 : -1
  6.        dfx, dfy = (dx - x).abs.to_i, (dy - y).abs.to_i
  7.        diff = [dfx, dfy].max / 2
  8.        if dfx >= dfy
  9.          (dfx + 1).times { |i|
  10.            if size == 1
  11.              self.set_pixel(x, y, color)
  12.            else
  13.              self.fill_rect(x, y, size, size, color)
  14.            end
  15.            x += mx
  16.            diff += dfy
  17.            if diff >= dfx
  18.              diff -= dfx
  19.              y += my
  20.            end
  21.          }
  22.        else
  23.          (dfy + 1).times { |i|
  24.            if size == 1
  25.              self.set_pixel(x, y, color)
  26.            else
  27.              self.fill_rect(x, y, size, size, color)
  28.            end
  29.            y += my
  30.            diff += dfx
  31.            if diff >= dfy
  32.              diff -= dfy
  33.              x += mx
  34.            end
  35.          }
  36.        end
  37.      end
  38. end
  39. class Window_Base < Window
  40.   def draw_six(actor,a,x,y,c,s)
  41.     x1 = Math.sqrt(3)/2.0*a
  42.     x2 = a/2.0
  43.     contents.draw_line(x,y-a,x+x1,y-x2,c,s)
  44.     contents.draw_line(x+x1,y-x2,x+x1,y+x2,c,s)
  45.     contents.draw_line(x+x1,y+x2,x,y+a,c,s)
  46.     contents.draw_line(x,y+a,x-x1,y+x2,c,s)
  47.     contents.draw_line(x-x1,y+x2,x-x1,y-x2,c,s)
  48.     contents.draw_line(x-x1,y-x2,x,y-a,c,s)
  49.     contents.draw_line(x,y-a,x,y+a,c,s)
  50.     contents.draw_line(x+x1,y-x2,x-x1,y+x2,c,s)
  51.     contents.draw_line(x-x1,y-x2,x+x1,y+x2,c,s)
  52.     draw_text(x-30, y-a-30, 180, line_height, "ATK")
  53.     draw_text(x+x1, y-x2, 180, line_height, "DEF")
  54.     draw_text(x+x1, y+x2, 180, line_height, "INT")
  55.     draw_text(x-30, y+a, 180, line_height, "RES")
  56.     draw_text(x-x1-40, y+x2, 180, line_height, "SPD")
  57.     draw_text(x-x1-40, y-x2, 180, line_height, "LUK")
  58.     draw_actor_paramm(actor,x-30, y-a-30, 2)
  59.     draw_actor_paramm(actor,x+x1, y-x2, 3)
  60.     draw_actor_paramm(actor,x+x1, y+x2, 4)
  61.     draw_actor_paramm(actor,x-30, y+a, 5)
  62.     draw_actor_paramm(actor,x-x1-70, y+x2+30, 6)
  63.     draw_actor_paramm(actor,x-x1-70, y-x2+30, 7)
  64.   end
  65.   def draw_six_status(actor,x,y,c,s,bl)
  66.     a = Math.sqrt(3)/2.0
  67.     b = 1.0/2.0
  68.     contents.draw_line(x,y-actor.atk/bl.to_f,x+a*actor.def/bl.to_f,y-b*actor.def/bl.to_f,c,s)
  69.     contents.draw_line(x+a*actor.def/bl.to_f,y-b*actor.def/bl.to_f,x+a*actor.mat/bl.to_f,y+b*actor.mat/bl.to_f,c,s)
  70.     contents.draw_line(x+a*actor.mat/bl.to_f,y+b*actor.mat/bl.to_f,x,y+actor.mdf/bl.to_f,c,s)
  71.     contents.draw_line(x,y+actor.mdf/bl.to_f,x-a*actor.agi/bl.to_f,y+b*actor.agi/bl.to_f,c,s)
  72.     contents.draw_line(x-a*actor.agi/bl.to_f,y+b*actor.agi/bl.to_f,x-a*actor.luk/bl.to_f,y-b*actor.luk/bl.to_f,c,s)
  73.     contents.draw_line(x-a*actor.luk/bl.to_f,y-b*actor.luk/bl.to_f,x,y-actor.atk/bl.to_f,c,s)
  74.   end
  75.   def draw_actor_paramm(actor, x, y, param_id)
  76.     change_color(normal_color)
  77.     draw_text(x+30, y, 36, line_height, actor.param(param_id), 2)
  78.   end
  79. end
复制代码

作者: 清远    时间: 2017-5-9 22:37
魔法丶小肉包 发表于 2017-5-9 21:39
方法需要楼主自己调用,可自由定义六边形的边长。
方法:
draw_six(actor,a,x,y,c,s)

楼主大英雄呀,我去试试看行不行先




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