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

Project1

 找回密码
 注册会员
搜索
Project1 查看内容

地图上显示伤害

2008-8-8 00:42| 发布者: 御灵| 查看: 6730| 评论: 0|原作者: 非法用户|来自: 点此进入发布帖

摘要: 在事件里输入脚本:get_character(事件编号).damage = 伤害数值get_character(事件编号).critical = trueget_character(事件编号).damage_pop = true事件编号就是地图上的事件编号,0为本事件,-1为角色,其他则为编
在事件里输入脚本:
get_character(事件编号).damage = 伤害数值
get_character(事件编号).critical = true
get_character(事件编号).damage_pop = true

事件编号就是地图上的事件编号,0为本事件,-1为角色,其他则为编号。
伤害数值为负数就是恢复的效果,伤害数值也可以为字符,不一定是数字。
如果不需要CRITICAL的伤害,彩色那行脚本不用写。




class Game_Character
  attr_accessor :damage
  attr_accessor :damage_pop
  attr_accessor :critical
  alias new_initialize initialize
  def initialize
    new_initialize
    @damage = 0
    @damage_pop = false
    @critical = false
  end
end

class Sprite_Character < Sprite_Base
  def initialize(viewport, character = nil)
    super(viewport)
    @character = character
    @balloon_duration = 0
    @_damage_duration = 0
    @damage_x = 0
    @damage_y = 0
    update
  end
  alias new_update update
  def update
    new_update
    update_damage
    if @character.damage_pop == true
      start_damage(@character.damage,@character.critical)
      @character.damage_pop = false
      @character.critical = false
    end
  end
  def start_damage(value, critical)
    dispose_damage
    if value.is_a?(Numeric)
      damage_string = value.abs.to_s
    else
      damage_string = value.to_s
    end
    bitmap = Bitmap.new(160, 48)
    bitmap.font.name = "Arial Black"
    bitmap.font.size = 28
    bitmap.font.color.set(0, 0, 0)
    bitmap.draw_text(-1, 12-1, 160, 36, damage_string, 1)
    bitmap.draw_text(+1, 12-1, 160, 36, damage_string, 1)
    bitmap.draw_text(-1, 12+1, 160, 36, damage_string, 1)
    bitmap.draw_text(+1, 12+1, 160, 36, damage_string, 1)
    if value.is_a?(Numeric) and value < 0
      bitmap.font.color.set(176, 255, 144)
    else
      bitmap.font.color.set(255, 255, 255)
    end
    bitmap.draw_text(0, 12, 160, 36, damage_string, 1)
    if critical
      bitmap.font.size = 20
      bitmap.font.color.set(0, 0, 0)
      bitmap.draw_text(-1, -1, 160, 20, "CRITICAL", 1)
      bitmap.draw_text(+1, -1, 160, 20, "CRITICAL", 1)
      bitmap.draw_text(-1, +1, 160, 20, "CRITICAL", 1)
      bitmap.draw_text(+1, +1, 160, 20, "CRITICAL", 1)
      bitmap.font.color.set(255, 255, 255)
      bitmap.draw_text(0, 0, 160, 20, "CRITICAL", 1)
    end
    @_damage_sprite = ::Sprite.new(self.viewport)
    @_damage_sprite.bitmap = bitmap
    @_damage_sprite.ox = 80
    @_damage_sprite.oy = 20
    @_damage_sprite.x = self.x
    @_damage_sprite.y = self.y - self.oy
    @_damage_sprite.z = 3000
    @_damage_duration = 40
    @damage_x = @character.screen_x
    @damage_y = @character.screen_y
    update_damage
  end
  def update_damage
    if @_damage_duration > 0
      @damage_sprite.x += (@character.screen_x - @damage_x)
      @damage_sprite.y += (@character.screen_y - @damage_y)
      @damage_x = @character.screen_x
      @damage_y = @character.screen_y
      @_damage_duration -= 1
      case @_damage_duration
      when 38..39
        @_damage_sprite.y -= 4
      when 36..37
        @_damage_sprite.y -= 2
      when 34..35
        @_damage_sprite.y += 2
      when 28..33
        @_damage_sprite.y += 4
      end
      @_damage_sprite.opacity = 256 - (12 - @_damage_duration) * 32
      if @_damage_duration == 0
        dispose_damage
      end
    end
  end
  def dispose_damage
    if @_damage_sprite != nil
      @_damage_sprite.bitmap.dispose
      @_damage_sprite.dispose
      @_damage_sprite = nil
      @_damage_duration = 0
    end
  end
