I have the attached excel games file. Please ignore the Tic-Tac-Toe and Hangman sheets.
I am trying to make a pong game in Excel, as kind of a mental excercise. I think I have this more or less working, except for a timing issue.
I have the following bit of code:
Sub PongTimer()
If Range("AJ1") < 4 Then
MsgBox ("You Win!")
ElseIf Range("AJ1") > 65 Then
MsgBox ("You lose!")
Else
BallMoveTime = Now + 0.000005785
Application.OnTime BallMoveTime, "MoveBall"
End If
End Sub
Sub MoveBall()
Range("AI3") = Range("AI3") + (Range("AK2") * 0.8)
If Cells(Range("AJ1") + Range("AK1"), Range("AJ2") + Range("AK2")) = "-" Then
Range("AK1") = Range("AK1") * -1
ElseIf Cells(Range("AJ1") + Range("AK1"), Range("AJ2") + Range("AK2")) = "|" Then
Range("AK2") = Range("AK2") * -1
End If
Range("AJ1") = Range("AJ1") + Range("AK1")
Range("AJ2") = Range("AJ2") + Range("AK2")
Call PongTimer
End Sub
This part in particular is giving me trouble
BallMoveTime = Now + 0.000005785
Application.OnTime BallMoveTime, "MoveBall"
When I set my BallMoveTime to 0.000005, the system is busy the whole time and I cannot move the player bar with the arrow key. When I set it to 0.000006, I can move the bar just fine, but the ball moves very sluggishly. So, I began to add digits to the BallMoveTime to see if there was a happy medium between being unable to move and the ball being too slow.
There is not, seemingly. It seems like when I move the BallMoveTime past some mysterious increment, it changes to either too fast or too slow. There is no gradual shift.
Can anyone help me either make the code more efficient, or adjust the timing so that the game runs smoothly?
Thanks.
Bookmarks