|
-
Mar 11th, 2000, 09:01 AM
#1
Thread Starter
Member
i have a game going in visual basic and it has little aliens bouncing around the screen(at least thats what i want it to do) anyways i have the the X & Y declared, and it checs to see if it has hit the wall. Could someone help me out i cant get it to bounce of in the opposite direction and i cant get it to move around really!?
-
Mar 11th, 2000, 09:22 AM
#2
Member
I once did something like that. What I did was, of course, use a timer to move the object and at every timer interval, I checked to see if the object was at the edge. The best way, in my mind to have it bounce off the wall is this:
1. Use variables for the x and y direction. And set them equal to something..like at form load or something.
2. Negate the variables if it hits a wall
Timer1_Timer()
if object.left <=0 or object.left >= form1.scalewidth then
directionx = -directionx
elseif object.top <=0 or object.top >= form1.scalewidth then
directiony = -directiony
end if
object.left = object.left + directionx
object.top = object.top + directiony
End Sub
You can play around with that and hopefully, it'll give you what you want.
-
Mar 11th, 2000, 10:26 AM
#3
Thread Starter
Member
thanx greenday it helped alot but it still needs to be tweaked a little bit but heres the code for the program :
CODE:
Dim X
Dim Y
Dim D1 As Integer
Dim D2 As Integer
Sub Form_Click ()
D1 = 1
D2 = -1
X = picture1.Left
Y = picture1.Top
timer1.Enabled = True
End Sub
Sub Form_Load ()
ScaleMode = 3
picture1.ScaleMode = 3
End Sub
Sub Timer1_Timer ()
If picture1.Left < 0 Then
D1 = -1
D2 = 1
ElseIf picture1.Left > 188 Then
D1 = 1
D2 = -1
ElseIf picture1.Top = 0 Then
D1 = 1
D2 = 1
ElseIf picture1.Top > 299 Then
D1 = -1
D2 = -1
End If
picture1.Left = picture1.Left + D2
picture1.Top = picture1.Top + D1
DoEvents
End Sub
try to fix it and tell me whats wrong with it
THANX!!
-
Mar 12th, 2000, 01:40 AM
#4
Member
Try this:
Dim x, y As Integer
Dim d1, d2 As Integer
Private Sub Form_Click()
d1 = 1
d2 = -1
x = Picture1.Left
y = Picture1.Top
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
If Picture1.Left <= 0 Then
d1 = -d1
ElseIf Picture1.Left + Picture1.ScaleWidth >= 188 Then
d1 = -d1
ElseIf Picture1.Top <= 0 Then
d2 = -d2
ElseIf Picture1.Top + Picture1.ScaleHeight >= 299 Then
d2 = -d2
End If
Picture1.Left = Picture1.Left + d1
Picture1.Top = Picture1.Top + d2
DoEvents
End Sub
If you want me to send you a program using this or if you have any other questions, email me at [email protected].
-
Mar 12th, 2000, 09:47 AM
#5
Thread Starter
Member
for some reason that doesent work probably because i have vb3 and it was also to slow
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
|