Jump to content

View more

Image of the Day

#ld38 #screenshotsaturday Mimosa Fizz action gif #2 https://t.co/TUzdppvfUL
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

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

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


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

#1 Chocolade   Members   

123
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.


#2 SeanMiddleditch   Members   

17493
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.

Game Developer, C++ Geek, Dragon Slayer - http://seanmiddleditch.com

C++ SG14 "Games & Low Latency" - Co-chair - public forums

Wargaming Seattle - Lead Server Engineer - We're hiring!





Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.