전투

데미지 출력 스크립트

by 백호 posted Feb 22, 2009
?

단축키

Prev이전 문서

Next다음 문서

ESC닫기

크게 작게 위로 아래로 댓글로 가기 인쇄
#=================================================
# Damage_Display Script
#-------------------------------------------------
# http://rmxp.org
#=================================================

class Damage < Sprite
  def initialize(x, y, dealt_damage = 0, viewport = Viewport.new(0,0,640,480))
    super(viewport)
    @_damage_duration = 0
    self.x = x
    self.y = y
    @damage = dealt_damage
    damage(@damage)
  end
   
  def dispose
    dispose_damage
    super
  end

  def damage(value)
    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 = "굴림"
    bitmap.font.size = 20
    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)
    @_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 / 2
    @_damage_sprite.z = 9000
    @_damage_duration = 40
  end

  def dispose_damage
    if @_damage_sprite != nil
      @_damage_sprite.bitmap.dispose
      @_damage_sprite.dispose
      @_damage_sprite = nil
      @_damage_duration = 0
    end
  end

  def update
    super
    if @_damage_duration > 0
      @_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
      end
    end
  end
end
###################################################
class Scene_Map
  alias trickster_update update
  def update
    if $damage != nil
      if $damage.disposed?
        $damage = nil
      else
        $damage.update
      end
    end
    trickster_update
  end
end
###################################################
class Interpreter
  def command_338
    # Get operate value
    value = operate_value(0, @parameters[2], @parameters[3])
    # Process with iterator
    iterate_battler(@parameters[0], @parameters[1]) do |battler|
      # If battler exists
      if battler.exist?
        # Change HP
        battler.hp -= value
        # If in battle
        if $game_temp.in_battle
          # Set damage
          battler.damage = value
          battler.damage_pop = true
        else
          if battler.is_a?(Game_Actor)
            x = $game_player.screen_x
            y = $game_player.screen_y
          else
            x = battler.screen_x
            y = battler.screen_y
          end
          viewport = Viewport.new(0,0,640,480)
          damage = value
          $damage = Damage.new(x,y,viewport,damage)
        end
      end
    end
    # Continue
    return true
  end
end

사용법
 $damage = Damage.new(x,y,내용)
수정, 추가 심플액션에서 데미지 출력을 이걸로 사용했음
잘쓰셈