Esempio n. 1
0
    IEnumerator MoveObjectCor(GameObject _go, List <NodeItem> _path, float _speed, MapCoord _coord)
    {
        for (int i = 0; i < _path.Count; i++)
        {
            //朝向下一节点
            //_go.GetComponent<MovableNode>().TowardNextNode(_path[i]);

            if (Event_MovingToNode != null)
            {
                Event_MovingToNode(_path[i]);
            }

            Vector3 targetPos = _path[i].transform.position;

            Vector3 dir = GetCoordDir(_coord, targetPos, _go.transform.position);

            //朝目标移动
            while (GetCoordDir(_coord, targetPos, _go.transform.position).magnitude > _speed * Time.fixedDeltaTime)
            {
                yield return(new WaitForFixedUpdate());

                _go.transform.Translate(dir.normalized * _speed * Time.deltaTime);
            }

            if (Event_ReachNode != null)
            {
                Event_ReachNode(_path[i]);
            }
        }

        MoveObjectFinish(_path[_path.Count - 1]);
    }
Esempio n. 2
0
        public static MapCoord ToWebMercator(this MapCoord mapCoord)
        {
            if (mapCoord.ProjectionWkid == CoordinateSystems.WebMercatorProjectionWkid)
            {
                return(mapCoord);
            }

            var wgs84XLon = mapCoord.Longitude;
            var wgs84YLat = mapCoord.Latitude;

            if ((Math.Abs(wgs84XLon) > 180 || Math.Abs(wgs84YLat) > 90))
            {
                throw new IndexOutOfRangeException("WGS84 coordinates out of bounds");
            }

            var num = wgs84XLon * 0.017453292519943295;
            var x   = 6378137.0 * num;
            var a   = wgs84YLat * 0.017453292519943295;

            wgs84XLon = x;
            wgs84YLat = 3189068.5 * Math.Log((1.0 + Math.Sin(a)) / (1.0 - Math.Sin(a)));

            var reprojPoint = new MapCoord {
                Latitude       = wgs84YLat,
                Longitude      = wgs84XLon,
                ProjectionWkid = CoordinateSystems.WebMercatorProjectionWkid
            };

            return(reprojPoint);
        }
Esempio n. 3
0
        void _walkThrough(Map map, Tile tile, Corridor corridor)
        {
            availableTiles.Remove(tile);
            corridor.AddTile(tile);
            tile.occupation = TILE_TYPE.CORRIDOR;
            tile.space      = corridor;
            List <int> directions = new List <int>(new int[] { 0, 1, 2, 3 });

            Tools.Shuffle(directions);
            while (directions.Count > 0)
            {
                int dir = directions[0];
                directions.Remove(dir);
                MapCoord pos = tile.coord + DELTA[dir];
                if (map.isInside(pos))
                {
                    Tile newTile = map.tile(pos);
                    if (availableTiles.IndexOf(newTile) != -1)
                    {
                        // quebrando paredes
                        tile.passages    |= DIRECTIONS[dir];
                        newTile.passages |= OPPOSITE_DIRECTIONS[dir];
                        _walkThrough(map, newTile, corridor);
                    }
                }
            }
        }
Esempio n. 4
0
        public static void Execute()
        {
            int             width     = 26;
            List <string>   rows      = File.ReadAllLines(@"C:\Work\Misc Projects\AdventOfCode\AdventOfCode\AdventOfCode\2019\Data\day10_full.txt").ToList();
            List <MapCoord> mapCoords = new List <MapCoord>();
            MapCoord        gun       = new MapCoord {
                IsAsteroid = true, X = 19, Y = 14
            };

            int y = 0;

            foreach (var row in rows)
            {
                for (int x = 0; x < width; x++)
                {
                    mapCoords.Add(new MapCoord
                    {
                        Y          = y,
                        X          = x,
                        IsAsteroid = row[x].ToString() == "#"
                    });
                }

                y++;
            }

            var asteroids = mapCoords.Where(x => x.IsAsteroid).ToList();

            FindAndDestroyAsteroids(gun, asteroids);
        }
Esempio n. 5
0
        private void ShowFlag(MapCoord coord, Uri imageUri)
        {
            var mapPoint = coord.ToEsriWebMercatorMapPoint();

            if (_flagsGraphicsLayer == null || mapPoint == null)
            {
                throw new ArgumentNullException("coord", "Coordinates or Graphic layers is null");
            }

            var symbol = new PictureMarkerSymbol {
                Source  = new BitmapImage(imageUri),
                OffsetX = 1,
                OffsetY = 30
            };


            // Ação quando o usuário responder o local
            var graphic = new Graphic
            {
                Symbol   = symbol,
                Geometry = mapPoint
            };

            _flagsGraphicsLayer.Graphics.Add(graphic);
        }
Esempio n. 6
0
        private void ShowFlag(MapCoord coord, Uri imageUri, bool target)
        {
            if (_informationLayer == null)
            {
                throw new NullReferenceException("Map not already created!");
            }

            var hotSpot = new HotSpot();

            if (target)
            {
                hotSpot.X = 0.15;
                hotSpot.Y = 0.85;
            }
            else
            {
                hotSpot.X = 0.22;
                hotSpot.Y = 0.9;
            }

            var reprojCoord = coord.ToGeographic();
            var mapPinPoint = new MapPinPoint {
                ImageSource = new BitmapImage(imageUri)
            };

            MapLayer.SetHotSpot(mapPinPoint, hotSpot);
            MapLayer.SetLocation(mapPinPoint, new Location(reprojCoord.Latitude, reprojCoord.Longitude));
            _informationLayer.Items.Add(mapPinPoint);
        }
Esempio n. 7
0
 public virtual void Init(MapCoord c, Ink initInk, bool _canTraverse = true)
 {
     coord       = c;
     canTraverse = _canTraverse;
     sr          = GetComponent <SpriteRenderer>();
     tileInk     = new Ink();
     SetColor(initInk, true);
 }
Esempio n. 8
0
 public void Init(MapCoord c, Ink initInk, bool _canTraverse = true)
 {
     coord       = c;
     canTraverse = _canTraverse;
     PumpColor   = initInk.colorMode;
     sr          = GetComponent <SpriteRenderer>();
     tileInk     = new Ink();
     SetColor(initInk);
 }
        public static MapCoord ToMapCoord(this Location mapPoint)
        {
            var mapCoord = new MapCoord {
                Latitude       = mapPoint.Latitude,
                Longitude      = mapPoint.Longitude,
                ProjectionWkid = CoordinateSystems.Wgs84ProjectionWkid
            };

            return(mapCoord);
        }
