your code assumes that neither the sprite or the controls have any width/height - so the top left co-ordinates of the sprite must be the same as the control. Try this instead:
VB Code:
For i = 0 To RedBox.Count - 1
If Sprite.X >= Round(RedBox(i).Left, 0) _
And (Sprite.X + Sprite.Width) <= Round(RedBox(i).Left + RedBox(i).Width, 0) Then
If Sprite.Y >= Round(RedBox(i).Top, 0) _
And (Sprite.Y + Sprite.Height) <= Round(RedBox(i).Top + RedBox(i).Height, 0) Then
192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
Posts
3,051
Not sure about the code above, so i'll post how i do it.
BTW, by using seperate if statements the program *should* be slightly faster.
This code assumes the coordinates of the sprite is top left, not the middle.
VB Code:
For i = 0 to Ubound(RedBox)
If Sprite.X <= RedBox(i).Left + RedBox(i).Width Then
If Sprite.X + Sprite.Width >= RedBox(i).Left Then
If Sprite.Y <= RedBox(i).Top + RedBox(i).Height Then
If Sprite.Y + Sprite.Height >= RedBox(i).Top Then
'Collision
End If
End If
End If
End If
Next i
Also this attached project will probably help (well maybe).
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
For the record, I'm not using anything to handle the sprites, the balls are all created via a drawing, some BitBlt code, and double buffering. I know the exact height and width of the ball also. It was much easier to do it this way rather than using a picture box.
Therefore, your Sprite.X + Sprite.Width and Sprite.Y + Sprite.Height codes are invalid. Use Sprite.X + 16 or Sprite.Y + 16.
Just letting you know for future reference.
Anyways, your code works fine (I had to edit it a bit to accomodate floating-point numbers, otherwise the program goes crazy and starts erasing every brick in the entire row), except for one thing: It works great on some bricks, but also leaves others behind. Then when the ball comes back around, it'll delete the bricks when it's nowhere near them.
Here's what the code looks like now.
VB Code:
Private Function CheckForCollisions()
For i = 0 To RedBrick.Count - 1
If Sprite.X <= Round(RedBrick(i).Left, 0) + Round(RedBrick(i).Width, 0) Then
If Sprite.X + 2 >= Round(RedBrick(i).Left, 0) Then
If Sprite.Y <= Round(RedBrick(i).Top, 0) + Round(RedBrick(i).Height, 0) Then
If Sprite.Y + 2 >= Round(RedBrick(i).Top, 0) Then
RedBrick(i).Visible = False
End If
End If
End If
End If
Next i
End Function
Should I try messing around with the settings a bit?
Last edited by hothead; Oct 13th, 2003 at 01:42 PM.
I nosed around your code digitalerror, and found one important thing: I didn't have the ScaleMode set to 3 - Pixel. I'm not used to doing that, as I only recently got into game programming.
I switched it, and everything works great now. Thanks a lot!
BTW, your game is flippin' fantastic, I couldn't stop playing it!