2016-04-14 03:16:15

I don't know how to code a speaker test, and I also want to make difficulty levels for my game. not sure where to start with either one

2016-04-14 06:55:18

I get the impression that most speaker tests just play a single file, already made in stereo.
But I never feel like making one of those is worth it.

The questions you need to answer first, though:
- Do you know how to play sounds?
- Do you know the properties of the sound object?
- Do you understand how code is executed well enough to combine these?
For the first two, the sound section of the manual (reference -> foundation layer -> object reference -> sound) has everything you need.
The last one, I think, is where most beginners get stuck.

Here's an example solution:

(I recommend trying to figure it out for at least another minute, first, though.)

void speaker_test() {
sound test;

// Load the narrator saying "left". You can replace this with tts, if you prefer.
test.load("left.wav");
test.play_wait();

// Using an arbitrary sound:
test.stream("test.wav");
test.pan=-100;
test.play_wait();

// Say "right". Again, you can replace the following two lines with tts if you prefer.
test.stream("right.wav");
test.pan=0;
test.play_wait();

test.stream("test.wav");
test.pan=100;
test.play_wait();
}

(You could also just use the "left" and "right" recordings, but I generally don't have those.)


As for difficulty settings, that is a good deal more complicated. It depends on the style of game, as well as all the underlying details of how it works. If it's a game with enemies, would difficulty make them stronger? Faster? Smarter? More numerous? Harder to predict? If it isn't, then what would you expect would make the game harder/easier?
If all you want to do is let the player select a difficulty, then remember it, something like this might work. It isn't my favorite solution, but it's probably the simplest if you don't want to make your own menus from scratch:

#include "dynamic_menu.bgt"

// There are two ways you could set up constants for this. This is probably the easiest, but it'd make me kinda nervous using it for something like this:

enum difficulties {
 easy, normal, hard, hardest
};

// Create a variable to keep track of the difficulty. We're using an int, since it's often useful to put the difficulty into some calculations at some point.
int difficulty=normal;

// This function returns true if the player successfully picked a difficulty, false if they hit escape or if an error occurred.
bool select_difficulty() {
dynamic_menu difmenu;

// I'll use tts for these. Using recordings instead is a matter of removing the _tts from each one, and replacing the text between quotes with the appropriate filename.
difmenu.add_item_tts("easy", "" + easy);
difmenu.add_item_tts("normal", "" + normal);
difmenu.add_item_tts("hard", "" + hard);
difmenu.add_item_tts("hardest", "" + hardest);

int result=difmenu.run("Choose difficulty", true);
// If you used recordings instead, you'd do something like int result=difmenu.run("select_difficulty.wav", false);

// There is a shortcut, here, if you know that the values are in ascending order. The rest of this example will be the long way, but if you want, you could just do this:
// if(result<=0) return false;
// difficulty=result-1; // Assuming the difficulty constants start at 0, otherwise just say difficulty=result.
// return true;

// The longer way:
if(difmenu.get_item_name(result)=="") return false;

int new_difficulty=string_to_number(difmenu.get_item_name(result));

// Check for valid results. You can skip this part if you care more about having a number than that it is necessarily one of our constants.
if(new_difficulty!= easy and new_difficulty!=normal and new_difficulty!=hard and new_difficulty!=hardest) return false;

// At this point, everything worked, so we set the global variable to the selection, and the program will remember it until we change it again.
difficulty=new_difficulty;
return true;
}

That's actually a lot more complicated than I normally do it, but I normally use my own menu class, or at worst just code overly specific menus from scratch.


(Also, I typed these into the quick reply box, and haven't run it through the compiler. Misplaced parentheses and quotes are the bane of many a programmer. Well, blind ones without IDEs, anyway; I don't know if that's true for everyone else.)

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2016-04-14 07:46:26

about the difficulty, its the virus game in the help file. I wanted to make the enemies faster. I'm still a beginner, so I'm just getting used to all this. Are there anymore tutorials or help files other then what came with bgt?

2016-04-18 20:28:49 (edited by vlad25 2016-04-18 20:30:28)

hi.
ok, i'm not sure how does the difficulty system works  because i don't use to make games with difficulty levels.
the speaker test would be like this.
tts_voice v;
void test _speaker(string filename, bool sound_looping)
{
sound test;
test.load(filename);
if(sound_looping)
{
v.speak-wait("left");
for(int i=-100; i<100; i++)
{
test.pan=i;
test.play();
wait(50);
}
test.stop();
v.speak_wait("right");
}
else
{
v.speak_wait("left");
test.pan=-100;
test.play();
v.speak_wait("center");
test.pan=0;
test.play();
v.speak_wait("right");
test.pan=100;
test.play();
}
}

2016-04-19 21:10:14

Hey JWoodill21, if you'd like you can add me to skype at alexander16262 and I'll be happy to help you with whatever you might need.

The universe is a rain storm. We are droplets sent to quench the problems of the world, yet we are blown sideways by the winds of distractions.

2016-04-20 03:44:45

Ok. thanks. I'll add you now