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

Project1

 找回密码
 注册会员
搜索
查看: 2880|回复: 10

[已经过期] 敌人血条

[复制链接]

Lv3.寻梦者

梦石
0
星屑
2150
在线时间
1010 小时
注册时间
2015-10-17
帖子
1283
发表于 2020-4-4 17:01:24 | 显示全部楼层 |阅读模式

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

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

x
本帖最后由 fjm 于 2020-4-4 17:04 编辑

问下如何把图片1的血条位置移动到图片2的位置,再把怪物的名字也显示在上面,例如图片2的效果,知道的指点下,谢谢
RUBY 代码复制
  1. #encoding:utf-8
  2. #==============================================================================
  3. # ■ Sprite_Hp
  4. #------------------------------------------------------------------------------
  5. #  显示血条的精灵。根据 绑定敌人 的状态自动变化。
  6. #==============================================================================
  7. class Sprite_Hp < Sprite
  8.   #--------------------------------------------------------------------------
  9.   # ● 初始化常量
  10.   #--------------------------------------------------------------------------
  11.   H = 36                             #位图 高度
  12.   DUR = 0.5                           #动画 持续时间
  13.   FPS = 60                            #每秒 帧数
  14.   #--------------------------------------------------------------------------
  15.   # ● 初始化对象
  16.   #--------------------------------------------------------------------------
  17.   def initialize( viewport, enemy)
  18.     super(viewport)
  19.     initPara(enemy)
  20.     create_bitmap
  21.     update
  22.   end
  23.   #--------------------------------------------------------------------------
  24.   # ● 初始化参数
  25.   #--------------------------------------------------------------------------
  26.   def initPara(enemy)
  27.     @enemy = enemy                          #绑定敌人
  28.     @colorset = [ MyColor.red, MyColor.green, MyColor.blue, MyColor.purple, MyColor.yellow] #不同管血条的颜色,可以Color.new(r,g,b,a)来设置
  29.     @life = getLife.to_i                    #获取生命数
  30.  
  31.     @tmphp = enemy.hp                       #用于动画的 临时血量
  32.     @perlife = ( @life == 0 ? enemy.hp : enemy.hp/@life)           
  33.                                             #每条命的血量
  34.     @dvalue = 0                             #临时血量差值
  35.     @anima = false                          #动画状态
  36.     setPara(@enemy.enemy.note)
  37.     @nameRect = Rect.new( 0, 0, @length, 18)    #名称矩形
  38.     @bgRect = Rect.new( 0, 18, @length, 18)     #背景矩形
  39.     @hlRect = Rect.new( 4, 20, @length - 16, 8)     #高光矩形
  40.   end
  41.   #--------------------------------------------------------------------------
  42.   # ● 设置参数(通过 注释)
  43.   #--------------------------------------------------------------------------
  44.   def setPara(note)
  45.     @offsetX = (/<OFFSETX\s*(\d+)>/ =~ note ? $1.to_i : 0)
  46.     @offsetY = (/<OFFSETY\s*(\d+)>/ =~ note ? $1.to_i : -20)
  47.     @length = (/<LEN\s*(\d+)>/ =~ note ? $1.to_i : 128)
  48.     #为了绘制高光,建议设置为 8 的倍数
  49.   end
  50.   #--------------------------------------------------------------------------
  51.   # ● 释放
  52.   #--------------------------------------------------------------------------
  53.   def dispose
  54.     self.bitmap.dispose
  55.     super
  56.   end
  57.   #--------------------------------------------------------------------------
  58.   # ● 生成位图
  59.   #--------------------------------------------------------------------------
  60.   def create_bitmap
  61.     self.bitmap = Bitmap.new( @length, H)
  62.     self.bitmap.fill_rect( @bgRect, color2)     #绘制背景矩形
  63.     self.bitmap.font.size = 16
  64.     self.bitmap.font.bold = true
  65.     self.bitmap.font.italic = true
  66.     self.bitmap.font.color.set(255, 255, 255)
  67.   end
  68.   #--------------------------------------------------------------------------
  69.   # ● 底层颜色(始终填充整个矩形)
  70.   #--------------------------------------------------------------------------
  71.   def color1
  72.     if @life == 0
  73.       MyColor.gray
  74.     else
  75.       @colorset[@life % @colorset.size - 1]
  76.     end
  77.   end
  78.   #--------------------------------------------------------------------------
  79.   # ● 血条颜色(变动矩形)
  80.   #--------------------------------------------------------------------------
  81.   def color2
  82.     @colorset[@life % @colorset.size ]
  83.   end
  84.   #--------------------------------------------------------------------------
  85.   # ● 获取生命条数
  86.   #--------------------------------------------------------------------------
  87.   def getLife
  88.     /<LIFE\s*(\d+)>/ =~ @enemy.enemy.note ? $1.to_s : 0
  89.   end
  90.   #--------------------------------------------------------------------------
  91.   # ● 血条长度
  92.   #--------------------------------------------------------------------------
  93.   def flexlen
  94.     if @tmphp % @perlife != 0
  95.       return (@tmphp % @perlife) * @length / @perlife
  96.     end
  97.     if (@tmphp != 0) && (@tmphp % @perlife == 0)
  98.       return @length
  99.     end
  100.   end
  101.   #--------------------------------------------------------------------------
  102.   # ● 更新画面
  103.   #--------------------------------------------------------------------------
  104.   def update
  105.     super
  106.     update_tmphp
  107.     update_life
  108.     update_bitmap
  109.     update_position
  110.     update_visibility
  111.   end
  112.   #--------------------------------------------------------------------------
  113.   # ● 更新临时血量(tmp Hp)
  114.   #--------------------------------------------------------------------------
  115.   def update_tmphp
  116.     if !@anima && (@tmphp != @enemy.hp)
  117.       @dvalue =  @tmphp - @enemy.hp
  118.       @anima = true
  119.       @tmphp = @tmphp - @dvalue/(DUR * FPS)
  120.     elsif @anima && (@tmphp == @enemy.hp)
  121.       @anima = false
  122.     elsif @anima && (@tmphp != @enemy.hp)
  123.       @tmphp = @tmphp - @dvalue/(DUR * FPS)
  124.       @tmphp = @enemy.hp if @tmphp < @enemy.hp
  125.     end
  126.   end
  127.   #--------------------------------------------------------------------------
  128.   # ● 更新命数(life)
  129.   #--------------------------------------------------------------------------
  130.   def update_life
  131.     @life = @life - 1 if @tmphp/@perlife < @life
  132.   end
  133.   #--------------------------------------------------------------------------
  134.   # ● 更新源位图(Source Bitmap)
  135.   #--------------------------------------------------------------------------
  136.   def update_bitmap
  137.     redraw
  138.   end
  139.   #--------------------------------------------------------------------------
  140.   # ● 重绘
  141.   #--------------------------------------------------------------------------
  142.   def redraw
  143.     self.bitmap.clear
  144.  
  145.     self.bitmap.fill_rect( @bgRect, color1)     #绘制背景矩形
  146.     self.bitmap.fill_rect( @bgRect.x, @bgRect.y, flexlen, @bgRect.height, color2) if @tmphp != 0
  147.                                                 #绘制血条矩形
  148.     self.bitmap.draw_border( @bgRect, MyColor.black, 2)
  149.     #绘制边框
  150.     draw_highlight( @hlRect)
  151.     #绘制高光
  152.     self.bitmap.draw_text(self.bitmap.rect, life_text, 2) if @life != 0  
  153.     #绘制生命数(当生命数不为0)
  154.     self.bitmap.draw_text(@bgRect, @tmphp.to_i.to_s, 1)
  155.     #绘制生命值
  156.   end
  157.   #--------------------------------------------------------------------------
  158.   # ● 绘制高光
  159.   #--------------------------------------------------------------------------
  160.   def draw_highlight( dest_rect)
  161.     leftCorner = Rect.new(0,0,8,8)
  162.     middle = Rect.new(8,0,8,8)
  163.     rightCorner = Rect.new(16,0,8,8)
  164.     pic = Cache.picture("hightLight01")
  165.     x = dest_rect.x
  166.     y = dest_rect.y
  167.     i = 1
  168.     self.bitmap.stretch_blt(Rect.new( x, y, 8, 8), pic, leftCorner)
  169.     while x < (dest_rect.x + dest_rect.width - 8)
  170.       x = x + 8
  171.       self.bitmap.stretch_blt(Rect.new( x, y, 8, 8), pic, middle)
  172.     end
  173.     x = x + 8
  174.     self.bitmap.stretch_blt(Rect.new( x, y, 8, 8), pic, rightCorner)
  175.   end
  176.   #--------------------------------------------------------------------------
  177.   # ● 生成绘制内容
  178.   #--------------------------------------------------------------------------
  179.   def life_text
  180.     sprintf("x%2d", @life)
  181.   end
  182.   #--------------------------------------------------------------------------
  183.   # ● 更新位置
  184.   #--------------------------------------------------------------------------
  185.   def update_position
  186.     self.x = @enemy.screen_x - self.bitmap.width/2 + @offsetX
  187.     self.y = @enemy.screen_y + @offsetY
  188.     self.z = 200
  189.   end
  190.   #--------------------------------------------------------------------------
  191.   # ● 更新可视状态
  192.   #--------------------------------------------------------------------------
  193.   def update_visibility
  194.     self.visible = true if @enemy.hp != 0
  195.     self.visible = false if (@enemy.hp == 0) && !@anima
  196.   end
  197. end
  198. #encoding:utf-8
  199. #==============================================================================
  200. # ■ Spriteset_Battle
  201. #------------------------------------------------------------------------------
  202. #  处理战斗画面的精灵的类。本类在 Scene_Battle 类的内部使用。
  203. #==============================================================================
  204. class Spriteset_Battle
  205.   #--------------------------------------------------------------------------
  206.   # ● 初始化对象
  207.   #--------------------------------------------------------------------------
  208.   def initialize
  209.     create_viewports
  210.     create_battleback1
  211.     create_battleback2
  212.     create_enemies
  213.     create_actors
  214.     create_pictures
  215.     create_timer
  216.     create_hp
  217.     update
  218.   end
  219.   #--------------------------------------------------------------------------
  220.   # ● Hp 精灵生成
  221.   #--------------------------------------------------------------------------
  222.   def create_hp
  223.     @hp_sprites = $game_troop.members.reverse.collect do |enemy|
  224.       Sprite_Hp.new(@viewport1, enemy)
  225.     end
  226.   end
  227.   #--------------------------------------------------------------------------
  228.   # ● 更新画面
  229.   #--------------------------------------------------------------------------
  230.   def update
  231.     update_battleback1
  232.     update_battleback2
  233.     update_enemies
  234.     update_actors
  235.     update_pictures
  236.     update_timer
  237.     update_hp
  238.     update_viewports
  239.   end
  240.   #--------------------------------------------------------------------------
  241.   # ● 更新敌人的精灵
  242.   #--------------------------------------------------------------------------
  243.   def update_hp
  244.     @hp_sprites.each {|sprite| sprite.update }
  245.   end
  246. end
  247. #encoding:utf-8
  248. #==============================================================================
  249. # ■ Bitmap_extension
  250. #------------------------------------------------------------------------------
  251. #  Bitmap类的扩展
  252. #==============================================================================
  253. class Bitmap
  254.   #--------------------------------------------------------------------------
  255.   # ● 绘制边框
  256.   #--------------------------------------------------------------------------
  257.   def draw_border( x, y, width, height, color, thick)
  258.     self.fill_rect( x, y, width, thick, color)
  259.     self.fill_rect( x + width - thick, y, thick, height, color)
  260.     self.fill_rect( x, y + height - thick, width, thick, color)
  261.     self.fill_rect( x, y, thick, height, color)
  262.   end
  263.   #--------------------------------------------------------------------------
  264.   # ● 绘制边框 参数为 Rect
  265.   #--------------------------------------------------------------------------
  266.   def draw_border( rect, color, thick)
  267.     self.fill_rect( rect.x, rect.y, rect.width, thick, color)
  268.     self.fill_rect( rect.x + rect.width - thick, rect.y, thick, rect.height, color)
  269.     self.fill_rect( rect.x, rect.y + rect.height - thick, rect.width, thick, color)
  270.     self.fill_rect( rect.x, rect.y, thick, rect.height, color)
  271.   end
  272. end
  273. #encoding:utf-8
  274. #==============================================================================
  275. # ■ Color_extension
  276. #------------------------------------------------------------------------------
  277. #  mColor类,包含常用色
  278. #==============================================================================
  279. class MyColor
  280.   #--------------------------------------------------------------------------
  281.   # ● 常用的颜色
  282.   #--------------------------------------------------------------------------
  283.   def self.black   ; Color.new(   0,   0,   0)   end
  284.   def self.white   ; Color.new( 255, 255, 255)   end
  285.   def self.red     ; Color.new( 255,   0,   0)   end
  286.   def self.green   ; Color.new(   0, 255,   0)   end
  287.   def self.blue    ; Color.new(   0,   0, 255)   end
  288.   def self.gray    ; Color.new( 128, 128, 128)   end
  289.   def self.yellow  ; Color.new( 255, 255,   0)   end
  290.   def self.purple  ; Color.new( 255,   0, 255)   end
  291.   def self.darkRed ; Color.new( 128,   0,   0)   end
  292.   def self.darkGreen;Color.new(   0, 128,   0)   end
  293.   def self.darkBlue; Color.new(   0,   0, 128)   end
  294.   def self.lighRed ; Color.new( 255, 128, 128)   end
  295. end
