public void InitializeMap(ZoneDeplacement zone) { _tMax._width = _tMax._width / _ecart._x; _tMax._height = _tMax._height / _ecart._y; this._map = new bool[_tMax._width, _tMax._height]; for (int y = 0; y < _tMax._height; y++) { for (int x = 0; x < _tMax._width; x++) { if (zone.Contains(new Vector2(x * _ecart._x + _mapPosStart, y * _ecart._y))) { _map[x, y] = true; } else { _map[x, y] = false; } } } //Position final sur l'écran ( x32 ) -posStart pour x int startX = (int)(_trajet.GetFirstPosition().X - _mapPosStart); int startY = (int)(_trajet.GetFirstPosition().Y); int endX = (int)(_trajet.GetLastPosition().X - _mapPosStart); int endY = (int)(_trajet.GetLastPosition().Y); _endLocation = new System.Drawing.Point(endX / _ecart._x, endY / _ecart._y); _startLocation = new System.Drawing.Point(startX / _ecart._x, startY / _ecart._y); _searchParameters = new SearchParameters(_startLocation, _endLocation, _map); }
public PathFinding(Trajet trajet, ZoneDeplacement zone) { _mapPosStart = zone._posStart; _tMax = new ZTaille(zone.GetTaille()); _ecart = zone.GetEcart(); _trajet = trajet; InitializeMap(zone); PathFinder pathFinder = new PathFinder(_searchParameters, 4); List <System.Drawing.Point> path = pathFinder.FindPath(); ApplyPath(path); //ShowRoute("The algorithm should find a direct path without obstacles:", path); }
private float _time; //temps d'attente avant un clic public PlaceUnit(Texture2D textureFleche, Texture2D textureZone, Map map, List <Unit> units, Vector2 position) { _units = units; _posPerso = position;//A la construction la position est la position du perso // _position = position; _ecart = new ZEcart(Constantes.CASE_W, Constantes.CASE_H); _mapPosStart = map._posStart; _unit = new Unit(_units.Last()); _unit._position = _posPerso; int id = _units.IndexOf(_unit); _unit = _units[id]; _zone = new ZoneDeplacement(textureZone, _ecart, new ZTaille((int)map._tailleEnPixel.X, (int)map._tailleEnPixel.Y), new ZPoint((int)_posPerso.X - _mapPosStart, (int)_posPerso.Y), map, _mapPosStart, _unit._rayon); _trajet = new Trajet(textureFleche, _zone, _ecart._x, _ecart._y); }