示例#1
0
        public double WallCheck(Pieton piet)
        {
            Coordinate Start = new Coordinate()
            {
                X = piet.Position.X, Y = piet.Position.Y
            };
            Coordinate End = piet.ComputeNewPosition(piet.Position);
            double     X   = End.X - Start.X;
            double     Y   = End.Y - Start.Y;

            if (X == 0)
            {
                X = CNST.EPSIL;
            }
            if (Y == 0)
            {
                Y = CNST.EPSIL;
            }
            double PietSlope = Y / X;
            double PietOff   = Start.Y - PietSlope * Start.X;

            Coordinate shock = new Coordinate();

            /*x = (d - b) / (a - c)*/
            shock.X = (PietOff - offset) / (Slope - PietSlope);
            shock.Y = offset + Slope * shock.X;

            double distToWall = Coordinate.Distance(shock, Start);

            if (distToWall > CNST.Radius * Coordinate.Distance(End, Start))
            {
                return(piet.Direction);
            }

            if (EndPoint.X - StartPoint.X > 0)
            {
                if (shock.X > EndPoint.X || shock.X < StartPoint.X)
                {
                    return(piet.Direction);
                }
            }
            else
            {
                if (shock.X < EndPoint.X || shock.X > StartPoint.X)
                {
                    return(piet.Direction);
                }
            }
            return(Math.Tan(Slope));
        }
示例#2
0
        public List <Pieton> CreatePieton()
        {
            List <Pieton> list = new List <Pieton>();

            for (int i = 0; i < CNST.NBCreate; i++)
            {
                Pieton p = new Pieton(CNST.PietonId++)
                {
                    Direction = this.Angle,
                    Position  = new Coordinate {
                        X = Draw.Width + this.Position.X, Y = (i * Draw.Height / CNST.NBCreate) + this.Position.Y
                    }
                };
                list.Add(p);
            }
            return(list);
        }