How can i make the WayPoints in my xna game to be automatic on my sprites path ?

Started by
0 comments, last by SeanMiddleditch 9 years, 8 months ago

I have a class and this is the top part:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Test
{
    class Level
    {
  
        private List<Texture2D> tileTextures = new List<Texture2D>();
        private List<int[,]> MapsArrays = new List<int[,]>();
        private Queue<Vector2> waypoints = new Queue<Vector2>();

  
        int[,] map = new int[,]
        {
        {1,1,1,0,0,0,0,0,},
        {0,0,1,0,0,0,0,0,},
        {0,0,1,1,0,0,1,1,},
        {0,0,0,1,0,0,1,0,},
        {0,0,1,1,0,0,1,0,},
        {0,0,1,0,0,0,1,0,},
        {0,0,1,1,1,0,1,0,},
        {0,0,0,0,1,1,1,0,},
        };

        int[,] map1 = new int[,]
        {
        {0,0,0,1,1,1,1,0,},
        {0,0,0,1,0,0,1,0,},
        {0,0,0,1,1,0,1,0,},
        {1,1,0,0,1,0,1,0,},
        {0,1,0,0,1,0,1,0,},
        {0,1,1,1,1,0,1,0,},
        {0,0,0,1,1,0,1,1,},
        {0,0,0,0,0,0,0,0,},
        };

        int[,] map2 = new int[,]
        {
        {1,1,0,0,1,0,0,0,},
        {0,1,0,0,1,0,1,1,},
        {0,1,0,0,1,0,1,0,},
        {0,1,1,1,1,1,1,0,},
        {0,0,0,0,0,1,0,0,},
        {0,1,1,1,1,1,1,1,},
        {0,1,0,1,0,0,0,0,},
        {0,1,0,1,0,0,0,0,},
        };

        public Level()
        {

            waypoints.Enqueue(new Vector2(2, 0) * 64);
            waypoints.Enqueue(new Vector2(2, 1) * 64);
            waypoints.Enqueue(new Vector2(3, 1) * 64);
            waypoints.Enqueue(new Vector2(3, 2) * 64);
            waypoints.Enqueue(new Vector2(4, 2) * 64);
            waypoints.Enqueue(new Vector2(4, 4) * 64);
            waypoints.Enqueue(new Vector2(3, 4) * 64);
            waypoints.Enqueue(new Vector2(3, 5) * 64);
            waypoints.Enqueue(new Vector2(2, 5) * 64);
            waypoints.Enqueue(new Vector2(2, 7) * 64);
            waypoints.Enqueue(new Vector2(7, 7) * 64);

The problem is that the waypoint not fit to the variable map the 2d int array map.

I had to manualy change the waypoints so the enemy iwll move on the map on the 1 numbers which are black.

So i changed the first 3 waypoints to this:


waypoints.Enqueue(new Vector2(0, 0) * 64);
            waypoints.Enqueue(new Vector2(2, 0) * 64);
            waypoints.Enqueue(new Vector2(2, 3) * 64);
            waypoints.Enqueue(new Vector2(3, 2) * 64);
            waypoints.Enqueue(new Vector2(4, 2) * 64);
            waypoints.Enqueue(new Vector2(4, 4) * 64);
            waypoints.Enqueue(new Vector2(3, 4) * 64);
            waypoints.Enqueue(new Vector2(3, 5) * 64);
            waypoints.Enqueue(new Vector2(2, 5) * 64);
            waypoints.Enqueue(new Vector2(2, 7) * 64);
            waypoints.Enqueue(new Vector2(7, 7) * 64);

But is there way to make it automatic and not manual ?

Advertisement
Just loop over the 2D array and add an entry for each 1, if I understand you correctly.

Sean Middleditch – Game Systems Engineer – Join my team!

This topic is closed to new replies.

Advertisement