Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3599484
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:22:24+00:00 2026-05-18T20:22:24+00:00

Alrighty well straight to it, I’m using this guide as I learn SDL and

  • 0

Alrighty well straight to it, I’m using this guide as I learn SDL and I’m having difficulties with the per pixel collision part. My implementation to this is slightly different to the guides and it is causing some unwanted issues. The issue being the moving ball goes straight through the stationary ball (it’s meant to be solid and block the moving ball as you might expect). I know that the rectangular collision boxes are in the proper places because I’ve recoloured the moving ball to be white (the ball.bmp is loaded red in colour) and the stationary ball to be blue, The collision boxes on top of each ball has been recoloured.

My Collision detection function is as follow

bool checkCol(std::vector<SDL_Rect> A,std::vector<SDL_Rect> B){
    int TOP1,           TOP2;
    int BOTTOM1,    BOTTOM2;
    int LEFT1,          LEFT2;
    int RIGHT1,     RIGHT2;
    for (int i = 0; i < A.size(); i++){
        TOP1         =      A[ i ].y;
        BOTTOM1  =      A[ i ].y + A[ i ].h;
        LEFT1        =      A[ i ].x;
        RIGHT1       =      A[ i ].x + A[ i ].w;
        for (int j = 0; j < B.size(); j++){
            TOP2         =      B[ i ].y;
            BOTTOM2  =      B[ i ].y + B[ i ].h;
            LEFT2        =      B[ i ].x;
            RIGHT2       =      B[ i ].x + B[ i ].w;

            if ( RIGHT1 <= LEFT2 ){ return false; }
            if ( LEFT1 >= RIGHT2 ){ return false; }
            if ( TOP1 >= BOTTOM2 ){ return false; }
            if ( BOTTOM1 <= TOP2 ){ return false; }
        }
    }
    return true;
}

here is the full source code(too large to post here) and executable(linux).

Could someone please tell me where I’ve gone wrong?.

[edit]
Ignore the rectangle in the middle.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T20:22:25+00:00Added an answer on May 18, 2026 at 8:22 pm

    Looks like the algorithm logic is incorrect. When you have a list of conditions and you want to check that all of them are false, you should not do return false; as soon as you have found one which is false.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alrighty well straight to it, I'm using this guide as I learn SDL and
Alright well, I connect to 3 different ip's when I run this script. It
Alright, well this is the deal. I have a page, and then it loads
Well, sorry about the confusing title but I'm having a slightly annoying problem with
Alright well I recently got into normalizing my database for this little side project
Alright guys, well, here is the thing. I used this wonderful website and found
i've got regex which was alright, but as it camed out doesn't work well
Alright. I have a query that looks like this: SELECT SUM(`order_items`.`quantity`) as `count`, `menu_items`.`name`
Alright, so everything on this website was finished, it all worked, it displayed right
Alright, Question #1: well i have a richtextbox, and id like to add emotions

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.