|
-
Jul 21st, 2001, 06:57 PM
#1
Thread Starter
Frenzied Member
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.
-
Jul 21st, 2001, 07:16 PM
#2
PowerPoster
-
Jul 21st, 2001, 07:43 PM
#3
Thread Starter
Frenzied Member
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.
-
Jul 21st, 2001, 07:58 PM
#4
Fanatic Member
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:
'in a module
Public Type MoveData
X As Long 'current X pos
Y As Long 'current Y pos
DeltaX As Integer 'number of units per change in X pos
DeltaY As Integer 'number of units per change in Y pos
XDir As Integer 'X direction, positive for right, negative for left
YDir As Integer 'Y direction, positive for down, negative for up because of the VB convention
End Type
'in the gen dec section of the form, or public in a module if you want
Dim Ball As MoveData
'wherever you have the movement, like a timer or something
'this assumes you have two pictureboxes, picGameBoard and picBall, and picBall has no border
With Ball
.X = .X + (.DeltaX * .XDir) 'do the X movement
.Y = .Y + (.DeltaY * .YDir) 'do the Y movement
'these statements change the direction of movement when the boundaries of
'the gameboard are reached
If .X >= (picGameBoard.ScaleWidth - picBall.Width) Then .XDir = -1
If .Y >= (picGameBoard.ScaleHeight - picBall.Height) Then .YDir = -1
If .X <= 0 Then .XDir = 1
If .Y <= 0 Then .YDir = 1
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 
-
Jul 21st, 2001, 08:07 PM
#5
Thread Starter
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|