Esempio n. 10
0
    public override bool Equals(object obj)
    {
        if (obj == null || GetType() != obj.GetType())
        {
            return(false);
        }
        MapCoord coord = (MapCoord)obj;

        return((x == coord.x) && (y == coord.y));
    }
Esempio n. 11
0
        public static double KmDistanceFrom(this MapCoord wgs84Coords1, MapCoord wgs84Coords2)
        {
            var location1Reproj = wgs84Coords1.ToWebMercator();
            var location2Reproj = wgs84Coords2.ToWebMercator();

            var meterDistance = location1Reproj.ToPoint().DistanceFrom(location2Reproj.ToPoint());
            var kmDistance    = meterDistance / 1000;

            return(kmDistance);
        }
Esempio n. 12
0
 public static float DirectionToAngle(MapCoord direction)
 {
     for (int i = 0; i < 4; i++)
     {
         if (direction == Directions()[i])
         {
             return(i * 90);
         }
     }
     return(0);
 }
Esempio n. 13
0
 public static                   MapCoord[] Directions()
 {
     MapCoord[] directions = new MapCoord[4]
     {
         new MapCoord(1, 0),
         new MapCoord(0, 1),
         new MapCoord(-1, 0),
         new MapCoord(0, -1)
     };
     return(directions);
 }
Esempio n. 14
0
    // Have a method that gives me the direction I should move!

    private bool CanTraverse(MapCoord candidateCoord)
    {
        bool canTraverse = false;

        if (Services.GameScene.board.ContainsCoord(candidateCoord) &&
            Services.GameScene.board.Map[candidateCoord.x, candidateCoord.y].canTraverse)
        {
            canTraverse = true;
        }

        return(canTraverse);
    }
Esempio n. 15
0
        private MapCoord QueryOffSetData(LatLngPoint point)
        {
            MapCoord _search = new MapCoord();

            _search.Lat = (int)(point.LatY * 100);
            _search.Lon = (int)(point.LonX * 100);
            MapOffsetComparer rc  = new MapOffsetComparer();
            int      _findedIndex = mapCoordArrayList.BinarySearch(0, mapCoordArrayList.Count, _search, rc);
            MapCoord _findedCoord = (MapCoord)mapCoordArrayList[_findedIndex];

            return(_findedCoord);
        }
Esempio n. 16
0
    //****************************************************************************************************
    //
    //****************************************************************************************************

    public override void Update()
    {
        if (Focusable.any)
        {
            return;
        }

        UpdateCoordSelection();

        if (MouseClick() == false)
        {
            if (MouseDrag())
            {
                return;
            }
        }

        if (Input.anyKey)
        {
            MapCoord coords = o.coords.req;

            if (Input.GetKeyDown(KeyCode.KeypadPlus))
            {
                o.StartTransition(coords.latitude.deg, coords.longitude.deg, coords.altitude - 1.0f);
            }

            else if (Input.GetKeyDown(KeyCode.KeypadMinus))
            {
                o.StartTransition(coords.latitude.deg, coords.longitude.deg, coords.altitude + 1.0f);
            }

            if (Input.GetKeyDown(KeyCode.UpArrow))
            {
                o.StartTransition(coords.latitude.deg + 45.0f, coords.longitude.deg, coords.altitude);
            }

            else if (Input.GetKeyDown(KeyCode.DownArrow))
            {
                o.StartTransition(coords.latitude.deg - 45.0f, coords.longitude.deg, coords.altitude);
            }

            if (Input.GetKeyDown(KeyCode.RightArrow))
            {
                o.StartTransition(coords.latitude.deg, coords.longitude.deg + 45.0f, coords.altitude);
            }

            else if (Input.GetKeyDown(KeyCode.LeftArrow))
            {
                o.StartTransition(coords.latitude.deg, coords.longitude.deg - 45.0f, coords.altitude);
            }
        }
    }
Esempio n. 17
0
 public override void Init(MapCoord c)
 {
     Ink     = new Ink(ColorMode.NONE);
     canMove = true;
     coord   = c;
     SetPosition(coord);
     direction = Swipe.Direction.NONE;
     Services.EventManager.Register <SwipeEvent>(OnSwipe);
     moveSpeed   = 2;
     arriveSpeed = 1;
     ResetIntensitySwipes();
     CurrentColorMode = Ink.colorMode;
 }
Esempio n. 18
0
        /// <summary>
        /// 火星坐标转 (GCJ-02)地球坐标(WGS-84)
        /// </summary>
        /// <param name="gcjPoint">火星坐标转 (GCJ-02)</param>
        /// <returns>地球坐标(WGS-84)</returns>
        public LatLngPoint GCJ02ToWGS84(LatLngPoint gcjPoint)
        {
            MapCoord _findedCoord = QueryOffSetData(gcjPoint);
            double   _pixY        = GeoHelper.LatToPixel(gcjPoint.LatY, 18);
            double   _pixX        = GeoHelper.LonToPixel(gcjPoint.LonX, 18);

            _pixY -= _findedCoord.Y_off;
            _pixX -= _findedCoord.X_off;
            double _lat = GeoHelper.PixelToLat(_pixY, 18);
            double _lng = GeoHelper.PixelToLon(_pixX, 18);

            return(new LatLngPoint(_lat, _lng));
        }
Esempio n. 19
0
        /// <summary>
        /// 地球坐标(WGS-84)转火星坐标 (GCJ-02)
        /// </summary>
        /// <param name="wgsPoint">地球坐标(WGS-84)</param>
        /// <returns>火星坐标 (GCJ-02)</returns>
        public LatLngPoint WGS84ToGCJ02(LatLngPoint wgsPoint)
        {
            MapCoord _findedCoord = QueryOffSetData(wgsPoint);
            double   _pixY        = GeoHelper.LatToPixel(wgsPoint.LatY, 18);
            double   _pixX        = GeoHelper.LonToPixel(wgsPoint.LonX, 18);

            _pixY += _findedCoord.Y_off;
            _pixX += _findedCoord.X_off;
            double _lat = GeoHelper.PixelToLat(_pixY, 18);
            double _lng = GeoHelper.PixelToLon(_pixX, 18);

            return(new LatLngPoint(_lat, _lng));
        }
