本文整理汇总了C++中Guard::collided方法的典型用法代码示例。如果您正苦于以下问题:C++ Guard::collided方法的具体用法?C++ Guard::collided怎么用?C++ Guard::collided使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guard
的用法示例。
在下文中一共展示了Guard::collided方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updateStatus
void updateStatus()
{
int nextX, nextY;
int nextSpeedX, nextSpeedY;
for (int i = 0; i < WINDOW_WIDTH; i++)
for (int j = 0; j < WINDOW_HEIGHT; j++)
if (pixelType[i][j] == BALL)
{
nextSpeedX = pixelSpeedX[i][j];
nextSpeedY = pixelSpeedY[i][j];
nextX = nextSpeedX + i;
nextY = nextSpeedY + j;
if (nextX < 0 || nextX >= WINDOW_WIDTH)
{
nextSpeedX = -nextSpeedX;
pixelSpeedX[i][j] = nextSpeedX;
continue;
}
if ((nextY >= BASE_HEIGHT && nextY <= BASE_HEIGHT + nextSpeedY && guard.collided(nextX)) || nextY < 0)
//if (nextY > BASE_HEIGHT || nextY < 0)
{
nextSpeedY = -nextSpeedY;
pixelSpeedY[i][j] = nextSpeedY;
continue;
}
if (nextY >= WINDOW_HEIGHT)
{
pixelTypeNext[i][j] = 0;
pixelType[i][j] = 0;
continue;
}
if (pixelType[nextX][nextY] == BRICK)
{
bool flag = false;
if (nextX + 1 < WINDOW_WIDTH && nextX - 1 >= 0 && pixelType[nextX + 1][nextY] == BRICK && pixelType[nextX - 1][nextY] == BRICK)
{
nextSpeedY = -nextSpeedY;
flag = true;
}
if (nextY - 1 >= 0 && pixelType[nextX][nextY + 1] == BRICK && pixelType[nextX][nextY - 1] == BRICK)
{
nextSpeedX = -nextSpeedX;
flag = !flag;
}
if (!flag)
{
nextSpeedY = -nextSpeedY;
nextSpeedX = -nextSpeedX;
}
pixelSpeedX[i][j] = nextSpeedX;
pixelSpeedY[i][j] = nextSpeedY;
pixelTypeNext[nextX][nextY] = BALL;
pixelSpeedX[nextX][nextY] = rand() % 2 ? -(rand() % 5 + 1) : (rand() % 5 + 1);
pixelSpeedY[nextX][nextY] = rand() % 5 + 1;
}
else if (pixelType[nextX][nextY] == 0)
{
pixelTypeNext[i][j] = 0;
pixelTypeNext[nextX][nextY] = BALL;
pixelColor[nextX][nextY] = pixelColor[i][j];
pixelSpeedX[nextX][nextY] = nextSpeedX;
pixelSpeedY[nextX][nextY] = nextSpeedY;
}
else
{
pixelType[i][j] = 0;
}
}
for (int i = 0; i < WINDOW_WIDTH; i++)
for (int j = 0; j < WINDOW_HEIGHT; j++)
pixelType[i][j] = pixelTypeNext[i][j];
}