diff --git a/.buildpath b/.buildpath
new file mode 100644
index 0000000..f9c181a
--- /dev/null
+++ b/.buildpath
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..a8ff279
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,45 @@
+# Created by .ignore support plugin (hsz.mobi)
+### Ruby template
+*.gem
+*.rbc
+/.config
+/coverage/
+/InstalledFiles
+/pkg/
+/spec/reports/
+/test/tmp/
+/test/version_tmp/
+/tmp/
+
+## Specific to RubyMotion:
+.dat*
+.repl_history
+build/
+
+## Documentation cache and generated files:
+/.yardoc/
+/_yardoc/
+/doc/
+/rdoc/
+
+## Environment normalisation:
+/.bundle/
+/vendor/bundle
+/lib/bundler/man/
+
+# for a library or gem, you might want to ignore these files since the code is
+# intended to run in multiple environments; otherwise, check them in:
+# Gemfile.lock
+# .ruby-version
+# .ruby-gemset
+
+# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
+.rvmrc
+
+# ignore idea stuff
+*.iml
+/.idea
+
+# ignore editor backups
+*~
+
diff --git a/.project b/.project
new file mode 100644
index 0000000..0e90e91
--- /dev/null
+++ b/.project
@@ -0,0 +1,17 @@
+
+
+ ruby-gamedev-book-examples
+
+
+
+
+
+ org.eclipse.dltk.core.scriptbuilder
+
+
+
+
+
+ org.eclipse.dltk.ruby.core.nature
+
+
diff --git a/.ruby-version b/.ruby-version
index ac2cdeb..5859406 100644
--- a/.ruby-version
+++ b/.ruby-version
@@ -1 +1 @@
-2.1.3
+2.2.3
diff --git a/01-hello/hello_sound.rb b/01-hello/hello_sound.rb
index 55b31a3..14cf3a3 100644
--- a/01-hello/hello_sound.rb
+++ b/01-hello/hello_sound.rb
@@ -16,7 +16,7 @@ def self.load_animation(window)
def self.load_sound(window)
Gosu::Sample.new(
- window, media_path('explosion.mp3'))
+ window, media_path('explosion.ogg'))
end
def initialize(animation, sound, x, y)
@@ -71,7 +71,7 @@ def initialize(width=800, height=600, fullscreen=false)
@background = Gosu::Image.new(
self, BACKGROUND, false)
@music = Gosu::Song.new(
- self, media_path('menu_music.mp3'))
+ self, media_path('menu_music.ogg'))
@music.volume = 0.5
@music.play(true)
@animation = Explosion.load_animation(self)
diff --git a/03-prototype/entities/bullet.rb b/03-prototype/entities/bullet.rb
index 470349a..26e1477 100644
--- a/03-prototype/entities/bullet.rb
+++ b/03-prototype/entities/bullet.rb
@@ -10,7 +10,7 @@ def initialize(source_x, source_y, target_x, target_y)
if trajectory_length > MAX_DIST
@target_x, @target_y = point_at_distance(MAX_DIST)
end
- sound.play
+ sound.play if sound
end
def draw
@@ -54,7 +54,7 @@ def fire(speed)
def sound
@@sound ||= Gosu::Sample.new(
- $window, Game.media_path('fire.mp3'))
+ $window, Game.media_path('fire.ogg'))
end
def trajectory_length
diff --git a/03-prototype/entities/explosion.rb b/03-prototype/entities/explosion.rb
index 0e36629..2856ef9 100644
--- a/03-prototype/entities/explosion.rb
+++ b/03-prototype/entities/explosion.rb
@@ -9,11 +9,11 @@ def animation
def sound
@@sound ||= Gosu::Sample.new(
- $window, Game.media_path('explosion.mp3'))
+ $window, Game.media_path('explosion.ogg'))
end
def initialize(x, y)
- sound.play
+ sound.play if sound
@x, @y = x, y
@current_frame = 0
end
diff --git a/03-prototype/entities/tank.rb b/03-prototype/entities/tank.rb
index 663a0f7..da2aaa2 100644
--- a/03-prototype/entities/tank.rb
+++ b/03-prototype/entities/tank.rb
@@ -13,12 +13,12 @@ def initialize(map)
@body_angle = 0.0
@gun_angle = 0.0
@last_shot = 0
- sound.volume = 0.3
+ sound.volume = 0.3 if sound
end
def sound
@@sound ||= Gosu::Song.new(
- $window, Game.media_path('tank_driving.mp3'))
+ $window, Game.media_path('tank_driving.ogg'))
end
def shoot(target_x, target_y)
@@ -47,9 +47,9 @@ def update(camera)
Gosu::KbW, Gosu::KbS, Gosu::KbA, Gosu::KbD)
if moving?
- sound.play(true)
+ sound.play(true) if sound
else
- sound.pause
+ sound.pause if sound
end
if $window.button_down?(Gosu::MsLeft)
diff --git a/03-prototype/states/menu_state.rb b/03-prototype/states/menu_state.rb
index c3ba398..6d9153f 100644
--- a/03-prototype/states/menu_state.rb
+++ b/03-prototype/states/menu_state.rb
@@ -10,18 +10,22 @@ def initialize
end
def enter
- music.play(true)
- music.volume = 1
+ if music
+ music.play(true)
+ music.volume = 1
+ end
end
def leave
- music.volume = 0
- music.stop
+ if music
+ music.volume = 0
+ music.stop
+ end
end
def music
@@music ||= Gosu::Song.new(
- $window, Game.media_path('menu_music.mp3'))
+ $window, Game.media_path('menu_music.ogg'))
end
def update
diff --git a/04-prototype-optimized/entities/bullet.rb b/04-prototype-optimized/entities/bullet.rb
index a119a92..9dbac09 100644
--- a/04-prototype-optimized/entities/bullet.rb
+++ b/04-prototype-optimized/entities/bullet.rb
@@ -10,7 +10,7 @@ def initialize(source_x, source_y, target_x, target_y)
if trajectory_length > MAX_DIST
@target_x, @target_y = point_at_distance(MAX_DIST)
end
- sound.play
+ sound.play if sound
end
def draw
@@ -55,7 +55,7 @@ def fire(speed)
def sound
@@sound ||= Gosu::Sample.new(
- $window, Game.media_path('fire.mp3'))
+ $window, Game.media_path('fire.ogg'))
end
def trajectory_length
diff --git a/04-prototype-optimized/entities/explosion.rb b/04-prototype-optimized/entities/explosion.rb
index 35db29b..217f43b 100644
--- a/04-prototype-optimized/entities/explosion.rb
+++ b/04-prototype-optimized/entities/explosion.rb
@@ -9,11 +9,11 @@ def animation
def sound
@@sound ||= Gosu::Sample.new(
- $window, Game.media_path('explosion.mp3'))
+ $window, Game.media_path('explosion.ogg'))
end
def initialize(x, y)
- sound.play
+ sound.play if sound
@x, @y = x, y
@current_frame = 0
end
diff --git a/04-prototype-optimized/entities/tank.rb b/04-prototype-optimized/entities/tank.rb
index 2dcfcd8..e596c04 100644
--- a/04-prototype-optimized/entities/tank.rb
+++ b/04-prototype-optimized/entities/tank.rb
@@ -13,12 +13,12 @@ def initialize(map)
@body_angle = 0.0
@gun_angle = 0.0
@last_shot = 0
- sound.volume = 0.3
+ sound.volume = 0.3 if sound
end
def sound
@@sound ||= Gosu::Song.new(
- $window, Game.media_path('tank_driving.mp3'))
+ $window, Game.media_path('tank_driving.ogg'))
end
def shoot(target_x, target_y)
@@ -48,9 +48,9 @@ def update(camera)
Gosu::KbW, Gosu::KbS, Gosu::KbA, Gosu::KbD)
if moving?
- sound.play(true)
+ sound.play(true) if sound
else
- sound.pause
+ sound.pause if sound
end
if $window.button_down?(Gosu::MsLeft)
diff --git a/04-prototype-optimized/states/menu_state.rb b/04-prototype-optimized/states/menu_state.rb
index c3ba398..6d9153f 100644
--- a/04-prototype-optimized/states/menu_state.rb
+++ b/04-prototype-optimized/states/menu_state.rb
@@ -10,18 +10,22 @@ def initialize
end
def enter
- music.play(true)
- music.volume = 1
+ if music
+ music.play(true)
+ music.volume = 1
+ end
end
def leave
- music.volume = 0
- music.stop
+ if music
+ music.volume = 0
+ music.stop
+ end
end
def music
@@music ||= Gosu::Song.new(
- $window, Game.media_path('menu_music.mp3'))
+ $window, Game.media_path('menu_music.ogg'))
end
def update
diff --git a/05-refactor/entities/components/bullet_sounds.rb b/05-refactor/entities/components/bullet_sounds.rb
index db09fde..099a0f8 100644
--- a/05-refactor/entities/components/bullet_sounds.rb
+++ b/05-refactor/entities/components/bullet_sounds.rb
@@ -1,14 +1,14 @@
class BulletSounds
class << self
def play
- sound.play
+ sound.play if sound
end
private
def sound
@@sound ||= Gosu::Sample.new(
- $window, Utils.media_path('fire.mp3'))
+ $window, Utils.media_path('fire.ogg'))
end
end
end
diff --git a/05-refactor/entities/components/explosion_sounds.rb b/05-refactor/entities/components/explosion_sounds.rb
index e3b3176..e315490 100644
--- a/05-refactor/entities/components/explosion_sounds.rb
+++ b/05-refactor/entities/components/explosion_sounds.rb
@@ -1,14 +1,14 @@
class ExplosionSounds
class << self
def play
- sound.play
+ sound.play if sound
end
private
def sound
@@sound ||= Gosu::Sample.new(
- $window, Utils.media_path('explosion.mp3'))
+ $window, Utils.media_path('explosion.ogg'))
end
end
end
diff --git a/05-refactor/entities/components/tank_sounds.rb b/05-refactor/entities/components/tank_sounds.rb
index 6fdb09d..df32608 100644
--- a/05-refactor/entities/components/tank_sounds.rb
+++ b/05-refactor/entities/components/tank_sounds.rb
@@ -4,7 +4,7 @@ def update
if @driving && @driving.paused?
@driving.resume
elsif @driving.nil?
- @driving = driving_sound.play(1, 1, true)
+ @driving = driving_sound.play(1, 1, true) if driving_sound
end
else
if @driving && @driving.playing?
@@ -14,14 +14,14 @@ def update
end
def collide
- crash_sound.play(1, 0.25, false)
+ crash_sound.play(1, 0.25, false) if crash_sound
end
private
def driving_sound
@@driving_sound ||= Gosu::Sample.new(
- $window, Utils.media_path('tank_driving.mp3'))
+ $window, Utils.media_path('tank_driving.ogg'))
end
def crash_sound
diff --git a/06-physics/entities/components/bullet_sounds.rb b/06-physics/entities/components/bullet_sounds.rb
index db09fde..099a0f8 100644
--- a/06-physics/entities/components/bullet_sounds.rb
+++ b/06-physics/entities/components/bullet_sounds.rb
@@ -1,14 +1,14 @@
class BulletSounds
class << self
def play
- sound.play
+ sound.play if sound
end
private
def sound
@@sound ||= Gosu::Sample.new(
- $window, Utils.media_path('fire.mp3'))
+ $window, Utils.media_path('fire.ogg'))
end
end
end
diff --git a/06-physics/entities/components/explosion_sounds.rb b/06-physics/entities/components/explosion_sounds.rb
index e3b3176..e315490 100644
--- a/06-physics/entities/components/explosion_sounds.rb
+++ b/06-physics/entities/components/explosion_sounds.rb
@@ -1,14 +1,14 @@
class ExplosionSounds
class << self
def play
- sound.play
+ sound.play if sound
end
private
def sound
@@sound ||= Gosu::Sample.new(
- $window, Utils.media_path('explosion.mp3'))
+ $window, Utils.media_path('explosion.ogg'))
end
end
end
diff --git a/06-physics/entities/components/tank_sounds.rb b/06-physics/entities/components/tank_sounds.rb
index de8a936..f486ddb 100644
--- a/06-physics/entities/components/tank_sounds.rb
+++ b/06-physics/entities/components/tank_sounds.rb
@@ -4,7 +4,7 @@ def update
if @driving && @driving.paused?
@driving.resume
elsif @driving.nil?
- @driving = driving_sound.play(0.3, 1, true)
+ @driving = driving_sound.play(0.3, 1, true) if driving_sound
end
else
if @driving && @driving.playing?
@@ -14,14 +14,14 @@ def update
end
def collide
- crash_sound.play(0.3, 0.25, false)
+ crash_sound.play(0.3, 0.25, false) if crash_sound
end
private
def driving_sound
@@driving_sound ||= Gosu::Sample.new(
- $window, Utils.media_path('tank_driving.mp3'))
+ $window, Utils.media_path('tank_driving.ogg'))
end
def crash_sound
diff --git a/06-physics/game_states/menu_state.rb b/06-physics/game_states/menu_state.rb
index d2b2b9d..85cb71b 100644
--- a/06-physics/game_states/menu_state.rb
+++ b/06-physics/game_states/menu_state.rb
@@ -10,18 +10,22 @@ def initialize
end
def enter
- music.play(true)
- music.volume = 1
+ if music
+ music.play(true)
+ music.volume = 1
+ end
end
def leave
- music.volume = 0
- music.stop
+ if music
+ music.volume = 0
+ music.stop
+ end
end
def music
@@music ||= Gosu::Song.new(
- $window, Utils.media_path('menu_music.mp3'))
+ $window, Utils.media_path('menu_music.ogg'))
end
def update
diff --git a/07-damage/entities/components/bullet_sounds.rb b/07-damage/entities/components/bullet_sounds.rb
index db09fde..099a0f8 100644
--- a/07-damage/entities/components/bullet_sounds.rb
+++ b/07-damage/entities/components/bullet_sounds.rb
@@ -1,14 +1,14 @@
class BulletSounds
class << self
def play
- sound.play
+ sound.play if sound
end
private
def sound
@@sound ||= Gosu::Sample.new(
- $window, Utils.media_path('fire.mp3'))
+ $window, Utils.media_path('fire.ogg'))
end
end
end
diff --git a/07-damage/entities/components/explosion_sounds.rb b/07-damage/entities/components/explosion_sounds.rb
index e3b3176..e315490 100644
--- a/07-damage/entities/components/explosion_sounds.rb
+++ b/07-damage/entities/components/explosion_sounds.rb
@@ -1,14 +1,14 @@
class ExplosionSounds
class << self
def play
- sound.play
+ sound.play if sound
end
private
def sound
@@sound ||= Gosu::Sample.new(
- $window, Utils.media_path('explosion.mp3'))
+ $window, Utils.media_path('explosion.ogg'))
end
end
end
diff --git a/07-damage/entities/components/tank_sounds.rb b/07-damage/entities/components/tank_sounds.rb
index b58f169..26a9ec5 100644
--- a/07-damage/entities/components/tank_sounds.rb
+++ b/07-damage/entities/components/tank_sounds.rb
@@ -4,7 +4,7 @@ def update
if @driving && @driving.paused?
@driving.resume
elsif @driving.nil?
- @driving = driving_sound.play(0.1, 1, true)
+ @driving = driving_sound.play(0.1, 1, true) if driving_sound
end
else
if @driving && @driving.playing?
@@ -14,14 +14,14 @@ def update
end
def collide
- crash_sound.play(0.3, 0.25, false)
+ crash_sound.play(0.3, 0.25, false) if crash_sound
end
private
def driving_sound
@@driving_sound ||= Gosu::Sample.new(
- $window, Utils.media_path('tank_driving.mp3'))
+ $window, Utils.media_path('tank_driving.ogg'))
end
def crash_sound
diff --git a/07-damage/game_states/menu_state.rb b/07-damage/game_states/menu_state.rb
index d2b2b9d..85cb71b 100644
--- a/07-damage/game_states/menu_state.rb
+++ b/07-damage/game_states/menu_state.rb
@@ -10,18 +10,22 @@ def initialize
end
def enter
- music.play(true)
- music.volume = 1
+ if music
+ music.play(true)
+ music.volume = 1
+ end
end
def leave
- music.volume = 0
- music.stop
+ if music
+ music.volume = 0
+ music.stop
+ end
end
def music
@@music ||= Gosu::Song.new(
- $window, Utils.media_path('menu_music.mp3'))
+ $window, Utils.media_path('menu_music.ogg'))
end
def update
diff --git a/08-ai/entities/components/bullet_sounds.rb b/08-ai/entities/components/bullet_sounds.rb
index db09fde..099a0f8 100644
--- a/08-ai/entities/components/bullet_sounds.rb
+++ b/08-ai/entities/components/bullet_sounds.rb
@@ -1,14 +1,14 @@
class BulletSounds
class << self
def play
- sound.play
+ sound.play if sound
end
private
def sound
@@sound ||= Gosu::Sample.new(
- $window, Utils.media_path('fire.mp3'))
+ $window, Utils.media_path('fire.ogg'))
end
end
end
diff --git a/08-ai/entities/components/explosion_sounds.rb b/08-ai/entities/components/explosion_sounds.rb
index e3b3176..e315490 100644
--- a/08-ai/entities/components/explosion_sounds.rb
+++ b/08-ai/entities/components/explosion_sounds.rb
@@ -1,14 +1,14 @@
class ExplosionSounds
class << self
def play
- sound.play
+ sound.play if sound
end
private
def sound
@@sound ||= Gosu::Sample.new(
- $window, Utils.media_path('explosion.mp3'))
+ $window, Utils.media_path('explosion.ogg'))
end
end
end
diff --git a/08-ai/entities/components/tank_sounds.rb b/08-ai/entities/components/tank_sounds.rb
index b58f169..26a9ec5 100644
--- a/08-ai/entities/components/tank_sounds.rb
+++ b/08-ai/entities/components/tank_sounds.rb
@@ -4,7 +4,7 @@ def update
if @driving && @driving.paused?
@driving.resume
elsif @driving.nil?
- @driving = driving_sound.play(0.1, 1, true)
+ @driving = driving_sound.play(0.1, 1, true) if driving_sound
end
else
if @driving && @driving.playing?
@@ -14,14 +14,14 @@ def update
end
def collide
- crash_sound.play(0.3, 0.25, false)
+ crash_sound.play(0.3, 0.25, false) if crash_sound
end
private
def driving_sound
@@driving_sound ||= Gosu::Sample.new(
- $window, Utils.media_path('tank_driving.mp3'))
+ $window, Utils.media_path('tank_driving.ogg'))
end
def crash_sound
diff --git a/08-ai/game_states/menu_state.rb b/08-ai/game_states/menu_state.rb
index d2b2b9d..85cb71b 100644
--- a/08-ai/game_states/menu_state.rb
+++ b/08-ai/game_states/menu_state.rb
@@ -10,18 +10,22 @@ def initialize
end
def enter
- music.play(true)
- music.volume = 1
+ if music
+ music.play(true)
+ music.volume = 1
+ end
end
def leave
- music.volume = 0
- music.stop
+ if music
+ music.volume = 0
+ music.stop
+ end
end
def music
@@music ||= Gosu::Song.new(
- $window, Utils.media_path('menu_music.mp3'))
+ $window, Utils.media_path('menu_music.ogg'))
end
def update
diff --git a/09-polishing/entities/components/bullet_sounds.rb b/09-polishing/entities/components/bullet_sounds.rb
index 8f3c9b6..bbfce7c 100644
--- a/09-polishing/entities/components/bullet_sounds.rb
+++ b/09-polishing/entities/components/bullet_sounds.rb
@@ -2,14 +2,14 @@ class BulletSounds
class << self
def play(object, camera)
volume, pan = Utils.volume_and_pan(object, camera)
- sound.play(object.object_id, pan, volume)
+ sound.play(object.object_id, pan, volume) if sound
end
private
def sound
@@sound ||= StereoSample.new(
- $window, Utils.media_path('fire.mp3'))
+ $window, Utils.media_path('fire.ogg'))
end
end
end
diff --git a/09-polishing/entities/components/explosion_sounds.rb b/09-polishing/entities/components/explosion_sounds.rb
index 019ed85..c58ad41 100644
--- a/09-polishing/entities/components/explosion_sounds.rb
+++ b/09-polishing/entities/components/explosion_sounds.rb
@@ -2,14 +2,14 @@ class ExplosionSounds
class << self
def play(object, camera)
volume, pan = Utils.volume_and_pan(object, camera)
- sound.play(object.object_id, pan, volume)
+ sound.play(object.object_id, pan, volume) if sound
end
private
def sound
@@sound ||= StereoSample.new(
- $window, Utils.media_path('explosion.mp3'))
+ $window, Utils.media_path('explosion.ogg'))
end
end
end
diff --git a/09-polishing/entities/components/tank_sounds.rb b/09-polishing/entities/components/tank_sounds.rb
index 037b3b0..c14108b 100644
--- a/09-polishing/entities/components/tank_sounds.rb
+++ b/09-polishing/entities/components/tank_sounds.rb
@@ -10,15 +10,19 @@ def update
move_volume = Utils.volume(
object, @object_pool.camera)
pan = Utils.pan(object, @object_pool.camera)
- if driving_sound.paused?(id)
- driving_sound.resume(id)
- elsif driving_sound.stopped?(id)
- driving_sound.play(id, pan, 0.5, 1, true)
+ if driving_sound
+ if driving_sound.paused?(id)
+ driving_sound.resume(id)
+ elsif driving_sound.stopped?(id)
+ driving_sound.play(id, pan, 0.5, 1, true)
+ end
+ driving_sound.volume_and_pan(id, move_volume * 0.5, pan)
end
- driving_sound.volume_and_pan(id, move_volume * 0.5, pan)
else
- if driving_sound.playing?(id)
- driving_sound.pause(id)
+ if driving_sound
+ if driving_sound.playing?(id)
+ driving_sound.pause(id)
+ end
end
end
end
@@ -26,14 +30,14 @@ def update
def collide
vol, pan = Utils.volume_and_pan(
object, @object_pool.camera)
- crash_sound.play(self.object_id, pan, vol, 1, false)
+ crash_sound.play(self.object_id, pan, vol, 1, false) if crash_sound
end
private
def driving_sound
@@driving_sound ||= StereoSample.new(
- $window, Utils.media_path('tank_driving.mp3'))
+ $window, Utils.media_path('tank_driving.ogg'))
end
def crash_sound
diff --git a/09-polishing/game_states/menu_state.rb b/09-polishing/game_states/menu_state.rb
index d2b2b9d..85cb71b 100644
--- a/09-polishing/game_states/menu_state.rb
+++ b/09-polishing/game_states/menu_state.rb
@@ -10,18 +10,22 @@ def initialize
end
def enter
- music.play(true)
- music.volume = 1
+ if music
+ music.play(true)
+ music.volume = 1
+ end
end
def leave
- music.volume = 0
- music.stop
+ if music
+ music.volume = 0
+ music.stop
+ end
end
def music
@@music ||= Gosu::Song.new(
- $window, Utils.media_path('menu_music.mp3'))
+ $window, Utils.media_path('menu_music.ogg'))
end
def update
diff --git a/10-partitioning/entities/components/bullet_sounds.rb b/10-partitioning/entities/components/bullet_sounds.rb
index 8f3c9b6..bbfce7c 100644
--- a/10-partitioning/entities/components/bullet_sounds.rb
+++ b/10-partitioning/entities/components/bullet_sounds.rb
@@ -2,14 +2,14 @@ class BulletSounds
class << self
def play(object, camera)
volume, pan = Utils.volume_and_pan(object, camera)
- sound.play(object.object_id, pan, volume)
+ sound.play(object.object_id, pan, volume) if sound
end
private
def sound
@@sound ||= StereoSample.new(
- $window, Utils.media_path('fire.mp3'))
+ $window, Utils.media_path('fire.ogg'))
end
end
end
diff --git a/10-partitioning/entities/components/explosion_sounds.rb b/10-partitioning/entities/components/explosion_sounds.rb
index 019ed85..c58ad41 100644
--- a/10-partitioning/entities/components/explosion_sounds.rb
+++ b/10-partitioning/entities/components/explosion_sounds.rb
@@ -2,14 +2,14 @@ class ExplosionSounds
class << self
def play(object, camera)
volume, pan = Utils.volume_and_pan(object, camera)
- sound.play(object.object_id, pan, volume)
+ sound.play(object.object_id, pan, volume) if sound
end
private
def sound
@@sound ||= StereoSample.new(
- $window, Utils.media_path('explosion.mp3'))
+ $window, Utils.media_path('explosion.ogg'))
end
end
end
diff --git a/10-partitioning/entities/components/tank_sounds.rb b/10-partitioning/entities/components/tank_sounds.rb
index 037b3b0..c14108b 100644
--- a/10-partitioning/entities/components/tank_sounds.rb
+++ b/10-partitioning/entities/components/tank_sounds.rb
@@ -10,15 +10,19 @@ def update
move_volume = Utils.volume(
object, @object_pool.camera)
pan = Utils.pan(object, @object_pool.camera)
- if driving_sound.paused?(id)
- driving_sound.resume(id)
- elsif driving_sound.stopped?(id)
- driving_sound.play(id, pan, 0.5, 1, true)
+ if driving_sound
+ if driving_sound.paused?(id)
+ driving_sound.resume(id)
+ elsif driving_sound.stopped?(id)
+ driving_sound.play(id, pan, 0.5, 1, true)
+ end
+ driving_sound.volume_and_pan(id, move_volume * 0.5, pan)
end
- driving_sound.volume_and_pan(id, move_volume * 0.5, pan)
else
- if driving_sound.playing?(id)
- driving_sound.pause(id)
+ if driving_sound
+ if driving_sound.playing?(id)
+ driving_sound.pause(id)
+ end
end
end
end
@@ -26,14 +30,14 @@ def update
def collide
vol, pan = Utils.volume_and_pan(
object, @object_pool.camera)
- crash_sound.play(self.object_id, pan, vol, 1, false)
+ crash_sound.play(self.object_id, pan, vol, 1, false) if crash_sound
end
private
def driving_sound
@@driving_sound ||= StereoSample.new(
- $window, Utils.media_path('tank_driving.mp3'))
+ $window, Utils.media_path('tank_driving.ogg'))
end
def crash_sound
diff --git a/10-partitioning/game_states/menu_state.rb b/10-partitioning/game_states/menu_state.rb
index d2b2b9d..85cb71b 100644
--- a/10-partitioning/game_states/menu_state.rb
+++ b/10-partitioning/game_states/menu_state.rb
@@ -10,18 +10,22 @@ def initialize
end
def enter
- music.play(true)
- music.volume = 1
+ if music
+ music.play(true)
+ music.volume = 1
+ end
end
def leave
- music.volume = 0
- music.stop
+ if music
+ music.volume = 0
+ music.stop
+ end
end
def music
@@music ||= Gosu::Song.new(
- $window, Utils.media_path('menu_music.mp3'))
+ $window, Utils.media_path('menu_music.ogg'))
end
def update
diff --git a/11-powerups/entities/components/bullet_sounds.rb b/11-powerups/entities/components/bullet_sounds.rb
index 8f3c9b6..bbfce7c 100644
--- a/11-powerups/entities/components/bullet_sounds.rb
+++ b/11-powerups/entities/components/bullet_sounds.rb
@@ -2,14 +2,14 @@ class BulletSounds
class << self
def play(object, camera)
volume, pan = Utils.volume_and_pan(object, camera)
- sound.play(object.object_id, pan, volume)
+ sound.play(object.object_id, pan, volume) if sound
end
private
def sound
@@sound ||= StereoSample.new(
- $window, Utils.media_path('fire.mp3'))
+ $window, Utils.media_path('fire.ogg'))
end
end
end
diff --git a/11-powerups/entities/components/explosion_sounds.rb b/11-powerups/entities/components/explosion_sounds.rb
index 019ed85..c58ad41 100644
--- a/11-powerups/entities/components/explosion_sounds.rb
+++ b/11-powerups/entities/components/explosion_sounds.rb
@@ -2,14 +2,14 @@ class ExplosionSounds
class << self
def play(object, camera)
volume, pan = Utils.volume_and_pan(object, camera)
- sound.play(object.object_id, pan, volume)
+ sound.play(object.object_id, pan, volume) if sound
end
private
def sound
@@sound ||= StereoSample.new(
- $window, Utils.media_path('explosion.mp3'))
+ $window, Utils.media_path('explosion.ogg'))
end
end
end
diff --git a/11-powerups/entities/components/powerup_sounds.rb b/11-powerups/entities/components/powerup_sounds.rb
index 654cfd4..b3bc931 100644
--- a/11-powerups/entities/components/powerup_sounds.rb
+++ b/11-powerups/entities/components/powerup_sounds.rb
@@ -2,14 +2,14 @@ class PowerupSounds
class << self
def play(object, camera)
volume, pan = Utils.volume_and_pan(object, camera)
- sound.play(object.object_id, pan, volume)
+ sound.play(object.object_id, pan, volume) if sound
end
private
def sound
@@sound ||= StereoSample.new(
- $window, Utils.media_path('powerup.mp3'))
+ $window, Utils.media_path('powerup.ogg'))
end
end
end
diff --git a/11-powerups/entities/components/tank_sounds.rb b/11-powerups/entities/components/tank_sounds.rb
index 037b3b0..c14108b 100644
--- a/11-powerups/entities/components/tank_sounds.rb
+++ b/11-powerups/entities/components/tank_sounds.rb
@@ -10,15 +10,19 @@ def update
move_volume = Utils.volume(
object, @object_pool.camera)
pan = Utils.pan(object, @object_pool.camera)
- if driving_sound.paused?(id)
- driving_sound.resume(id)
- elsif driving_sound.stopped?(id)
- driving_sound.play(id, pan, 0.5, 1, true)
+ if driving_sound
+ if driving_sound.paused?(id)
+ driving_sound.resume(id)
+ elsif driving_sound.stopped?(id)
+ driving_sound.play(id, pan, 0.5, 1, true)
+ end
+ driving_sound.volume_and_pan(id, move_volume * 0.5, pan)
end
- driving_sound.volume_and_pan(id, move_volume * 0.5, pan)
else
- if driving_sound.playing?(id)
- driving_sound.pause(id)
+ if driving_sound
+ if driving_sound.playing?(id)
+ driving_sound.pause(id)
+ end
end
end
end
@@ -26,14 +30,14 @@ def update
def collide
vol, pan = Utils.volume_and_pan(
object, @object_pool.camera)
- crash_sound.play(self.object_id, pan, vol, 1, false)
+ crash_sound.play(self.object_id, pan, vol, 1, false) if crash_sound
end
private
def driving_sound
@@driving_sound ||= StereoSample.new(
- $window, Utils.media_path('tank_driving.mp3'))
+ $window, Utils.media_path('tank_driving.ogg'))
end
def crash_sound
diff --git a/11-powerups/game_states/menu_state.rb b/11-powerups/game_states/menu_state.rb
index d2b2b9d..85cb71b 100644
--- a/11-powerups/game_states/menu_state.rb
+++ b/11-powerups/game_states/menu_state.rb
@@ -10,18 +10,22 @@ def initialize
end
def enter
- music.play(true)
- music.volume = 1
+ if music
+ music.play(true)
+ music.volume = 1
+ end
end
def leave
- music.volume = 0
- music.stop
+ if music
+ music.volume = 0
+ music.stop
+ end
end
def music
@@music ||= Gosu::Song.new(
- $window, Utils.media_path('menu_music.mp3'))
+ $window, Utils.media_path('menu_music.ogg'))
end
def update
diff --git a/12-stats/entities/components/bullet_sounds.rb b/12-stats/entities/components/bullet_sounds.rb
index 8f3c9b6..bbfce7c 100644
--- a/12-stats/entities/components/bullet_sounds.rb
+++ b/12-stats/entities/components/bullet_sounds.rb
@@ -2,14 +2,14 @@ class BulletSounds
class << self
def play(object, camera)
volume, pan = Utils.volume_and_pan(object, camera)
- sound.play(object.object_id, pan, volume)
+ sound.play(object.object_id, pan, volume) if sound
end
private
def sound
@@sound ||= StereoSample.new(
- $window, Utils.media_path('fire.mp3'))
+ $window, Utils.media_path('fire.ogg'))
end
end
end
diff --git a/12-stats/entities/components/explosion_sounds.rb b/12-stats/entities/components/explosion_sounds.rb
index 019ed85..c58ad41 100644
--- a/12-stats/entities/components/explosion_sounds.rb
+++ b/12-stats/entities/components/explosion_sounds.rb
@@ -2,14 +2,14 @@ class ExplosionSounds
class << self
def play(object, camera)
volume, pan = Utils.volume_and_pan(object, camera)
- sound.play(object.object_id, pan, volume)
+ sound.play(object.object_id, pan, volume) if sound
end
private
def sound
@@sound ||= StereoSample.new(
- $window, Utils.media_path('explosion.mp3'))
+ $window, Utils.media_path('explosion.ogg'))
end
end
end
diff --git a/12-stats/entities/components/powerup_sounds.rb b/12-stats/entities/components/powerup_sounds.rb
index 654cfd4..b3bc931 100644
--- a/12-stats/entities/components/powerup_sounds.rb
+++ b/12-stats/entities/components/powerup_sounds.rb
@@ -2,14 +2,14 @@ class PowerupSounds
class << self
def play(object, camera)
volume, pan = Utils.volume_and_pan(object, camera)
- sound.play(object.object_id, pan, volume)
+ sound.play(object.object_id, pan, volume) if sound
end
private
def sound
@@sound ||= StereoSample.new(
- $window, Utils.media_path('powerup.mp3'))
+ $window, Utils.media_path('powerup.ogg'))
end
end
end
diff --git a/12-stats/entities/components/tank_sounds.rb b/12-stats/entities/components/tank_sounds.rb
index 037b3b0..c14108b 100644
--- a/12-stats/entities/components/tank_sounds.rb
+++ b/12-stats/entities/components/tank_sounds.rb
@@ -10,15 +10,19 @@ def update
move_volume = Utils.volume(
object, @object_pool.camera)
pan = Utils.pan(object, @object_pool.camera)
- if driving_sound.paused?(id)
- driving_sound.resume(id)
- elsif driving_sound.stopped?(id)
- driving_sound.play(id, pan, 0.5, 1, true)
+ if driving_sound
+ if driving_sound.paused?(id)
+ driving_sound.resume(id)
+ elsif driving_sound.stopped?(id)
+ driving_sound.play(id, pan, 0.5, 1, true)
+ end
+ driving_sound.volume_and_pan(id, move_volume * 0.5, pan)
end
- driving_sound.volume_and_pan(id, move_volume * 0.5, pan)
else
- if driving_sound.playing?(id)
- driving_sound.pause(id)
+ if driving_sound
+ if driving_sound.playing?(id)
+ driving_sound.pause(id)
+ end
end
end
end
@@ -26,14 +30,14 @@ def update
def collide
vol, pan = Utils.volume_and_pan(
object, @object_pool.camera)
- crash_sound.play(self.object_id, pan, vol, 1, false)
+ crash_sound.play(self.object_id, pan, vol, 1, false) if crash_sound
end
private
def driving_sound
@@driving_sound ||= StereoSample.new(
- $window, Utils.media_path('tank_driving.mp3'))
+ $window, Utils.media_path('tank_driving.ogg'))
end
def crash_sound
diff --git a/12-stats/game_states/menu_state.rb b/12-stats/game_states/menu_state.rb
index 73b451d..b158dae 100644
--- a/12-stats/game_states/menu_state.rb
+++ b/12-stats/game_states/menu_state.rb
@@ -10,18 +10,22 @@ def initialize
end
def enter
- music.play(true)
- music.volume = 1
+ if music
+ music.play(true)
+ music.volume = 1
+ end
end
def leave
- music.volume = 0
- music.stop
+ if music
+ music.volume = 0
+ music.stop
+ end
end
def music
@@music ||= Gosu::Song.new(
- $window, Utils.media_path('menu_music.mp3'))
+ $window, Utils.media_path('menu_music.ogg'))
end
def update
diff --git a/12-stats/game_states/pause_state.rb b/12-stats/game_states/pause_state.rb
index 16aa5e7..db8cb49 100644
--- a/12-stats/game_states/pause_state.rb
+++ b/12-stats/game_states/pause_state.rb
@@ -10,21 +10,25 @@ def initialize
end
def enter
- music.play(true)
- music.volume = 1
+ if music
+ music.play(true)
+ music.volume = 1
+ end
@score_display = ScoreDisplay.new(@play_state.object_pool)
@mouse_coords = [$window.mouse_x, $window.mouse_y]
end
def leave
- music.volume = 0
- music.stop
+ if music
+ music.volume = 0
+ music.stop
+ end
$window.mouse_x, $window.mouse_y = @mouse_coords
end
def music
@@music ||= Gosu::Song.new(
- $window, Utils.media_path('menu_music.mp3'))
+ $window, Utils.media_path('menu_music.ogg'))
end
def draw
diff --git a/13-advanced-ai/entities/components/bullet_sounds.rb b/13-advanced-ai/entities/components/bullet_sounds.rb
index 8f3c9b6..bbfce7c 100644
--- a/13-advanced-ai/entities/components/bullet_sounds.rb
+++ b/13-advanced-ai/entities/components/bullet_sounds.rb
@@ -2,14 +2,14 @@ class BulletSounds
class << self
def play(object, camera)
volume, pan = Utils.volume_and_pan(object, camera)
- sound.play(object.object_id, pan, volume)
+ sound.play(object.object_id, pan, volume) if sound
end
private
def sound
@@sound ||= StereoSample.new(
- $window, Utils.media_path('fire.mp3'))
+ $window, Utils.media_path('fire.ogg'))
end
end
end
diff --git a/13-advanced-ai/entities/components/explosion_sounds.rb b/13-advanced-ai/entities/components/explosion_sounds.rb
index 019ed85..c58ad41 100644
--- a/13-advanced-ai/entities/components/explosion_sounds.rb
+++ b/13-advanced-ai/entities/components/explosion_sounds.rb
@@ -2,14 +2,14 @@ class ExplosionSounds
class << self
def play(object, camera)
volume, pan = Utils.volume_and_pan(object, camera)
- sound.play(object.object_id, pan, volume)
+ sound.play(object.object_id, pan, volume) if sound
end
private
def sound
@@sound ||= StereoSample.new(
- $window, Utils.media_path('explosion.mp3'))
+ $window, Utils.media_path('explosion.ogg'))
end
end
end
diff --git a/13-advanced-ai/entities/components/powerup_sounds.rb b/13-advanced-ai/entities/components/powerup_sounds.rb
index 654cfd4..b3bc931 100644
--- a/13-advanced-ai/entities/components/powerup_sounds.rb
+++ b/13-advanced-ai/entities/components/powerup_sounds.rb
@@ -2,14 +2,14 @@ class PowerupSounds
class << self
def play(object, camera)
volume, pan = Utils.volume_and_pan(object, camera)
- sound.play(object.object_id, pan, volume)
+ sound.play(object.object_id, pan, volume) if sound
end
private
def sound
@@sound ||= StereoSample.new(
- $window, Utils.media_path('powerup.mp3'))
+ $window, Utils.media_path('powerup.ogg'))
end
end
end
diff --git a/13-advanced-ai/entities/components/tank_sounds.rb b/13-advanced-ai/entities/components/tank_sounds.rb
index 037b3b0..36f448d 100644
--- a/13-advanced-ai/entities/components/tank_sounds.rb
+++ b/13-advanced-ai/entities/components/tank_sounds.rb
@@ -10,15 +10,19 @@ def update
move_volume = Utils.volume(
object, @object_pool.camera)
pan = Utils.pan(object, @object_pool.camera)
- if driving_sound.paused?(id)
- driving_sound.resume(id)
- elsif driving_sound.stopped?(id)
- driving_sound.play(id, pan, 0.5, 1, true)
+ if driving_sound
+ if driving_sound.paused?(id)
+ driving_sound.resume(id)
+ elsif driving_sound.stopped?(id)
+ driving_sound.play(id, pan, 0.5, 1, true)
+ end
end
driving_sound.volume_and_pan(id, move_volume * 0.5, pan)
else
- if driving_sound.playing?(id)
- driving_sound.pause(id)
+ if driving_sound
+ if driving_sound.playing?(id)
+ driving_sound.pause(id)
+ end
end
end
end
@@ -26,14 +30,14 @@ def update
def collide
vol, pan = Utils.volume_and_pan(
object, @object_pool.camera)
- crash_sound.play(self.object_id, pan, vol, 1, false)
+ crash_sound.play(self.object_id, pan, vol, 1, false) if crash_sound
end
private
def driving_sound
@@driving_sound ||= StereoSample.new(
- $window, Utils.media_path('tank_driving.mp3'))
+ $window, Utils.media_path('tank_driving.ogg'))
end
def crash_sound
diff --git a/13-advanced-ai/game_states/menu_state.rb b/13-advanced-ai/game_states/menu_state.rb
index a3e3306..822b7df 100644
--- a/13-advanced-ai/game_states/menu_state.rb
+++ b/13-advanced-ai/game_states/menu_state.rb
@@ -10,18 +10,22 @@ def initialize
end
def enter
- music.play(true)
- music.volume = 1
+ if music
+ music.play(true)
+ music.volume = 1
+ end
end
def leave
- music.volume = 0
- music.stop
+ if music
+ music.volume = 0
+ music.stop
+ end
end
def music
@@music ||= Gosu::Song.new(
- $window, Utils.media_path('menu_music.mp3'))
+ $window, Utils.media_path('menu_music.ogg'))
end
def update
diff --git a/13-advanced-ai/game_states/pause_state.rb b/13-advanced-ai/game_states/pause_state.rb
index 955d5a5..977cc73 100644
--- a/13-advanced-ai/game_states/pause_state.rb
+++ b/13-advanced-ai/game_states/pause_state.rb
@@ -10,21 +10,25 @@ def initialize
end
def enter
- music.play(true)
- music.volume = 1
+ if music
+ music.play(true)
+ music.volume = 1
+ end
@score_display = ScoreDisplay.new(@play_state.object_pool)
@mouse_coords = [$window.mouse_x, $window.mouse_y]
end
def leave
- music.volume = 0
- music.stop
+ if music
+ music.volume = 0
+ music.stop
+ end
$window.mouse_x, $window.mouse_y = @mouse_coords
end
def music
@@music ||= Gosu::Song.new(
- $window, Utils.media_path('menu_music.mp3'))
+ $window, Utils.media_path('menu_music.ogg'))
end
def draw
diff --git a/Gemfile b/Gemfile
index 9e35cbd..ca38332 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,10 +1,10 @@
source 'https://rubygems.org'
-gem 'rake'
-gem 'gosu'
-gem 'gosu_texture_packer'
-gem 'gosu_tiled'
-gem 'perlin_noise'
-gem 'ruby-prof'
+gem 'rake', '~> 10.4.2'
+gem 'gosu', '~> 0.9.2'
+gem 'gosu_texture_packer', '~> 0.1.6'
+gem 'gosu_tiled', '~> 0.1.1'
+gem 'perlin_noise', '~> 0.1.2'
+gem 'ruby-prof', '~> 0.15.8'
-gem 'rspec', '~> 3.0.0'
+gem 'rspec', '~> 3.3.0'
diff --git a/Gemfile.lock b/Gemfile.lock
index 073ea82..cae8fb5 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -2,40 +2,44 @@ GEM
remote: https://rubygems.org/
specs:
diff-lcs (1.2.5)
- gosu (0.8.5)
- gosu_texture_packer (0.1.4)
+ gosu (0.9.2)
+ gosu_texture_packer (0.1.6)
gosu
json
rmagick
gosu_tiled (0.1.1)
gosu
json
- json (1.8.1)
+ json (1.8.3)
perlin_noise (0.1.2)
- rake (10.3.2)
- rmagick (2.13.3)
- rspec (3.0.0)
- rspec-core (~> 3.0.0)
- rspec-expectations (~> 3.0.0)
- rspec-mocks (~> 3.0.0)
- rspec-core (3.0.4)
- rspec-support (~> 3.0.0)
- rspec-expectations (3.0.4)
+ rake (10.4.2)
+ rmagick (2.15.4)
+ rspec (3.3.0)
+ rspec-core (~> 3.3.0)
+ rspec-expectations (~> 3.3.0)
+ rspec-mocks (~> 3.3.0)
+ rspec-core (3.3.2)
+ rspec-support (~> 3.3.0)
+ rspec-expectations (3.3.1)
diff-lcs (>= 1.2.0, < 2.0)
- rspec-support (~> 3.0.0)
- rspec-mocks (3.0.4)
- rspec-support (~> 3.0.0)
- rspec-support (3.0.4)
- ruby-prof (0.15.2)
+ rspec-support (~> 3.3.0)
+ rspec-mocks (3.3.2)
+ diff-lcs (>= 1.2.0, < 2.0)
+ rspec-support (~> 3.3.0)
+ rspec-support (3.3.0)
+ ruby-prof (0.15.8)
PLATFORMS
ruby
DEPENDENCIES
- gosu
- gosu_texture_packer
- gosu_tiled
- perlin_noise
- rake
- rspec (~> 3.0.0)
- ruby-prof
+ gosu (~> 0.9.2)
+ gosu_texture_packer (~> 0.1.6)
+ gosu_tiled (~> 0.1.1)
+ perlin_noise (~> 0.1.2)
+ rake (~> 10.4.2)
+ rspec (~> 3.3.0)
+ ruby-prof (~> 0.15.8)
+
+BUNDLED WITH
+ 1.10.6
diff --git a/media/explosion.ogg b/media/explosion.ogg
new file mode 100644
index 0000000..2e12c8a
Binary files /dev/null and b/media/explosion.ogg differ
diff --git a/media/fire.ogg b/media/fire.ogg
new file mode 100644
index 0000000..0830fc3
Binary files /dev/null and b/media/fire.ogg differ
diff --git a/media/menu_music.ogg b/media/menu_music.ogg
new file mode 100644
index 0000000..33205c3
Binary files /dev/null and b/media/menu_music.ogg differ
diff --git a/media/powerup.ogg b/media/powerup.ogg
new file mode 100644
index 0000000..d431314
Binary files /dev/null and b/media/powerup.ogg differ
diff --git a/media/tank_driving.ogg b/media/tank_driving.ogg
new file mode 100644
index 0000000..9d9e008
Binary files /dev/null and b/media/tank_driving.ogg differ