I am creating a basic shooting game, one shape the player moves around. You press space and create another shape as a bullet trying to hit the enemies. I cannot figure out how to make it so when the bullet (Shape2) isnt visible, it will not check to see if the enemy (Shape3) is hitting it.
With what I have there it does not detect any of them being hit, where as if i remove the If Shape2(a).visible = true then statement it does, but the bullet will still hit an enemy after it goes invisible. Hopefully I explained this well enough, thanks to anyone who can help!Code:Dim x As Integer Dim y As Integer Dim score As Integer Dim a As Integer Dim k As Integer Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) Select Case KeyCode Case vbKeyUp Shape1.Top = Shape1.Top - 50 Case vbKeyDown Shape1.Top = Shape1.Top + 50 Case vbKeyRight Shape1.Left = Shape1.Left + 50 Case vbKeyLeft Shape1.Left = Shape1.Left - 50 Case vbKeySpace x = x + 1 Load Shape2(x) 'make it visible and set it in position Shape2(x).Visible = True 'put it at the top of the shape 1 Shape2(x).Top = Shape1.Top 'centre it over the shape 1 Shape2(x).Left = Shape1.Left + (Shape1.Width / 2) - (Shape2(x).Width / 2) 'fire the shape 2 Do While Shape2(x).Top > -300 Shape2(x).Top = Shape2(x).Top - 1 Loop If Shape2(x).Top <= -300 Then Shape2(x).Visible = False End If End Select End Sub Private Sub Timer1_Timer() For a = 0 To x For k = 0 To 2 If Shape3(k).Visible = True Then If Shape2(a).Visible = True Then If Shape2(a).Left > Shape3(k).Left - Shape2(a).Width And Shape2(a).Left < Shape3(k).Left + Shape3(k).Width Then If Shape2(a).Top < Shape3(k).Top + Shape3(k).Height Then 'And Shape2(a).Top > Shape3(k).Top - Shape2(a).Height Then Shape2(a).Visible = False Shape3(k).Visible = False score = score + 10 End If End If End If End If Next k Next a Label1.Caption = "Score: " & score End Sub Private Sub Timer2_Timer() Randomize Shape3(y).Top = Shape3(y).Top + 100 If Shape3(y).Top >= 7680 Then Shape3(y).Top = -120 Shape3(y).Left = Rnd(100) * 10000 End If y = y + 1 If y = 3 Then y = 0 End Sub![]()




Reply With Quote