-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenustate.rb
58 lines (48 loc) · 1.74 KB
/
menustate.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
require_relative 'menu.rb'
class MainMenuState
ITEM_SPACE = 60
def initialize (window)
@window = window
@background = Shared::background
@splash = Shared::title
@cursor = Shared::cursor
@first_menu_option_pos = {x: (window.width / 2) - 100, y: (window.height / 2) - 50}
@menu = Menu.new(window)
@menu.add_item(Gosu::Image.new(window, "images/mainmenu/startgame.png", false), @first_menu_option_pos[:x], @first_menu_option_pos[:y], ZOrdinals::MENU_CURSOR - 1, lambda {
#StateMachine.set_state(:game,:restart)
StateMachine.set_state(:playerselection,:restart)
}, Gosu::Image.new(window, "images/mainmenu/startgame_hover.png", false))
.add_item(Gosu::Image.new(window, "images/mainmenu/highscores.png", false), @first_menu_option_pos[:x] - 10, @first_menu_option_pos[:y] + ITEM_SPACE, ZOrdinals::MENU_CURSOR - 1, lambda {
StateMachine.set_state(:highscores, :restart)
}, Gosu::Image.new(window, "images/mainmenu/highscores_hover.png", false))
.add_item(Gosu::Image.new(window, "images/mainmenu/exit.png", false), @first_menu_option_pos[:x] + 75, @first_menu_option_pos[:y] + ITEM_SPACE * 2, ZOrdinals::MENU_CURSOR - 1, lambda {
window.close
}, Gosu::Image.new(window, "images/mainmenu/exit_hover.png", false))
#AudioManager::intro_song.play
end
def update
@background.update
@cursor.draw(@window.mouse_x, @window.mouse_y, ZOrdinals::MENU_CURSOR)
@menu.update
end
def draw
@background.draw
@splash.draw(0, 0, ZOrdinals::TITLE)
@menu.draw
end
def button_down (id)
if id == Gosu::KbEscape then
if Shared::is_game_running then
StateMachine.set_state(:game,:resume)
return
end
@window.close
end
if id == Gosu::MsLeft then
@menu.clicked
end
end
def close_game
@window.close
end
end