Sign in to follow this  

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

This topic is 1249 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites

This topic is 1249 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this