littlebrat 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/bin/littlebrat ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'littlebrat'
4
+
5
+ # TODO: Grab the config values from the arguments
6
+
7
+ # Time to shut the little brats up!
8
+ # LittleBrat.new(800, 600, false).show
9
+ LittleBrat.new.show
data/lib/littlebrat.rb ADDED
@@ -0,0 +1,124 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'gosu'
3
+
4
+ class LittleBrat < Gosu::Window
5
+ LETTER_LIMIT = 60
6
+ def initialize width=Gosu.screen_width, height=Gosu.screen_height, fullscreen=true
7
+ # Full resolution, fullscreen
8
+ super width, height, !!fullscreen #force to boolean for Gosu
9
+ self.caption = "Leave me alone you little brat!"
10
+ # The letters the little brat hits on the keyboard
11
+ @letters, @new_letters = [], []
12
+ # Load up the instructions to show at first
13
+ @letters.push Instructions.new(self)
14
+ @beeps = load_beeps
15
+ @redraw = true # init this because it needs to be true or false
16
+ end
17
+
18
+ def load_beeps
19
+ Dir.glob(File.dirname(__FILE__) + '/../sounds/**/*.WAV').map do |beep|
20
+ Gosu::Sample.new(self, beep)
21
+ end
22
+ end
23
+
24
+ def update
25
+ if !@new_letters.empty?
26
+ # Add new letter to the queue
27
+ while str = @new_letters.shift
28
+ @letters.push(Letter.new self, str)
29
+ end
30
+ beep # Only beep once per game loop
31
+ # Keep the total number of letter sprites at a managable number
32
+ @letters = @letters[-LETTER_LIMIT..-1] if @letters.size > LETTER_LIMIT
33
+ # We updated the letters, so we need to redraw
34
+ @redraw = true
35
+ end
36
+ end
37
+
38
+ def draw
39
+ @letters.each { |letter| letter.draw }
40
+ @redraw = false # Done drawing, don't need to draw no more
41
+ end
42
+
43
+ def needs_redraw?; @redraw; end # Don't paint/draw unless we need to
44
+
45
+ def needs_cursor?; false; end # Don't show the cursor, even on Ubuntu
46
+
47
+ def button_down id # Callback, not on main thread
48
+ close if close? # Close if we press the right keys
49
+ @new_letters.push str_from_button_id(id)
50
+ end
51
+
52
+ def str_from_button_id id
53
+ self.button_id_to_char(id) || random_letter
54
+ end
55
+
56
+ def random_letter
57
+ @random_letters ||= %w{ ▲ ▼ ☻ ♠ ♣ ♥ ♦ ☀ ☁ ☂ ✔ ✘ ☎ ✈ ✪ }
58
+ @random_letters[rand @random_letters.size]
59
+ end
60
+
61
+ def close?
62
+ (button_down? Gosu::KbEscape or
63
+ button_down? Gosu::KbLeftControl or
64
+ button_down? Gosu::KbRightControl) &&
65
+ (button_down? Gosu::KbQ or button_down? Gosu::KbW or
66
+ button_down? Gosu::KbZ or button_down? Gosu::KbC or
67
+ button_down? Gosu::KbBackspace or button_down? Gosu::KbDelete)
68
+ end
69
+
70
+ def beep
71
+ @beeps[rand @beeps.size].play
72
+ end
73
+
74
+ class Instructions
75
+ def initialize window, text = "Let's shut those little brats up!"
76
+ @image = Gosu::Image.from_text window,
77
+ "#{text}\nPress CTRL+Q to exit",
78
+ Gosu::default_font_name,
79
+ 100
80
+ @color = 0xffffff00
81
+ @x, @y = 10, 10
82
+ end
83
+
84
+ def draw
85
+ @image.draw @x, @y, 1, 0.5, 0.5, @color
86
+ end
87
+ end
88
+
89
+ class Letter
90
+ def initialize window, text
91
+ text_height = random_text_size window
92
+ @image = Gosu::Image.from_text window, text,
93
+ Gosu::default_font_name,
94
+ text_height
95
+ @color = random_color # Image text is white, so this is to modulate it
96
+ @x, @y = random_position window, text_height
97
+ end
98
+
99
+ def draw
100
+ @image.draw @x, @y, 1, 0.5, 0.5, @color
101
+ end
102
+
103
+ def random_text_size(window)
104
+ (window.height / (rand + 1)).to_i
105
+ end
106
+
107
+ def random_color
108
+ color = Gosu::Color.new 0xff000000
109
+ color.red = random_byte
110
+ color.green = random_byte
111
+ color.blue = random_byte
112
+ color
113
+ end
114
+
115
+ def random_byte
116
+ rand(255 - 40) + 40
117
+ end
118
+
119
+ def random_position window, text_height
120
+ [ rand * window.width - (text_height / 4),
121
+ rand * window.height - (text_height / 4) ]
122
+ end
123
+ end
124
+ end
Binary file
data/sounds/ARRP.WAV ADDED
Binary file
data/sounds/BADUMM.WAV ADDED
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
data/sounds/KLICK.WAV ADDED
Binary file
Binary file
Binary file
Binary file
data/sounds/WATER.WAV ADDED
Binary file
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: littlebrat
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 1
9
+ version: 0.1.1
10
+ platform: ruby
11
+ authors:
12
+ - Mike Moore
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-09-27 00:00:00 -06:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: gosu
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ - 7
31
+ - 24
32
+ version: 0.7.24
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description: Because kids like to smash buttons
36
+ email:
37
+ - mike@blowmage.com
38
+ executables:
39
+ - littlebrat
40
+ extensions: []
41
+
42
+ extra_rdoc_files: []
43
+
44
+ files:
45
+ - lib/littlebrat.rb
46
+ - sounds/AMFMBEEP.WAV
47
+ - sounds/ARRP.WAV
48
+ - sounds/BADUMM.WAV
49
+ - sounds/BEEP_FM.WAV
50
+ - sounds/BEEPCASI.WAV
51
+ - sounds/BEEPCOME.WAV
52
+ - sounds/BEEPDOUB.WAV
53
+ - sounds/BEEPMETA.WAV
54
+ - sounds/BEEPMULT.WAV
55
+ - sounds/BEEPPURE.WAV
56
+ - sounds/BEEPROBO.WAV
57
+ - sounds/KLICK.WAV
58
+ - sounds/TEESWING.WAV
59
+ - sounds/TYPEKEY.WAV
60
+ - sounds/TYPESPAC.WAV
61
+ - sounds/WATER.WAV
62
+ - bin/littlebrat
63
+ has_rdoc: true
64
+ homepage: http://rubygems.org/gems/littlebrat
65
+ licenses: []
66
+
67
+ post_install_message:
68
+ rdoc_options: []
69
+
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ segments:
78
+ - 0
79
+ version: "0"
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ segments:
86
+ - 1
87
+ - 3
88
+ - 6
89
+ version: 1.3.6
90
+ requirements: []
91
+
92
+ rubyforge_project: littlebrat
93
+ rubygems_version: 1.3.7
94
+ signing_key:
95
+ specification_version: 3
96
+ summary: A handy little app to entertain the kiddos
97
+ test_files: []
98
+