Example #1
0
        private Tuple <PCar, PCar> hitInformation(PCar self, List <PCar> enemies)
        {
            //double maxAngle = Math.Atan2(car.Height, car.Width);
            double maxAngle = Math.PI / 2.57;//70degrees

            self.setEnginePower(1);
            MoveToAngleFunction mover = new MoveToAngleFunction(new Vector(path[0].DirOut.X, path[0].DirOut.Y).Angle);

            for (int i = 0; i < MaxCheckTicks; i++)
            {
                foreach (PCar enemy in enemies)
                {
                    Vector distance = enemy.Pos - self.Pos;
                    double angle    = Math.Abs(Math.Acos(distance.Normalize().Dot(self.Dir)));
                    if (distance.Length < game.CarWidth && angle < maxAngle)
                    {
                        return(new Tuple <PCar, PCar>(self, enemy));
                    }
                    enemy.Iteration(1);
                }
                mover.Iteration(self, 1);
            }

            return(null);
        }
        private void setupEnvironments(Car car, World world, Game game, Move move)
        {
            TilePos.TileSize = game.TrackTileSize;

            GlobalMap.InstanceInit(world);
            GlobalMap.Instance.SetupEnvironment(world, game);

            AngleReachEvent.setupEnvironment(game);

            MoveToAngleFunction.setupEnvironment(world);
            MoveToPoint.setupEnvironment(world);

            PhysicExtensions.setupEnvironment(game);
            PhysicEventsCalculator.setupEnvironment(game, world);

            CollisionSide.SetupEnvironment(game);
            CollisionCircle.SetupEnvironment(game);
            CollisionDetector.SetupEnvironment(game, GlobalMap.Instance);

            map.SetupEnvironment(car, GlobalMap.Instance);
            path.SetupEnvironment(car, GlobalMap.Instance, world, game);

            foreach (IAction action in actions.Values)
            {
                action.setupEnvironment(car, world, game, path);
            }

            foreach (AdditionalPoints action in additionalPointsActions)
            {
                action.setupEnvironment(car, world, game, path);
            }
        }
        private bool checkHit(PCar self, PTire tire)
        {
            double selfRadius  = 0.5 * Math.Sqrt(game.CarWidth * game.CarWidth + game.CarHeight * game.CarHeight);
            double checkRadius = selfRadius + game.TireRadius;

            self.setEnginePower(1);
            MoveToAngleFunction mover = new MoveToAngleFunction(new Vector(path[0].DirOut.X, path[0].DirOut.Y).Angle);

            for (int i = 0; i < MaxCheckTicks; i++)
            {
                Vector lastDistance = tire.LastPos - self.LastPos;
                Vector distance     = tire.Pos - self.Pos;

                if (lastDistance.Length > checkRadius && distance.Length < checkRadius)
                {
                    return(true);
                }

                tire.Iteration(1);
                mover.Iteration(self, 1);
            }

            return(false);
        }