Développement XNA pour la XBox et le PC
198
Map map;
public ChapitreNeuf()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
map = new Map(new byte[,] {
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0},
{0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
{0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0},
{1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 2, 2, 0, 1, 0, 1, 0},
{0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0},
{0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 1, 0, 1, 1},
{0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1},
{0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1},
{0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1},
{0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0},
{0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0},
{0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0}
});
graphics.PreferredBackBufferWidth = map.TileList.GetLength(1) * 32;
graphics.PreferredBackBufferHeight = map.TileList.GetLength(0) * 32;
}
protected override void Initialize()
{
Tile start = map.TileList[13, 0];
Tile end = map.TileList[11, 15];
start.Color = Color.Green;
end.Color = Color.Red;
List liste = Pathfinding.CalculatePathWithAStar(map, start, end);
if (liste != null)
{
liste[0].Color = Color.Red;
for (int i = 1; i < liste.Count; i++)
liste[i].Color = Color.Orange;
}
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
foreach (Tile tile in map.TileList)
{
tile.LoadContent(Content, "tile");
}
}
protected override void Update(GameTime gameTime)
{
=Labat FM.book Page 198 Vendredi, 19. juin 2009 4:01 16
198
Map map;
public ChapitreNeuf()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
map = new Map(new byte[,] {
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0},
{0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
{0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0},
{1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 2, 2, 0, 1, 0, 1, 0},
{0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0},
{0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 1, 0, 1, 1},
{0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1},
{0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1},
{0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1},
{0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0},
{0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0},
{0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0}
});
graphics.PreferredBackBufferWidth = map.TileList.GetLength(1) * 32;
graphics.PreferredBackBufferHeight = map.TileList.GetLength(0) * 32;
}
protected override void Initialize()
{
Tile start = map.TileList[13, 0];
Tile end = map.TileList[11, 15];
start.Color = Color.Green;
end.Color = Color.Red;
List
if (liste != null)
{
liste[0].Color = Color.Red;
for (int i = 1; i < liste.Count; i++)
liste[i].Color = Color.Orange;
}
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
foreach (Tile tile in map.TileList)
{
tile.LoadContent(Content, "tile");
}
}
protected override void Update(GameTime gameTime)
{
=Labat FM.book Page 198 Vendredi, 19. juin 2009 4:01 16
