mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-15 23:52:35 +00:00
Added require_all method to replace explicitly requiring every source file, added SoundManager and sound effects, added sound for shield/health regen
This commit is contained in:
32
lib/sound_effects/fade_in.rb
Normal file
32
lib/sound_effects/fade_in.rb
Normal file
@@ -0,0 +1,32 @@
|
||||
class IMICFPS
|
||||
class SoundEffect
|
||||
class FadeIn < SoundEffect
|
||||
def setup
|
||||
@start_time = Gosu.milliseconds
|
||||
@duration = @options[:duration] # in milliseconds
|
||||
@initial_volume = @options[:volume] ? @options[:volume] : 0.0
|
||||
@sound = @options[:sound]
|
||||
|
||||
raise "duration not specified!" unless @duration
|
||||
|
||||
@channel = @sound.play(calculate_volume)
|
||||
end
|
||||
|
||||
def ratio
|
||||
(Gosu.milliseconds - @start_time.to_f) / @duration
|
||||
end
|
||||
|
||||
def calculate_volume
|
||||
volume = (SoundManager.sfx_volume - @initial_volume) * ratio
|
||||
end
|
||||
|
||||
def update
|
||||
@channel.volume = calculate_volume
|
||||
end
|
||||
|
||||
def done?
|
||||
(Gosu.milliseconds - @start_time.to_f) / @duration >= 1.0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
22
lib/sound_effects/fade_in_and_out.rb
Normal file
22
lib/sound_effects/fade_in_and_out.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
class IMICFPS
|
||||
class SoundEffect
|
||||
class FadeInAndOut < FadeIn
|
||||
def setup
|
||||
@hang_time = @options[:hang_time] ? @options[:hang_time] : 0.0
|
||||
|
||||
super
|
||||
end
|
||||
|
||||
# TODO: Handle hang time
|
||||
def ratio
|
||||
r = super
|
||||
|
||||
if r < 0.5
|
||||
r * 2
|
||||
else
|
||||
2.0 - (r * 2)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
9
lib/sound_effects/fade_out.rb
Normal file
9
lib/sound_effects/fade_out.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
class IMICFPS
|
||||
class SoundEffect
|
||||
class FadeOut < FadeIn
|
||||
def ratio
|
||||
1.0 - super
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
25
lib/sound_effects/shield_regen.rb
Normal file
25
lib/sound_effects/shield_regen.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
class IMICFPS
|
||||
class SoundEffect
|
||||
class ShieldRegen < SoundEffect
|
||||
def setup
|
||||
@sound = SoundManager.sound("base", :shield_regen)
|
||||
@player = @options[:player]
|
||||
|
||||
@channel = @sound.play(0.0, 0.0, true)
|
||||
end
|
||||
|
||||
def ratio
|
||||
@player.health
|
||||
end
|
||||
|
||||
def update
|
||||
@channel.speed = 0.5 + ratio / 2
|
||||
@channel.volume = 1.0 - ratio / 2
|
||||
end
|
||||
|
||||
def done?
|
||||
ratio >= 1.0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user