Class: HudImage

Inherits:
Object
  • Object
show all
Includes:
Draggable
Defined in:
lib/fantasy/hud_image.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Draggable

#drag

Constructor Details

#initialize(position:, image_name:) ⇒ HudImage

Returns a new instance of HudImage.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/fantasy/hud_image.rb', line 8

def initialize(position:, image_name:)
  @image = Image.new(image_name)
  @name = image_name
  @position = position
  @scale = 1
  @visible = true
  @draggable_on_debug = true
  @dragging = false
  @layer = 100

  Global.hud_images.push(self)
end

Instance Attribute Details

#colorObject

Returns the value of attribute color.



6
7
8
# File 'lib/fantasy/hud_image.rb', line 6

def color
  @color
end

#layerObject

Returns the value of attribute layer.



6
7
8
# File 'lib/fantasy/hud_image.rb', line 6

def layer
  @layer
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/fantasy/hud_image.rb', line 6

def name
  @name
end

#positionObject

Returns the value of attribute position.



6
7
8
# File 'lib/fantasy/hud_image.rb', line 6

def position
  @position
end

#scaleObject

Returns the value of attribute scale.



6
7
8
# File 'lib/fantasy/hud_image.rb', line 6

def scale
  @scale
end

#visibleObject

Returns the value of attribute visible.



6
7
8
# File 'lib/fantasy/hud_image.rb', line 6

def visible
  @visible
end

Instance Method Details

#destroyObject



45
46
47
# File 'lib/fantasy/hud_image.rb', line 45

def destroy
  Global.hud_images.delete(self)
end

#drawObject



33
34
35
36
37
38
39
# File 'lib/fantasy/hud_image.rb', line 33

def draw
  if visible
    @image.draw(x: @position.x, y: @position.y, scale: @scale)
  end

  draw_debug if Global.debug
end

#draw_debugObject



41
42
43
# File 'lib/fantasy/hud_image.rb', line 41

def draw_debug
  Global.pixel_fonts["medium"].draw_text("#{@position.x.floor},#{@position.y.floor}", @position.x, @position.y - 20, 1)
end

#heightObject



25
26
27
# File 'lib/fantasy/hud_image.rb', line 25

def height
  @image.height * @scale
end

#moveObject



29
30
31
# File 'lib/fantasy/hud_image.rb', line 29

def move
  drag if Global.debug
end

#widthObject



21
22
23
# File 'lib/fantasy/hud_image.rb', line 21

def width
  @image.width * @scale
end