当 PictureBox1 击中 PictureBox2 时加点

Add points when PictureBox1 hits PictureBox2

我正在尝试使用 VB.Net 制作一个简单的游戏,它的概念就像抓鸡蛋。

我的期望是,当鸡蛋掉落时(PictureBox1),接球手(PictureBox2)接住鸡蛋,每次接球得1分。我的想法是,当鸡蛋的位置与捕手的位置相匹配时,它会增加分数。但它没有用。这里有什么建议吗?

 Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    PictureBox1.Top += 5

    If PictureBox1.Location.Y = PictureBox2.Location.Y Then
        score += 1
        Label1.Text = score

    End If

End Sub

这是游戏结束的代码:

 Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
    If PictureBox1.Location.Y > 400 Then
        Me.Dispose()
        MsgBox("game over")
    End If
 End Sub

欢迎来到本站!我相信 Bounds 属性 应该适用于此。 此外,可能只想为碰撞使用布尔值(或引发事件),这样你就不会重复工作。

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    PictureBox1.Top += 5
    Dim itHappened as Boolean

    Dim other_boxes as New List(Of PictureBox) from {PictureBox2} ', PictureBox3, PictureBox4}
    For each box in other_boxes
         If PictureBox1.Bounds.IntersectsWith(box.Bounds) Then
                    score += 1
                    Label1.Text = score
                    itHappened = True                  
         else
                itHappened = False 'depending on your logic, may not be the best place
         End If
    Next


    If PictureBox1.Location.Y > 400 Then
        Me.Dispose()
        MsgBox("game over")
    End If

End Sub