本文整理汇总了C++中Physics::boundarycheck方法的典型用法代码示例。如果您正苦于以下问题:C++ Physics::boundarycheck方法的具体用法?C++ Physics::boundarycheck怎么用?C++ Physics::boundarycheck使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Physics
的用法示例。
在下文中一共展示了Physics::boundarycheck方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
spritecollection.push_back(sprite);
SDL_Texture *shrub = loadTexture(resPath + "shrub.png", renderer);
if (shrub == nullptr){
cleanup(shrub, renderer, window);
IMG_Quit();
SDL_Quit();
return 1;
}
Sprite* obstacle1 = new Sprite(50, 50, renderer); //random objects
obstacle1->setID("SHRUB");
obstacle1->setPos(200, 200);
int obstacleframe = obstacle1->makeFrame(shrub, 0, 0);
spritecollection.push_back(obstacle1);
int x = SCREEN_WIDTH / 2;
int y = SCREEN_HEIGHT / 2;
sprite->setPos(x, y);
Physics* physic = new Physics();
SDL_Event e;
bool quit = false;
std::string spriteDirection = "float up";
while (!quit){
while (SDL_PollEvent(&e)){
if (e.type == SDL_QUIT){
quit = true;
}
/*std::vector<Sprite*>::iterator it; //collding not working
if (physic->boundarycheck(sprite, 100, 100, 440, 280) == physic->NONE) //sprite is inside boundary, not touching the "walls/corners"
{
for (it = spritecollection.begin(); it != spritecollection.end(); ++it) //going through each sprite to test for collision
{
if (physic->collisiondetection(sprite, *it) == physic->LEFT) //it is touching sprite's left
{
if (e.type == SDL_KEYDOWN){
if (e.key.keysym.sym == SDLK_RIGHT)
{
sprite->movex(5);
spriteDirection = "walk right";
}
else if (e.key.keysym.sym == SDLK_UP)
{
sprite->movey(-5);
spriteDirection = "float up";
}
else if (e.key.keysym.sym == SDLK_DOWN)
{
sprite->movey(5);
spriteDirection = "float down";
}
}
}
else if (physic->collisiondetection(sprite, *it) == physic->RIGHT) //object is touching sprite's right
{
if (e.type == SDL_KEYDOWN){
if (e.key.keysym.sym == SDLK_LEFT)
{
sprite->movex(-5);
spriteDirection = "walk left";
}
else if (e.key.keysym.sym == SDLK_UP)