I have been thinking about making an interactive program(game most likely) that has some composed music in the background. I don't know how i could do this without creating my own kind of time function. I've tried many things and have already made my own(im sure there already is one but its good practice for me =\) note function which is basically just void note(char letter[], int volume, length) and is being used with delay. Problem is: delay sucks. It stops everything. I'm very new to programing so if the solution is obvious don't do anything drastic =\. Thanks in advance. Il post some of my old code too, i cant think of anything and am very stuck =(
Code:
void note(char note[], int num);
int expo(int num, int power);
main()
{
clrscr();
getch();
return 0;
}
int expo(int num, int power)
{
int newnum=1;
if (power == 0)
return 1;
else
for (power; power>0; power--)
newnum *=num;
return newnum;
}
void note(char note[], int num)
{
if (strcmp(note, "C") == 0)
{
sound(16.35*expo(2, num));
delay(1000);
nosound();
}
if (strcmp(note, "C#") == 0)
{
sound(17.32*expo(2, num));
delay(1000);
nosound();
}
if (strcmp(note, "D") == 0)
{
sound(18.35*expo(2, num));
delay(1000);
nosound();
}
if (strcmp(note, "D#") == 0)
{
sound(19.45*expo(2, num));
delay(1000);
nosound();
}
if (strcmp(note, "E") == 0)
{
sound(20.60*expo(2, num));
delay(1000);
nosound();
}
if (strcmp(note, "F") == 0)
{
sound(21.83*expo(2, num));
delay(1000);
nosound();
}
if (strcmp(note, "F#") == 0)
{
sound(23.12*expo(2, num));
delay(1000);
nosound();
}
if (strcmp(note, "G") == 0)
{
sound(24.50*expo(2, num));
delay(1000);
nosound();
}
if (strcmp(note, "G#") == 0)
{
sound(25.96*expo(2, num));
delay(1000);
nosound();
}
if (strcmp(note, "A") == 0)
{
sound(27.50*expo(2, num));
delay(1000);
nosound();
}
if (strcmp(note, "Bb") == 0)
{
sound(29.14*expo(2, num));
delay(1000);
nosound();
}
if (strcmp(note, "B") == 0)
{
sound(30.87*expo(2, num));
delay(1000);
nosound();
}
}