OpenGL,我如何在到达目标后禁用glutSpecialFunc

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

本文关键字:目标 glutSpecialFunc OpenGL      更新时间:2023-10-16

我们正在OpenGL中制作一个迷宫式的程序,我们允许用户使用箭头键在屏幕上移动目的地。当用户使用箭头键到达目的地时,我想禁止用户再使用键盘。有没有办法让我做一些glutSpecialFunc.disable?以下是我想在if语句中禁用的地方:

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 */ 
    }
}

当玩家到达目标/目的地时,您可以简单地切换一个布尔值,并在myKeyboard()函数中检查该布尔值。

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

然后,当玩家到达目标/目的地时,简单地说game_done = true;

您可以将其称为lock_keyboard,而不是调用布尔值game_done,这可能在总体上更有意义。

然后,如果您想再次"激活"键盘,只需再次切换布尔值(将其设置为false)