for a proper system you will either use a vector (
) or have some mess with pointers (which could produce the same effect as the vector), so the best thing is to use a vector, here's some pseudo code:
struct TARGETPOINT
{
int x;
int y;
};
vector<TARGETPOINT> wayPointV; //this should be a member of the Enemy1 struct
to set up your way points, do this:
TAGETPOINT points[] = {
{ x, y }, //some x/y points
{ x, y },
{ x, y },
{ x, y },
{ x, y },
{ x, y },
{ x, y }
};
for ( int i = 0; i < sizeof ( points ) / sizeof ( TAGETPOINT ); i++ )
wayPointV.push_back ( points[i] );
now for every loop, probably in the Update function of every enemy
if ( wayPointV.size ( ) > 0 ) //like: "if we have any way points"
{
dbPointSprite ( id, wayPointV[0].x, wayPointV[0].y ); //use the first element of the vector, this is our "next" way point to reach
dbMoveSprite ( id, speed );
if ( check if the sprite reached the point (wayPointV[0].x, wayPointV[0].y) )
wayPointV.erase ( wayPointV.begin ( ) ); //delete the first element, which is the point we currently are at
}
so for the loop, we're doing this:
do we have more than 0 way points?
YES: point the sprite towards it and move, have we reached it?
YES: remove this target point from the vector(our array), we know it's the 0th (very first) element of the vector so we will erase the beginning of the vector
so then, next waypoint on the vector will be the 0th because the 0th was erased, thus this will keep going untill the size reaches 0 which indicates no more points to go
note that checking if a point is reached won't be a "==", you will check if it's in range, for example:
if ( abs ( x1 - x2 ) < speed / 2 && abs ( y1 - y2 ) < speed / 2 )
//reached
i used speed/2 to be the epsilon because, it will be the best to fit to cause no flickering, i think that's the best you can check for
also, i gave you the d bPointSprite function a couple of weeks ago so i think you'll be fine