Esempio n. 1
0
static float dollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ,float ang)
{
    /*  SDL_FloatPoint p[DOLLARNPOINTS]; */
    float dist = 0;
    SDL_FloatPoint p;
    int i;
    for (i = 0; i < DOLLARNPOINTS; i++) {
        p.x = (float)(points[i].x * SDL_cos(ang) - points[i].y * SDL_sin(ang));
        p.y = (float)(points[i].x * SDL_sin(ang) + points[i].y * SDL_cos(ang));
        dist += (float)(SDL_sqrt((p.x-templ[i].x)*(p.x-templ[i].x)+
                                 (p.y-templ[i].y)*(p.y-templ[i].y)));
    }
    return dist/DOLLARNPOINTS;

}
Esempio n. 2
0
void Cannon::aimAtPoint(float timeElapsed, Vector2f pos, Vector2f vel)
{
	float myPosX = myStation->getPos().x + ((cos(myStation->getRotation()*M_PI/180)*position.x)-(sin(myStation->getRotation()*M_PI/180)*position.y));
	float myPosY = myStation->getPos().y + ((sin(myStation->getRotation()*M_PI/180)*position.x)+(cos(myStation->getRotation()*M_PI/180)*position.y));
	Vector2f distBetween = Vector2f(pos.x-myPosX,pos.y-myPosY);
	float time = 826.0f/distBetween.length();
	Vector2f fDist = (myStation->getVelocity()/time)*-1;
	Vector2f fDist2 = (vel/time);
	float rot =  rotation;
	if(rot < 0)
	{
		rot+=360;
	}
	if(rot>=360)
	{
		rot -= 360;
	}
	float dir = 0;
	distBetween = Vector2f((pos.x+fDist.x+fDist2.x)-(myPosX),(pos.y+fDist.y+fDist2.y)-(myPosY));
	distBetween /= distBetween.length();
	dir = ( ( SDL_cos((rot)*M_PI/180)*180/M_PI) * (distBetween.y) - ( SDL_sin((rot)*M_PI/180)*180/M_PI) * (distBetween.x));
	if(dir <-2)
	{
		rotation -=20*timeElapsed;
	}
	else if(dir > 2)
	{
		rotation += 20*timeElapsed;
	}
	if( dir <=2 && dir >= -2)
	{
		action(timeElapsed);
	}
}
Esempio n. 3
0
float
SDL_cosf(float x)
{
#if defined(HAVE_COSF)
    return cosf(x);
#else
    return (float)SDL_cos((double)x);
#endif
}
Esempio n. 4
0
/* DollarPath contains raw points, plus (possibly) the calculated length */
static int dollarNormalize(const SDL_DollarPath *path,SDL_FloatPoint *points)
{
    int i;
    float interval;
    float dist;
    int numPoints = 0;
    SDL_FloatPoint centroid;
    float xmin,xmax,ymin,ymax;
    float ang;
    float w,h;
    float length = path->length;

    /* Calculate length if it hasn't already been done */
    if (length <= 0) {
        for (i=1;i < path->numPoints; i++) {
            float dx = path->p[i  ].x - path->p[i-1].x;
            float dy = path->p[i  ].y - path->p[i-1].y;
            length += (float)(SDL_sqrt(dx*dx+dy*dy));
        }
    }

    /* Resample */
    interval = length/(DOLLARNPOINTS - 1);
    dist = interval;

    centroid.x = 0;centroid.y = 0;

    /* printf("(%f,%f)\n",path->p[path->numPoints-1].x,path->p[path->numPoints-1].y); */
    for (i = 1; i < path->numPoints; i++) {
        float d = (float)(SDL_sqrt((path->p[i-1].x-path->p[i].x)*(path->p[i-1].x-path->p[i].x)+
                                   (path->p[i-1].y-path->p[i].y)*(path->p[i-1].y-path->p[i].y)));
        /* printf("d = %f dist = %f/%f\n",d,dist,interval); */
        while (dist + d > interval) {
            points[numPoints].x = path->p[i-1].x +
                ((interval-dist)/d)*(path->p[i].x-path->p[i-1].x);
            points[numPoints].y = path->p[i-1].y +
                ((interval-dist)/d)*(path->p[i].y-path->p[i-1].y);
            centroid.x += points[numPoints].x;
            centroid.y += points[numPoints].y;
            numPoints++;

            dist -= interval;
        }
        dist += d;
    }
    if (numPoints < DOLLARNPOINTS-1) {
        SDL_SetError("ERROR: NumPoints = %i\n",numPoints);
        return 0;
    }
    /* copy the last point */
    points[DOLLARNPOINTS-1] = path->p[path->numPoints-1];
    numPoints = DOLLARNPOINTS;

    centroid.x /= numPoints;
    centroid.y /= numPoints;

    /* printf("Centroid (%f,%f)",centroid.x,centroid.y); */
    /* Rotate Points so point 0 is left of centroid and solve for the bounding box */
    xmin = centroid.x;
    xmax = centroid.x;
    ymin = centroid.y;
    ymax = centroid.y;

    ang = (float)(SDL_atan2(centroid.y - points[0].y,
                            centroid.x - points[0].x));

    for (i = 0; i<numPoints; i++) {
        float px = points[i].x;
        float py = points[i].y;
        points[i].x = (float)((px - centroid.x)*SDL_cos(ang) -
                              (py - centroid.y)*SDL_sin(ang) + centroid.x);
        points[i].y = (float)((px - centroid.x)*SDL_sin(ang) +
                              (py - centroid.y)*SDL_cos(ang) + centroid.y);


        if (points[i].x < xmin) xmin = points[i].x;
        if (points[i].x > xmax) xmax = points[i].x;
        if (points[i].y < ymin) ymin = points[i].y;
        if (points[i].y > ymax) ymax = points[i].y;
    }

    /* Scale points to DOLLARSIZE, and translate to the origin */
    w = xmax-xmin;
    h = ymax-ymin;

    for (i=0; i<numPoints; i++) {
        points[i].x = (points[i].x - centroid.x)*DOLLARSIZE/w;
        points[i].y = (points[i].y - centroid.y)*DOLLARSIZE/h;
    }
    return numPoints;
}
void CHighCloud::moveCould(SDL_Rect playerRect)
{
	if (health->checkLife())
	{
		if (!inShock)
		{
			float playerCenterX = playerRect.x + playerRect.w / 2;
			float playerCenterY = playerRect.y + playerRect.h / 2;
			float cloudCenterX = cloud->getX() + cloud->getW() / 2;
			float cloudCenterY = cloud->getY() + cloud->getH() / 2;

			if (movementtimer * 5 % 180 == 0)
			{
			if (cloudCenterX - playerCenterX != 0) { angleTraveling = (180 / M_PI) * atan((cloudCenterY - playerCenterY) / (cloudCenterX - playerCenterX)); }
			//else  angleTraveling = (180 / M_PI) * atan((cloudCenterY - playerCenterY) / (cloudCenterX - playerCenterX)+0.01);
			if (cloudCenterY - playerCenterY <= 0 & cloudCenterX - playerCenterX >= 0) { angleTraveling = 180 + angleTraveling; }
			if (cloudCenterY - playerCenterY >= 0 & cloudCenterX - playerCenterX >= 0) { angleTraveling = 180 + angleTraveling; }
			if (cloudCenterY - playerCenterY >= 0 & cloudCenterX - playerCenterX <= 0) { angleTraveling = 360 + angleTraveling; }
			}

			movementtimer++;
			if (movementtimer * 5 % 180 == 0)
			{
				if (movementtimer * 5 % 360 == 0)
					directionToggle = 1;
				else
					directionToggle = -1;
			}

			cloud->setX(cloud->getX() + (SDL_cos(angleTraveling*(M_PI / 180))*cloudSpeed)*(directionToggle*SDL_sin((float)movementtimer * 5 * (M_PI / 180))));
			cloud->setY(cloud->getY() + (SDL_sin(angleTraveling*(M_PI / 180))*cloudSpeed)*(directionToggle*SDL_sin((float)movementtimer * 5 * (M_PI / 180))));

			float distance = sqrt((cloudCenterX - playerCenterX)*(cloudCenterX - playerCenterX) + (cloudCenterY - playerCenterY)*(cloudCenterY - playerCenterY));
			if (distance / 3 < highPower)
				cloud->setHigh(highPower - (distance / 3));
		}
		else
		{
			hurtTimer++;

			if (knockBack > 0)
				knockBack--;
			if (knockBack < 0)
				knockBack++;

			cloud->setX(cloud->getX() + knockBack);

			if (hurtTimer > 15)
			{
				cloud->setFrame(0);
				inShock = false;
				hurtTimer = 0;
			}
		}
	}
	else
	{
		fallingAngle += 10;
		deadFallingSpeed += 0.5;
		cloud->setY(cloud->getY() + deadFallingSpeed);
		cloud->setX(cloud->getX() + deadPushBackSpeed);
		cloud->setAngle(fallingAngle);
	}
}