Esempio n. 1
0
bool checkNearness(Disc d1,Disc d2)
{
	double vrel_radial,arel_radial;
	double vector_par[2],x,y,l;
	double xgap = abs(d1.getX() - d2.getX());
	double ygap = abs(d1.getY() - d2.getY());
	y=(d1.getY()-d2.getY());
	x=(d1.getX()-d2.getX());
	l=sqrt(y*y+x*x);
	
	vector_par[0]=x/l;
	vector_par[1]=y/l;
	vrel_radial=(d1.getVx()-d2.getVx())*vector_par[0]+(d1.getVy()-d2.getVy())*vector_par[1];
	arel_radial=(d1.getAx()-d2.getAx())*vector_par[0]+(d1.getAy()-d2.getAy())*vector_par[1];
	error=vrel_radial*delt+0.5*arel_radial*delt*delt;
	double r = d1.getRadius() + d2.getRadius()+error;
	if(xgap*xgap + ygap*ygap<=r*r )
	//sleep(1);
	if(xgap*xgap + ygap*ygap <= r*r && (checkNextCollision(d1,d2)))
	{
		cout<<"colission bw "<<d1.getDiscNo()<<" "<<d2.getDiscNo()<<endl;
		//sleep(1);
		error=0;
		return true;
		
	}
	error=0;
	return false;
}
Esempio n. 2
0
bool checkNextCollision(Disc d1,Disc d2)
{
	double relVx = d1.getVx() - d2.getVx();
	double relVy = d1.getVy() - d2.getVy();
	double relx = d1.getX() - d2.getX();
	double rely = d1.getY() - d2.getY();
	if(relVx*relx + relVy*rely < 0) return true;
	return false;
}
Esempio n. 3
0
bool isDiscInside(Disc d,Hole h)
{
	if(isLessThan(abs(d.getX() - h.getX()),h.getRadius()) && isLessThan(abs(d.getY() - h.getY()),h.getRadius()))
		return true;
	else
		return false;
}
Esempio n. 4
0
void afterCollision(Disc d1,Disc d2,double v[][2])
{
	//double **v = (double**) malloc(4*sizeof(double));
	//cout<<"array declared"<<endl;
	//sleep(2);
	double vector_par[2],vector_per[2],u_par[2],v_per[2],v_par[2],l;
	double v1[2][2],y,x;
	double v1x = d1.getVx(),v2x = d2.getVx(),v1y = d1.getVy(),v2y = d2.getVy(),m1 = d1.getMass(),m2 = d2.getMass();
	double slope;
	y=(d1.getY()-d2.getY());
	x=(d1.getX()-d2.getX());
	l=sqrt(y*y+x*x);
	vector_par[0]=x/l;
	vector_par[1]=y/l;
	vector_per[0]=y/l;
	vector_per[1]=-x/l;
	//cout<<"vector par"<<vector_par[0]<<"+"<<vector_par[1]<<"\n";
	//cout<<"vector_per"<<vector_per[0]<<"+"<<vector_per[1]<<"\n";
	//cout<<"v1"<<v1x<<"+"<<v1y<<"\n";
	//cout<<"v2"<<v2x<<"+"<<v2y<<"\n";
	u_par[0]=v1x*vector_par[0]+v1y*vector_par[1];
	u_par[1]=v2x*vector_par[0]+v2y*vector_par[1];
	//cout<<u_par[0]<<"+"<<u_par[1]<<"\n";
	
	v_per[0]=v1x*vector_per[0]+v1y*vector_per[1];
	v_per[1]=v2x*vector_per[0]+v2y*vector_per[1];
		//cout<<v_per[0]<<"+"<<v_per[1]<<"\n";

	v_par[0]=(m1*u_par[0] + m2*u_par[1] + m2*ed*(u_par[1]-u_par[0]))/(m1+m2);
	v_par[1]=(m1*u_par[0] + m2*u_par[1] - m1*ed*(u_par[1]-u_par[0]))/(m1+m2);
	//cout<<v_par[0]<<"+"<<v_par[1]<<"+";
	
	//cout<<"slope"<<slope<<"\n";
	//sleep(2);
	v[0][0]=v_par[0]*vector_par[0]+v_per[0]*vector_per[0];
	v[0][1]=v_par[0]*vector_par[1]+v_per[0]*vector_per[1];
	v[1][0]=v_par[1]*vector_par[0]+v_per[1]*vector_per[0];
	v[1][1]=v_par[1]*vector_par[1]+v_per[1]*vector_per[1];
	//cout<<"disk"<<v[0][0]<<"+"<<v[0][1]<<"\n";
	//cout<<"striker"<<v[1][0]<<"+"<<v[1][1]<<"\n";
	
	
}
Esempio n. 5
0
bool checkNearness(Disc d, Wall w,int wallno)
{
	bool cond = (wallno==0 || wallno==2);
	if(abs((cond?d.getY():d.getX()) - (cond?w.getY():w.getX())) <= d.getRadius() && (cond?d.getVy():d.getVx())*(cond?w.getY():w.getX())>= 0)
	{
		//cout<<d.getDiscNo()<<" colliding with wall"<<wallno<<endl;
		return true;
	}
	return false;
}
Esempio n. 6
0
void playHole(int holeName, Hole currentHole, Player jimmy, int *score )
{
    //array of things to pass from graphics to disc class
    double* stuff;   
    int scoreHole = 0 ;
    Disc disc;
    int past = 0;
    int diff;
    
    std::string currentPic;
    
     while( !disc.checkHole(currentHole.getX(), currentHole.getY()) && !past)
    {
    	currentPic = disc.pickScreen(holeName);
    	
    	//cout << currentPic << endl;
    	
    	//play the current hole
        stuff = play(currentPic, jimmy.getSong(), currentHole.getY() - disc.getY(), currentHole.getX() - disc.getX(), *score, scoreHole);
        //throw the frisbee
        disc.letFly(stuff[0],stuff[1],stuff[2],jimmy.getPower(),jimmy.getAccuracy(), currentHole);
        //track score
        (*score)++;
        scoreHole++;
        
        //see if disc has passed hole
         if(disc.getX() > currentHole.getX()) {
        	past = 1;
        	//cout << "You passed the hole. Auto score set to 8." << endl;
        	diff = 8 - scoreHole;
        	scoreHole = 8;
        	(*score) += diff;
        }
    } 
    	// determine which end screen to show
   	if( past )
		play(currentPic,jimmy.getSong(), -6, -6, *score, scoreHole);  
        else
		play(currentPic,jimmy.getSong(), 0,0, *score, scoreHole);
	
	if( holeName == 5)
		play("../../pictures/Pat_being_a_goon.png",jimmy.getSong(), -7,-7, *score, 0);
}