-
Notifications
You must be signed in to change notification settings - Fork 0
/
banner.rb
55 lines (47 loc) · 1.05 KB
/
banner.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
require 'gosu'
require './event_handler'
class Banner
def initialize(heading, subheading='')
@heading = heading
@subheading = subheading
@heading_font = Gosu::Font.new(20)
@subheading_font = Gosu::Font.new(12)
EventHandler.register_listener(:game_start, self, :clear)
EventHandler.register_listener(:gameover, self, :gameover)
EventHandler.register_listener(:paused, self, :pause)
EventHandler.register_listener(:unpaused, self, :clear)
end
def clear(context)
@heading = ""
@subheading = ""
end
def gameover(context)
@heading = "Game Over"
@subheading = "Press space to restart"
end
def pause(context)
@heading = "Paused"
@subheading = "Press space to continue"
end
def draw
x = Config::WINDOW_X / 2
y = Config::WINDOW_Y / 2
@heading_font.draw_text_rel(
@heading,
x,
y,
1,
0.5,
0.5,
)
y += @heading_font.height * 2
@subheading_font.draw_text_rel(
@subheading,
x,
y,
1,
0.5,
0.5,
)
end
end