Otto’s lines of dialouge

Now when we’re so close to the Final turn in of our game, we thought that we should make Otto talk. This feature is in the game just to tell the player of where Otto is. It is also in the game to make it more humorous. He will say stuff like “Get out of my house!”, “You should see my secret stash” and “Get your finger of my cane!”. These lines are all there to make Otto feel a little crazy. Some crazy laughs are thrown in to make the feeling a little more like we wanted it to be.
ottolines_550af763ddf2b33d42927c74 (1)
The way to put in sounds in SFML is to make a sound buffer, it will use a string of text to get the sound file from our assets and then we need a sound that will use that buffer to play it. But since we have 26 lines with Otto, I didn’t want to make a buffer for every line nor a sound for every line. That would take to long to code to make it worth while. It would also take up unnecessary space in the game.
What I did was a vector, a list of strings. All strings were the names of the sound files we were going to use. Then I made the sound buffer. We wanted the lines to spill out a little randomly so I used a randomization function from Visual Studios library. It would pick a number between 0 and 25. If it were to pick the number 0 it would buffer the first element in my vector. The vector also helped the randomization code since I would otherwise have to write a bunch of “if (this number) play this sound from that buffer”.
The rest is based on the distance between the player and the enemy and also time. Since we don’t have a lot of lines, we didn’t want the player to be bombarded with the same lines over and over again. Therefore Otto will only speak when the player is close to him. But that wasn’t enough to make him speak less. I put in a timer that was based on the gametime. When it exceeded a certain value Otto was allowed to speak. Then the timer is reset afterwards since Otto wouldn’t shut up otherwise.
What I learned from this was to more effectively assign sound files to buffers in order to play sounds. Using the vector saved time and effort and is also easier to handle for the program.

About Rasmus Lindgren

2014 Programming