Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


sdl mouse collision


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 yengold   Members   -  Reputation: 103

Like
0Likes
Like

Posted 15 September 2013 - 01:20 PM

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)
            {
                score++;
            }
        }

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"};

    srand(time(NULL));
    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;

    SDL_Delay(500);
}


this is create_racoon function :)



Sponsor:

#2 yengold   Members   -  Reputation: 103

Like
0Likes
Like

Posted 15 September 2013 - 01:43 PM

ok i found out its saving it and also i made a mistake at collision function so it wasnt returning true :/






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS