本文整理汇总了C++中CollisionDetector::hasCollision方法的典型用法代码示例。如果您正苦于以下问题:C++ CollisionDetector::hasCollision方法的具体用法?C++ CollisionDetector::hasCollision怎么用?C++ CollisionDetector::hasCollision使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CollisionDetector
的用法示例。
在下文中一共展示了CollisionDetector::hasCollision方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char* args[]) {
Renderer* renderer = new Renderer();
if(!renderer->init()) {
printf( "Failed to initialize!\n" );
} else {
Character* c = new Character(new Texture("res/img/dot.bmp", 200, 200));
renderer->addTexture(new Texture("res/img/waterlevel2.png", 0, 0));
renderer->render();
renderer->addTexture(c->getTexture());
bool quit = false;
SDL_Event e;
LoadCollisionMap lcm;
list<Circle> circlesList;
circlesList = lcm.load();
list<Circle> l;
Circle c1(200,0,10);
l.push_back(c1);
CollisionDetector cd;
int y = 0;
while(!cd.hasCollision(circlesList, l)) {
l.pop_back();
y += 1;
Circle c1(200,y,10);
l.push_back(c1);
}
y -= 1;
c->setPosX(200);
c->setPosY(y);
renderer->render();
int mVelX = 0;
int DOT_VEL = 1;
while(!quit) {
while(SDL_PollEvent(&e) != 0) {
if(e.type == SDL_QUIT) {
quit = true;
}
if(e.type == SDL_KEYDOWN && e.key.repeat == 0) {
switch(e.key.keysym.sym) {
case SDLK_LEFT: mVelX -= DOT_VEL; break;
case SDLK_RIGHT: mVelX += DOT_VEL; break;
}
} else if(e.type == SDL_KEYUP && e.key.repeat == 0) {
switch(e.key.keysym.sym) {
case SDLK_LEFT: mVelX += DOT_VEL; break;
case SDLK_RIGHT: mVelX -= DOT_VEL; break;
}
}
}
c->setPosX(c->getPosX() + mVelX);
LoadCollisionMap lcm;
list<Circle> circlesList;
circlesList = lcm.load();
int mPosX = c->getPosX();
int mPosY = c->getPosY();
list<Circle> l;
Circle c1(mPosX,mPosY,10);
l.push_back(c1);
CollisionDetector cd;
int y = mPosY;
while(cd.hasCollision(circlesList, l)) {
l.pop_back();
y -= 1;
Circle c1(mPosX,y,10);
l.push_back(c1);
};
while(!cd.hasCollision(circlesList, l)) {
l.pop_back();
y += 1;
Circle c1(mPosX,y,10);
l.push_back(c1);
};
c->setPosY(y);
renderer->render();
}
}
return 0;
}