Jump to content

  • Log In with Google      Sign In   
  • Create Account


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

  • You cannot reply to this topic
1 reply to this topic

#1 Chocolade   Members   -  Reputation: 108

Like
0Likes
Like

Posted 15 August 2014 - 11:53 AM

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 ?


Edited by Chocolade, 15 August 2014 - 11:54 AM.


Sponsor:

#2 SeanMiddleditch   Members   -  Reputation: 5056

Like
0Likes
Like

Posted 15 August 2014 - 04:44 PM

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





PARTNERS