|
-
Dec 3rd, 1999, 07:24 AM
#1
Thread Starter
Frenzied Member
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
-
Dec 3rd, 1999, 07:35 AM
#2
So Unbanned
what's deltax and deltay?
------------------
DiGiTaIErRoR
-
Dec 3rd, 1999, 07:39 AM
#3
Thread Starter
Frenzied Member
Sorry, These are there also:
Desclarations:
Dim DeltaX, DeltaY As Integer
FormLoad:
Private Sub Form_Load()
DeltaX = 100
DeltaY = 100
End Sub
-
Dec 3rd, 1999, 08:06 AM
#4
Try this for your DeltaX. BTW I assume that Image2 is to the left of Picture1.
Code:
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).]
-
Dec 3rd, 1999, 08:16 AM
#5
Thread Starter
Frenzied Member
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).]
-
Dec 3rd, 1999, 09:00 AM
#6
if you want to send me a zip of your project, I'll take a look at it.
------------------
Marty
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
|