2014-05-20 124 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]中的處理方式。