Black
Black

Reputation: 89

OpenGL, How do I disable glutSpecialFunc after I reach a target?

We are making a Maze sort of program in OpenGL, and we allow the user to use the arrow keys in order to move a destination on the screen. When the user reaches that destination using the arrow keys, I want to disable the user from being able to use the keyboard anymore. Is there a way I can do some sort of glutSpecialFunc.disable? Here is where I want to put the disable in this if statement:

void myKeyboard(int keys, int x, int y){

switch(keys){ ...
    }
    if(location == G.source){
    cout<<"\nYou have completed the game";
    drawShortestPath();
  /* Enter disable code here */ 
    }
}

Upvotes: 0

Views: 352

Answers (1)

vallentin
vallentin

Reputation: 26157

You could simply toggle a boolean value when the player reaches the target/destination, and check that boolean value in your myKeyboard() function.

bool game_done = false;

void myKeyboard(int keys, int x, int y) {
    if (!game_done) {
        switch(keys) {
            // ... the rest of your code ...
        }
    }
}

Then when the player reaches the target/destination simply say game_done = true;

Instead of calling the boolean game_done you could instead call it something like lock_keyboard that would probably make more sense overall.

Then if you want to "activate" the keyboard again you simply toggle the boolean value again (set it to false)

Upvotes: 1

Related Questions