Try taking 'while (key_any) {wait (1);}' out of your 'begin_level()' function.