Sha256: 38135b699d1c09f0175b0a932598dae42360f1b537971ea9161ee36018d87b57

Contents?: true

Size: 1.17 KB

Versions: 5

Compression:

Stored size: 1.17 KB

Contents

class HudText
  attr_accessor :text, :size, :color, :visible, :layer, :in_world

  def initialize(position:, text: "")
    @position = position
    @text = text
    @size = "medium"
    @color = Gosu::Color::WHITE
    @visible = true
    @layer = 100
    @in_world = false

    Global.hud_texts.push(self)
  end

  def move; end

  def draw
    if visible
      Global.pixel_font.draw_markup(text, screen_position.x + scale, screen_position.y - 20 + scale, 1, scale, scale, Gosu::Color::BLACK)
      Global.pixel_font.draw_markup(text, screen_position.x, screen_position.y - 20, 1, scale, scale, color)
    end

    draw_debug if Global.debug
  end

  def scale
    case @size
    when "small"
      1
    when "medium"
      2
    when "big"
      3
    when "huge"
      4
    else
      raise "HudText.size not valid '#{@size}'. Valid sizes: 'small, medium, big, huge'"
    end
  end

  def screen_position
    if @in_world
      @position - Global.camera.position
    else
      @position
    end
  end

  def destroy
    Global.hud_texts.delete(self)
  end

  def draw_debug
    Global.pixel_font.draw_text("#{@position.x.floor},#{@position.y.floor}", @position.x, @position.y, 1)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
fantasy-0.1.5.1 lib/fantasy/hud_text.rb
fantasy-0.1.5 lib/fantasy/hud_text.rb
fantasy-0.1.3 lib/fantasy/hud_text.rb
fantasy-0.1.1 lib/fantasy/hud_text.rb
fantasy-0.1.0 lib/fantasy/hud_text.rb