shared_ptr<Action> Player::kickBetween(const Vector2f& goalLeft, const Vector2f& goalRight) { const Vector2f& posBall = WM.getBallGlobalPos2D(); Vector2f vBL = goalLeft - posBall; Vector2f vBR = goalRight - posBall; const AngDeg angLeft = vBL.angle(); const AngDeg angRight = vBR.angle(); const AngDeg angBisector = calBisectorTwoAngles(angRight, angLeft); Vector2f goal = posBall + pol2xyz(Vector2f(10.0f, angBisector)); return kickTo(goal); }
bool MidCirclePerceptor::searchWithSXAndT(MidCircle& midCircle) const { std::vector<const FieldLineIntersections::Intersection*> useSmallXIntersections; for(const FieldLineIntersections::Intersection& intersection : theFieldLineIntersections.intersections) if(intersection.type == FieldLineIntersections::Intersection::X && intersection.additionalType == FieldLineIntersections::Intersection::none) useSmallXIntersections.push_back(&intersection); if(useSmallXIntersections.empty()) return false; static const float distance = theFieldDimensions.yPosLeftSideline - theFieldDimensions.centerCircleRadius ; std::vector<const FieldLineIntersections::Intersection*> useTIntersections; for(const FieldLineIntersections::Intersection& intersection : theFieldLineIntersections.intersections) if(intersection.type == FieldLineIntersections::Intersection::T) useTIntersections.push_back(&intersection); for(const FieldLineIntersections::Intersection* intersectionSX : useSmallXIntersections) for(const FieldLineIntersections::Intersection* intersectionT : useTIntersections) if(intersectionT->indexDir1 == intersectionSX->indexDir1 || intersectionT->indexDir1 == intersectionSX->indexDir2) if(std::abs((intersectionT->pos - intersectionSX->pos).norm() - distance) < allowedTsXVariance) { const Vector2f dirTToX = intersectionSX->pos - intersectionT->pos; midCircle.translation = intersectionSX->pos + dirTToX.normalized(theFieldDimensions.centerCircleRadius); midCircle.rotation = Angle(dirTToX.angle() + pi_2).normalize();// OR intersectionT->dir2.angle(); midCircle.markedPoints.emplace_back(midCircle.translation, MarkedPoint::midCircle); theIntersectionRelations.propagateMarkedIntersection(MarkedIntersection(intersectionT->ownIndex, MarkedIntersection::BT), theFieldLineIntersections, theFieldLines, midCircle); return true; } return false; }
void Bullet::update() { this->PhysicsObject::updatePhysics(); if (timer.getRunTime() > startTime + Lifespan) { mIsDead = true; } static Vector2f Normal; static Vector2f CollisionPoint; static Vector2f MTD; if (mFriendly && game.mEnemyManager.checkBulletCollision(this)) { game.mEffectManager.addEffect( new StaticAnimationEffect(position, .4, BulletCollisionAnimation32, velocity.angle(), 1)); kill(); return; } if (!mFriendly && player.checkBulletCollision(this, Normal, CollisionPoint, MTD)) { //player collision game.mEffectManager.addEffect( new StaticAnimationEffect(position, .4, BulletCollisionAnimation32, velocity.angle(), 1)); player.health -= 25; kill(); return; } if (TerrainCollide(position, mRadius)) { Vector2f normal; world.getNormal(position.x, normal); game.mEffectManager.addEffect( new StaticAnimationEffect( Vector2f(position.x, world.getHeight(position.x)) + normal, .8, GroundCollisionAnimation32, normal.angle() + PI / 2, 1)); kill(); return; } }
shared_ptr<Action> Player::goTo(const Vector2f& stopPos, const Vector2f& lookAt, bool avoidBall) { Vector2f v = lookAt - stopPos; return goTo(stopPos, v.angle(), avoidBall); }