Note: Use a prefixes in naming of each objects/controls.
controls that has a code: form_load, form_mousemove,timer,command button
Dim v As Integer, Y As Integer, score As Integer
Private Sub Form_Load()
ball.Left = 2500
ball.Top = 1300
X = -50
Y = -50
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
pad.Left = X - pad.Width / 2
End Sub
Private Sub reset_Click()
ball.Left = 2500
ball.Top = 1300
X = -50
Y = -50
reset..Visible = False
score = 0 ' reset the score
scorecard.Caption = "score:" & score ' show the score on our label
Me.Caption = "score:" & score
Timer1.Enabled = True ' start the timer again to get the ball moving
End Sub
Private Sub Time1_Timer()
ball.Move ball.Left + X, ball.Top + Y
If balll.Top <= 0 Then Y = Y * -1 End If If ball.Left <= 0 Then X = X * -1 End If If ball.Left + ball.Width >= Me.ScaleWidth Then
X = X * -1
End If
If ball.Top + ball.Height >= pad.Top Then
If (ball.Left + ball.Width < pad.Left) Or (ball.Left > pad.Left + pad.Width) Then
'if the ball is to the left or right of the pad then
Me.Caption = "game over" ' set the forms captions to read game over
reset.Visible = True 'make the reset button visible
Timer.Enabled = False ' pause the program
Else
Y = Y * -1.05 'speed up the ball
X = X * 1.05 '
score = score + 1 'add 1 more hit to the score
scorecard.Caption = "score:" & score 'show the score on our label
Me.Caption = "score:" & score ' show the score as our forms caption
If (ball.Left + ball.Width / 2) < (pad.Left + pad.Width / 2) Then 'if the ball is to the left or the pad center then If X > 0 Then ' if it is going to the right
X = X * -1 'make it go left
End If
Else ' the ball must be on the right of the pad
If X < 0 Then 'if it is going left
X = X * -1 'make it go right
End If
End If
End If
End If
endif
End Sub
Design View
Output View
2 comments:
"hi sir gooD day!!
"hi sir gooD day!!
Post a Comment