Пример #1
0
        private void GenerateMap(Map map)
        {
            var mapSize = map.GetSize();
            int width   = (int)mapSize.Width - 1;
            int height  = (int)mapSize.Height - 1;

            int count = (int)(width * height * 0.35);

            var mapWithRiver = GenerateRiver(map);

            for (int i = 0; i < mapWithRiver.GetLength(0); i++)
            {
                for (int j = 0; j < mapWithRiver.GetLength(1); j++)
                {
                    if (mapWithRiver[i, j] > 0)
                    {
                        map.SetObjectFromCell(new Point(i, j), new FixedObject(new Size(1, 1), (uint)(mapWithRiver[i, j] > 1 ? 0x00002000 : 0x00002100))
                        {
                            IsPassable = false
                        });
                    }
                }
            }

            int    tmpX, tmpY;
            Random rand = new Random();

            while (count > 0)
            {
                tmpX = rand.Next(width);
                tmpY = rand.Next(height);

                if (map.GetObjectFromCell(new Point(tmpX, tmpY)) != null)
                {
                    continue;
                }

                var typesCount = Game.Factory.ObjectsToGenMap.Count;

                /*
                 * var typesOnMap = Assembly.GetExecutingAssembly().GetTypes().Where(
                 *  type => type.GetCustomAttribute<GenerateMapAttribute>() != null).ToList();
                 */
                var randIndex = count % typesCount;//typesOnMap.Count;

                //map.SetObjectFromCell(new Point(tmpX, tmpY), Activator.CreateInstance(typesOnMap[randIndex]) as FixedObject);
                //  map.SetObjectFromCell(new Point(tmpX, tmpY), Game.Factory.Produce(Game.Factory.ObjectsToGenMap[randIndex]) as FixedObject);

                count--;
            }

            for (int i = 0; i < 20; i++)
            {
                while (true)
                {
                    tmpX = rand.Next(width);
                    tmpY = rand.Next(height);

                    if (map.GetObjectFromCell(new Point(tmpX, tmpY)) != null)
                    {
                        continue;
                    }

                    //       map.AddMobileObject(new Dikabryozik(new Point(tmpX, tmpY)));
                    map.AddMobileObject(new Hare(Map.CellToPoint(new Point(tmpX, tmpY))));
                    map.AddMobileObject(new Fox(Map.CellToPoint(new Point(tmpX, tmpY))));
                    break;
                }
            }
        }
Пример #2
0
        private void DrawSurface()
        {
            _drawer.DrawSurface(curRect.Width, curRect.Height);

            var visibleCells = Map.RectToCellRect(Map.VisibleRect);

            var lightObjectsList = new List <BurningProps>();

            //var mapSize = _map.GetSize();
            for (int j = visibleCells.Top; j < visibleCells.Top + visibleCells.Height; j++)
            {
                for (int i = visibleCells.Left; i < visibleCells.Left + visibleCells.Width; i++)
                {
                    var gameObject = Map.GetHObjectFromCell(new Point(i, j));

                    if (gameObject == null)
                    {
                        continue;
                    }
                    if (gameObject is LargeObjectOuterAbstract largeObjectOuter && !largeObjectOuter.isLeftCorner)
                    {
                        continue;
                    }

                    var visibleDestination = Map.GetVisibleDestinationFromRealDestination(Map.CellToPoint(new Point(i, j)));

                    var drawingCode = GetDrawingCode(gameObject);

                    _drawer.DrawObject(drawingCode, visibleDestination.X, visibleDestination.Y, gameObject.Height);

                    if (gameObject is IBurning burning)
                    {
                        lightObjectsList.Add(new BurningProps(visibleDestination, burning.LightRadius));
                    }
                }

                if ((j * Map.CellMeasure <= _hero.Position.Y) && ((j + 1) * Map.CellMeasure > _hero.Position.Y))
                {
                    _drawer.DrawHero(Map.GetVisibleDestinationFromRealDestination(_hero.Position), _hero.Angle, _hero.PointList.Select(p => Map.GetVisibleDestinationFromRealDestination(p)).ToList(), _hero.IsHorizontal());
                }
            }

            var mobileObjects = Map.GetMobileObjects();

            foreach (var mobileObject in mobileObjects)
            {
                if (Map.PointInVisibleRect(mobileObject.Position))
                {
                    var visibleDestination = Map.GetVisibleDestinationFromRealDestination(mobileObject.Position);
                    _drawer.DrawObject(mobileObject.GetDrawingCode(), visibleDestination.X, visibleDestination.Y, mobileObject.Height);
                }
            }

            //  _drawer.DrawHero(Map.GetVisibleDestinationFromRealDestination(_hero.Position), _hero.Angle, _hero.PointList.Select(p => Map.GetVisibleDestinationFromRealDestination(p)).ToList(), _hero.IsHorizontal());

            if (IsHeroInInnerMap())
            {
                var innerMapSize       = Map.GetInnerMapRect();
                var visibleDestination = Map.GetVisibleDestinationFromRealDestination(Map.CellToPoint(new Point(innerMapSize.Left, innerMapSize.Top)));
                _drawer.DrawShaddow(visibleDestination, new Size(innerMapSize.Width, innerMapSize.Height));
            }
            else
            {
                _drawer.DrawDayNight(_dayNightCycle.Lightness(), lightObjectsList);
            }

            _drawer.DrawActing(_hero.State.ShowActing);
        }