111111111.png
222222.jpg
头像被屏蔽

Lv4.逐梦者 (禁止发言)

梦石
0
星屑
5701
在线时间
922 小时
注册时间
2013-8-29
帖子
1468
发表于 2020-4-4 17:04:00 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
2150
在线时间
1010 小时
注册时间
2015-10-17
帖子
1283
 楼主| 发表于 2020-4-4 20:26:34 | 显示全部楼层
chanszeman1018 发表于 2020-4-4 17:04
#encoding:utf-8
    #=========================================================================== ...


非常感谢,不过29行报错了

3333.png
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
2150
在线时间
1010 小时
注册时间
2015-10-17
帖子
1283
 楼主| 发表于 2020-4-4 21:55:01 | 显示全部楼层
本帖最后由 fjm 于 2020-4-4 21:57 编辑
chanszeman1018 发表于 2020-4-4 17:04
#encoding:utf-8
    #=========================================================================== ...


再问下,敌人名字字体在哪行改下,斜的名字感觉不好看,改正下,我找了半天也没找到在哪里改
555.png
666.png
回复 支持 反对

使用道具 举报

头像被屏蔽

Lv4.逐梦者 (禁止发言)

梦石
0
星屑
5701
在线时间
922 小时
注册时间
2013-8-29
帖子
1468
发表于 2020-4-4 22:18:26 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-4-19 07:30

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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