Results 1 to 4 of 4

Pong Excel Game - Timing issue

Threaded View

  1. #1
    Forum Expert Whizbang's Avatar
    Join Date
    08-05-2009
    Location
    Greenville, NH
    MS-Off Ver
    2010
    Posts
    1,395

    Pong Excel Game - Timing issue

    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.
    Attached Files Attached Files
    Last edited by Whizbang; 06-08-2010 at 03:03 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1