Reputation: 11
I have this in a new class constructor i did:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace TowerDefense
{
public class Level
{
private List<Texture2D> tileTextures = new List<Texture2D>();
private List<int[,]> MapsArrays = new List<int[,]>();
private Queue<Vector2> waypoints = new Queue<Vector2>();
private List<int> waypath = new List<int>();
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()
{
MapsArrays.Add(map);
MapsArrays.Add(map1);
MapsArrays.Add(map2);
for (int i = 0; i < Width; i++)
{
for (int f = 0; f < Height; f++)
{
int textureIndex = MapsArrays[0][i, f];
waypath.Add(textureIndex);
}
}
}
So now waypath contain all the first map 0 and 1 inside. Now i need somehow to assign those 0 and 1 to a waypooint line:
waypoints.Enqueue(new Vector2(3, 4) * 64);
But instead many lines like this with coordinates inside 3,4 3,5 7,8 and so on...I need somehow to use the 0 and 1 in the waypath List so the waypoints.Enqueue will be automatic using the 0 and 1.
This is how i used the waypoints before hardcoded:
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 i don't want to use it this way but make it automatic the waypoints using the List waypath.
EDIT:
The firsy waypoint should be manualy for example in the first map the first number 1 is at the top left corner so i want it to be the start so left top corner is 0,0 so the first way point will be:
while (true)
{
int rows = map.GetUpperBound(0);
int cols = map.GetUpperBound(1);
int textureIndex = MapsArrays[0][rows,cols];
waypoints.Enqueue(new Vector2(0, 0) * 64);
if (textureIndex == 1)
{
waypath.Add(textureIndex);
}
I'm not sure about this code yet but the idea is to make whi(true) since i don't know how long the map it can be 8x* or 800x800 or 90X100 Then the firsy waypoint is 0,0 So i know the next waypoint cant (-1,0) it can move only right it also cant move up so it can be (0,-1) And somehow i need to use many if's checkings i think 4 if's or more to check the directions.
If the first 1 is at 0,0 so i need to scan right down top left and check where is the next 1 and then decide if the next move will in the waypoint (x,0) or (0,x) or (-1,x) or (x,-1) since maybe i moved right and now it should move down then left. Again the logic is somehow to scan in loop all the directions and find where there is the number 1 and the to move to this way.
Again for sure the first waypoint is 0,0 Then from there is should by using IF's to find the path for all directions automatic i need to use 4 IF's or 6 If's to check all ways.
So in the end if i'm not wrong i should have like 4 or 6 IF's and 4-6 waypoints lines and that's it.
Upvotes: 1
Views: 104