【发布时间】:2026-01-27 21:30:01
【问题描述】:
我正在用 opengl 制作吃豆人游戏,我想在由矩阵表示的游戏中移动我的吃豆人。
矩阵有 16x16,当我想绘制墙壁时,我放了 4 个,小球体放了 3 个,吃豆人放了 2 个。
在我项目的主类中,我从键盘读取一个键并将信息发送到我定义游戏的类。在那个班级我有这个功能:
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
}
Pacman 它没有被删除。你能告诉我接下来我需要做什么,我做错了什么吗?
【问题讨论】:
-
我不明白你为什么在移动 pacman 时要删除它。当然你应该只在同一个 Pacman 对象上使用 pacman->setPacX() 和 pacman->setPacY()?
-
我试图删除它,因为我无法翻译它......当我翻译它时,他简单地创建了另一个吃豆人......