Arkanoid problem

Discussion in 'Questions (Windows Mobile)' started by Sta, Mar 16, 2008.

  1. Sta

    Sta Member

    Hi I'm new here, i've tried to create simple game - arkanoid. I wrote the code but if the ball contacts with bricks, sometimes the error is shown. I don't know where's the problem, please :sign0085:, thanks.

    Attached Files:

  2. specci48

    specci48 Well-Known Member Licensed User

    Hi sta,

    I'm not really sure if I'm able to explain this error so you can understand it :sign0013:
    This sub is buggy:
    Sub CollisionCheck
    For a=0 To AlBricksX.Count-1
    If rect.X>AlBricksX.Item(a)-15 AND rect.X<AlBricksX.Item(a)+30 AND rect.Y>AlBricksY.Item(a)-15 AND rect.Y<AlBricksY.Item(a)+17 Then 
    Control("Brick" & a).Dispose
    End If
    End Sub
    If you add the return statement, one of your errors will vanish. This is because you are altering the array within a loop around this array. E.g. AlBricksX.Count = 4 your loop goes from 0 to 3. If a brick is hit, you delete values of each array so only 3 entries are left (from 0 to 2). After that your loop tries to access these arrays with the last value of the loop definition (here 3) but this entry is not available any more.

    The second error I came up is because of this:
    You added 4 bricks naming brick0, brick1, brick2 and brick3. If the ball hits first e.g. brick2, you dispose brick2 so brick0, brick1 and brick3 are left. Then you remove the position 2 in the x and y array. Now your brick data is messed up! The values AlBricksX.ItemAt(2) and AlBricksY.ItemAt(2) belong to brick3 because the positions in the arrays changed but not the image names.

  3. Sta

    Sta Member


    Thank you very much for a quick reply, now i understand. I solve it this way:

    I know this isn't very nice way to solve it but it works for now, so i will fix it later...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice