本文整理汇总了C++中Obstacle::hitTest方法的典型用法代码示例。如果您正苦于以下问题:C++ Obstacle::hitTest方法的具体用法?C++ Obstacle::hitTest怎么用?C++ Obstacle::hitTest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Obstacle
的用法示例。
在下文中一共展示了Obstacle::hitTest方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: doHitTest
char TGame::doHitTest(int x, int y) {
//do hit test
if(Tank1.hitTest(x,y,2,2))//could be for dynamic bullet size
{
//delete &Tank1
Tank1.isHit = true;
return '1';
}
if(Tank2.hitTest(x,y,2,2))//could be for dynamic bullet size
{
//delete &Tank2
Tank2.isHit = true;
return '2';
}
for(int i=0;i<vObs.size();i++)
{
Obstacle O = (Obstacle) vObs[i];
int w,h;
w = .5;
h = .5;
if(O.hitTest(x,y,w,h))
return 'w';
}
return 'n';
}
示例2:
void TGame::moveTank2(char direction) {
bool canMove = true;
point tm;
tm = Tank2.getMovePoint(direction);
if(!Tank1.hitTest(tm.x,tm.y,Tank2.width,Tank2.height))//check contact with opposing tank
{
for(int i=0;i<vObs.size();i++)
{
Obstacle O = (Obstacle) vObs[i];
int x,y,w,h;
point p = Tank2.getMovePoint(direction);
x= p.x;
y= p.y;
w = Tank1.width;
h = Tank1.height;
if(O.hitTest(x,y,w+2,h+2))
canMove = false;
}
}
else{canMove = false;}
if(canMove)
Tank2.move(direction);
}