Pathfinding : programmer les déplacements des personnages
CHAPITRE 9
205
{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, 3, 3, 0, 1, 2, 0, 0, 0, 0, 1},
{0, 0, 0, 1, 0, 1, 1, 3, 3, 1, 1, 1, 2, 0, 1, 0, 0, 1},
{0, 0, 0, 1, 0, 0, 1, 3, 3, 3, 3, 2, 2, 0, 1, 1, 0, 1},
{0, 0, 0, 1, 0, 0, 1, 3, 3, 3, 3, 2, 1, 1, 1, 0, 0, 0},
{0, 0, 0, 1, 0, 0, 0, 3, 1, 1, 3, 2, 0, 0, 1, 0, 0, 0},
{0, 0, 0, 1, 0, 0, 3, 3, 1, 1, 3, 2, 0, 0, 0, 0, 0, 0}
});
graphics.PreferredBackBufferWidth = map.TileList.GetLength(1) * 32;
graphics.PreferredBackBufferHeight = map.TileList.GetLength(0) * 32;
IsMouseVisible = true;
}
protected override void Initialize()
{
heros = new Hero(13, 0, 4);
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
foreach (Tile tile in map.TileList)
{
tile.LoadContent(Content, "tile");
}
heros.LoadContent(Content, "tile");
}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
if (ServiceHelper.Get().LeftButtonHasBeenPressed())
{
if (heros.X != ((int)ServiceHelper.Get()
➥.GetCoordinates().X / 32) || heros.Y != ((int)ServiceHelper
➥.Get().GetCoordinates().Y / 32))
heros.WalkingList = Pathfinding.CalculatePathWithAStar(map, heros, map
➥.TileList[(int)ServiceHelper.Get().GetCoordinates().Y
➥/ 32,(int)ServiceHelper.Get().GetCoordinates().X / 32]);
}
heros.Update(gameTime);
base.Update(gameTime);
}
=Labat FM.book Page 205 Vendredi, 19. juin 2009 4:01 16
Précédent

- 226/366

Suivant