-
Notifications
You must be signed in to change notification settings - Fork 17
Arx 13 Basic Sound
In this part, I'm going to add some basic sound effects to the game.
Audacity - a free audio editor and recorder.
Sound effects are either synthesized from scratch, or some prerecorded samples are used.
I don't have any experience with sound synthesis, and the only thing I can recommend in this aspect is sfxr/bfxr programs, which are excellent chiptune effects generators (a Lua port of sfxr exists).
Speaking of sound samples, a couple of sites to look for them are OpenGameArt and Freesound. Another possibility is to look for instrument samples pack, bundled with music-making software (such as LMMS or Hydrogen). In dealing with samples, Audacity is immensely helpful tool. It allows to extract a part of the track, normalize volume, suppress certain frequencies, and so on. The number of available editing options is more than enough. Of course, instead of using someone else's samples, you can record your own. Such possibility should not be completely discarded: it is possible to get a decent result (enough to convey the idea) with minimal effort. For example, one of the sounds for this game is a tea cup hit by a pen, recorded on the internal microphone of my computer. Audacity makes the recording process simple enough. When dealing with samples, my advice to keep track of all file renames. They will be necessary to compile a proper credits list.
In LÖVE the sounds are stored and played by audio sources, which are
a part of the love.audio
module. Each source stores a single sound, which is usually specified on source creation. When needed, the sound can be played with the play
method of the source.
For now, I'm going to add sound effects only on ball-bricks collisions and I'll use different sounds for collisions with different brick types.
First, we need to load the sounds from a disk and initialize the audio sources. It is convenient to make the sources class variables, just like the tileset image.
local Brick = {}
.....
simple_break_sound = love.audio.newSource(
"sounds/recordered_glass_norm.ogg",
"static") --(*1)
armored_hit_sound = love.audio.newSource(
"sounds/qubodupImpactMetal_short_norm.ogg",
"static")
armored_break_sound = love.audio.newSource(
"sounds/armored_glass_break_short_norm.ogg",
"static")
ball_heavyarmored_sound = love.audio.newSource(
"sounds/cast_iron_clangs_11_short_norm.ogg",
"static")
(*1): "static" means that the sound is decompressed and stored in the memory, instead of being streamed from the file. This is the preferred method for the small sounds, that are played frequently.
A good place to play the sound is react_on_ball_collision
method.
The sound is chosen according to the brick type.
function Brick:react_on_ball_collision( another_shape, separating_vector )
local big_enough_overlap = 0.5
local dx, dy = separating_vector.x, separating_vector.y
if ( math.abs( dx ) > big_enough_overlap ) or
( math.abs( dy ) > big_enough_overlap ) then
if self:is_simple() then
self.to_destroy = true
simple_break_sound:play()
elseif self:is_armored() then
self:armored_to_scrathed()
armored_hit_sound:play()
elseif self:is_scratched() then
self:scrathed_to_cracked()
armored_hit_sound:play()
elseif self:is_cracked() then
self.to_destroy = true
armored_break_sound:play()
elseif self:is_heavyarmored() then
ball_heavyarmored_sound:play()
end
end
end
Sounds on other collisions: ball-wall, ball-platform and platform-wall -- can be coded in a similar way.
Feedback is crucial to improve the tutorial!
Let me know if you have any questions, critique, suggestions or just any other ideas.
Chapter 1: Prototype
- The Ball, The Brick, The Platform
- Game Objects as Lua Tables
- Bricks and Walls
- Detecting Collisions
- Resolving Collisions
- Levels
Appendix A: Storing Levels as Strings
Appendix B: Optimized Collision Detection (draft)
Chapter 2: General Code Structure
- Splitting Code into Several Files
- Loading Levels from Files
- Straightforward Gamestates
- Advanced Gamestates
- Basic Tiles
- Different Brick Types
- Basic Sound
- Game Over
Appendix C: Stricter Modules (draft)
Appendix D-1: Intro to Classes (draft)
Appendix D-2: Chapter 2 Using Classes.
Chapter 3 (deprecated): Details
- Improved Ball Rebounds
- Ball Launch From Platform (Two Objects Moving Together)
- Mouse Controls
- Spawning Bonuses
- Bonus Effects
- Glue Bonus
- Add New Ball Bonus
- Life and Next Level Bonuses
- Random Bonuses
- Menu Buttons
- Wall Tiles
- Side Panel
- Score
- Fonts
- More Sounds
- Final Screen
- Packaging
Appendix D: GUI Layouts
Appendix E: Love-release and Love.js
Beyond Programming: