Développement XNA pour la XBox et le PC
234
La classe Map modifiée
class Map
{
Tile[,] tileList;
public Tile[,] TileList
{
get { return tileList; }
set { tileList = value; }
}
public Map(byte[,] table)
{
tileList = new Tile[table.GetLength(0),table.GetLength(1)];
for (int y = 0; y < table.GetLength(0); y++)
{
for (int x = 0; x < table.GetLength(1); x++)
{
tileList[y, x] = new Tile(y, x, table[y, x]);
}
}
}
public void Draw(SpriteBatch spriteBatch, Rectangle camera)
{
for (int y = camera.Y; y < camera.Y + camera.Height; y++)
{
for(int x = camera.X; x < camera.X + camera.Width; x++)
{
tileList[y, x].Position = new Vector2((x - camera.X) * 32, (y -
➥camera.Y) * 32);
tileList[y, x].Draw(spriteBatch);
}
}
}
public bool ValidCoordinates(int x, int y)
{
if (x < 0)
return false;
if (y < 0)
return false;
if (x >= tileList.GetLength(1))
return false;
if (y >= tileList.GetLength(0))
return false;
return true;
}
}
=Labat FM.book Page 234 Vendredi, 19. juin 2009 4:01 16
234
La classe Map modifiée
class Map
{
Tile[,] tileList;
public Tile[,] TileList
{
get { return tileList; }
set { tileList = value; }
}
public Map(byte[,] table)
{
tileList = new Tile[table.GetLength(0),table.GetLength(1)];
for (int y = 0; y < table.GetLength(0); y++)
{
for (int x = 0; x < table.GetLength(1); x++)
{
tileList[y, x] = new Tile(y, x, table[y, x]);
}
}
}
public void Draw(SpriteBatch spriteBatch, Rectangle camera)
{
for (int y = camera.Y; y < camera.Y + camera.Height; y++)
{
for(int x = camera.X; x < camera.X + camera.Width; x++)
{
tileList[y, x].Position = new Vector2((x - camera.X) * 32, (y -
➥camera.Y) * 32);
tileList[y, x].Draw(spriteBatch);
}
}
}
public bool ValidCoordinates(int x, int y)
{
if (x < 0)
return false;
if (y < 0)
return false;
if (x >= tileList.GetLength(1))
return false;
if (y >= tileList.GetLength(0))
return false;
return true;
}
}
=Labat FM.book Page 234 Vendredi, 19. juin 2009 4:01 16
