Skip to content

Commit

Permalink
I suppose I should use SCM...
Browse files Browse the repository at this point in the history
  • Loading branch information
blowmage committed Sep 28, 2010
0 parents commit 5d726ea
Show file tree
Hide file tree
Showing 23 changed files with 211 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
pkg/*
*.gem
1 change: 1 addition & 0 deletions Gemfile
@@ -0,0 +1 @@
gemspec
1 change: 1 addition & 0 deletions README
@@ -0,0 +1 @@
SHUT UP YOU LITTLE BRATS!!!
40 changes: 40 additions & 0 deletions Rakefile
@@ -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
7 changes: 7 additions & 0 deletions bin/littlebrat
@@ -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
141 changes: 141 additions & 0 deletions lib/littlebrat.rb
@@ -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
19 changes: 19 additions & 0 deletions littlebrat.gemspec
@@ -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 added sounds/AMFMBEEP.WAV
Binary file not shown.
Binary file added sounds/ARRP.WAV
Binary file not shown.
Binary file added sounds/BADUMM.WAV
Binary file not shown.
Binary file added sounds/BEEPCASI.WAV
Binary file not shown.
Binary file added sounds/BEEPCOME.WAV
Binary file not shown.
Binary file added sounds/BEEPDOUB.WAV
Binary file not shown.
Binary file added sounds/BEEPMETA.WAV
Binary file not shown.
Binary file added sounds/BEEPMULT.WAV
Binary file not shown.
Binary file added sounds/BEEPPURE.WAV
Binary file not shown.
Binary file added sounds/BEEPROBO.WAV
Binary file not shown.
Binary file added sounds/BEEP_FM.WAV
Binary file not shown.
Binary file added sounds/KLICK.WAV
Binary file not shown.
Binary file added sounds/TEESWING.WAV
Binary file not shown.
Binary file added sounds/TYPEKEY.WAV
Binary file not shown.
Binary file added sounds/TYPESPAC.WAV
Binary file not shown.
Binary file added sounds/WATER.WAV
Binary file not shown.

0 comments on commit 5d726ea

Please sign in to comment.