Example #1
0
void BulletController::update(SDL_Surface* screen)
{
    for(int i=0; i < bulletCount; i++)
    {
        apply_surface( bullets[i].x, bullets[i].y, SHEET_bullet, screen);
        bullets[i].x += bullets[i].x_vel;
        bullets[i].y += bullets[i].y_vel;
        if(bullets[i].x < 0-BULLET_FRAME_WIDTH || bullets[i].y < 0-BULLET_FRAME_HEIGHT || bullets[i].x > SCREEN_WIDTH || bullets[i].y > SCREEN_HEIGHT)
        {
            destroyBullet(i);
        }
    }
}
Example #2
0
void move_Bullets(BULLET_MANAGER *b_m)
{
	if( NULL == b_m){
		printf("Bullet_Manager is null;");
		return;
	}

	int i=0,lengh = b_m->bullet_Count;
	for(i=0 ; i<lengh; i++)
	{
		if( b_m->bullets[i].button )  // true, mean the bullet be FaShe
		{
			switch(b_m->bullets[i].dir)
			{
				case UP:
					b_m->bullets[i].y--;
					break;

				case DOWN:
					b_m->bullets[i].y++;
					break;

				case LEFT:
					b_m->bullets[i].x--;
					break;

				case RIGHT:
					b_m->bullets[i].x++;
					break;
			}

			if( b_m->bullets[i].x < 0 ||
				b_m->bullets[i].x > WIDTH - 1||
				b_m->bullets[i].y < 0 ||
				b_m->bullets[i].y > HEIGHT-1 )
			{
                destroyBullet( (b_m->bullets)+i );
			}
		}
	}
	return;
}