VPN termux about China.net

#ifndef colision sdl

#ifndef    _COLISIONSDL2_C_
#define    _COLISIONSDL2_C_
#include "SDL/SDL.h"
    #include <SDL2/SDL.h>
#include <string>
#include <vector>
#include <cmath>
/*Func. metod c*/
bool CheckCollision(SDL_Rect A,  std::vector<SDL_Rect> B )
 {
     int cX, cY;
       for( int Bbox = 0; Bbox < B.size(); Bbox++ )
     if(A.x > B[ Bbox ].x +B[ Bbox ].w){return false;}
else if(A.y > B[ Bbox ].y+B[ Bbox ].h){ return false; }
 else if(A.x+A.w < B[ Bbox ].x ){ return false; }
 else if(A.y+A.h < B[ Bbox ].y){ return false;}

else{
return true;

}
}
/*colision rerctangle and rectangle (ball and player)*/
 bool CheckCollision(SDL_Rect r1, SDL_Rect r2)
 {
if(r1.x > r2.x+r2.w){return false;}
else if(r1.y > r2.y+r2.h){ return false; }
 else if(r1.x+r1.w < r2.x){ return false; }
 else if(r1.y+r1.h < r2.y){ return false;}

else{
return true;
        }
}

#endif

/* ^usage :
&@check collision with rect and rect
if (CheckCollision(shot, hit)) {
   
    speed.b=-3;
    }
&&@colizion witch rect and vector
  std::vector<SDL_Rect> box( 1 );

    //Set the shapes' attributes
    box[ 0 ].x = 60;
    box[ 0 ].y = 60;
    box[ 0 ].w = 40;
    box[ 0 ].h = 40;
SDL_RenderGetViewport(renderer, &darea);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0xFF);

SDL_RenderFillRect(renderer, &box[0]);
if (CheckCollision( shot , box)){

    speed.b=-3;
}

} */

No comments:

Post a Comment