At the moment, I am programming a game in VB.NET. My game consists of a ball, paddle, and some blocks, all of which are PictureBoxes. The way one section of the game works is that, whenever the ball touches a block, that block is supposed to disappear. Here is a snippet of code that shows how the system works:
Dim left_motion As Integer = 5 Dim top_motion As Integer = 5 Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick Ball.Top += top_motion Ball.Left += left_motion If Ball.Bounds.IntersectsWith(YellowBlock6.Bounds) Then top_motion = top_motion * -1 YellowBlock6.Hide() Score = Score + 1 lblScore.Text = Score
This code may be a little hard to understand, so I'll break it down. Basically, left_motion and top_motion relate to the direction in which the ball moves in, and I set them both to 5, as I want this to be the speed of the ball. When the ball touches the block, the direction of travel will be reversed, the block is hidden, and my score label updates by 1. All of this occurs within a timer. The hiding of the block is the part I am having trouble with.
I found out that, even the block is hidden and you can't see it, the ball acts like the ball is still there. So sometimes, when the ball is moving and it touches a blank area where one of the blocks has disappeared, it still acts as though the block is there. How do I make it so that the block fully disappears instead of just being hidden? In reality, the rest of the code shouldn't need editing. It should just be the YellowBlock6.Hide() part (line 8)