simple arkanoid problem..

Feb 1, 2009 at 8:38 PM
Hi dear friends & masters,

i created a simple break-out game design. there are bricks(30x10) and a ball on the screen and all of them have body and geoms accordingly assigned in a loop of my code .. i throw a ball from a bat below the game screen (as you know..).
my problem is : when ball collides the same brick again it bounces from geometry (or body) although i remove it from the list.so i never reach the inner bricks at all.
i tried Dispose method at two different places as i stated below code but this time ball does not bounce reverse.
    at first place : when it collides any brick it removes everybrick on the line of its way.
    at second place : it does not dispose appropriate geometry or body when it collides the brick

    :(
pls somenone help me, i try to make a simple arkanoid(break-out). best regards,

 for (int k = 0; k < brick.Count; k++)
                    {
                         for (int j = 0; j < ball.Count; j++)
                        {
                            if (ball[j].ballgeom.Collide(brick[k].brickgeom))
                                  {
                         // brick[k].brickgeom.Dispose(); // when i active this line, the ball sweeps off all the bricks on its way, (not bouncing, suppose that just like a fireball in a real break-out game )
                            brick.RemoveAt(k);  // this line remove brick from list and its appearance of the screen.
                         // brick[k].brickgeom.Dispose(); // when i active the same line here,this time the ball bounces appropriate way when it collides the brick, but second time it meets the same brick again it bounces from brick geometry coz i think it stands still there !!
                                   }
                        
                         }
                    
                    }
Coordinator
Feb 1, 2009 at 9:49 PM
Edited Feb 1, 2009 at 9:53 PM
Instead of calling Dispose() on the geometry, try using the PhysicsSimulator.Remove() method.
The remove method also cleans up the internals of the engine.

You should note that the engine does not remove the geometry right away. It waits until the next update is called.

Oh, and the way you check for collisions is not very good in performance. If you call that code on each update, you are not using the engine internals at all. It's better to use the OnCollision event. Right now you check each ball against each brick and use the narrow phase collision detection directly. All the engine collision internals run first and then you do it again on your own. :)

I will make a note of this and see if I can speed up things for others doing it this way.
Feb 3, 2009 at 7:36 PM
first i create this :

public bool OnCollision(Geom geom1, Geom geom2, ContactList contactlist)
        {
           
            return true;

         }

then in gameupdate

for (int k = 0; k < brick.Count; k++)
                    {
                         for (int j = 0; j < ball.Count; j++)
                        {

                           
                            if (OnCollision(ty.ballgeom,miktars[k].blgeom, contactlist))
                                    {
                                         .
                                         .
                                         .

it not works,

where am i wrong ? pls genbox help :(

error codes are :
Error    1    The best overloaded method match for 'hs2.Game1.OnCollision(FarseerGames.FarseerPhysics.Collisions.Geom, FarseerGames.FarseerPhysics.Collisions.Geom, FarseerGames.FarseerPhysics.Collisions.ContactList)' has some invalid arguments  
Error    2    Argument '3': cannot convert from 'System.Collections.Generic.List<FarseerGames.FarseerPhysics.Collisions.ContactList>' to 'FarseerGames.FarseerPhysics.Collisions.ContactList' 


Coordinator
Feb 3, 2009 at 8:45 PM
myriac, are you able to send me your code?
I will fix your error and move your collision code accordingly with what I described before. Don't worry about not understanding it, I will write some code comments to assure you know what's going on.

Send me an email and I will reply with mine. (I don't like writing my email on public forums) or upload your project to a free upload site and send the link to me. You can contact me by clicking on my username.