|
Point A to Point B |
Cerpin Taxt
Member #8,304
February 2007
|
Just trying to get a dot moving smoothly from predecided point A to moving, player-controlled point B. Because of the way I'm doing it, the dots stop just short of point B. I'd just like to know about any better ways of doing this. for( iRe2 = 0 ; iRe2 < n; ++iRe2) { iLX = (mouse_x-iEnemyX[iRe2])*0.1; iLY = (mouse_y-iEnemyY[iRe2])*0.1; iEnemyX[iRe2] += iLX; iEnemyY[iRe2] += iLY; circlefill( buffer, iEnemyX[iRe2], iEnemyY[iRe2], 2, makecol( 255, 0, 0 )); if( iEnemyX[iRe2] == mouse_x && iEnemyY[iRe2] == mouse_y ) return(0); } Relevant code and exe attatched. I know it's because of the 0.1's at the end of the iLX and iLY lines. |
CursedTyrant
Member #7,080
April 2006
|
I'm not sure if that's what you want tough... --------- |
Cerpin Taxt
Member #8,304
February 2007
|
This seems to give me the same result as when I had the super-simple movement. Enemies moving in either straight lines or fourty-five degree angles. I'm looking for lines directly toward the target, but the way I was doing it earlier kept the enemies from reaching the target. Any more help would be fantastic. |
Kikaru
Member #7,616
August 2006
|
Get x/y distances, use Pythagorean Theorem to find total distance, divide the total distance by the speed, divide x and y distances total distance, you got x and y speeds. Only slow part is the sqrt() in the total distance. |
Cerpin Taxt
Member #8,304
February 2007
|
Okay, I'm sure I'm doing that wrong, but it's not going well. It seems way more complicated than what I was doing. Is there any way to just fix what I did before, so that it doesn't fail at the end? |
Kikaru
Member #7,616
August 2006
|
Some example code: This assumes you declared a struct/class called point, with member x and y. It also assumes you set up a proper constructor for that class. (P.S. sorry of it's really messy) |
Paul whoknows
Member #5,081
September 2004
|
Your game ends abruptly when I intentionally "touch" a red dot. ____ "The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner. |
Cerpin Taxt
Member #8,304
February 2007
|
Sorry about that. It's not really much of a game yet, huh? I must have been doing something wrong with that, but I was able to adapt Kikaru's code to something that sems to work for me. Thank you very much. |
|