i neez help manz.

here is what i have so far:


------------------------------------

Dim x As Integer

Private Sub cmdexit_Click()
'this will end the program
End
End Sub


Private Sub picmario_KeyPress(KeyAscii As Integer)
'this will allow the user to use various keys to
'move mario

'this will move the mario up using the 8 key
If KeyAscii = 56 Then
picmario.Top = picmario.Top - 50
End If

'this will move mario down using the 2 key
If KeyAscii = 50 Then
picmario.Top = picmario.Top + 50
End If

'this will move mario left using the 4 key
If KeyAscii = 52 Then
picmario.Left = picmario.Left - 50
End If

'this will move mario right using the 6 key
If KeyAscii = 54 Then
picmario.Left = picmario.Left + 50
End If


'this will make the program exit if mario touches the walls or the goomba
If picmario.Top = 960 & picmario.Left = 600 Then
End
End If


End Sub


Private Sub tmrgoomba1_Timer()
'this will move the goomba.
picgoomba1.Move picgoomba1.Left - -10
If picgoomba1.Left = 5640 Then
picgoomba1.Move picgoomba1.Left - -10 = False
picgoomba1.Left = 1560
picgoomba1.Top = 5640
picgoomba1.Move picgoomba1.Left - 10
End If

End Sub

----------------------------
now i have a problem...

every time my pic called mario touches something i want the program end. how do i do this?
please and thankz

I think you should unload your current form ( i call it myform in this case )

'this will make the program exit if mario touches the walls or the goomba
If picmario.Top = 960 & picmario.Left = 600 Then
'if your exit function works, you can use.
cmdexit_Click
End If

Edited 6 Years Ago by neosonic: n/a

First, you should never use End to end your program. You should use unload me...
Second, for readability you should use the built in constants (vbKeyUp, vbKeyLeft, vbKeyRight, vbKeyDown)...
Third, does your code work as it is??? Use the forms KeyDown event in conjunction with setting the forms keypreview property equal to True

Then there are these codes...

this one makes your picture box stay to the left...
picgoomba1.Move picgoomba1.Left - -10 = False

and this is the same as saying +
picgoomba1.Move picgoomba1.Left - -10
(picgoomba1.Move picgoomba1.Left + 10)

and then why the use of the left and top properties of the control when you are already using the move statement, which is faster as you can set all its properties (left, top, width, height) at once...

So to answer your question, when you detect a collision or "collision detection" (hint: keyword search...), you want your program to end. So as I said previously, use Unload Me

Good Luck

yes my code works perfectly....besides the 'collision detection'

i haven't exactly learned about 'unload me' Im only a sophmore taking a vb class ><

what is it exactly? i looked up collision detection and i found some interesting stuff. ima try and incorporate into my game.

When you start a new standard exe program, you start out with form1. Press F5 and it runs. Use the X in the upper right corner, and it ends, but what happens in the backgound is what you need to be aware of...

So to figure this out, place debug.print "procedure name" in every event of the form...

Private Sub Form_Initialize()
Debug.Print "Form_Initialize"
End Sub

and form load and so on...

now run this program once you have all the debug.print s in there. Use ALT+Tab to change to another program and switch back, resize the form, minimize the form, then close the form with the X.

Then place a command button on the form and put unload me in its click event...

Now, what Unload Me refers to, is the current form (Me) and the command is to Unload. So unload the current form... Rerun the expermental program and instead of using the X to close the form, click the button...

Good Luck

Edited 6 Years Ago by vb5prgrmr: n/a

well thanks for your detailed explanation but that is not what i need.
i need to somehow figure out how if a picture crashes into another picture the game exits or the form resets....sorta like pacman.
the vb class i am in, we haven't learned a whole lot.

I understand that,... that some teachers are lacking. My teacher published her own book that was only an inch thick that we had to buy for the class. Talking about conflicts of interest..., But while it did cover a lot of different topics, it did not go into much detail with explanations, so I had to buy my own book that was published by Que and it showed me the things I wanted to know...

Now, as for collision detection, there are a couple of different ways in which to accomplish what you want. There are a couple of different methods using the api but unless you really want to delve into it, you don't have to...

Okay, you have an object that has four properties. Left, Top, Width, Height, so we will start with checking collision with the borders of the form...

'here are the two obvious and easy detections...
If Object.Left <= 0 Then
  'we have collided with the left side of the form
ElseIf Object.Top = <= 0 Then
  'we have collided with the top edge of the form
  'next up is some simple math...
ElseIf (Object.Left + Object.Width) >= Me.ScaleWidth Then
  'collision with the right of the form
ElseIf (Object.Top + Object.Height) >= Me.ScaleHeight Then
  'collision with the bottom of the form
End If

Now, when it comes to decting two objects colliding, well this is where it can get interesting and quite complicated. So complicated in fact, you may want to write your formulas down before putting them in your code just to make sure you have them right because you will have to check for all instances, meaning both objects properties as listed above.

So to give you a hint, I will only give you the easy part...

'this checks the objects lower right corner with the upper left corner of the otherobject.
'what is left to check is the other three corners (and if you think about it, you will be done as with these checks, each side is also done...
If (((Object.Left + Object.Width) >= (OtherObject.Left)) And ((Object.Left + Object.Width) <= (OtherObject.Left + OtherObject.Width))) And (((Object.Top + Object.Height) >= (OtherObject.Top)) And ((Object.Top + Object.Heigth) <= (OtherObject.Top + OtherObject.Heigth))) Then
  'so is that complicated enough??? :)
'....

Good Luck

Well one of my friends were able to figure it out ><

he used something like STEP:
here is a little of what he told me what to do:
--------------------------
Private Sub Form_Load()
lblfinish.Visible = False
a = picmario.Left
b = picmario.Top
c = picgoomba1.Top
d = picgoomba1.Left

For n = 0 To b Step 10
For m = 0 To b Step 10
If c + n >= b & c + n <= b + (Height + b) & a + n >= d & a + n >= d + (Height + d) Then
End
Next m
End If
Next n
End Sub
---------

problem is everytime i do this and try to play the program it says Next without For ><

all i need to try and do is make the picture reset to it's original spot everytime it touches something or maybe make it disapper or even make the program exit...which i was doing in the above code.
i tried using what u told me and im still figuring it out but i wanna try and use this STEP thing.

nevermind htat...i was able to figure out my error....but it does nothing >< god i am so confused.

This question has already been answered. Start a new discussion instead.