Class: LittleBrat
- Inherits:
-
Gosu::Window
- Object
- Gosu::Window
- LittleBrat
show all
- Defined in:
- lib/littlebrat.rb
Defined Under Namespace
Classes: Instructions, Letter
Constant Summary
collapse
- LETTER_LIMIT =
60
Instance Method Summary
collapse
Constructor Details
#initialize(width = Gosu.screen_width, height = Gosu.screen_height, fullscreen = true) ⇒ LittleBrat
Returns a new instance of LittleBrat.
6
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/littlebrat.rb', line 6
def initialize width=Gosu.screen_width, height=Gosu.screen_height, fullscreen=true
super width, height, !!fullscreen self.caption = "Leave me alone you little brat!"
@letters, @new_letters = [], []
@letters.push Instructions.new(self)
@beeps = load_beeps
@redraw = true end
|
Instance Method Details
#beep ⇒ Object
71
72
73
|
# File 'lib/littlebrat.rb', line 71
def beep
@beeps[rand @beeps.size].play
end
|
Callback, not on main thread
47
48
49
50
|
# File 'lib/littlebrat.rb', line 47
def button_down id close if close? @new_letters.push str_from_button_id(id)
end
|
#close? ⇒ Boolean
62
63
64
65
66
67
68
69
|
# File 'lib/littlebrat.rb', line 62
def close?
(button_down? Gosu::KbEscape or
button_down? Gosu::KbLeftControl or
button_down? Gosu::KbRightControl) &&
(button_down? Gosu::KbQ or button_down? Gosu::KbW or
button_down? Gosu::KbZ or button_down? Gosu::KbC or
button_down? Gosu::KbBackspace or button_down? Gosu::KbDelete)
end
|
#draw ⇒ Object
38
39
40
41
|
# File 'lib/littlebrat.rb', line 38
def draw
@letters.each { |letter| letter.draw }
@redraw = false end
|
#load_beeps ⇒ Object
18
19
20
21
22
|
# File 'lib/littlebrat.rb', line 18
def load_beeps
Dir.glob(File.dirname(__FILE__) + '/../sounds/**/*.WAV').map do |beep|
Gosu::Sample.new(self, beep)
end
end
|
#needs_cursor? ⇒ Boolean
Don’t show the cursor, even on Ubuntu
45
|
# File 'lib/littlebrat.rb', line 45
def needs_cursor?; false; end
|
#needs_redraw? ⇒ Boolean
Don’t paint/draw unless we need to
43
|
# File 'lib/littlebrat.rb', line 43
def needs_redraw?; @redraw; end
|
#random_letter ⇒ Object
57
58
59
60
|
# File 'lib/littlebrat.rb', line 57
def random_letter
@random_letters ||= %w{ ▲ ▼ ☻ ♠ ♣ ♥ ♦ ☀ ☁ ☂ ✔ ✘ ☎ ✈ ✪ }
@random_letters[rand @random_letters.size]
end
|
52
53
54
55
|
# File 'lib/littlebrat.rb', line 52
def str_from_button_id id
c = self.button_id_to_char(id).to_s.strip
c.empty? ? random_letter : c
end
|
#update ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/littlebrat.rb', line 24
def update
if !@new_letters.empty?
while str = @new_letters.shift
@letters.push(Letter.new self, str)
end
beep @letters = @letters[-LETTER_LIMIT..-1] if @letters.size > LETTER_LIMIT
@redraw = true
end
end
|