Win a copy of High Performance Python for Data Analytics this week in the Python forum!
    Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Making my ball move and bounce of the borders /making my paddle move on keyevents

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Could you maybe take a look at my collision intersection Methods? I cannot seem to find the error, why the last row of blocks just gets ignored.
 
Bartender
Posts: 4272
160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
I had a look at the intersectsTargetDown method. Now, I did not check this for correctness (it is obviously not correct), so I thought of creating a new version.

Thoughts:

1) since the ball hits the brick from below, the touchpoint must be:
  ballYTouchpoint = ballYPos - durch / 2;   (make a sketch if that isn't clear). The corresponding x of this touchpoint is of course ballXPos.

2) and the opposite point on the circle is therefore: ballYOppositeSide = ballYTouchpoint + durch; (why the '+'?)

3) the downside of the brick has as left coordinate: downsideXL = col * gapX + startX

4) and has a right X of: downsideXR = downsideXL + brickW;

5) the downside has an Y coordinate of: downsideY = row * gapY + startY + brickH  (why the '+'?)

6) and now we demand for a collision:

  -   downsideXL <= ballXPos <= downsideXR
  -   downsideY <= ballYTouchpoint
  -   ballYOppositeSide >= downsideY - brickH   // so lies below the upperside

This is the code. It is a bit large, but that was to test the code

Can you check the other collisions? The code seems to run fine with only this change, though, so the others seem correct.
 
Matthias Utrata
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
I thought, that the figures get drawn from the upper left. So ballYpos would already be at the top of the ball, but I suppose not.
 
Curse your sudden but inevitable betrayal! And this tiny ad too!
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic