Object locations

  • Thread starter Thread starter JonnyF2000
  • Start date Start date
J

JonnyF2000

Guest
Hello all,

I'm trying to write an extremely basic spaceship program and i want to know if there is an easier way to detect if my ship(a picturebox with a ship picture) hits an asteroid(another picture box). Right now i just have loads of if ...then statements that say for example...

if picship.left > 16 and picship.left < 48 and picship.top > 48 and picship.top < 88 then

msgbox(strname & " You crashed!")
intlives = intlives - 1
lbllives.text = intlives
picship.location = new point(8,8)
endif

what i want to know is if there is anyway to just write the code so that if picship.location = picasteroid.location then do my above statements. i tried saving the objects locations as system.drawing.point variables and running it when loc1(the ships location) = loc2(the asteriouds location) but it says "=" isnt allowed with type system.drawing.point. Any help would be greatly welcomed. Thanks in advance/
 
i know i mgiht sound rude/impatient but if someone could please answer this by 7 AM EST i would be very gratful, thanks in advance.
 
This is very simple to do. The picturebox has a Bounds property,
which is a Recantgle class containing its position and size.

The Rectangle class has a Contains method, which returns true if
a point or other rectangle (it's overloaded) is contained within the
bounds of that rectangle.

So, use the Contains method of the Bounds property of one picturebox
to see if it contains the Bounds of the other picturebox.
 
hello again,

Well i finally got to school and it dawned on me that i had no idea what your talking about (i'm a newbie to programing in general) I tried the statment...

if picship.contains(pic6th) then
msgbox("Debug")

but the box never showed up, leaving me to think im doing this way wrong, could you please just type up the line of code that i would use insteed of what i have? thanks again
 
Wait, i just re-read your post and remembered the bounds property, which i tried to use unsuccessfully. I tryed the code picship.bounds, but that isnt valid. If it wouldn't be to much trouble would you please show me some expample code on how to do this?
 
hello,
over the last 2 days i've tried every possible solution i can think of to this problem with no avail. I tried picship.bounds.contains wiht no success, i tried picship.contains(pic5th.loncation) with no luck either. Would someone please kindly help me out?
 
I'm so terribly sorry, I mistold you. Use the IntersectsWith method
to determine if that one bounds intersects with the other.

Visual Basic:
MessageBox.Show(PictureBox1.Bounds.Contains(PictureBox2.Bounds))

Once again, I'm so sorry for the misinformation, and good luck with
your project.
 
Any idea on why this didn't work?

BtnRight_click(byval....Etc.)
picship.left = picship.left + 5

if picship.bounds.contains(pic1.bounds) = true then

msgbox("You crashed")

picship.location = new point(8,8)

I clicked the button many times until i ran into an asteriod and still nothing happened. Any idea why?
 
Back
Top