Things a bit
quiet? Sounds and Music add a lot of atmos to a map.
In mapping terms,
Sounds and Music are different things. Music is not 'heard' in the map as such.
It is like the music in a movie. Sounds are localised and have a position in
the map and are louder the nearer the Player is to them.
Sounds need to
be created in a similar way to objects, etc. If you intend using lots of them,
make a separate file. Name it mysounds.py or sonidos.py (to keep it in its
native language.) Yes, there is a source file Sounds.py . This
is the code to create sounds:
The filepath to the sound file in the Sounds folder is
included in the code. There are a lot of sound files and most of them have
Spanish names, but you soon figure it out. (golpe = hit for example). Exec the
file in cfg.py as before.
What happens after you have created the sound?
Nothing . You have to play it with a function
snd_bang1.Play(49000, 6000, -58000,0)
This code is usually
put in a function to correspond with an event. The first three arguments are
the map coords for the focus of the sound. The last 0 is the number of times the
file will be played, in this case once. (put 1 and you get 2 bangs.).
Some sounds are looped so that they can play continuously. For a looped sound
(wind,waterfall,fire, etc) put -1.
Sometimes you want a sound to play at
the Player position. You may not know where exactly the Player may be. You can
'get' the current Player position (and anything else for that matter) with
might be wondering why all the s have appeared. Why not just put charpos. Well,
the variable charpos has three values stored. You have to unpack them. So
charpos acesses the first value (the X coord), etc. You could do it like
can assign it to individual enemies or a whole Kind.
I haven't quite
figured all the args yet, but the first is the priority. If you have lots of
enemies in a group, set this value slightly lower for each one so that they
don't all try to play their music at once.
If there was a piece of
background music playing when you started fighting the Ork, it will not resume
after he is dead. His combat music will stop and there will be silence. I made a
little routine to restore the music (if any).
CurrentMusic="" # declare a variable and assign and empty
ChangeMusic(music): Bladex.KillMusic() Bladex.ExeMusicEvent(music)
#then, start all music
A word on global
variables. If you need to access a variable within the body of a function, you
must declare it as a global or it will not be recognised. With this func you can
change the music at any time and the identity of the music is stored in the
Then if you happen to have to interrupt the music for
any reason, you can restore it with:
if CurrentMusic != "":
# to clear the var if necessary
This func is most likely to be called after the death of an
enemy. Then, whatever music was playing when you started the fight will carry on
after enemy is dead. For this you have to tap into his ImDead function. I'll
come to that later.
You can either use the Sounds library, or you can
make your own. To use your own stuff, just alter the filepath to your own