Class: Menu
- Inherits:
-
Object
- Object
- Menu
- Defined in:
- lib/menu.rb
Instance Method Summary collapse
- #button_down(id) ⇒ Object
- #draw ⇒ Object
-
#initialize(window, opts = {}) ⇒ Menu
constructor
A new instance of Menu.
- #update ⇒ Object
Constructor Details
#initialize(window, opts = {}) ⇒ Menu
Returns a new instance of Menu.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/menu.rb', line 2 def initialize(window, opts={}) @window = window @pointer = Gosu::Image.new(@window,BLAST_IMG_PATH + "cursor.png",true) @background = Gosu::Image.load_tiles(@window, BLAST_IMG_PATH + 'menu.png', 1024, 768, true).first @title = Gosu::Image.load_tiles(@window, BLAST_IMG_PATH + 'title.png', 350, 80, true) @new_game = Gosu::Image.load_tiles(@window, BLAST_IMG_PATH + 'newgame.png', 150, 40, true) @options = Gosu::Image.load_tiles(@window, BLAST_IMG_PATH + 'options.png', 150, 40, true) @exit_game = Gosu::Image.load_tiles(@window, BLAST_IMG_PATH + 'exitgame.png', 150, 40, true) @song = Gosu::Song.new(@window, BLAST_SND_PATH + 'menu.wav') @new_game_index = @options_index = @exit_game_index = 1 @song.play(true) @song.volume = 0.3 @px = @py = 0 end |
Instance Method Details
#button_down(id) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/menu.rb', line 31 def (id) Processor.close if id == Gosu::KbEscape start_game if id == Gosu::KbReturn mouse_clicked(@px, @py) if id == Gosu::MsLeft @song.volume -= 0.1 if id == Gosu::KbNumpadSubtract @song.volume += 0.1 if id == Gosu::KbNumpadAdd end |
#draw ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/menu.rb', line 22 def draw @background.draw(0,0,0) @title.first.draw(340, 190, 1) @new_game[@new_game_index].draw(450, 280, 1) @options[@options_index].draw(450, 330, 1) @exit_game[@exit_game_index].draw(450, 380, 1) @pointer.draw(@px,@py,2) end |
#update ⇒ Object
17 18 19 20 |
# File 'lib/menu.rb', line 17 def update @px, @py = @window.mouse_x, @window.mouse_y update_hovers end |