PDA

Click to See Complete Forum and Search --> : Finding the middle of a line....


CyberCarsten
Jan 18th, 2001, 04:16 AM
Hi guys! :)
I'm programming a "Space-Shoot-Em-Up" game!
In the bottom of the screen I have the "Shooter" , which is 5 lines. I need to find the middle of the bottom line Shooter(0), and then "fire" another line, "Fire", up in the "sky"....How is this possible....??

kedaman
Jan 18th, 2001, 08:39 AM
middle point of a line is the average of the endpoints of the line, calculate for each dimension component. I don't know how you want it to fire it up in the "sky"

CyberCarsten
Jan 18th, 2001, 11:53 AM
What you say is, X2 / 2......or am I wrong....????
I want the Fire line to go upwards on the screen(fly up the screen) I know i can do that by altering the Y2, but it has to start from the middle of the bottom line, Shooter.

kedaman
Jan 18th, 2001, 11:57 AM
The average of a say 2 2d points is (point1.x+point2.x)\2,(point1.y+point2.y)\2 you start the fire line from this point and decreament Y of both points in the line that represent the fire i guess..

CyberCarsten
Jan 18th, 2001, 12:02 PM
I don't quite understand that....
Let's say the that I want to find the middle of Line1, which vb code do I use....And how do I make the other line start from there...

kedaman
Jan 18th, 2001, 12:52 PM
What kind of line are you using, the line control?

HarryW
Jan 18th, 2001, 12:53 PM
MidLineX = (Line.X1 + Line.X2) / 2
MidLineY = (Line.Y1 + Line.Y2) / 2

' Midpoint is (MidLineX, MidlineY)

CyberCarsten
Jan 18th, 2001, 02:08 PM
Thanks harryw....but.....(to kedaman) I am using the line control, but I want to fire more than one line at a time, so I think I'm going to use the Line function.....Is this the best way....???

kedaman
Jan 18th, 2001, 03:08 PM
There are better ways, but i guess you could use line control for a lightweight game, Harry just showed you the point where your line should be fired from. Yes it's possible (everything is) to fire several lines, you would have to either create a control array of them or add them into a collection object.

SteveCRM
Jan 20th, 2001, 05:26 PM
if it was diagonal you would do something like this:

(not using control names, just an equation)

sqrt((x2-x1)+(y2-y1))

Jan 23rd, 2001, 02:04 PM
Steve:
thats the formula for the length of a line, not the midpoint =)

HarryW
Jan 23rd, 2001, 02:26 PM
Well it's nearly the formula for the length of a line... that would be sqrt((x2-x1)²+(y2-y1)²) ;)