Class: Asteroids::MenuItem
- Inherits:
-
Object
- Object
- Asteroids::MenuItem
- Defined in:
- lib/asteroids/menu/menu_item.rb
Instance Attribute Summary collapse
-
#x ⇒ Object
writeonly
Sets the attribute x.
-
#y ⇒ Object
writeonly
Sets the attribute y.
Instance Method Summary collapse
- #deselect ⇒ Object
- #draw ⇒ Object
- #execute ⇒ Object
- #height ⇒ Object
-
#initialize(text, callback, selected) ⇒ MenuItem
constructor
A new instance of MenuItem.
- #is_selected? ⇒ Boolean
- #select ⇒ Object
- #width ⇒ Object
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
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
3 4 5 |
# File 'lib/asteroids/menu/menu_item.rb', line 3 def y=(value) @y = value end |
Instance Method Details
#deselect ⇒ Object
30 31 32 |
# File 'lib/asteroids/menu/menu_item.rb', line 30 def deselect @selected = false end |
#draw ⇒ Object
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 |
#execute ⇒ Object
34 35 36 37 38 |
# File 'lib/asteroids/menu/menu_item.rb', line 34 def execute if @selected @callback.call end end |
#height ⇒ Object
44 45 46 |
# File 'lib/asteroids/menu/menu_item.rb', line 44 def height @image.height end |
#is_selected? ⇒ Boolean
22 23 24 |
# File 'lib/asteroids/menu/menu_item.rb', line 22 def is_selected? @selected end |
#select ⇒ Object
26 27 28 |
# File 'lib/asteroids/menu/menu_item.rb', line 26 def select @selected = true end |
#width ⇒ Object
40 41 42 |
# File 'lib/asteroids/menu/menu_item.rb', line 40 def width @image.width end |