Hi,

I am trying to implement some parabolic trajectories for the missiles

used in the game Magnant (

http://www.insectwar.com) . It would enable

Ants to shoot more realistic arrows to other ants.

Right now ants are shooting point to point arrows, that follow along a

straight path (a line).

I am wondering if anybody knows a good algorithm or a good formula for

implementing this?

The GPL code is currently written like this ( stratagus engine v1.18 ):

I can send the complete .C if necessary.

int dx;

int dy;

int xstep;

int ystep;

int i;

if( !(missile->State&1) ) {

// initialize

dy=missile->DY-missile->Y;

ystep=1;

if( dy<0 ) {

dy=-dy;

ystep=-1;

}

dx=missile->DX-missile->X;

xstep=1;

if( dx<0 ) {

dx=-dx;

xstep=-1;

}

// FIXME: could be better written

if( missile->Type->Class == MissileClassWhirlwind

|| missile->Type->Class == MissileClassFlameShield ) {

// must not call MissileNewHeading nor frame change

} else if( missile->Type->Class == MissileClassBlizzard ) {

missile->SpriteFrame = 0;

} else if( missile->Type->Class == MissileClassPointToPoint3Bounces ) {

missile->DX-=xstep*TileSizeX/2;

missile->DY-=ystep*TileSizeY/2;

} else {

MissileNewHeadingFromXY(missile,dx*xstep,dy*ystep) ;

}

if( dy==0 ) { // horizontal line

if( dx==0 ) {

return 1;

}

} else if( dx==0 ) { // vertical line

} else if( dx<dy ) { // step in vertical direction

missile->D=dy-1;

dx+=dx;

dy+=dy;

} else if( dx>dy ) { // step in horizontal direction

missile->D=dx-1;

dx+=dx;

dy+=dy;

}

missile->Dx=dx;

missile->Dy=dy;

missile->Xstep=xstep;

missile->Ystep=ystep;

++missile->State;

DebugLevel3Fn("Init: %d,%d, %d,%d, =%d\n"

_C_ dx _C_ dy _C_ xstep _C_ ystep _C_ missile->D);

return 0;

} else {

// on the way

dx=missile->Dx;

dy=missile->Dy;

xstep=missile->Xstep;

ystep=missile->Ystep;

}

//

// Move missile

//

if( dy==0 ) { // horizontal line

for( i=0; i<missile->Type->Speed; ++i ) {

if( missile->X==missile->DX ) {

return 1;

}

missile->X+=xstep;

}

return 0;

}

if( dx==0 ) { // vertical line

for( i=0; i<missile->Type->Speed; ++i ) {

if( missile->Y==missile->DY ) {

return 1;

}

missile->Y+=ystep;

}

return 0;

}

if( dx<dy ) { // step in vertical direction

for( i=0; i<missile->Type->Speed; ++i ) {

if( missile->Y==missile->DY ) {

return 1;

}

missile->Y+=ystep;

missile->D-=dx;

if( missile->D<0 ) {

missile->D+=dy;

missile->X+=xstep;

}

}

return 0;

}

if( dx>dy ) { // step in horizontal direction

for( i=0; i<missile->Type->Speed; ++i ) {

if( missile->X==missile->DX ) {

return 1;

}

missile->X+=xstep;

missile->D-=dy;

if( missile->D<0 ) {

missile->D+=dx;

missile->Y+=ystep;

}

}

return 0;

}

// diagonal line

for( i=0; i<missile->Type->Speed; ++i ) {

if( missile->Y==missile->DY ) {

return 1;

}

missile->X+=xstep;

missile->Y+=ystep;

}

return 0;

Mohydine

--

Posted via

http://dbforums.com