Esempio n. 20
0
        /// <summary>
        /// 比较两个对象并返回一个值,指示一个对象是小于、等于还是大于另一个对象。
        /// </summary>
        /// <param name="x">要比较的第一个对象。</param>
        /// <param name="y">要比较的第二个对象。</param>
        /// <returns>
        /// 值 条件 小于零 <paramref name="x" /> 小于 <paramref name="y" />。 零 <paramref name="x" /> 等于 <paramref name="y" />。 大于零 <paramref name="x" /> 大于 <paramref name="y" />。
        /// </returns>
        public int Compare(object x, object y)
        {
            MapCoord _coord1 = (MapCoord)x, _coord2 = (MapCoord)y;
            int      _dlng = _coord1.Lon - _coord2.Lon;

            if (_dlng != 0)
            {
                return(_dlng);
            }
            else
            {
                return(_coord1.Lat - _coord2.Lat);
            }
        }
Esempio n. 21
0
    Vector3 GetCoordDir(MapCoord _coord, Vector3 _origin, Vector3 _target)
    {
        Vector3 dir = _origin - _target;

        if (_coord == MapCoord.xz)
        {
            dir.y = 0;
        }
        else
        {
            dir.z = 0;
        }

        return(dir);
    }
Esempio n. 22
0
 public static int getDirectionInt(Vector2 delta)
 {
     for (int i = 0; i < Constants.DELTA.Length; i++)
     {
         MapCoord d_type = Constants.DELTA[i];
         if ((delta.x == d_type.x) && (delta.y == d_type.y))
         {
             return(i);
         }
     }
     Debug.LogWarning(String.Format("Could not find direction for: {0}, {1}.", new object[2] {
         delta.x, delta.y
     }));
     return(-1);
 }
Esempio n. 23
0
    internal override void OnEnter(TransitionData data)
    {
        Services.GameScene = this;
        Services.Board     = board;

        Services.Board.CreateBoard(MapData);
        PrepGameUI();
        //Services.Board.CreateBaord(3, 3);
        Services.CameraController.AdjustCameraToGameBoard(board.Width, board.Height);

        player = Instantiate <Player>(Services.Prefabs.Player);
        player.transform.parent = transform;
        MapCoord startCoord = new MapCoord(MapData.PlayerStartPos.x, MapData.PlayerStartPos.y);

        player.Init(startCoord);
    }
Esempio n. 24
0
        /// <summary>
        /// 将字节转化为具体的数据对象
        /// </summary>
        /// <param name="bytes">bytes</param>
        /// <returns>MapCoord</returns>
        private MapCoord ToCoord(byte[] bytes)
        {
            //经度,纬度,x偏移量,y偏移量 【均两个字节】
            MapCoord coord = new MapCoord();

            byte[] b1 = new byte[2], b2 = new byte[2], b3 = new byte[2], b4 = new byte[2];
            Array.Copy(bytes, 0, b1, 0, 2);
            Array.Copy(bytes, 2, b2, 0, 2);
            Array.Copy(bytes, 4, b3, 0, 2);
            Array.Copy(bytes, 6, b4, 0, 2);
            coord.Lon   = BitConverter.ToInt16(b1, 0);
            coord.Lat   = BitConverter.ToInt16(b2, 0);
            coord.X_off = BitConverter.ToInt16(b3, 0);
            coord.Y_off = BitConverter.ToInt16(b4, 0);
            return(coord);
        }
Esempio n. 25
0
        /// <summary>
        /// 将字节转化为具体的数据对象
        /// </summary>
        /// <param name="bytes">bytes</param>
        /// <returns>MapCoord</returns>
        private MapCoord ToCoord(byte[] bytes)
        {
            //经度,纬度,x偏移量,y偏移量 【均两个字节】
            MapCoord _coord = new MapCoord();

            byte[] _b1 = new byte[2], _b2 = new byte[2], _b3 = new byte[2], _b4 = new byte[2];
            Array.Copy(bytes, 0, _b1, 0, 2);
            Array.Copy(bytes, 2, _b2, 0, 2);
            Array.Copy(bytes, 4, _b3, 0, 2);
            Array.Copy(bytes, 6, _b4, 0, 2);
            _coord.Lon   = BitConverter.ToInt16(_b1, 0);
            _coord.Lat   = BitConverter.ToInt16(_b2, 0);
            _coord.X_off = BitConverter.ToInt16(_b3, 0);
            _coord.Y_off = BitConverter.ToInt16(_b4, 0);
            return(_coord);
        }
Esempio n. 26
0
        private void GetOffsetData(Action <MapCoord> mapCoordHanlder)
        {
            using (FileStream stream = new FileStream(offsetFullPath, FileMode.OpenOrCreate, FileAccess.Read))
            {
                using (BinaryReader reader = new BinaryReader(stream))
                {
                    int size = (int)stream.Length / 8;

                    for (int i = 0; i < size; i++)
                    {
                        byte[]   buffer = reader.ReadBytes(8);
                        MapCoord coord  = ToCoord(buffer);
                        mapCoordHanlder(coord);
                    }
                }
            }
        }
Esempio n. 27
0
        private static void FindAndDestroyAsteroids(MapCoord asteroid, List <MapCoord> asteroids)
        {
            List <MapCoord> asteroidDistances = new List <MapCoord>();

            foreach (var a in asteroids)
            {
                if (a.X == asteroid.X && a.Y == asteroid.Y)
                {
                    continue;
                }

                asteroidDistances.Add(new MapCoord
                {
                    X         = a.X - asteroid.X,
                    Y         = a.Y - asteroid.Y,
                    OriginalX = a.X,
                    OriginalY = a.Y
                });
            }

            List <double> degrees = asteroidDistances.Select(x => x.Degrees).Distinct().OrderBy(x => x).ToList();

            int index = 1;

            while (!asteroidDistances.All(x => x.Destroyed))
            {
                foreach (var degree in degrees)
                {
                    var asteroidsWithDegree = asteroidDistances.Where(x => x.Degrees == degree && !x.Destroyed);

                    if (asteroidsWithDegree != null && asteroidsWithDegree.Any())
                    {
                        var closestAsteroidDistance = asteroidsWithDegree.Min(x => x.ManhattanDistance);
                        var asteroidToDestroy       = asteroidsWithDegree.First(x => x.ManhattanDistance == closestAsteroidDistance);
                        asteroidToDestroy.Destroyed = true;
                        if (index == 200)
                        {
                            Console.WriteLine($"#{index} - Destroyed asteroid at ({asteroidToDestroy.OriginalX}, {asteroidToDestroy.OriginalY}) - value: {(asteroidToDestroy.OriginalX * 100) + asteroidToDestroy.OriginalY}");
                        }
                        index++;
                    }
                }
            }
        }
