class part
	{
     private:
     	float x,y;
        float dx,dy;
        int angle;
        BITMAP *pic;
        int spin;	    //0 is false 1 is true
        int exist;	    //0 is false 1 is true

	public:
    	void init(void);
        void create(float xx, float yy, int aangle, BITMAP *ppic, int sspin, float ddx,float ddy);
        void draw(BITMAP *backgr, float sx, float sy);
        void move(int grav);
        void move_to_top(float s_x, float s_y);
	};

void part::move_to_top(float s_x, float s_y)
	{
     //if the particle goes off of the bottom of the screen
     //replace it so that it will appear on the screen
     if(y-s_y>=510)
       {
       //move to top of screen
       y=-10+s_y;

       //create a random x position
       x=rand()%900;
       x-=100;
       //and put it so that it will appear on the screen
       x+=s_x;

       //it exists
       exist=1;
       }
    }

void part::init(void)
	{
	 x=0;
     y=0;
     angle=0;
     spin=0;
     exist=0;
    }

void part::create(float xx, float yy, int aangle, BITMAP *ppic, int sspin, float ddx, float ddy)
	{
     x=xx;
     y=yy;
     angle=aangle;
     pic=ppic;
     spin=sspin;
     dx=ddx*7;
     dy=ddy*7;
     exist=1;
    }

void part::draw(BITMAP *backgr, float sx, float sy)
	{
     if(exist==1)
       {
     	rotate_sprite(backgr,pic,(int)x-(int)sx,(int)y-(int)sy,itofix(angle));

        if(x-sx<-500 || x-sx>1100 || y-sy<-500 || y-sy>900)
          exist=0;
       }
    }

void part::move(int grav)
	{
     if(exist==1)
       {
     	x+=dx;
     	y+=dy;
     	if(spin==1)
       	   angle+=5;
        if(dy>-14 && grav==1)
        	dy+=gravity/2;
       }
    }

class part_set
	{
     private:
     	part p[200];
        int next;
     public:
     	void init(void);
        void create_new(float x, float y, int angle, BITMAP *pic, int spin, float dx, float dy);
        void move_all(int grav);
        void draw_all(BITMAP *backgr, float s_x, float s_y);
        void move_to_top(float s_x,float s_y);

        void draw_some(BITMAP *backgr, float s_x, float s_y,int from, int to);
	};

void part_set::draw_some(BITMAP *backgr, float s_x, float s_y,int from, int to)
	{
     for (int n=from ; n<to ; n++)
        p[n].draw(backgr, s_x,s_y);
    }

void part_set :: move_to_top(float s_x, float s_y)
	{
     for(int n=0; n<200 ; n++)
        p[n].move_to_top(s_x,s_y);
    }

void part_set::init(void)
	{
     for (int n=0 ; n<200 ; n++)
        p[n].init();
     next=0;
    }

void part_set::create_new(float x, float y, int angle, BITMAP* pic, int spin, float dx, float dy)
	{
     p[next].create(x,y,angle,pic,spin,dx,dy);
     next++;
     if(next>198)
       next=0;
    }

void part_set::move_all(int grav)
	{
     for(int n=0 ; n<200 ; n++)
        p[n].move(grav);
    }

void part_set::draw_all(BITMAP *backgr, float s_x, float s_y)
	{
     for (int n=0 ; n<200 ; n++)
        p[n].draw(backgr, s_x,s_y);
    }



