Permalink
Browse files

added some basic ability to play sound, but only if command line swit…

…ch enables it, for now
  • Loading branch information...
michaelchadwick committed Jun 25, 2015
1 parent c817d78 commit 9c93ad69711fd0e201726e189a7bc4cecb64785a
View
@@ -8,7 +8,7 @@ require_relative '../lib/gemwarrior/game'
GAME_NAME = "Gem Warrior"
def parse_options
options = {:debug_mode => false, :god_mode => false, :beast_mode => false, :use_wordnik => false}
options = {:debug_mode => false, :god_mode => false, :beast_mode => false, :use_wordnik => false, :sound => false}
optparse = OptionParser.new do |opts|
opts.on('-v', '--version', 'Display version number and exit') do
@@ -31,6 +31,10 @@ def parse_options
opts.on('-w', '--wordnik', 'Use Wordnik to generate more diverse, dynamic descriptors of entities') do
options[:use_wordnik] = true
end
opts.on('-s', '--sound', 'Turn sound on') do
options[:sound] = true
end
end
optparse.parse!()
View
@@ -20,13 +20,13 @@ Gem::Specification.new do |spec|
spec.license = 'MIT'
spec.add_runtime_dependency 'os', '~> 0.9', '>= 0.9.6'
spec.add_runtime_dependency 'matrext', '~> 0.4.7'
spec.add_runtime_dependency 'matrext', '~> 0.4.8'
spec.add_runtime_dependency 'http', '~> 0.8.10'
spec.add_runtime_dependency 'json', '~> 1.8.2'
spec.add_runtime_dependency 'colorize', '~> 0.7.7'
spec.add_runtime_dependency 'feep', '~> 0.1.3'
#spec.add_runtime_dependency 'hr', '~> 0.0.1'
#spec.add_runtime_dependency 'feep', '~> 0.1.0'
#spec.add_runtime_dependency 'wordnik', '~> 4.12'
spec.add_development_dependency 'pry-byebug', '~> 3.0'
@@ -142,7 +142,7 @@ def list_inventory
inventory.list_contents
end
def go(locations, direction)
def go(locations, direction, sound)
case direction
when 'north', 'n'
self.cur_coords = {
@@ -173,7 +173,7 @@ def go(locations, direction)
}
direction_text = '<<<'
end
print_traveling_text(direction_text)
print_traveling_text(direction_text, sound)
end
def attack(world, monster)
@@ -217,8 +217,13 @@ def player_death
end
# TRAVEL
def print_traveling_text(direction_text)
def print_traveling_text(direction_text, sound)
Animation::run({:oneline => false, :phrase => "* #{direction_text} *"})
if sound
Music::cue([
{:freq_or_note => 'C3,E3'}
])
end
end
# CHARACTER
@@ -347,7 +347,7 @@ def evaluate(input)
else
direction = param1
if world.can_move?(direction)
world.player.go(world.locations, param1)
world.player.go(world.locations, param1, world.sound)
world.location_by_coords(world.player.cur_coords).checked_for_monsters = false
world.describe(world.location_by_coords(world.player.cur_coords))
else
View
@@ -3,10 +3,12 @@
require 'colorize'
require 'matrext'
require 'feep'
require_relative 'entities/player'
require_relative 'misc/player_levels'
require_relative 'misc/animation'
require_relative 'misc/music'
require_relative 'world'
require_relative 'evaluator'
require_relative 'repl'
@@ -32,6 +34,7 @@ def initialize(options)
world.debug_mode = options.fetch(:debug_mode)
world.use_wordnik = options.fetch(:use_wordnik)
world.sound = options.fetch(:sound)
world.player = Player.new({
:description => PLAYER_DESC_DEFAULT,
@@ -0,0 +1,36 @@
# lib/gemwarrior/misc/music.rb
# Music cue
module Gemwarrior
module Music
def self.cue(sequence)
defaults = {
:freq_or_note => 440,
:waveform => 'saw',
:volume => 0.5,
:duration => 500,
:notext => true
}
th = Thread.new do
sequence.each do |note|
note_to_play = note[:freq_or_note]
waveform = note[:waveform].nil? ? defaults[:waveform] : note[:waveform]
volume = note[:volume].nil? ? defaults[:volume] : note[:volume]
duration = note[:duration].nil? ? defaults[:duration] : note[:duration]
notext = note[:notext].nil? ? defaults[:notext] : note[:notext]
Feep::Base.new({
:freq_or_note => note_to_play,
:waveform => waveform,
:volume => volume,
:duration => duration,
:notext => notext
})
end
end
return th.join
end
end
end
@@ -2,5 +2,5 @@
# Version of Gem Warrior
module Gemwarrior
VERSION = "0.8.1"
VERSION = "0.8.2"
end
View
@@ -53,6 +53,12 @@ def print_logo
puts "/-+-+-+ +-+-+-+-+-+-+-\\".colorize(:yellow)
puts '|G|E|M| |W|A|R|R|I|O|R|'.colorize(:yellow)
puts "\\-+-+-+ +-+-+-+-+-+-+-/".colorize(:yellow)
if world.sound
Music::cue([
{:freq_or_note => 'A3,E4,C#5,F#5', :duration => 1000}
])
end
end
def print_splash_message
View
@@ -17,7 +17,7 @@ class World
ERROR_LIST_PARAM_INVALID = 'That is not something that can be listed.'
ERROR_LOCATION_DESCRIBE_ENTITY_INVALID = 'You do not see that here.'
attr_accessor :monsters, :locations, :player, :debug_mode, :use_wordnik
attr_accessor :monsters, :locations, :player, :debug_mode, :use_wordnik, :sound
def initialize
self.monsters = init_monsters

0 comments on commit 9c93ad6

Please sign in to comment.