Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5d726ea
Showing
23 changed files
with
211 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pkg/* | ||
*.gem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SHUT UP YOU LITTLE BRATS!!! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require 'rake' | ||
require 'rake/clean' | ||
|
||
require 'rake/gempackagetask' | ||
gemspec = eval(File.read('littlebrat.gemspec')) | ||
Rake::GemPackageTask.new(gemspec) do |p| | ||
p.gem_spec = gemspec | ||
end | ||
|
||
require 'rake/rdoctask' | ||
rd = Rake::RDocTask.new("rdoc") do |rdoc| | ||
rdoc.title = "#{gemspec.name} (#{gemspec.version}) - #{gemspec.description}" | ||
rdoc.options << '--line-numbers --inline-source --main README' | ||
rdoc.rdoc_files.include(gemspec.files) | ||
rdoc.main = 'README' | ||
end | ||
|
||
require 'rake/testtask' | ||
Rake::TestTask.new(:test) do |test| | ||
test.libs << 'lib' << 'test' | ||
test.pattern = 'test/**/test_*.rb' | ||
test.verbose = true | ||
end | ||
|
||
task :default => :test | ||
|
||
begin | ||
require 'rcov/rcovtask' | ||
Rcov::RcovTask.new do |test| | ||
test.libs << 'test' | ||
test.pattern = 'test/**/test_*.rb' | ||
test.verbose = true | ||
end | ||
rescue LoadError | ||
task :rcov do | ||
abort 'RCov is not available. In order to run rcov, you must: gem install rcov' | ||
end | ||
end | ||
|
||
task :test => :check_dependencies |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'littlebrat' | ||
|
||
# TODO: Grab the config values from the arguments | ||
|
||
# Time to shut the little brats up! | ||
# LittleBrat.new(800, 600, false).show | ||
LittleBrat.new.show |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
# -*- encoding: utf-8 -*- | ||
require 'gosu' | ||
|
||
class LittleBrat < Gosu::Window | ||
LETTER_LIMIT = 60 | ||
def initialize width=Gosu.screen_width, height=Gosu.screen_height, fullscreen=true | ||
# Full resolution, fullscreen | ||
super width, height, !!fullscreen #force to boolean for Gosu | ||
self.caption = "Leave me alone you little brat!" | ||
# The letters the little brat hits on the keyboard | ||
@letters, @new_letters = [], [] | ||
# Load up the instructions to show at first | ||
@letters.push Instructions.new(self) | ||
@beeps = load_beeps | ||
@redraw = true # init this because it needs to be true or false | ||
end | ||
|
||
def load_beeps | ||
%w{ AMFMBEEP.WAV | ||
ARRP.WAV | ||
BADUMM.WAV | ||
BEEPCASI.WAV | ||
BEEPCOME.WAV | ||
BEEPDOUB.WAV | ||
BEEPMETA.WAV | ||
BEEPMULT.WAV | ||
BEEPPURE.WAV | ||
BEEPROBO.WAV | ||
BEEP_FM.WAV | ||
KLICK.WAV | ||
TEESWING.WAV | ||
TYPEKEY.WAV | ||
TYPESPAC.WAV | ||
WATER.WAV | ||
}.map do |f| | ||
Gosu::Sample.new(self, "sounds/#{f}") | ||
end | ||
end | ||
|
||
def update | ||
if !@new_letters.empty? | ||
# Add new letter to the queue | ||
while str = @new_letters.shift | ||
@letters.push(Letter.new self, str) | ||
end | ||
beep # Only beep once per game loop | ||
# Keep the total number of letter sprites at a managable number | ||
@letters = @letters[-LETTER_LIMIT..-1] if @letters.size > LETTER_LIMIT | ||
# We updated the letters, so we need to redraw | ||
@redraw = true | ||
end | ||
end | ||
|
||
def draw | ||
@letters.each { |letter| letter.draw } | ||
@redraw = false # Done drawing, don't need to draw no more | ||
end | ||
|
||
def needs_redraw?; @redraw; end # Don't paint/draw unless we need to | ||
|
||
def needs_cursor?; false; end # Don't show the cursor, even on Ubuntu | ||
|
||
def button_down id # Callback, not on main thread | ||
close if close? # Close if we press the right keys | ||
@new_letters.push str_from_button_id(id) | ||
end | ||
|
||
def str_from_button_id id | ||
self.button_id_to_char(id) || random_letter | ||
# random_letter | ||
end | ||
|
||
def random_letter | ||
@random_letters ||= %w{ ▲ ▼ ☻ ♠ ♣ ♥ ♦ ☀ ☁ ☂ ✔ ✘ ☎ ✈ ✪ } | ||
@random_letters[rand @random_letters.size] | ||
end | ||
|
||
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 | ||
|
||
def beep | ||
@beeps[rand @beeps.size].play | ||
end | ||
|
||
class Instructions | ||
def initialize window, text = "Let's shut those little brats up!" | ||
@image = Gosu::Image.from_text window, | ||
"#{text}\nPress CTRL+Q to exit", | ||
Gosu::default_font_name, | ||
100 | ||
@color = 0xffffff00 | ||
@x, @y = 10, 10 | ||
end | ||
|
||
def draw | ||
@image.draw @x, @y, 1, 0.5, 0.5, @color | ||
end | ||
end | ||
|
||
class Letter | ||
def initialize window, text | ||
text_height = random_text_size window | ||
@image = Gosu::Image.from_text window, text, | ||
Gosu::default_font_name, | ||
text_height | ||
@color = random_color # Image text is white, so this is to modulate it | ||
@x, @y = random_position window, text_height | ||
end | ||
|
||
def draw | ||
@image.draw @x, @y, 1, 0.5, 0.5, @color | ||
end | ||
|
||
def random_text_size(window) | ||
(window.height / (rand + 1)).to_i | ||
end | ||
|
||
def random_color | ||
color = Gosu::Color.new 0xff000000 | ||
color.red = random_byte | ||
color.green = random_byte | ||
color.blue = random_byte | ||
color | ||
end | ||
|
||
def random_byte | ||
rand(255 - 40) + 40 | ||
end | ||
|
||
def random_position window, text_height | ||
[ rand * window.width - (text_height / 4), | ||
rand * window.height - (text_height / 4) ] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# -*- encoding: utf-8 -*- | ||
Gem::Specification.new do |s| | ||
s.name = "littlebrat" | ||
s.version = '0.1.0' | ||
s.platform = Gem::Platform::RUBY | ||
s.authors = ['Mike Moore'] | ||
s.email = ['mike@blowmage.com'] | ||
s.homepage = "http://rubygems.org/gems/littlebrat" | ||
s.summary = "A handy little app to entertain the kiddos" | ||
s.description = "Because kids like to smash buttons" | ||
|
||
s.required_rubygems_version = ">= 1.3.6" | ||
s.add_dependency(%q<gosu>, ["~> 0.7.24"]) | ||
s.rubyforge_project = "littlebrat" | ||
|
||
s.files = Dir.glob 'lib/**/*.rb' | ||
s.executables = ['littlebrat'] | ||
s.require_path = 'lib' | ||
end |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.