Ejemplo n.º 1
0
void Bird::Contact(b2Vec2 impulse, GameItem *gameItem)
{
    if(impulse.Length()>0)
    {
        remove=1;
        travel=false;
        isOut = 2;
        setScore(impulse.Length());
    }
    else
    {
        isContact = false;
    }
}
Ejemplo n.º 2
0
bool Neural_SB::accumForce(b2Vec2 & totForce, b2Vec2 force) const
{
    //std::cout << "\t\tTotalForce : " << totForce.x << " " << totForce.y << std::endl;
    b2Vec2 tot = totForce + force;
    if( tot.LengthSquared() <= m_fMaxForce*m_fMaxForce )
    {
        totForce += force;
        return true;
    }

    force.Normalize();
    force *= abs(m_fMaxForce - totForce.Length());
    totForce += force;
    return false;
}
void LiquidFunScene::ccTouchEnded(cocos2d::CCTouch* touch,
                                  cocos2d::CCEvent* event){

  if (m_startSprite != NULL) {
    const CCPoint& startSpritePosition = m_startSprite->getPosition();
    const CCPoint& endSpritePosition = m_endSprite->getPosition();
    // Calculate the start / end and length of the vector between them in
    // world coordinates.
    const b2Vec2 startPosition = ConvertScreenPositionToWorld(
        b2Vec2(startSpritePosition.x, startSpritePosition.y));
    const b2Vec2 endPosition = ConvertScreenPositionToWorld(
        b2Vec2(endSpritePosition.x, endSpritePosition.y));
    const b2Vec2 startEndVector = endPosition - startPosition;
    const float32 startEndLength = startEndVector.Length();

    // Calculate the middle point along the vector between startPosition and
    // endPosition.
    b2Vec2 midPoint;
    midPoint = startEndVector;
    midPoint *= 0.5f;
    midPoint += startPosition;

    b2PolygonShape box;
    box.SetAsBox(startEndLength * 0.5f,
                 k_drawableBoxThickness * m_worldExtentMin);
    b2BodyDef bodyDef;
    bodyDef.type = b2_staticBody;
    bodyDef.position = midPoint;
    bodyDef.angle = atan2(startEndVector.y, startEndVector.x);
    b2Body* body = m_world->CreateBody(&bodyDef);
    body->CreateFixture(&box, 0);

    removeChild(m_startSprite);
    removeChild(m_endSprite);
    // These will be cleaned up by the autorelease system since they were
    // allocated by init()
    m_startSprite = NULL;
    m_endSprite = NULL;
  }
}
Ejemplo n.º 4
0
float RadiansOf(b2Vec2 vec) {
  static b2Vec2 vertical(0, -1);
  float dot = (vertical.x * vec.x) + (vertical.y * vec.y);
  float angle_r = acos(dot / (vertical.Length() * vec.Length()));
  return angle_r;
}
Ejemplo n.º 5
0
//Chase firing
bool Enemy::chaseFire(b2Vec2 & rFireV)
{
	bool trigger = false;

	//Did we fire?
	if (fired_)
	{
		angry_ = fmaxf(angry_ - triggerSatisfaction_[brainStem_.weapon_training], 0);
		fired_ = false;
	}

	//Fire at player?
	if (play_)
	{
		b2Vec2 myPos = getPosition();
		b2Vec2 pPos = player_->getPosition();
		b2Vec2 between = (pPos - myPos);
		float dist = between.Length();

		//Fire if in visible range and 
		if (dist < visRange_[brainStem_.sensitivity] && chill_ > freezingPoint_)
		{
			rFireV = LJP(pPos, 100, 0, 2.0, 0); //*//Fire LJP const?
		}
	}

	//DECIDE TO FIRE
	float seePlayer = rFireV.Length();
	float ammo = (float)getWeaponBar() / (float)getWeaponBarMAX();

	//Otherwise, heat up, chill first
	if (seePlayer != 0)
	{
		orient(rFireV);
		if (chill_ != 0) chill_ = fminf(chill_ += seePlayer * 4 * moodMult_[brainStem_.aggression], 0);
		else angry_ = fminf(angry_ + seePlayer * moodMult_[brainStem_.aggression], angryMAX_);
	}

	//If we're mad enough and we can see the player, fire
	if (angry_ > boilingPoint_ && seePlayer != 0)
	{
		trigger = true;
	}

	//Reload if we're cool enough
	if (angry_ - boilingPoint_ > (angryMAX_ - boilingPoint_) * accuracy_[brainStem_.weapon_training] * moodMult_[brainStem_.aggression]) //*//weapon training, aggression
	{
		if (ammo < accuracy_[brainStem_.weapon_training]) //*// weapon training causes later reloads
			reup();
	}

	//Chill out when idle
	if (angry_ == 0 && seePlayer == 0)
	{
		chill_ -= 1 * moodMult_[brainStem_.inner_peace];

		if (chill_ <= freezingPoint_)
		{
			if (ammo < 1.f)
				reup();

			spin(-0.05f);
		}
	}
	chill_ = fmax(chill_, chillMIN_);

	return trigger;
}
Ejemplo n.º 6
0
	float sumMagnitude(sf::Vector2f& V1, b2Vec2& V2)
	{
		return sqrtf(V1.x*V1.x + V1.y*V1.y) + V2.Length();
	}
Ejemplo n.º 7
0
	float sumMagnitude(b2Vec2& V1, sf::Vector2f& V2)
	{
		return V1.Length() + sqrtf(V2.x * V2.x + V2.y * V2.y);
	}
Ejemplo n.º 8
0
	float sumMagnitude(const b2Vec2& V1, const b2Vec2& V2)
	{
		return V1.Length() + V2.Length();
	}