Esempio n. 1
0
Meteor::Meteor(float radius)
{
	vertices.setPrimitiveType(sf::LinesStrip);
	for (int angle = 0; angle < 360 - maxAngle+minAngle; angle += minAngle + rand() % (maxAngle-minAngle))
	{
		float r = radius - rand() % (int(radius)/4);
		sf::Vector2f pos = r * radiansToVector(degreesToRadians(angle));
		vertices.append(sf::Vertex(pos));
	}
	vertices.append(sf::Vertex(vertices[0].position));

	angularVel = rand() % 100 - 50;
	
	objectType = ObjectType::METEOR;
	VertexObject::VerexObject();
}
CCPoint AnalogStick::getPressedVector ( KDvoid )
{
	KDfloat		fMagnitude = kdSqrtf ( kdPowf ( m_tPressedVector.x, 2 ) + kdPowf ( m_tPressedVector.y, 2 ) );
	fMagnitude += 0.25f;
	
	CCPoint		tPressedVector = ccp ( m_tPressedVector.x * 1.25f, m_tPressedVector.y * 1.25f );
	
	// 25% end deadzone to make it easier to hold highest magnitude
	if ( fMagnitude > 1 )
	{
		KDfloat		fRadians = vectorToRadians ( m_tPressedVector );
		tPressedVector = radiansToVector ( fRadians + KD_PI_F / 2 );
	}
	
	return tPressedVector;
}
KDvoid AnalogStick::repositionBarWithPoint ( const CCPoint& tPoint )
{
	const CCSize	tSize = this->getContentSize ( );

	// Rotation	
	KDfloat		fRadians = vectorToRadians ( m_tPressedVector );
	KDfloat		fDegrees = radiansToDegrees ( fRadians );	
	m_pBar->setRotation ( fDegrees );


	CCSpriteFrameCache*		pCache = CCSpriteFrameCache::sharedSpriteFrameCache ( );

	m_pBar->setDisplayFrame ( pCache->spriteFrameByName ( "analog_bar.png" ) );

	CCRect		tBarTexRect = m_pBar->getTextureRect ( );

	KDfloat		fDistFromCenter = distanceBetweenPoints ( tPoint, this->getPosition ( ) );
	KDfloat		fSizeMod = fDistFromCenter / tSize.cx;
	KDfloat		fOldHeight = tBarTexRect.size.cy;
	KDfloat		fNewHeight = fOldHeight * fSizeMod * 5;

	// Custom fixes
	if ( fNewHeight < 100 )
	{
		fNewHeight = 100.0f; 
	}
	if ( fDistFromCenter < 3 )
	{
		fNewHeight = 0.0f; 
	}

	m_pBar->setTextureRect ( CCRect ( tBarTexRect.origin.x, tBarTexRect.origin.y + ( fOldHeight - fNewHeight ), tBarTexRect.size.cx, fNewHeight ) );	
	m_pBar->setAnchorPoint ( ccp ( 0.5f, 0 ) );

	CCPoint		tDirectionVector = radiansToVector ( fRadians - KD_PI_F / 2 );
	m_pBar->setPosition ( ccp ( tSize.cx / 2 + tDirectionVector.x * tSize.cx / 4, tSize.cy / 2 + tDirectionVector.y * tSize.cy / 4 ) );
}
Esempio n. 4
0
inline sf::Vector2f randomVector(float radius)
{
	return float(radius * sqrt((double) rand() / RAND_MAX)) * radiansToVector(rand() % PIx2);
}