Esempio n. 28
0
    IEnumerator MoveObjectFlyingCor(GameObject _go, NodeItem _node, float _speed, MapCoord _coord)
    {
        Vector3 targetPos = _node.transform.position;
        Vector3 dir       = GetCoordDir(_coord, targetPos, _go.transform.position);

        if (Event_MovingToNode != null)
        {
            Event_MovingToNode(_node);
        }

        while (GetCoordDir(_coord, targetPos, _go.transform.position).magnitude > _speed * Time.fixedDeltaTime)
        {
            _go.transform.Translate(dir.normalized * _speed * Time.deltaTime);

            yield return(new WaitForFixedUpdate());
        }

        _go.transform.position = _node.transform.position;

        MoveObjectFinish(_node);
    }
Esempio n. 29
0
        public static MapCoord ToGeographic(this MapCoord mapCoord)
        {
            if (mapCoord.ProjectionWkid == CoordinateSystems.Wgs84ProjectionWkid)
            {
                return(mapCoord);
            }

            var mercatorXLon = mapCoord.Longitude;
            var mercatorYLat = mapCoord.Latitude;

            if (Math.Abs(mercatorXLon) < 180 && Math.Abs(mercatorYLat) < 90)
            {
                throw new IndexOutOfRangeException("It appears to be Geographic coordinates");
            }

            if ((Math.Abs(mercatorXLon) > 20037508.3427892) || (Math.Abs(mercatorYLat) > 20037508.3427892))
            {
                throw new IndexOutOfRangeException("WebMercator coordinates out of bounds");
            }

            var x    = mercatorXLon;
            var y    = mercatorYLat;
            var num3 = x / 6378137.0;
            var num4 = num3 * 57.295779513082323;
            var num5 = Math.Floor(((num4 + 180.0) / 360.0));
            var num6 = num4 - (num5 * 360.0);
            var num7 = 1.5707963267948966 - (2.0 * Math.Atan(Math.Exp((-1.0 * y) / 6378137.0)));

            mercatorXLon = num6;
            mercatorYLat = num7 * 57.295779513082323;

            var reprojPoint = new MapCoord
            {
                Latitude       = mercatorYLat,
                Longitude      = mercatorXLon,
                ProjectionWkid = CoordinateSystems.Wgs84ProjectionWkid
            };

            return(reprojPoint);
        }
Esempio n. 30
0
        public static MapPoint ToEsriWebMercatorMapPoint(this MapCoord mapLocation)
        {
            if (mapLocation.ProjectionWkid == CoordinateSystems.WebMercatorProjectionWkid)
            {
                var esriMapPoint = new MapPoint(mapLocation.Longitude, mapLocation.Latitude, new SpatialReference(CoordinateSystems.WebMercatorProjectionWkid));
                return(esriMapPoint);
            }
            else
            {
                if (mapLocation.ProjectionWkid != CoordinateSystems.Wgs84ProjectionWkid)
                {
                    throw new NotSupportedException(
                              String.Format(
                                  "The WKID {0} is not supported.\nThe only supported coordinate systemas are WebMercator(102100) and WGS84 (4326))",
                                  mapLocation.ProjectionWkid));
                }

                var esriMapPoint = new MapPoint(mapLocation.Longitude, mapLocation.Latitude, new SpatialReference(CoordinateSystems.Wgs84ProjectionWkid));
                // Project from WGS84 to WebMercator
                var reprojMapPoint = new WebMercator().FromGeographic(esriMapPoint) as MapPoint;
                return(reprojMapPoint);
            }
        }
Esempio n. 31
0
        /// <summary>
        /// Add a PlayerUnit to the specified position and class
        /// </summary>
        /// <param name="Coord">Position of Unit</param>
        /// <param name="UnitClass">Class of Unit</param>
        public void AddPlayerUnit(MapCoord Coord, UnitClasses UnitClass)
        {
            if (map.Tiles[Coord.Row][Coord.Column].Type == TileType.Normal && !PlayerUnits.ContainsCoord(Coord))
            {
                if (Gold >= PlayerUnit.LevelCost(1) && UnitClass == UnitClasses.Thieft && PlayerUnits.CountClass(UnitClasses.Thieft) < 4)
                {
                    Gold -= PlayerUnit.LevelCost(1);
                    PlayerUnits.Add(Coord, new Thieft());
                    PlayerUnits[Coord].Position = Coord.ToPointMiddle();
                    Score += 100;
                }
                else if (Gold >= PlayerUnit.LevelCost(1) && UnitClass != UnitClasses.Thieft)
                {
                    Gold -= PlayerUnit.LevelCost(1);
                    Score += 100;

                    if (UnitClass == UnitClasses.Archer)
                    {
                        PlayerUnits.Add(Coord, new Archer());
                        PlayerUnits[Coord].Position = Coord.ToPointMiddle();
                    }
                    else if (UnitClass == UnitClasses.Mage)
                    {
                        PlayerUnits.Add(Coord, new Mage());
                        PlayerUnits[Coord].Position = Coord.ToPointMiddle();
                    }
                    else if (UnitClass == UnitClasses.Soldier)
                    {
                        PlayerUnits.Add(Coord, new Soldier());
                        PlayerUnits[Coord].Position = Coord.ToPointMiddle();
                    }
                    else if (UnitClass == UnitClasses.Paladin)
                    {
                        PlayerUnits.Add(Coord, new Paladin());
                        PlayerUnits[Coord].Position = Coord.ToPointMiddle();
                    }
                }
            }
        }
Esempio n. 32
0
        /// <summary>
        /// Increase the level of a Player Unit at the specified position
        /// </summary>
        /// <param name="Coord">Position of Unit</param>
        public void IncreaseUnitLevel(MapCoord Coord)
        {
            if (PlayerUnits.ContainsCoord(Coord) && PlayerUnits.GetUnitAt(Coord).Class != UnitClasses.None)
            {
                int Cost = PlayerUnit.LevelCost(PlayerUnits.GetUnitAt(Coord).Level+1);

                if (Gold >= Cost)
                {
                    PlayerUnits.GetUnitAt(Coord).LevelUp();
                    Gold -= Cost;
                    Score += PlayerUnits.GetUnitAt(Coord).Level * 100;
                }
            }
        }
Esempio n. 33
0
        public void DrawUnitRange(Surface GameSurface, MapCoord Coord, PlayerUnit Unit)
        {
            Circle MaxRange = new Circle(Coord.ToPointMiddle(), (short)Unit.Range);
            GameSurface.Draw(MaxRange, Color.Aqua, true);

            if (Unit.MinusRange != 0)
            {
                Circle MinusRange = new Circle(Coord.ToPointMiddle(), (short)Unit.MinusRange);
                GameSurface.Draw(MinusRange, Color.Red, true);
            }
        }
