1

First off, I'm using Visual Basics 2013.

I'm coding a game using VB.net In this game you control spaceships and choose where you want them to fly. And I'm trying to set it up to where when a ship (which is represented by a picture box) PictureBox1 and PictureBox2. get within a certain radius of each other they attack.

I would show you the code, but currently it is just a empty Sub.

NOTE It's not a revolutionary or advanced game, but it's a small step closer to making better quality programs.

I thank you for ANY help or guidance you have to offer.

Garrett
  • 11
  • 5

1 Answers1

2

This seems like basic math.

distance = Math.Sqrt(xDist * xDist + yDist * yDist)

Where xDist and yDist are the difference in x position and y position.

You can then check if distance is smaller than some value a to invoke your "attack" scenario.

Luke Joshua Park
  • 9,527
  • 5
  • 27
  • 44
  • 2
    Math.Pow needs a second parameter, in this case a 2. Using multiplication (e.g. xDist * xDist) to do the squaring is faster than the power function. And there is no need to determine the absolute value here. If a distance is negative, squaring it will make it positive. – JerryM Oct 19 '15 at 23:06
  • My mistake, I'll edit my answer. I didn't know that Math.Pow was slower. – Luke Joshua Park Oct 19 '15 at 23:07