【问题标题】:How can I translate this game loop into Linux (C) [closed]如何将此游戏循环转换为 Linux(C)[关闭]
【发布时间】:2020-05-22 12:54:34
【问题描述】:

所以我完全是初学者,我开始用 C 构建一个蛇游戏。我有一个字段,一个蛇体,我为它做了一个游戏循环,但它只适用于代码块,因为在 Linux 中没有 Windows .h 库,我无法真正翻译它。这是我的游戏循环小功能:

int ResetScreenPosition() {
HANDLE hOut;
COORD Position;
hOut = GetStdHandle(STD_OUTPUT_HANDLE);
Position.X = 0;
Position.Y = 0;
SetConsoleCursorPosition(hOut,Position);
}

我需要的只是光标需要回到位置(0,0),然后循环从那里继续。我的代码在代码块中工作,我想在 Linux 中编写它,文本编辑器:vim。

【问题讨论】:

标签: c linux vim codeblocks game-loop


【解决方案1】:

将光标位置设置为坐标 0,0 的最简单方法是:

void ResetScreenPosition(void){
  printf("\033[%d;%dH", 0, 0);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-01
    • 2013-10-23
    • 2018-03-26
    • 2020-11-25
    • 1970-01-01
    • 2019-05-28
    • 2021-12-16
    • 2023-04-01
    相关资源
    最近更新 更多