Esempio n. 34
0
 /*
 ====================================================================
 Writes into the given array the coordinates of all friendly
 airports, returning the number of coordinates written.
 The array must be big enough to hold all the coordinates.
 The function is guaranteed to never write more than (map_w*map_h)
 entries.
 ====================================================================
 */
 public int map_write_friendly_depot_list(Unit unit, List<MapCoord> coords)
 {
     short x, y;
     MapCoord p;
     int count = 0;
     for (x = 0; x < map_w; x++)
         for (y = 0; y < map_h; y++)
             if (map_is_allied_depot (map [x, y], unit)) {
                 p = new MapCoord ();
                 p.x = x;
                 p.y = y;
                 coords.Add (p);
                 count++;
             }
     return count;
 }
Esempio n. 35
0
        public void Init()
        {
            TextureIndex Textures = TextureIndex.LoadTextureIndex("../../../../assets/Textures/MapTiles.xml");
            CreepTextures = CreepTextureIndex.LoadIndex("../../../../assets/GameData/CreepSpriteIndex.xml");
            MapTiles = Textures.LoadTextures();

            GameStartP = new Point(200, 100);

            CritSprites = new TextSpriteList();

            MapRender = new MapRenderer(GameObj.map, MapTiles);
            CreepRender = new CreepRenderer(CreepTextures.GetEntry(GameObj.CurrentWave.GfxName));

            GameRectangle = new Rectangle(GameStartP,new Size(GameObj.map.Columns*Tile.TILE_WIDTH,GameObj.map.Rows*Tile.TILE_HEIGHT));
            SelectedTile = new MapCoord();

            MageSprites = new MageAttackSprites();

            TopLevelContainer = new List<GuiItem>();

            MapBackground = MapRender.Render();

            Background = new BackgroundItem(Color.WhiteSmoke);
            Background.X = 0;
            Background.Y = 0;
            Background.Width = Width;
            Background.Height = Height;

            ButtonPanel = new BackgroundItem(Color.LightGray);
            ButtonPanel.X = 0;
            ButtonPanel.Y = 0;
            ButtonPanel.Width = Width;
            ButtonPanel.Height = 80;

            HudPanel = new BackgroundItem(Color.SteelBlue);
            HudPanel.X = 0;
            HudPanel.Y = 640;
            HudPanel.Width = Width;
            HudPanel.Height = 120;

            CloseButton = new ButtonItem("Close",120,22,"Quit");
            CloseButton.X = 10;
            CloseButton.Y = 20;

            PauseButton = new ButtonItem("Pause", 120, 22, "Pause");
            PauseButton.X = 140;
            PauseButton.Y = 20;

            StartWaveButton = new ButtonItem("StartWave", 120, 22, "Start Wave");
            StartWaveButton.X = 270;
            StartWaveButton.Y = 20;

            CombatLogButton = new ButtonItem("CombatLog", 120, 22, "View Combat Log");
            CombatLogButton.X = 10;
            CombatLogButton.Y = 50;

            BuyUnitButton = new ButtonItem("BuyUnit", 120, 22, "Buy a Unit");
            BuyUnitButton.X = 140;
            BuyUnitButton.Y = 50;

            ResetButton = new ButtonItem("Reset", 120, 22, "Restart");
            ResetButton.X = 270;
            ResetButton.Y = 50;

            LabelScore = new LabelItem("Score : 0");
            LabelScore.X = 10;
            LabelScore.Y = 650;
            LabelScore.Foreground = Color.White;

            LabelWave = new LabelItem("Wave : " + GameObj.Wave);
            LabelWave.X = 350;
            LabelWave.Y = 650;
            LabelWave.Foreground = Color.White;

            LabelCrystal = new LabelItem("Crystal Left : " + GameObj.Crystal);
            LabelCrystal.X = 10;
            LabelCrystal.Y = 680;
            LabelCrystal.Foreground = Color.White;

            LabelGold = new LabelItem("Gold : " + GameObj.Gold);
            LabelGold.X = 350;
            LabelGold.Y = 680;
            LabelGold.Foreground = Color.White;

            LabelFps = new LabelItem("Fps : 30");
            LabelFps.X = Width - 70;
            LabelFps.Y = 4;

            LogBox = new CombatLogBox(GameObj.LastCombatLog, Garbage);

            UnitInfoBox = new PlayerUnitInfoBox(new Point(GameStartP.X + GameRectangle.Width + 10,GameStartP.Y));

            CreepBox = new CreepInfoBox();
            CreepBox.FromPoint(new Point(GameStartP.X + GameRectangle.Width + 10, GameStartP.Y + UnitInfoBox.Height + 10));

            UnitClassesChooserBox = new UnitClassesChooser(Garbage);
            UnitClassesChooserBox.X = GameStartP.X + ((GameRectangle.Width - UnitClassesChooserBox.Width) / 2); ;
            UnitClassesChooserBox.Y = GameStartP.Y + ((GameRectangle.Height - UnitClassesChooserBox.Height) / 2); ;

            WaveBox = new WaveInfoBox(GameObj.GetNextWaveInfo(),Garbage);
            WaveBox.X = GameStartP.X + ((GameRectangle.Width - WaveBox.Width) / 2);
            WaveBox.Y = GameStartP.Y + ((GameRectangle.Height - WaveBox.Height) / 2);

            NextWaveBox = new CreepNextWaveBox(GameObj.CreepWaves);
            NextWaveBox.X = 10;
            NextWaveBox.Y = GameStartP.Y;

            PlayerNameDialog = new TextInputDialogBox("Highscore Entry", "Player Name : ");
            PlayerNameDialog.X = (Width - PlayerNameDialog.Width) / 2;
            PlayerNameDialog.Y = (Height - PlayerNameDialog.Height) / 2;
            PlayerNameDialog.TextEntry = PlayerName;

            Container.Add(Background);
            Container.Add(ButtonPanel);
            Container.Add(HudPanel);

            Container.Add(CloseButton);
            Container.Add(PauseButton);
            Container.Add(StartWaveButton);
            Container.Add(CombatLogButton);
            Container.Add(BuyUnitButton);
            Container.Add(ResetButton);

            Container.Add(LabelScore);
            Container.Add(LabelCrystal);
            Container.Add(LabelWave);
            Container.Add(LabelGold);

            Container.Add(LabelFps);

            Container.Add(NextWaveBox);
            Container.Add(UnitInfoBox);
            Container.Add(CreepBox);
        }
