2014-05-20 125 views
0

我正在努力通过一些ncurses教程,因为我想提高一些C编程技能。我正在教程模拟一个简单的网球比赛的点。C编程中的2D游戏编程

什么让我困惑的是:

* think of posX as relating to rows, the bottom of the screen will be at 
maximum Y value, so subtract 2, to set the racket near the bottom */ 
p.posX = SCREEN_HEIGHT - 2; 

/* think of posY as relating to a column, the middle of the screen will be 
at the middle of the screen_width, divided by 2, to set racket at center */ 
p.posY = SCREEN_WIDTH/2; 

说,球拍是向左移动用户:

void moveRacketLeft() { 
if (p.posY - 2 > 0) { // ensure racket is still on screen 
    mvprintw(p.posX, p.posY-1, " "); // if true, it will print an empty space, deleting the racket 
    p.posY --; // remember to decrement, as we are going to the left 
    } 

}

什么混淆了我这个,就是X和Y的位置似乎已经逆转,我不知道如何在逻辑上“得到它”。

在C编程的常规坐标和使用ncurses库之间是否存在某种灰色区域?或者是教程犯了一个错误?

非常感谢

回答

1

在诅咒xy坐标是按预期:x是横坐标,对应的列。 y是对行应用的垂直坐标。

但是在curses中,这些坐标通常以y,x的顺序给出。例如,在您的代码段中提到的原型mfprintw是:

int mvprintw(int y, int x, const char *fmt, ...); 

甚至有那么几个功能,在他们的名字,例如有yx(或宏相当。) getyx

我想这个符号是被选中的,因为它反映了二维数组在C:array[row][col]中的处理方式。