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

  • Home
  • SEARCH
  • 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 6644863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:13:01+00:00 2026-05-26T00:13:01+00:00

I want to do really simple collision detection in a pong like game. The

  • 0

I want to do really simple collision detection in a pong like game.
The ball is a square and the paddle (bats) is rectangles.

I have two entities coming in where I can get the current X and Y position, and the bitmap height and width. Which is the simplest way to do this?

I have this code:

public void getCollision(Entity enitityOne, Entity enitityTwo){

    double eventCoordX = (enitityOne.getCenterX() - (enitityTwo.getBitmapWidth() / 2));
    double eventCoordY = (enitityOne.getCenterY() - (enitityTwo.getBitmapHeight() / 2));

    double X = Math.abs(enitityTwo.getxPos() - eventCoordX);
    double Y = Math.abs(enitityTwo.getyPos() - eventCoordY);

    if(X <= (enitityTwo.getBitmapWidth()) && Y <= (enitityTwo.getBitmapHeight())){
        enitityOne.collision();
        enitityTwo.collision();
    }
}

But I’m pretty blind, this only works in the middle of the paddle not on the sides.
The problem is I can’t see where the code is wrong.
Anybody?
Anybody have a better idea?

  • 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-26T00:13:01+00:00Added an answer on May 26, 2026 at 12:13 am

    If all you want is to find whether or not 2 given rectangles somehow intersect (and therefore collide), here’s the simplest check (C code; feel free to use floating-point values):

    int RectsIntersect(int AMinX, int AMinY, int AMaxX, int AMaxY,
                       int BMinX, int BMinY, int BMaxX, int BMaxY)
    {
        assert(AMinX < AMaxX);
        assert(AMinY < AMaxY);
        assert(BMinX < BMaxX);
        assert(BMinY < BMaxY);
    
        if ((AMaxX < BMinX) || // A is to the left of B
            (BMaxX < AMinX) || // B is to the left of A
            (AMaxY < BMinY) || // A is above B
            (BMaxY < AMinY))   // B is above A
        {
            return 0; // A and B don't intersect
        }
    
        return 1; // A and B intersect
    }
    

    The rectangles A and B are defined by the minimum and maximum X and Y coordinates of their corners.

    Um… This has been asked before.

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

Sidebar

Related Questions

I have a really simple table with two rows and two columns. I want
It's really simple, I just want one screen. Wow, that [shiny thing] must have
I have a really simple blog application and I want to add a really
I have a really simple Rails app. Basically an article with comments. I want
I have a really simple Javascript BBCode Parser for client-side live preview (don't want
What I want to achieve is really simple. I have a Select statement where
I want to do something really simple like this: JPanel htmlPanel = new HtmlPanel(<html><body><h1>hello
What I am want to do is really simple. I have an gwt app
I have a really simple question, but I just want to know what the
I want to keep it really simple at first. Basically allow two people to

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.