Esempio n. 36
0
        public override void MouseClick(object sender, MouseButtonEventArgs args)
        {
            if (args.Button == MouseButton.PrimaryButton)
            {
                String ItemName = GetItemName(args);
                if (ItemName == CloseButton.ButtonName)
                {
                    //Events.QuitApplication();
                    MainMenuWindow mainWindow = new MainMenuWindow(Screen);

                    UnsetEvents();
                    mainWindow.SetEvents();

                }
                else if (ItemName == StartWaveButton.ButtonName && TopLevelContainer.Count == 0)
                {
                    if (GameObj.State == GameState.NoAttack)
                    {
                        GameObj.StartWave();
                        SelectedTile = new MapCoord();
                    }
                }
                else if (ItemName == ResetButton.ButtonName)
                {
                    GameObj.NewGame(GameObj.Difficulty);
                    LastAttackInfo = 0;
                    AskedPlayerName = false;
                }
                else if (ItemName == CombatLogButton.ButtonName)
                {
                    if (GameObj.State == GameState.NoAttack && !TopLevelContainer.Contains(LogBox))
                    {
                        LogBox.Y = GameStartP.Y;
                        LogBox.X = (Width - LogBox.Width) / 2;
                        LogBox.Log = GameObj.LastCombatLog;
                        LogBox.UpdateLabel();
                        TopLevelContainer.Add(LogBox);
                        LogBox.SetEvents();
                    }
                }
                else if (ItemName == BuyUnitButton.ButtonName && TopLevelContainer.Count == 0)
                {
                    if (GameObj.State == GameState.NoAttack)
                    {
                        TopLevelContainer.Add(UnitClassesChooserBox);
                        UnitClassesChooserBox.SetEvents();
                    }
                }
                else if (TopLevelContainer.Contains(PlayerNameDialog) && PlayerNameDialog.GetButtonOkRect().Contains(args.Position))
                {
                    PlayerName = PlayerNameDialog.TextEntry;
                    PlayerNameDialog.UnsetEvents();
                    TopLevelContainer.Remove(PlayerNameDialog);
                }
                else if (GameObj.State == GameState.NoAttack && UnitClassesChooserBox.ChoosenClass != UnitClasses.None && TopLevelContainer.Count == 0)
                {
                    if (GameRectangle.Contains(MousePos))
                    {
                        Point relpoint = new Point(MousePos.X - GameStartP.X, MousePos.Y - GameStartP.Y);

                        MapCoord Coord = new MapCoord(relpoint);

                        GameObj.AddPlayerUnit(Coord, UnitClassesChooserBox.ChoosenClass);

                        UnitClassesChooserBox.Reset();

                        UnitInfoBox.ChangeUnit(GameObj.PlayerUnits.GetUnitAt(Coord));
                    }
                }
                else if (UnitInfoBox.GetIncLvlRect().Contains(args.Position) && GameObj.State == GameState.NoAttack && TopLevelContainer.Count == 0)
                {
                    GameObj.IncreaseUnitLevel(UnitInfoBox.Unit);
                }
                else if (GameRectangle.Contains(args.Position) && TopLevelContainer.Count == 0)
                {
                    SelectedTile = GetCoordFromPoint(args.Position);

                    if (GameObj.PlayerUnits.GetUnitAt(SelectedTile).Class != UnitClasses.None)
                    {
                        UnitInfoBox.ChangeUnit(GameObj.PlayerUnits.GetUnitAt(SelectedTile));
                    }
                    else
                    {
                        UnitInfoBox.ChangeUnit(new PlayerUnit());
                    }

                    if (GameObj.State == GameState.CreepAttack)
                    {
                        foreach (CreepUnit Unit in GameObj.Creeps)
                        {
                            if (!Unit.Position.IsEmpty)
                            {
                                Rectangle rect = new Rectangle(new Point(GameStartP.X + Unit.Position.X, GameStartP.Y + Unit.Position.Y), new Size(CreepUnit.CREEP_WIDTH_PX, CreepUnit.CREEP_HEIGHT_PX));

                                if (rect.Contains(args.Position))
                                {
                                    CreepBox.ChangeUnit(Unit);
                                }

                            }
                        }
                    }

                }
                else if (TopLevelContainer.Contains(WaveBox))
                {
                    Garbage.Add(WaveBox);
                }
                //Removed
                /*else if (GameRectangle.Contains(args.Position) && GameObj.State == GameState.NoAttack && TopLevelContainer.Count == 0 && SelectedTile.SameCoord(GetCoordFromPoint(args.Position)))
                {
                    if (GameObj.PlayerUnits.ContainsCoord(SelectedTile) && GameObj.PlayerUnits.GetUnitAt(SelectedTile).Class != UnitClasses.None)
                    {
                        PlayerUnitMenu m = new PlayerUnitMenu(GameObj, SelectedTile, Garbage);
                        m.X += GameStartP.X;
                        m.Y += GameStartP.Y;
                        TopLevelContainer.Add(m);
                        m.SetEvents();
                    }
                    else if (GameObj.map.Tiles[SelectedTile.Row][SelectedTile.Column].Type == TileType.Normal)
                    {
                        EmptyTileMenu m = new EmptyTileMenu(GameObj, SelectedTile, TopLevelContainer, Garbage);
                        m.X += GameStartP.X;
                        m.Y += GameStartP.Y;
                        TopLevelContainer.Add(m);
                        m.SetEvents();
                    }
                }*/
            }
        }
