Class: Asteroids::MenuItem

Inherits:
Object
  • Object
show all
Defined in:
lib/asteroids/menu/menu_item.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, callback, selected) ⇒ MenuItem

Returns a new instance of MenuItem.



5
6
7
8
9
10
11
12
# File 'lib/asteroids/menu/menu_item.rb', line 5

def initialize (text, callback, selected)
  @image = Gosu::Image.from_text($window, text,
    Utils.get_font_path('victor-pixel.ttf'), 65)
  @x = 0
  @y = 0
  @callback = callback
  @selected = selected
end

Instance Attribute Details

#x=(value) ⇒ Object (writeonly)

Sets the attribute x

Parameters:

  • value

    the value to set the attribute x to.



3
4
5
# File 'lib/asteroids/menu/menu_item.rb', line 3

def x=(value)
  @x = value
end

#y=(value) ⇒ Object (writeonly)

Sets the attribute y

Parameters:

  • value

    the value to set the attribute y to.



3
4
5
# File 'lib/asteroids/menu/menu_item.rb', line 3

def y=(value)
  @y = value
end

Instance Method Details

#deselectObject



30
31
32
# File 'lib/asteroids/menu/menu_item.rb', line 30

def deselect
  @selected = false
end

#drawObject



14
15
16
17
18
19
20
# File 'lib/asteroids/menu/menu_item.rb', line 14

def draw
  if @selected
      @image.draw(@x, @y, 10, 1, 1, 0xffffff00)
  else
      @image.draw(@x, @y, 10)
  end
end

#executeObject



34
35
36
37
38
# File 'lib/asteroids/menu/menu_item.rb', line 34

def execute
  if @selected
      @callback.call
  end
end

#heightObject



44
45
46
# File 'lib/asteroids/menu/menu_item.rb', line 44

def height
  @image.height
end

#is_selected?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/asteroids/menu/menu_item.rb', line 22

def is_selected?
  @selected
end

#selectObject



26
27
28
# File 'lib/asteroids/menu/menu_item.rb', line 26

def select
  @selected = true
end

#widthObject



40
41
42
# File 'lib/asteroids/menu/menu_item.rb', line 40

def width
  @image.width
end