我正在使用opengl制作Pacman游戏,我希望在由矩阵表示的游戏中移动我的pacman。
矩阵有16x16,当我想要绘制墙壁时我放4个,3个用于小球体,2个用于pacman。
在我项目的主要课程中,我从键盘上读取了一个键,然后将信息发送到我定义游戏的课程中。在那个班级,我有这个功能:
void boardGame::refreshPacman(int n, int m)
{
int x, y;
(* pacman).movePacman(n, m); // This is working, it send information to class Pacman. In there I store the n (x axe) and m(y axe), and i get the next coordinates where pacman should translate.
x = (* pacman).getPacX(); // get coordinate of the old pacman
y = (* pacman).getPacY(); // get coordinate of the old pacman
board[x][y] = 0; // delete old information of pacman in matrix
x += n; // set the coordinates of x axis for new pacman
y += m; // set the coordinates of y axis for new pacman
wall[x][y] = 2; // insert the information of new pacman in matrix
pac->redraw (x, y, 0.5); // construct the new pacman
}
吃豆子它没有被抹去。你能告诉我接下来我需要做什么,而且我做错了吗?
答案 0 :(得分:4)
吃豆子它没有被抹去。你能告诉我接下来我需要做什么,而且我做错了吗?
OpenGL不是一个场景图(这是我几乎在每个答案中都显示的一个声明)。它是一个绘图API,允许您绘制dancy点,线和三角形。没有“几何对象”的概念。
如果你改变了什么:清除旧图片并画一个新图片!
答案 1 :(得分:2)
将->
运算符与类指针一起使用。
(* pacman).movePacman(n, m);
应该是:
pacman->movePacman(n,m);
要删除较早的pacman,请在添加新屏幕之前重新绘制屏幕。另外,pacman析构函数内部也会结束pacman图像/精灵的渲染吗?