Esempio n. 37
0
        public override void Tick(object sender, TickEventArgs args)
        {
            //Game Logic Tick
            GameObj.GameTick();

            //HUD Update
            LabelScore.Caption = "Score : " + GameObj.Score;
            LabelWave.Caption = "Wave : " + GameObj.Wave;
            LabelCrystal.Caption = "Crystals Left : " + GameObj.Crystal;
            LabelGold.Caption = "Gold : " + GameObj.Gold;

            LabelFps.Caption = "Fps : " + args.Fps;

            NextWaveBox.CurrentWave = GameObj.Wave - 1;

            CleanGarbage();

            //Normal GUI Render
            foreach (GuiItem Item in Container)
            {
                Surface RenderedItem = RenderItem(Item);

                Screen.Blit(RenderedItem, Item.GetRect());
            }

            //Game Graphics Render
            //Surface GameSurface = MapRender.Render();
            Surface GameSurface = new Surface(MapBackground);
            //GameSurface.Blit(MapBackground, new Point(0, 0));
            //Surface GameSurface = new Surface(MapRenderer.MAP_WIDTH_PX, MapRenderer.MAP_HEIGHT_PX);
            if (GameObj.State == GameState.CreepAttack)
            {
                isNewWave = true;
                Surface CreepsLayer = CreepRender.Render(GameObj.Creeps,GameObj.map);
                GameSurface.Blit(CreepsLayer, new Point(0, 0));
            }
            else if (GameObj.State == GameState.NoAttack)
            {
                if (isNewWave)
                {
                    LastAttackInfo = 0;
                    isNewWave = false;
                    WaveBox.Wave = GameObj.GetNextWaveInfo();
                    WaveBox.UpdateCaption();

                    CreepRender.Clean();
                    CreepRender = new CreepRenderer(CreepTextures.GetEntry(GameObj.CurrentWave.GfxName));

                    TopLevelContainer.Add(WaveBox);
                }

                if (UnitClassesChooserBox.ChoosenClass != UnitClasses.None)
                {
                    if (GameRectangle.Contains(MousePos))
                    {
                        Point relpoint = new Point(MousePos.X - GameStartP.X, MousePos.Y - GameStartP.Y);

                        MapCoord Coord = new MapCoord(relpoint);

                        PlayerUnit tmpUnit = PlayerUnit.CreateUnit(UnitClassesChooserBox.ChoosenClass);
                        UnitInfoBox.ChangeUnit(tmpUnit);
                        Surface UnitGfx = PlayerUnitRenderer.Render(tmpUnit);

                        if (GameObj.map.Tiles[Coord.Row][Coord.Column].Type == TileType.Normal)
                        {
                            GameSurface.Blit(UnitGfx, new Rectangle(new Point(Coord.ToPoint().X + (Tile.TILE_WIDTH - UnitGfx.Width) / 2, Coord.ToPoint().Y + (Tile.TILE_HEIGHT - UnitGfx.Height) / 2), new Size(UnitGfx.Width, UnitGfx.Height)));

                            DrawUnitRange(GameSurface, Coord, tmpUnit);
                        }
                    }
                }
            }
            else if (GameObj.State == GameState.GameOver && TopLevelContainer.Count == 0)
            {
                if (!AskedPlayerName)
                {
                    PlayerNameDialog.TextEntry = PlayerName;

                    TopLevelContainer.Add(PlayerNameDialog);
                    PlayerNameDialog.SetEvents();
                    AskedPlayerName = true;
                }
                else
                {
                    GameOverBox box = new GameOverBox(GameObj, Garbage);
                    box.SetEvents();
                    box.X = (Width - box.Width) / 2;
                    box.Y = (Height - box.Height) / 2;
                    TopLevelContainer.Add(box);

                    //Saving Score , must ask for name before
                    GameObj.SaveScore(PlayerName);
                    LastAttackInfo = 0;
                    AskedPlayerName = false;
                }
            }
            else if (GameObj.State == GameState.Complete && TopLevelContainer.Count == 0)
            {
                if (!AskedPlayerName)
                {
                    PlayerNameDialog.TextEntry = PlayerName;

                    TopLevelContainer.Add(PlayerNameDialog);
                    PlayerNameDialog.SetEvents();
                    AskedPlayerName = true;
                }
                else
                {
                    GameCompleteBox box = new GameCompleteBox(GameObj, Garbage);
                    box.SetEvents();
                    box.X = (Width - box.Width) / 2;
                    box.Y = (Height - box.Height) / 2;
                    TopLevelContainer.Add(box);

                    //Saving Score , must ask for name before
                    GameObj.SaveScore(PlayerName);
                    LastAttackInfo = 0;
                    AskedPlayerName = false;
                }
            }

            foreach (MapCoord Coord in GameObj.PlayerUnits.Keys)
            {
                Surface Unit = PlayerUnitRenderer.Render(GameObj.PlayerUnits[Coord]);
                Point Dest = new Point(Coord.ToPoint().X + ((Tile.TILE_WIDTH - Unit.Width) / 2), Coord.ToPoint().Y + ((Tile.TILE_HEIGHT - Unit.Height) / 2));
                Rectangle Clip = new Rectangle(Dest, Unit.Size);
                GameSurface.Blit(Unit, Clip);

                if (!SelectedTile.isEmpty && Coord.SameCoord(SelectedTile))
                {
                    DrawUnitRange(GameSurface, Coord, GameObj.PlayerUnits[Coord]);
                }

            }

            if (!SelectedTile.isEmpty && GameObj.map.Tiles[SelectedTile.Row][SelectedTile.Column].Type == TileType.Normal)
            {
                Surface Sqr = new Surface(Tile.TILE_WIDTH, Tile.TILE_HEIGHT);
                Sqr.Alpha = 100;
                Sqr.AlphaBlending = true;
                Sqr.Fill(Color.LightBlue);

                Box Border = new Box(new Point(0, 0), new Size(Sqr.Width-1, Sqr.Height-1));
                Sqr.Draw(Border, Color.Black);

                Rectangle Clip = new Rectangle(SelectedTile.ToPoint(), new Size(Tile.TILE_WIDTH, Tile.TILE_HEIGHT));

                GameSurface.Blit(Sqr, Clip);
            }

            UpdateAttackSpriteCollection();

            MageSprites.Update(args);

            if (GameObj.State == GameState.CreepAttack)
            {
                foreach (TextSprite Spr in CritSprites)
                {
                    GameSurface.Blit(Spr, new Rectangle(Spr.Position, Spr.Size));

                }

                foreach (MageAttackSprite Spr in MageSprites.Sprites)
                {
                    GameSurface.Blit(Spr);
                }

                foreach (Projectile pro in GameObj.Projectiles)
                {
                    Circle c = new Circle(pro.Position, 3);
                    Circle d = new Circle(pro.Position, 2);
                    GameSurface.Draw(c, Color.Blue);
                    GameSurface.Draw(d, Color.BlueViolet);
                }
            }

            Screen.Blit(GameSurface, GameRectangle);

            //Top Level gui Render (Menu to Add Tower and Upgrade Tower)
            foreach (GuiItem Item in TopLevelContainer)
            {
                Surface RenderedItem = RenderItem(Item);

                Screen.Blit(RenderedItem, Item.GetRect());
            }

            Screen.Update();
        }
