public override Vector2 calculatCartPosition(TrainCart cart)
        {
            int offset = 59;
            int radius = 50;

            double cartPos = cart.position;

            int angle = Convert.ToInt32((90 * cartPos / 100) + MathHelper.ToDegrees(rotation));
            int moveAngle = angle - 90;
            Vector2 result = new Vector2();

            if (direction)
            {

                if (MathHelper.ToDegrees(rotation) == 90)
                {
                    angle =  90 - angle;
                    moveAngle =  90 - moveAngle;
                    result = new Vector2(position.X - offset + Convert.ToInt32(radius * Math.Cos(Math.PI / 180 * moveAngle)), position.Y + Convert.ToInt32(radius * Math.Sin(Math.PI / 180 * moveAngle)));
                }
                else if (MathHelper.ToDegrees(rotation) == 180)
                {
                    angle = 270 - angle;
                    moveAngle = 270 - moveAngle;
                    result = new Vector2(position.X + Convert.ToInt32(radius * Math.Cos(Math.PI / 180 * moveAngle)), position.Y - offset + Convert.ToInt32(radius * Math.Sin(Math.PI / 180 * moveAngle)));
                }
                else if (MathHelper.ToDegrees(rotation) == 270)
                {
                    angle = 90 - angle;
                    moveAngle = 90 - moveAngle;
                    result = new Vector2(position.X + offset + Convert.ToInt32(radius * Math.Cos(Math.PI / 180 * moveAngle)), position.Y + Convert.ToInt32(radius * Math.Sin(Math.PI / 180 * moveAngle)));
                }
                else
                {
                    angle = 270 - angle;
                    moveAngle = 270 - moveAngle;
                    result = new Vector2(position.X + Convert.ToInt32(radius * Math.Cos(Math.PI / 180 * moveAngle)), position.Y + offset + Convert.ToInt32(radius * Math.Sin(Math.PI / 180 * moveAngle)));
                }

            }
            else
            {
                //if (cart.previousTrack != prevTrack)
                //    cartPos = 100 - cartPos;

                if (MathHelper.ToDegrees(rotation) == 90)
                    result = new Vector2(position.X - offset + Convert.ToInt32(radius * Math.Cos(Math.PI / 180 * moveAngle)), position.Y + Convert.ToInt32(radius * Math.Sin(Math.PI / 180 * moveAngle)));
                else if (MathHelper.ToDegrees(rotation) == 180)
                    result = new Vector2(position.X + Convert.ToInt32(radius * Math.Cos(Math.PI / 180 * moveAngle)), position.Y - offset + Convert.ToInt32(radius * Math.Sin(Math.PI / 180 * moveAngle)));
                else if (MathHelper.ToDegrees(rotation) == 270)
                    result = new Vector2(position.X + offset + Convert.ToInt32(radius * Math.Cos(Math.PI / 180 * moveAngle)), position.Y + Convert.ToInt32(radius * Math.Sin(Math.PI / 180 * moveAngle)));
                else
                    result = new Vector2(position.X + Convert.ToInt32(radius * Math.Cos(Math.PI / 180 * moveAngle)), position.Y + offset + Convert.ToInt32(radius * Math.Sin(Math.PI / 180 * moveAngle)));
            }
            cart.rotation = (float)(angle * Math.PI / 180);
            return result;
        }
        public override Vector2 calculatCartPosition(TrainCart cart)
        {
            Vector2 result = new Vector2(0, 0);
            double cartPos = cart.position;

            if (MathHelper.ToDegrees(rotation) == 0 || MathHelper.ToDegrees(rotation) == 180)
            {
                if (cart.currentPos.X <= cart.previousTrack.position.X)
                    cartPos = 100 - cartPos;

                result = new Vector2(Convert.ToInt32(position.X + (50 * cartPos / 100)), position.Y + 9);
            }
            else if (MathHelper.ToDegrees(rotation) == 90 || MathHelper.ToDegrees(rotation) == 270)
            {
                if (cart.currentPos.Y <= cart.previousTrack.position.Y)
                    cartPos = 100 - cartPos;

                result = new Vector2(position.X - 9, Convert.ToInt32(position.Y + (50 * cartPos / 100)));
            }

            return result;
        }
        public override Vector2 calculatCartPosition(TrainCart cart)
        {
            Vector2 result = new Vector2();
            int offset = 59;
            int radius = 50;

            double cartPos = cart.position;

            if (MathHelper.ToDegrees(rotation) == 0 || MathHelper.ToDegrees(rotation) == 180)
            {
                if (cart.currentPos.X <= cart.previousTrack.position.X)
                    cartPos = 100 - cartPos;
            }
            else if (MathHelper.ToDegrees(rotation) == 90 || MathHelper.ToDegrees(rotation) == 270)
            {
                if (cart.currentPos.Y <= cart.previousTrack.position.Y)
                    cartPos = 100 - cartPos;
            }

            int angle = Convert.ToInt32((90 * cartPos / 100)); // + MathHelper.ToDegrees(rotation));
            int moveAngle = angle - 90;

            if (cart.previousTrack == nextTrack || (cart.previousTrack == prevTrack && !turn))
            {
                if (MathHelper.ToDegrees(rotation) == 0)
                    result = new Vector2(Convert.ToInt32(position.X + (50 * cartPos / 100)), position.Y + 9);
                else if (MathHelper.ToDegrees(rotation) == 90)
                    result = new Vector2(position.X - 9, Convert.ToInt32(position.Y + (50 * cartPos / 100)));
                else if (MathHelper.ToDegrees(rotation) == 180)
                    result = new Vector2(Convert.ToInt32(position.X -50 + (50 * cartPos / 100)), position.Y - 9);
                else if (MathHelper.ToDegrees(rotation) == 270)
                    result = new Vector2(position.X + 9, Convert.ToInt32(position.Y - 50 + (50 * cartPos / 100)));

            }
            else
            {
                if (MathHelper.ToDegrees(rotation) == 90)
                {
                    angle = 90 + angle;
                    moveAngle = 90 + moveAngle;
                    result = new Vector2(position.X - offset + Convert.ToInt32(radius * Math.Cos(Math.PI / 180 * moveAngle)), position.Y + Convert.ToInt32(radius * Math.Sin(Math.PI / 180 * moveAngle)));
                }
                else if (MathHelper.ToDegrees(rotation) == 180)
                {
                    angle = 90 - angle;
                    moveAngle = 90 - moveAngle;
                    result = new Vector2(position.X + Convert.ToInt32(radius * Math.Cos(Math.PI / 180 * moveAngle)), position.Y - offset + Convert.ToInt32(radius * Math.Sin(Math.PI / 180 * moveAngle)));
                }
                else if (MathHelper.ToDegrees(rotation) == 270)
                {
                    angle = -angle;
                    moveAngle = 180 - moveAngle;
                    result = new Vector2(position.X + offset + Convert.ToInt32(radius * Math.Cos(Math.PI / 180 * moveAngle)), position.Y + Convert.ToInt32(radius * Math.Sin(Math.PI / 180 * moveAngle)));
                }
                else
                    result = new Vector2(position.X + Convert.ToInt32(radius * Math.Cos(Math.PI / 180 * moveAngle)), position.Y + offset + Convert.ToInt32(radius * Math.Sin(Math.PI / 180 * moveAngle)));

                cart.rotation = (float)(angle * Math.PI / 180);
            }

            return result;
        }
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            RailRoadCtr rCtr = new RailRoadCtr();
            railroad = rCtr.loadRailRoad("Railroad2.xml", Content);

            TrainSet train1;
            train1 = new TrainSet("Train #1", new List<TrainCart>(), new Engine(30));

            TrainCart cart1 = new TrainCart(Content);
            cart1.currentTrack = railroad.tracks[0];
            cart1.previousTrack = railroad.tracks[25];
            cart1.position = 50;
            cart1.maxSpeed = 60;
            cart1.setCart();
            train1.cartList.Add(cart1);

            railroad.trains.Add(train1);

            train1.locoDriver =  new LocoDriver("Per", train1, railroad);

            TrainSet train2;
            train2 = new TrainSet("Train #2", new List<TrainCart>(), new Engine(20));

            TrainCart cart2 = new TrainCart(Content);
            cart2.currentTrack = railroad.tracks[27];
            cart2.previousTrack = railroad.tracks[26];
            cart2.position = 50;
            cart2.maxSpeed = 60;
            cart2.rotation = MathHelper.ToRadians(0);
            cart2.setCart();
            train2.cartList.Add(cart2);

            railroad.trains.Add(train2);

            train2.locoDriver = new LocoDriver("Ole", train2, railroad);
            //TrainCart cart2 = new TrainCart(Content);
            //cart2.currentTrack = railroad.tracks[1];
            //cart2.previousTrack = railroad.tracks[0];
            //cart2.position = 5;
            //cart2.maxSpeed = 60;
            //cart2.setCart();
            //train1.cartList.Add(cart2);

            //TrainCart cart3 = new TrainCart(Content);
            //cart3.currentTrack = railroad.tracks[0];
            //cart3.previousTrack = railroad.tracks[7];
            //cart3.position = 30;
            //cart3.maxSpeed = 60;
            //cart3.setCart();
            //train1.cartList.Add(cart3);

            whistle = Content.Load<SoundEffect>("train");
            initPanels(railroad);
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
        }
 public abstract Vector2 calculatCartPosition(TrainCart cart);
        public override Vector2 calculatCartPosition(TrainCart cart)
        {
            int offset = 47;
            int radius = 38;

            int angle = Convert.ToInt32((90 * cart.position / 100) + MathHelper.ToDegrees(rotation));
            int moveAngle = angle - 90;

            Vector2 result = new Vector2();

            //Check if the traincar shall turn off at the SwitchTrack
            if (turn)
            {
                //Cheack if the traincar shall turn left or right
                if (direction)
                {
                    //Check the rotation
                    if (MathHelper.ToDegrees(rotation) == 180)
                    {
                        //Right turn when driving backwards
                        result = new Vector2(position.X + Convert.ToInt32(radius * Math.Cos(Math.PI / 180 * moveAngle)), position.Y - offset + Convert.ToInt32(radius * Math.Sin(Math.PI / 180 * moveAngle)));
                    }
                    else if (MathHelper.ToDegrees(rotation) == 270)
                    {
                        result = new Vector2(position.X + offset + Convert.ToInt32(radius * Math.Cos(Math.PI / 180 * moveAngle)), position.Y + Convert.ToInt32(radius * Math.Sin(Math.PI / 180 * moveAngle)));
                    }
                    else
                    {
                        //Right turn when driving forward
                        result = new Vector2(position.X + Convert.ToInt32(radius * Math.Cos(Math.PI / 180 * moveAngle)), position.Y + offset + Convert.ToInt32(radius * Math.Sin(Math.PI / 180 * moveAngle)));
                    }
                }
                else if (!direction && rotation == 0)
                {
                    result = new Vector2(position.X + Convert.ToInt32(radius * Math.Cos(Math.PI / 180 * moveAngle)), position.Y + offset + Convert.ToInt32(radius * Math.Sin(Math.PI / 180 * moveAngle)));
                }
                else
                {
                    if (MathHelper.ToDegrees(rotation) == 90)
                    {
                        //Left turn when driving forward
                        result = new Vector2(position.X - offset + Convert.ToInt32(radius * Math.Cos(Math.PI / 180 * moveAngle)), position.Y + Convert.ToInt32(radius * Math.Sin(Math.PI / 180 * moveAngle)));
                    }
                    else
                    {
                        //Left turn when driving backwards
                        result = new Vector2(position.X + offset + Convert.ToInt32(radius * Math.Cos(Math.PI / 180 * moveAngle)), position.Y + Convert.ToInt32(radius * Math.Sin(Math.PI / 180 * moveAngle)));
                    }
                }

                cart.rotation = (float)(angle * Math.PI / 180);

            }
            else
            {
                double cartPos = cart.position;

                if (!direction && rotation == 0)
                {
                    result = new Vector2(position.X - 9, Convert.ToInt32(position.Y + (50 * cartPos / 100)));
                }

                if (rotation == 0)
                {
                    result = new Vector2(Convert.ToInt32(position.X + (50 * cartPos / 100)), position.Y + 9);
                }
                else
                {
                    result = new Vector2(position.X - 9, Convert.ToInt32(position.Y + (50 * cartPos / 100)));
                }
            }

            return result;
        }