当前位置: 首页>>代码示例>>C#>>正文


C# Ball.GetDistanceTo方法代码示例

本文整理汇总了C#中Ball.GetDistanceTo方法的典型用法代码示例。如果您正苦于以下问题:C# Ball.GetDistanceTo方法的具体用法?C# Ball.GetDistanceTo怎么用?C# Ball.GetDistanceTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Ball的用法示例。


在下文中一共展示了Ball.GetDistanceTo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ChooseDirection

        public static Vector ChooseDirection(Player player, Ball ball)
        {
            var k1 = Line.K0(ball.Position, Field.MyGoal.Top);
            var k2 = Line.K0(ball.Position, Field.MyGoal.Bottom);
            var kball = ball.Velocity.Y / ball.Velocity.X;
            var lineball = Line.One(ball.Position, ball.Position + ball.Velocity);

            if ( ball.Owner == null
                && lineball.K >= Math.Min(k1, k2)
                && lineball.K <= Math.Max(k1, k2))
            {
                var nball = Line.Normal(lineball, player.Position);
                var intpos = Line.Cross(lineball, nball);
                if (Field.Borders.Contains(intpos)) return intpos;
                return Line.Cross(lineball, Line.One(Field.MyGoal.Top, Field.MyGoal.Bottom));
            }

            var line = Line.One(ball.Position, Field.MyGoal.Center);

            var n1 = Line.Normal(line, Field.MyGoal.Top);
            var n2 = Line.Normal(line, Field.MyGoal.Bottom);
            var a = Line.Cross(line, n1);
            var b = Line.Cross(line, n2);

            if (ball.GetDistanceTo(a) <= ball.GetDistanceTo(b))
                return a;
            return b;
        }
开发者ID:yojig,项目名称:CloudBall,代码行数:28,代码来源:GoalKeeper.cs

示例2: Action

        public void Action(Team myTeam, Team enemyTeam, Ball ball, MatchInfo matchInfo)
        {
            foreach (Player player in myTeam.Players)
            {
                Player closestEnemy = player.GetClosest(enemyTeam);
                switch (player.PlayerType)
                {
                    case PlayerType.Keeper:
                        if (ball.Owner == player)
                        {
                            var partner = player.GetClosestUncovered(myTeam, enemyTeam);
                            if (partner != null)
                            {
                                var power = player.GetDistanceTo(partner) / 10;
                                player.ActionShoot(partner, power);
                                continue;
                            }
                            else
                            {
                                // todo: shoot just to enemy side
                                player.ActionShootGoal();
                                continue;
                            }
                        }
                        if (player.GetDistanceTo(ball) < 50 
                            && player.CanPickUpBall(ball))
                        {
                            player.ActionPickUpBall();
                            continue;
                        }
                        if (ball.GetClosest(myTeam) == player
                            && ball.GetClosest(enemyTeam).GetDistanceTo(ball) < player.GetDistanceTo(ball)
                            && ball.GetDistanceTo(Field.MyGoal.Center) < 400)
                        {
                            player.ActionGo(ball.Position);
                            continue;
                        }

                        var direction = GoalKeeper.ChooseDirection(player, ball);
                        player.ActionGo(direction);
                        continue;

                    default:
                        if (ball.Owner == player)
                            if (player.GetDistanceTo(Field.EnemyGoal.Center) > 400)
                            {
                                var inters = player.GetClosestInterceptors(enemyTeam, 400);
                                if (!inters.Any())
                                {
                                    player.ActionGo(Field.EnemyGoal.Center);
                                    continue;
                                }
                                else if (inters.Count() >= 3)
                                {
                                    var partner = player.GetClosestUncovered(myTeam, enemyTeam);
                                    if (partner != null) player.ActionShoot(partner, 100);
                                }
                                var goalDirect = (Field.EnemyGoal.Center - player.Position).GetDirection();
                                var direct = (from i in inters
                                              select (i.Velocity) + (player.Position - i.Position).GetDirection() * (1 - i.GetDistanceTo(player) / 500))
                                              .Aggregate(Vector.Zero, (acc, v) => acc + v).GetDirection() + goalDirect;
                                var dest = player.Position + direct;
                                //if (direct.X < -50 && partner != null)
                                //{
                                //    player.ActionShoot(partner, 100);
                                //    continue;
                                //}
                                //else 
                                //    if (dest.Y < Field.Borders.Top.Y + 200
                                //    || dest.Y > Field.Borders.Bottom.Y - 200)
                                //{
                                //    player.ActionGo(dest + goalDirect * 2);
                                //    continue;
                                //}
                                //else 
                                //        if (dest.X > Field.Borders.Right.X - 100)
                                //{
                                //    player.ActionGo(Field.Borders.Center);
                                //    continue;
                                //}
                                //else 
                                //if (Field.Borders.Contains(dest))
                                //{
                                    player.ActionGo(dest);
                                    continue;
                                //}
                                //else
                                //{
                                //    player.ActionGo(Field.EnemyGoal.Center);
                                //    continue;
                                //}
                            }
                            else
                            {
                                //var goalkepers = from ep in enemyTeam.InFrontOf(player)
                                //                 ;

                                player.ActionShootGoal();
                            }
                        break;
//.........这里部分代码省略.........
开发者ID:yojig,项目名称:CloudBall,代码行数:101,代码来源:MadGuys.cs


注:本文中的Ball.GetDistanceTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。