我正在设计一款Breakout风格的游戏,你可以在这里击倒砖块以获得积分并完成游戏。游戏包括桨,球和一些砖块。当它从屏幕两侧反弹时,我已经实现了球方向的变化。因此,当球接触左侧和右侧时,它将向另一个方向反弹,当球接触顶侧时,它将向相反方向反弹。然而,当球击中底侧时,它应该将桨叶的数量减少1,并且球和桨叶都应该出现在其原始位置(即在桨叶上)。这就是我为此编写的代码:
'check bottom of screen
If PictureBox_ball.Top >= 403 Then
Timer_Main.Enabled = False
lbl_PaddlesLeft.Text = lbl_PaddlesLeft.Text - 1
PictureBox_ball.Location = New Point(321, 365)
PictureBox_paddle.Location = New Point(288, 383)
Timer_Main.Enabled = True
End If
当我运行此代码时,它拒绝更改拨片的位置。它只是停留在原地。这会受到我为桨叶运动编码的影响吗?这就是我编码的内容:
Private Sub Form1_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
If e.X > 0 And e.X < Me.Width - PictureBox_paddle.Width Then
PictureBox_paddle.Location = New Point(e.X, PictureBox_paddle.Top)
End If
End Sub
如果桨的数量小于0(总桨= 3)并且球到达屏幕的底部,那么游戏应该会显示一个消息框,上面写着“你失去了!”。这就是我为此编写的代码:
'check number of paddles left and bottom of screen
If lbl_PaddlesLeft.Text < 0 And PictureBox_ball.Top >= 403 Then
Timer_Main.Enabled = False
MsgBox("You Lost!", MessageBoxButtons.RetryCancel)
End If
然而,当我运行此代码时,当拨片小于0时,消息框不显示。它所做的就是球从原始位置开始,即使左侧的拨片是负数。我该如何解决? 注意:代码的第一个和第三个代码段位于Timer_Main_Tick事件中