#### motorollin

##### Member

- Joined
- Jul 31, 2007

- Messages
- 163

As a test, I added a line of code to blit the enemy's sprite to the screen and this did show, so I know the file is being loaded correctly. I just can't figure this out! Can anyone shed any light?

CODE

class Green

{

private:

int frame, dx, dy;

bool run;

public:

int col_l, col_r, col_t, col_b, x, y, xVel, yVel;

Green();

void move();

void show();

void runaway( int x1, int y1, int x2, int y2 );

};

Green::Green()

{

x=rand() % 600 + 20;

y=rand() % 440 + 20;

xVel=greenspeed;

yVel=greenspeed;

run=false;

}

void Green::show()

{

frame++;

//Loop the animation

if( frame >= 6 )

{

frame = 0;

}

//Show the enemy

apply_surface( x - camera.x, y - camera.y, green, screen, &greenClips[ frame ] );

}

void Green::runaway( int x1, int y1, int x2, int y2 )

{

run=true;

int ddx = x1-x-(x1-x2)*4;

int ddy = y1-y-(y1-y2)*4;

int bdx = x1-x2;

int bdy = y1-y2;

int distd = sqrt(ddx*ddx + ddy*ddy)+0.001;

int distb = sqrt(bdx*bdx + bdy*bdy)+0.001;

if( distd < 100 )

{

ddx = -ddx/distd*30;

ddy = -ddy/distd*30;

ddx :+ bdx/distb*30;

ddy :+ bdy/distb*30;

dx = dx + ddx;

dy = dy + ddy;

}

}

vector<Green> greens;

void Bullet::move()

{

//The bullet gets moved

...

//Make the green enemies run away from the bullet

for ( int i=1; i<greens.size(); i++ )

{

int distx = x-greens

*.x;*

int disty = y-greens

int disty = y-greens

*.y;*

double dist = sqrt( (distx*distx) + (disty*disty) );

if ( dist < 50 )

{

greensdouble dist = sqrt( (distx*distx) + (disty*disty) );

if ( dist < 50 )

{

greens

*.runaway( x, y, dx, dy );*

}

}

}

void Green::move()

{

if( !run )

{

if( x < playerx-(PLAYER_WIDTH/2) ) dx = greenspeed;

if( x > playerx-(PLAYER_WIDTH/2) ) dx = -greenspeed;

if( y < playery+(PLAYER_HEIGHT/2)-7 ) dy = greenspeed;

if( y > playery+(PLAYER_HEIGHT/2)-7 ) dy = -greenspeed;

}

run=false;

x+=dx;

y+=dy;

col_l = x - (GREEN_WIDTH / 2);

col_r = col_l + GREEN_WIDTH;

col_t = y - (GREEN_HEIGHT / 2);

col_b = col_t + GREEN_HEIGHT;

}

Extract from main loop:

CODE

for ( int i = 1; i<greens.size(); i++ )

{

greens}

}

}

void Green::move()

{

if( !run )

{

if( x < playerx-(PLAYER_WIDTH/2) ) dx = greenspeed;

if( x > playerx-(PLAYER_WIDTH/2) ) dx = -greenspeed;

if( y < playery+(PLAYER_HEIGHT/2)-7 ) dy = greenspeed;

if( y > playery+(PLAYER_HEIGHT/2)-7 ) dy = -greenspeed;

}

run=false;

x+=dx;

y+=dy;

col_l = x - (GREEN_WIDTH / 2);

col_r = col_l + GREEN_WIDTH;

col_t = y - (GREEN_HEIGHT / 2);

col_b = col_t + GREEN_HEIGHT;

}

Extract from main loop:

CODE

for ( int i = 1; i<greens.size(); i++ )

{

greens

*.move();*

}

for ( int i = 1; i < greens.size(); i++ )

{

if ( collision( myPlayer.col_l , greens}

for ( int i = 1; i < greens.size(); i++ )

{

if ( collision( myPlayer.col_l , greens

*.col_l, myPlayer.col_r , greens**.col_r, myPlayer.col_t , greens**.col_t, myPlayer.col_b , greens**.col_b ) )*

{

status=2;

loop=false;

}

for ( int j = 1; j<bullets.size(); j++ )

{

if ( collision( bullets[j].col_l , greens{

status=2;

loop=false;

}

for ( int j = 1; j<bullets.size(); j++ )

{

if ( collision( bullets[j].col_l , greens

*.col_l, bullets[j].col_r , greens**.col_r, bullets[j].col_t , greens**.col_t, bullets[j].col_b , greens**.col_b ) )*

{

greens.erase(greens.begin()+i);

bullets.erase(bullets.begin()+j);

}

}

}

for ( int i = 1; i < greens.size(); i++ ) greens{

greens.erase(greens.begin()+i);

bullets.erase(bullets.begin()+j);

}

}

}

for ( int i = 1; i < greens.size(); i++ ) greens

*.show();*