Ejemplo n.º 1
0
        public TrackScreen(Background background, Vector2 startPos, ContentManager content, EventHandler screenEvent)
            : base(screenEvent)
        {
            carBasicTex = content.Load<Texture2D>("Cars//redcar");
            hudFont = content.Load<SpriteFont>("Fonts//hudFont");
            countdownFont = content.Load<SpriteFont>("Fonts//countdownFont");
            winnerFont = content.Load<SpriteFont>("Fonts//winnerFont");

            this.startPos = startPos;
            this.background = background;

            carBasic = new CarBasic(new Vector2(startPos.X, startPos.Y + 15), carBasicTex);
            aiCar = new AICarBasic(new Vector2(startPos.X, startPos.Y - 15), carBasicTex);
        }
Ejemplo n.º 2
0
        public static void AICarSteer(AICarBasic car, Background track)
        {
            Matrix transformCarToTrack = car.transformMatrix * Matrix.Invert(track.transformMatrix);

            Vector2 positionInBL = Vector2.Transform(new Vector2(-10, -car.Height * 2), transformCarToTrack);
            Vector2 positionInBR = Vector2.Transform(new Vector2(car.Width + 10, -car.Height * 2), transformCarToTrack);

            int xL = (int)Math.Round(positionInBL.X);
            int yL = (int)Math.Round(positionInBL.Y);
            int xR = (int)Math.Round(positionInBR.X);
            int yR = (int)Math.Round(positionInBR.Y);

            Color colorRight = track.colorData[xR + yR * track.Width];
            Color colorLeft = track.colorData[xL + yL * track.Width];
            Color colorGrass = new Color(24, 199, 42); // Color of grass

            if ((colorRight == colorGrass && colorLeft == colorGrass) ||
                (colorLeft != colorGrass && colorRight == colorGrass))
                car.rotation -= (2 * car.speed) / car.handling;
            else if (colorLeft == colorGrass && colorRight != colorGrass)
                car.rotation += (2 * car.speed) / car.handling;
        }