Is there any way to find out which box in the array the ball hits, and make that specific box invisible?
I tried loops, but that was disastrous!!
Printable View
Is there any way to find out which box in the array the ball hits, and make that specific box invisible?
I tried loops, but that was disastrous!!
Whoops, I forgot my code. THis is what I tried:
VB Code:
For i = 0 To RedBox.Count - 1 If Sprite.X = Round(RedBox(i).Left, 0) And Sprite.Y = Round(RedBox(i).Top, 0) Then RedBox(i).Visible = False End If Next i
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 RedBox(i).Visible = False End If End If Next i
No bricks disappear at all when I try that code.
I'll have to try again later, I'm pressed for time right now.
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).
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?
im working on a ball game right now and the collition code works fine!
here's the code:
Here's my take on the classic:
Nice ripple effects. It'd be cooler in DX though.Quote:
Originally posted by cyborg
im working on a ball game right now and the collition code works fine!
here's the code:
:cool:
well...i've just started on the game, so who knows what i'll add....
but it runs pretty smooth though...100 fps with 1000 balls moving with a 900mhz cpu :)
DOH!!
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!
One more thing DigitalError.
Could you explain what some of these variables are? I can't seem to get the bounce codes working correctly without an understanding of them.
I need explanations on the following variables:
BlR
bRad
BaB
Thanks in advance.
Oh, and since I'm using your code, would you like me to do anything special, like put your name in the credits or something?