end

可能有些人认为XP默认的不好看,想要用图片显示,所以这里也做了准备。
这个是图片版,从伤害显示美化脚本里踢出来的,图片格式也一样,请自行参考。
http://bbs.66rpg.com/web/htm/news216.htm

效果图:


图片素材(注:图片请放入picture的文件夹底下):

class Game_Character
  attr_accessor :damage
  attr_accessor :damage_pop
  attr_accessor :critical
  alias new_initialize initialize
  def initialize
    new_initialize
    @damage = 0
    @damage_pop = false
    @critical = false
  end
end

class Sprite_Character < Sprite_Base
  def initialize(viewport, character = nil)
    super(viewport)
    @character = character
    @balloon_duration = 0
    @_damage_duration = 0
    @damage_x = 0
    @damage_y = 0
    update
  end
  alias new_update update
  def update
    new_update
    update_damage
    if @character.damage_pop == true
      start_damage(@character.damage,@character.critical)
      @character.damage_pop = false
      @character.critical = false
    end
  end
  def start_damage(value, critical)
    dispose_damage
    if value.is_a?(Numeric)
      damage_string = value.abs.to_s
    else
      damage_string = value.to_s
    end
    bitmap = Bitmap.new(162, 64)
    bitmap.font.name = "Arial Black"
    bitmap.font.size = 28
    if value.is_a?(Numeric)
      damage_array = damage_string.scan(/./)
      damage_x = 81 - damage_string.size * 9
      if value < 0
        rect_y = 32
      else
        rect_y = 0
      end
      for char in damage_array
        number = char.to_i
        bitmap.blt(damage_x, 32, Cache.picture("Damage"),
        Rect.new(number * 18, rect_y, 18, 32))
        damage_x += 18
      end
    else
      unless value == "Miss"
        bitmap.font.color.set(0, 0, 0)
        bitmap.draw_text(-1, 27, 162, 36, damage_string, 1)
        bitmap.draw_text(+1, 27, 162, 36, damage_string, 1)
        bitmap.draw_text(-1, 29, 162, 36, damage_string, 1)
        bitmap.draw_text(+1, 29, 162, 36, damage_string, 1)
        bitmap.font.color.set(255, 255, 255)
        bitmap.draw_text(0, 28, 162, 36, damage_string, 1)
      else
        bitmap.blt(36, 28, Cache.picture("Damage"), Rect.new(90, 64, 90, 32))
      end
    end
    if critical
      bitmap.blt(36, 0, Cache.picture("Damage"), Rect.new(0, 64, 90, 32))
    end
    @_damage_sprite = ::Sprite.new(self.viewport)
    @_damage_sprite.bitmap = bitmap
    @_damage_sprite.ox = 81
    @_damage_sprite.oy = 20
    @_damage_sprite.x = self.x
    @_damage_sprite.y = self.y - self.oy * 3 / 2
    @_damage_sprite.z = 3000
    @_damage_duration = 40
    @damage_x = @character.screen_x
    @damage_y = @character.screen_y
    update_damage
  end
  def update_damage
    if @_damage_duration > 0
      @damage_sprite.x += (@character.screen_x - @damage_x)
      @damage_sprite.y += (@character.screen_y - @damage_y)
      @damage_x = @character.screen_x
      @damage_y = @character.screen_y
      @_damage_duration -= 1
      case @_damage_duration
      when 38..39
        @_damage_sprite.y -= 4
      when 36..37
        @_damage_sprite.y -= 2
      when 34..35
        @_damage_sprite.y += 2
      when 28..33
        @_damage_sprite.y += 4
      end
      @_damage_sprite.opacity = 256 - (12 - @_damage_duration) * 32
      if @_damage_duration == 0
        dispose_damage
      end
    end
  end
  def dispose_damage
    if @_damage_sprite != nil
      @_damage_sprite.bitmap.dispose
      @_damage_sprite.dispose
      @_damage_sprite = nil
      @_damage_duration = 0
    end
  end
end

最后,以上内容脚本可以任意转载使用,不过请注明从66RPG转载。
还有,要是有人能够拿去优化更好,毕竟是偷懒的产物。
1

鲜花

刚表态过的朋友 (1 人)

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

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

GMT+8, 2024-11-15 14:05

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

返回顶部