Results 1 to 5 of 5

Thread: Bouncing

  1. #1

    Thread Starter
    Frenzied Member SomethinCool's Avatar
    Join Date
    Jan 2001
    Location
    Malvern, PA
    Posts
    1,407

    Bouncing

    Does anyone know how to make a picture (of a ball) bounce around the form until it passes the left side of the form or it hits the bumper like pong? I would also like it to reset itself to where it was after it goes off the screen. (there is only one bumper) I need code please...i'm a newbie to VB.
    Last edited by SomethinCool; Jul 21st, 2001 at 07:01 PM.

  2. #2
    PowerPoster eiSecure's Avatar
    Join Date
    Jul 2000
    Location
    Texas
    Posts
    2,209
    Pong is kinda tricky for a newbie to VB. Maybe you can try writing something a tiny bit easier, like Tic-Tac-Toe?

    Or maybe minesweeper?

  3. #3

    Thread Starter
    Frenzied Member SomethinCool's Avatar
    Join Date
    Jan 2001
    Location
    Malvern, PA
    Posts
    1,407
    actually, all i need is the code and i can do it. All i need is the bouncing ball code and then i can do the rest.

  4. #4
    Fanatic Member Kaverin's Avatar
    Join Date
    Oct 2000
    Posts
    930
    It's not very difficult to do that. It's just an incremental change of X,Y position, and checking for boundaries. This is out of something I did a long time ago, but it does the "bounce" when it strikes a wall.
    VB Code:
    1. 'in a module
    2. Public Type MoveData
    3.    X As Long 'current X pos
    4.    Y As Long 'current Y pos
    5.    DeltaX As Integer 'number of units per change in X pos
    6.    DeltaY As Integer 'number of units per change in Y pos
    7.    XDir As Integer 'X direction, positive for right, negative for left
    8.    YDir As Integer 'Y direction, positive for down, negative for up because of the VB convention
    9. End Type
    10.  
    11. 'in the gen dec section of the form, or public in a module if you want
    12. Dim Ball As MoveData
    13.  
    14. 'wherever you have the movement, like a timer or something
    15. 'this assumes you have two pictureboxes, picGameBoard and picBall, and picBall has no border
    16. With Ball
    17.    .X = .X + (.DeltaX * .XDir) 'do the X movement
    18.    .Y = .Y + (.DeltaY * .YDir) 'do the Y movement
    19.    'these statements change the direction of movement when the boundaries of
    20.    'the gameboard are reached
    21.    If .X >= (picGameBoard.ScaleWidth - picBall.Width) Then .XDir = -1
    22.    If .Y >= (picGameBoard.ScaleHeight - picBall.Height) Then .YDir = -1
    23.    If .X <= 0 Then .XDir = 1
    24.    If .Y <= 0 Then .YDir = 1
    25. End With
    All you need to supply is whatever draws the things in.
    Last edited by Kaverin; Jul 21st, 2001 at 08:37 PM.
    I'm baaaack...
    VB5 Professional Edition, VC++ 6
    Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se

    I feel special because I finally figured out how to loop midis: Post link
    I'm a fanatic too

  5. #5

    Thread Starter
    Frenzied Member SomethinCool's Avatar
    Join Date
    Jan 2001
    Location
    Malvern, PA
    Posts
    1,407
    is there a way to make one with a randomize timer and make it go around the screen using that?

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