void Draw() {
int c1;
int x = 59;
int y = 500;
int temp = x;
for (int i = 0; i < 13; ++i){
for (int j = 0; j < 10; ++j){
x_coordinates[i][j] = x;
y_coordinates[i][j] = y;
c1 = temp_color[i][j];
DrawRectangle(x, y, 65, 25, colors[c1]);
x += 67;
}
x = temp;
y -= 28;
}
DrawRectangle(tempx, 0, 85, 12, colors[5]);
DrawCircle(templx, temply, 10, colors[7]);
}
// This function will be called automatically by this frequency 1000.0/FPS
void Animate() {
//if (temply < - 10)
//exit(1);
Brick_collision();
glutPostRedisplay(); // Once again call the Draw member function
}
int Brick_collision(){
for (int i=0; i<13; ++i){
for (int j=0; j<10; ++j){
if (((templx >= x_coordinates[i][j]) && (templx <= x_coordinates[i][j] + 65)) && ((temply + 5 >= y_coordinates[i][j]) && (temply + 5 <= y_coordinates[i][j] + 35 ))){
vy = -vy;
temp_color[i][j] = 2;
// x_coordinates[i][j] -= 300;
// y_coordinates[i][j] -= 300;
// I HAVE USED THESE VALUES BECAUSE NOW THE BRICK WOULD BE OUTSIDE THE SCREEN AND THE BALL WILL NOT COLLIDE WITH IT AGAIN BUT THIS DOESN'T WORK.
return 1;
}
}
}
}
我正在尝试使用OpenGL制作BrickSlayer游戏。在Draw()
函数中,我绘制了游戏的结构,即砖块,踏板和球。现在我将这些砖的x和y坐标存储在一个二维数组中。在Animate()
函数中,我调用函数Brick_collision()
其中我已经应用了检测砖的条件。当球与砖块发生碰撞时,我使它变得不可思议,即我将它的颜色更改为白色,并且我必须从二维阵列中移除它的坐标,以便球不再检测到它。我怎样才能做到这一点?我用于去除坐标的所有方法都没有奏效。从C++中删除二维数组中的值
你是什么意思_remove_?您不能从固定大小的阵列中移除元素。你的意思是你需要重置这些值吗?否则,我会推荐使用'std :: vector>'。 –
2015-04-03 13:42:39
通过删除我的意思是我可以更改数组中的'x'和'y'坐标的值。 – 2015-04-03 13:56:29
供参考:这是*不是*二维阵列,它是一个锯齿状阵列 – 2015-04-03 13:57:10