Esempio n. 38
0
        public static MapCoordList FindCreepPath(Map map)
        {
            MapCoordList Path = new MapCoordList();
            MapCoord CreepStart = new MapCoord();
            MapCoord LastCoord = new MapCoord();
            int Tick = 0;

            for (int i = 0; i < map.Rows; i++)
            {
                for (int j = 0; j < map.Columns; j++)
                {
                    if (map.Tiles[i][j].Type == TileType.CreepStart)
                    {
                        CreepStart = new MapCoord(i, j);

                    }
                }

                if (!CreepStart.isEmpty)
                    break;
            }

            if (CreepStart.isEmpty)
            {
                throw new Exception("CreepStart Not Found !");
            }

            Path.Add(CreepStart);
            LastCoord = CreepStart;
            while (map.Tiles[LastCoord.Row][LastCoord.Column].Type != TileType.CreepEnd)
            {
                bool isFound = false;
                LastCoord = Path[Path.Count - 1];

                if (LastCoord.Row > 0 && !isFound)
                {
                    if (map.Tiles[LastCoord.Row - 1][LastCoord.Column].Type == TileType.CreepPath ||
                       map.Tiles[LastCoord.Row - 1][LastCoord.Column].Type == TileType.CreepEnd)
                    {
                        if (!Path.ContainsCoord(new MapCoord(LastCoord.Row - 1, LastCoord.Column)))
                        {
                            isFound = true;
                            Path.Add(new MapCoord(LastCoord.Row - 1, LastCoord.Column));
                        }
                    }
                }

                if (LastCoord.Row < map.Rows - 1 && !isFound)
                {
                    if (map.Tiles[LastCoord.Row + 1][LastCoord.Column].Type == TileType.CreepPath ||
                        map.Tiles[LastCoord.Row + 1][LastCoord.Column].Type == TileType.CreepEnd)
                    {
                        if (!Path.ContainsCoord(new MapCoord(LastCoord.Row + 1, LastCoord.Column)))
                        {
                            isFound = true;
                            Path.Add(new MapCoord(LastCoord.Row + 1, LastCoord.Column));
                        }
                    }
                }

                if (LastCoord.Column < map.Columns - 1 && !isFound)
                {
                    if (map.Tiles[LastCoord.Row][LastCoord.Column + 1].Type == TileType.CreepPath ||
                        map.Tiles[LastCoord.Row][LastCoord.Column + 1].Type == TileType.CreepEnd)
                    {
                        if (!Path.ContainsCoord(new MapCoord(LastCoord.Row, LastCoord.Column+1)))
                        {
                            isFound = true;
                            Path.Add(new MapCoord(LastCoord.Row, LastCoord.Column + 1));
                        }
                    }
                }

                if (LastCoord.Column > 0 && !isFound)
                {
                    if (map.Tiles[LastCoord.Row][LastCoord.Column - 1].Type == TileType.CreepPath ||
                        map.Tiles[LastCoord.Row][LastCoord.Column - 1].Type == TileType.CreepEnd)
                    {
                        if (!Path.ContainsCoord(new MapCoord(LastCoord.Row, LastCoord.Column - 1)))
                        {
                            isFound = true;
                            Path.Add(new MapCoord(LastCoord.Row, LastCoord.Column - 1));
                        }
                    }
                }

                if (Tick == MaxTry)
                {
                    throw new Exception("CreepEnd not found after " +MaxTry+ " Tries !");
                }

                Tick++;
            }

            return Path;
        }
Esempio n. 39
0
        /// <summary>
        /// Creep mouvement
        /// </summary>
        public void CreepMoveTick()
        {
            if (Tick % 30 == 0)
            {
                StartNewCreep = true;
            }

            foreach (CreepUnit Unit in Creeps)
            {
                if (StartNewCreep && Unit.Position.IsEmpty)
                {
                    StartNewCreep = false;
                    Unit.Position = CreepPath[0].ToPoint();
                }
                else if(!Unit.Position.IsEmpty)
                {
                    MapCoord UnitCoord = new MapCoord(Unit.Position);
                    MapCoord before = CreepPath.Before(UnitCoord);
                    MapCoord Diff = new MapCoord();
                    int Next = CreepPath.GetIndex(UnitCoord);

                    if(Next == CreepPath.Count-1)
                    {
                        Diff = CreepPath[Next-1].Diff(UnitCoord);
                    }
                    else
                    {
                        Diff = UnitCoord.Diff(CreepPath[Next+1]);
                    }

                    if (Diff.Row == 1)
                    {
                        Unit.Position = new Point(Unit.Position.X, Unit.Position.Y + Unit.Speed);
                        Unit.Direction = Direction.Down;
                    }
                    else if (Diff.Row == -1)
                    {
                       	Unit.Position = new Point(Unit.Position.X, Unit.Position.Y - Unit.Speed);
                        Unit.Direction = Direction.Up;
                    }
                    else if (Diff.Column == 1)
                    {
                        if (!before.isEmpty)
                        {
                            if (Unit.Position.Y % Tile.TILE_HEIGHT != 0 && before.Diff(UnitCoord).Row == -1)
                            {
                                Unit.Position = new Point(Unit.Position.X, Unit.Position.Y - Unit.Speed);
                                Unit.Direction = Direction.Up;
                            }
                            else
                            {
                                Unit.Position = new Point(Unit.Position.X + (Unit.Speed*Diff.Column), Unit.Position.Y);
                                Unit.Direction = Direction.Left;
                            }
                        }
                        else
                        {
                            Unit.Position = new Point(Unit.Position.X + Unit.Speed, Unit.Position.Y);
                            Unit.Direction = Direction.Left;
                        }
                    }
                    else if (Diff.Column == -1)
                    {
                        if (!before.isEmpty)
                        {
                            if (Unit.Position.Y % Tile.TILE_HEIGHT != 0 && before.Diff(UnitCoord).Row == -1)
                            {
                                int mustX = UnitCoord.ToPoint().X;

                                if (mustX == Unit.Position.X)
                                {
                                    Unit.Position = new Point(Unit.Position.X, Unit.Position.Y - Unit.Speed);
                                    Unit.Direction = Direction.Up;
                                }
                                else
                                {
                                    Unit.Position = new Point(Unit.Position.X + (Unit.Speed * Diff.Column), Unit.Position.Y);
                                    Unit.Direction = Direction.Right;
                                }
                            }
                            else
                            {
                                Unit.Position = new Point(Unit.Position.X + (Unit.Speed*Diff.Column), Unit.Position.Y);
                                Unit.Direction = Direction.Right;
                            }
                        }
                        else
                        {
                            Unit.Position = new Point(Unit.Position.X - Unit.Speed, Unit.Position.Y);
                            Unit.Direction = Direction.Right;
                        }
                    }
                }

            }

            if (Creeps.Count == 0)
            {
                FinishedWave();
            }

            Tick++;
        }