Esempio n. 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 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);
        }