void BaseTank::FireRockets() { if(mRocketDelay <= 0.0f) { mRocketDelay = kTimeBetweenRockets; mFiringRocket = true; //Get the direction of fire from the current heading. Vector2D fireDirection = mHeading * -1; //fireDirection.y *= -1; //Set the projectile setup details. ProjectileSetupDetails details; details.Direction = fireDirection; details.GameObjectType = GAMEOBJECT_ROCKET; details.ImagePath = kRocketPath; details.RotationAngle = mRotationAngle; //Fire left rocket. if( (mRockets > 0) && (mCannonAttachedLeft) ) { details.StartPosition = GetCentralPosition(); details.StartPosition += fireDirection.Perp()*-14.0f; ProjectileManager::Instance()->CreateProjectile(mRenderer, details, this); } //Fire right rocket. if( (mRockets > 0) && (mCannonAttachedRight) ) { details.StartPosition = GetCentralPosition(); details.StartPosition += fireDirection.Perp()*14.0f; ProjectileManager::Instance()->CreateProjectile(mRenderer, details, this); } } }
MovingEntity::MovingEntity(int id, Vector2D _position, double _radius, Vector2D _velocity, double _max_speed, Vector2D _heading, double _mass, Vector2D _scale, double _turn_rate, double _max_force) : BaseGameEntity(id, 0, _position, _radius), heading(_heading), velocity(_velocity), mass(_mass), side(_heading.Perp()), maxSpeed(_max_speed), maxTurnRate(_turn_rate), maxForce(_max_force) { scale = _scale; }
//----------------------- isPassSafeFromOpponent ------------------------- // // test if a pass from 'from' to 'to' can be intercepted by an opposing // player //------------------------------------------------------------------------ bool AbstSoccerTeam::isPassSafeFromOpponent(Vector2D from, Vector2D target, const PlayerBase* const receiver, const PlayerBase* const opp, double PassingForce)const { //move the opponent into local space. Vector2D ToTarget = target - from; Vector2D ToTargetNormalized = Vec2DNormalize(ToTarget); Vector2D LocalPosOpp = PointToLocalSpace(opp->Pos(), ToTargetNormalized, ToTargetNormalized.Perp(), from); //if opponent is behind the kicker then pass is considered okay(this is //based on the assumption that the ball is going to be kicked with a //velocity greater than the opponent's max velocity) if ( LocalPosOpp.x < 0 ) { return true; } //if the opponent is further away than the target we need to consider if //the opponent can reach the position before the receiver. if (Vec2DDistanceSq(from, target) < Vec2DDistanceSq(opp->Pos(), from)) { if (receiver) { if ( Vec2DDistanceSq(target, opp->Pos()) > Vec2DDistanceSq(target, receiver->Pos()) ) { return true; } else { return false; } } else { return true; } } //calculate how long it takes the ball to cover the distance to the //position orthogonal to the opponents position double TimeForBall = Pitch()->Ball()->TimeToCoverDistance(Vector2D(0,0), Vector2D(LocalPosOpp.x, 0), PassingForce); //now calculate how far the opponent can run in this time double reach = opp->MaxSpeed() * TimeForBall + Pitch()->Ball()->BRadius()+ opp->BRadius(); //if the distance to the opponent's y position is less than his running //range plus the radius of the ball and the opponents radius then the //ball can be intercepted if ( fabs(LocalPosOpp.y) < reach ) { return false; } return true; }