PDA

Click to See Complete Forum and Search --> : Ball Getting Stuck!


SteveCRM
Dec 3rd, 1999, 06:24 AM
In my air hockey game (i guess you can call it pong) I got the puck to bounce around the screen, but I can't get it to bounce off of an object. Something always goes wrong. Here is what I used:

'Bounces Puck Around Screen
Image1.Move Image1.Left + DeltaX, Image1.Top + DeltaY
If Image1.Left < Picture1.Left Then DeltaX = 100
If Image1.Left + Image1.Width > Picture1.Width + Picture1.Left Then
DeltaX = -100
End If
If Image1.Top < Picture1.Top Then DeltaY = 100
If Image1.Top + Image1.Height > Picture1.Height + Picture1.Top Then
DeltaY = -100
End If

'Bounces Off Of Paddle
If Image1.Left < Image2.Left Then DeltaX = 100
If Image1.Left + Image1.Width > Image2.Left + Image2.Width Then
DeltaX = -100
End If

Please Help (Please do not send new code, I am comfortable with this for now, please just fix it.)
Thanx.

Steve

DiGiTaIErRoR
Dec 3rd, 1999, 06:35 AM
what's deltax and deltay?


------------------
DiGiTaIErRoR

SteveCRM
Dec 3rd, 1999, 06:39 AM
Sorry, These are there also:
Desclarations:
Dim DeltaX, DeltaY As Integer
FormLoad:
Private Sub Form_Load()
DeltaX = 100
DeltaY = 100
End Sub

MartinLiss
Dec 3rd, 1999, 07:06 AM
Try this for your DeltaX. BTW I assume that Image2 is to the left of Picture1.If DeltaX = -100 Then ' Going left
If Image1.Left + Image1.Width > Image2.Left + Image2.Width Then
DeltaX = -100
Else
DeltaX = 100
End If
ElseIf Image1.Left + Image1.Width > Picture1.Width + Picture1.Left Then ' Going right
DeltaX = -100
Else
DeltaX = 100
End If

Image1.Move Image1.Left + DeltaX, Image1.Top + DeltaY


------------------
Marty

[This message has been edited by MartinLiss (edited 12-03-1999).]

SteveCRM
Dec 3rd, 1999, 07:16 AM
The picture box is what this is all in, it is the "arena". Image2 is the paddle, and image1 is the ball. Sorry if I confused you.

Steve

[This message has been edited by SteveCRM (edited 12-03-1999).]

MartinLiss
Dec 3rd, 1999, 08:00 AM
if you want to send me a zip of your project, I'll take a look at it.

------------------
Marty