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