while(1) means that the loop never ending, it is always true (1).
remove the if () and the while(), and use:
while (key_space) // it is true if the space key is pressed
{
...
}