Results 1 to 6 of 6

Thread: What's wrong with this code?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2001
    Location
    Lebanon
    Posts
    90

    Unhappy What's wrong with this code?

    Hi all of you!

    I'm doing a small game using DDraw, it's called CrossBall.
    A ball is moving along the horizontal part of a cross. The user has to try and stop it in the middle of the cross. If he succeeds in doing so, another ball will start moving on the vertical part, so he has to stop aver the first one.
    The problem is, that when the first ball stops in the middle, the second one appears on the vertical part but doesn't move.

    This is the code in general:
    Code:
    'First, the BallType
    BallType
        XPosition 'Sets the X-coordinate
        Yposition 'Sets the Y-coordinate
        Xspeed 'A constant added to the X-coordinate simulating the ball's speed in the x direction
        yspeed 'A constant added to the Y-coordinate simulating the ball's speed in the y direction
    End Type
    
    CrossBall function()
        setHorizontalBall
        Do
        DoEvents
            MoveHorizontalBall
            If vbKeySpace Then
                'if Ball is in the middle
                    ball.Xspeed = 0
                    SetVerticalBall
                    Do
                    DoEvents
                        MoveVerticalBall
                        if vbKeySpace
                            'if bal is over the other one
                                ball.yspeed = 0
                                Exit Do
                        End If
                    Loop
            End If
        Loop
    End Function
    SetVertical and SetHorizontal are sub's that set the balls in theie places and sets their speeds.
    MoveHorizontal: ball.Xposition=Ball.Xposition+Ball.Speed
    MoveVertical: ball.yposition=ball.yposition+ball.speed

    I think that's it.

    Thank you all for your help.
    Last edited by sandra; May 24th, 2001 at 04:08 PM.

  2. #2
    New Member
    Join Date
    May 2001
    Location
    Colorado
    Posts
    11
    I'm pretty new at this stuff, but it looks to me like it may be a problem with the first "if vbKeySpace". Perhaps that is not always true when you are expecting the vertical ball movement to occur. I think You need to do the vertical movement outside of that if statement.



    Just my $.02 and overpriced at that.
    "Stuff is stuff."

  3. #3
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    TMTOMH, that was pseudo-code ^_^

    ---

    If vbKeySpace Then
    How do you realize that? Do you have a keys buffer? If so you'd need to clear that buffer after this line, because else Space would still be 'pressed' and the next check for Space would return true.. see?

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Apr 2001
    Location
    Lebanon
    Posts
    90
    No Fox actually I have a "buffer" for keys pressed. It's an array holding all the keys.
    What hapens is:

    Code:
    sub form_keydown(anykey) (or something like that)
      key(anykey)=true
    end sub
    
    sub form_keyup(anykey)
      key(anykey)=false
    end sub

  5. #5
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Read my posts carefully I said "Do you have a keys buffer? If so you'd need to clear that buffer after this line.."

    So after checking if space is true do:

    Code:
    Key( vbKeySpace ) = False

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Apr 2001
    Location
    Lebanon
    Posts
    90
    Ok! I'm sorry. Now I got what you mean.

    Ok, I'll try it

Posting Permissions

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



Click Here to Expand Forum to Full Width