GDI Breakout and MUCH better collision detection, check this out!

Started by OceanJeff32, September 23, 2005, 11:44:44 AM

Previous topic - Next topic

OceanJeff32

Ok, I had to improve my latest.

THIS one will bounce off the center rectangle, no matter what velocity is chosen.  When the ball comes NEAR the boundaries of the rectangle, it bounces, and accurately I might add.

Now I might think of doing this in MMX, just to test myself.  Anybody have any suggestions?  I would just do the collision detection with MMX...I've already thought of a way, just have to try it...

You'll see more from me, besides I haven't even BEGUN to put this thing into shape!

:clap:

Later,

Jeff C
:dazzled:

[attachment deleted by admin]
Any good programmer knows, every large and/or small job, is equally large, to the programmer!

OceanJeff32

Ok, this program does exactly the same thing as the previous version, except that I'm using ARRAYS and INDEX ADDRESSING to access the array information to draw the block, the ball not yet, but I figured now I can work on drawing and bouncing off of multiple blocks, then multiple balls, so there's my next two updates...

Stay Tuned,

Jeff C
:U

[attachment deleted by admin]
Any good programmer knows, every large and/or small job, is equally large, to the programmer!


brixton

OceanJeff32,

I watched it for a short while, and sometimes it would hit the corner of the red rectangle and go straight through it!
If you love somebody, set them free.
If they return, they were always yours. If they don't, they never were..

OceanJeff32

That is one bug that I have to fix... :bdg

I think it's because when it hits right on the corner, I test for greater than one axis, or less than one axis, by velocity pixels away...then the opposite axis is a greater than or less than comparison, and if it's right on, it sneaks into the rectangle, and out of velocity distance away....hence all the way through the rectangle!

sneaky devil...haha

I will figure it out, I'm kind of stuck trying to figure out how to implement a simple two dimensional array for the blocks that I want shown on the screen.  I want an array to hold 100 blocks, so a simple loop will be required to check the ball against collision with them all.

My latest version is around here somewhere, and it's quite fun with the paddle moving around the screen following the mouse...

Anyways, I may choose to implement the blocks as not even a stored array! Simply programmatically display each one, and only keep track if one has been hit, but that still takes an array of 100 bits, each bit being on or off for the death or life of the block...

hmmmmmmmmmmmmmm...

later,

jeff c
:eek
Any good programmer knows, every large and/or small job, is equally large, to the programmer!

Eóin

I've a suggestion for the 100 blocks-

This is a simplified layout, but the idea can be addapted to more complicated ones. Say you put them in 5 rows of 20 all at the very top of the screen. And imagine our coordinates start from the top left, and a block is 10x5 pixels in size. Then the top left block occupies space form (0,0) to (10,5). The block to its right occupies (10,0) to (20,5) etc. So this means that if the ball is at say (123,12), then by dividing by the width and height of a block you get (123,12) / (10,5) = (12,2) meaning you only need to test for collision against the block in row 2 column 12, and possible also it neighbour blocks depending on how you do the test.

Like I say this is a simplistic layout but even for complicated layout you should be able to find a similar way to narrow down your collision test to just a handful of blocks, and not have to loop through them all :U .