Jump to content
  • Advertisement
Sign in to follow this  

sdl mouse collision

This topic is 2137 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello everyone,

im showing random images at screen, when i click on them my game score will ++.

i got some problems and want to get your feedback about it.

if (mainEvent->type == SDL_MOUSEBUTTONDOWN)
            SDL_Rect B;
            B.x = mainEvent->button.x;
            B.y = mainEvent->button.y;
            B.w = mainEvent->button.x + 10;
            B.h = mainEvent->button.y + 10;

            if (check_collision(A, B) == true)

here i got the coordinates of my mouse click. pls have a look check collision function. since i can work with B and its coodinates i think i cannot take information of A. its decleared at the beginning of file like SDL_Rect A; but the values changed in another function. my question is when those values changed did they registered to memory or after i pass the function are they gone?

void Create_Racoon(void){
    static int kordinatx[] = {10,20,30,40,50,300,70,180,100,400};
    static int kordinaty[] = {10,20,30,40,50,400,70,180,300,420};
    static const char* const images[] = {"rsz.png", "rsz_.png"};

    int RandKordinat = rand() % 11;    
    int RandIndex = rand() % 2;

    racoon = LoadImage(images[RandIndex]);    

    SDL_QueryTexture(racoon, NULL, NULL, &bW, &bH);
    ApplySurface(kordinatx[RandKordinat], kordinaty[RandKordinat], racoon, renderer);

    A.x = kordinatx[RandKordinat];
    A.y = kordinaty[RandKordinat];
    A.w = kordinatx[RandKordinat]+bW;
    A.h = kordinaty[RandKordinat]+bH;


this is create_racoon function :)

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!