Esempio n. 1
0
 public void Add(Curio curio)
 {
     Behavior.Apply(new BehaviorOnTile(this, curio));
 }
Esempio n. 2
0
        private void GenerateMap()
        {
            var generator = new MapGenerator();

            generator.Generate();
            generator.Print(Map);

            RunStats.Level += 1;

            new Curio(Template.BellTower).MoveTo(Map.GetTile(0, 0));

            var   positions = Map.EnumerateTiles().Shuffle(Random);
            Point?start     = null;

            var weak   = new List <Template>();
            var strong = new List <Template>();

            bool hasOmicron = PlayerCurio.HasBehaviors <BehaviorOmicron>();

            //TODO: There was gonna be a tutorial with blood urns for smashing
            if (RunStats.Level >= 1)
            {
                weak.Add(Template.Grunt);
            }
            if (RunStats.Level >= 2)
            {
                weak.Add(Template.Twitch);
            }
            if (RunStats.Level >= 3)
            {
                weak.Add(Template.Bulwark);
            }
            if (RunStats.Level >= 4)
            {
                strong.Add(Template.Lich);
            }
            if (RunStats.Level >= 5)
            {
                weak.Remove(Template.Grunt);
            }
            if (RunStats.Level % 2 == 0)
            {
                weak.Add(Template.Rat);
            }

            weak.Add(Template.Executioner);
            weak.Add(Template.Lich);

            var toSpawn = new List <Template>();

            if (weak.Any())
            {
                for (int i = 0; i < 30; i++)
                {
                    toSpawn.Add(weak.Pick(Random));
                }
            }
            if (strong.Any())
            {
                for (int i = 0; i < 5; i++)
                {
                    toSpawn.Add(strong.Pick(Random));
                }
            }
            if (hasOmicron || (RunStats.Level >= 6 && RunStats.Level % 3 == 0))
            {
                toSpawn.Add(Template.Nemesis);
            }

            var spawned = new List <ICurio>();

            foreach (var tile in positions)
            {
                if (toSpawn.Any() && !tile.IsSolid() && !tile.IsChasm())
                {
                    var template = toSpawn[0];
                    toSpawn.RemoveAt(0);
                    var enemy = new Curio(template);
                    enemy.MoveTo(tile);
                    if (template != Template.Nemesis && template != Template.Rat)
                    {
                        spawned.Add(enemy);
                    }
                    if (template == Template.Nemesis && hasOmicron)
                    {
                        Behavior.Apply(new BehaviorKillTarget(enemy));
                    }
                }
                else if (tile.HasBehaviors <BehaviorLevelStart>())
                {
                    start = new Point(tile.X, tile.Y);
                }
                if (toSpawn.Empty() && start.HasValue)
                {
                    break;
                }
            }

            if (RunStats.Level % 3 == 0)
            {
                foreach (var enemy in spawned.Shuffle(Random).Take(3))
                {
                    Behavior.Apply(new BehaviorKillTarget(enemy));
                }
            }

            PlayerCurio.MoveTo(Map.GetTile(start.Value.X, start.Value.Y));
            CameraCurio.MoveTo(Map.GetTile(start.Value.X, start.Value.Y));
        }
Esempio n. 3
0
 public void AddPrimary(Curio curio)
 {
     Add(curio);
 }
Esempio n. 4
0
        public void Print(Map map)
        {
            SimpleNoise spikeNoise = new SimpleNoise(Random.Next());

            if (map.Width != Width || map.Height != Height)
            {
                throw new Exception();
            }
            var tiles = Rooms.SelectMany(x => x.GetCoveredTiles().Select(y => new Tuple <Room, Point>(x, y))).GroupBy(pair => pair.Item2, pair => pair.Item1);

            foreach (var rooms in tiles)
            {
                var        pos         = rooms.Key;
                var        tile        = map.GetTile(pos.X, pos.Y);
                var        count       = rooms.Count();
                var        singleRoom  = count == 1 ? rooms.Single() : null;
                RoomType[] normalRooms = new[] { RoomType.None, RoomType.Start, RoomType.End, RoomType.Corridor };
                RoomType[] startEnd    = new[] { RoomType.Start, RoomType.End };
                Template[] floors      = new[] { null, Template.Corridor };

                Template template = null;

                if (singleRoom != null && singleRoom.Type == RoomType.Filled)
                {
                    template = Template.Wall;
                }
                if (singleRoom != null && singleRoom.Type == RoomType.Chasm)
                {
                    template = Template.Chasm;
                }
                if (count > 1)
                {
                    template = Template.Wall;
                }
                if (rooms.Any(x => x.Type == RoomType.Chasm))
                {
                    template = Template.Corridor;
                }
                if (rooms.All(x => x.Type == RoomType.Chasm))
                {
                    template = Template.Chasm;
                }
                if (rooms.All(x => x.Type == RoomType.Corridor))
                {
                    template = Template.Corridor;
                }
                if (singleRoom?.Type == RoomType.Start || singleRoom?.Type == RoomType.End)
                {
                    template = Template.Floor;
                }
                if (count == 2 && IsConnected(rooms.First(), rooms.Last()) && !floors.Contains(template))
                {
                    template = null;
                }
                if (IsEdgeTile(pos) && floors.Contains(template) && !rooms.All(x => startEnd.Contains(x.Type)))
                {
                    template = Template.Wall;
                }

                int spikeValue = spikeNoise.GetValue(pos.X / 3, pos.Y / 3);

                if (template == Template.Wall && (spikeValue % 10 == 0 || spikeNoise.GetValue(pos.X, pos.Y) % 30 == 0))
                {
                    template = Template.SpikeWall;
                }
                if (template == Template.Wall && Random.NextDouble() < 0.1)
                {
                    template = Template.WraithWall;
                }

                if (template == null)
                {
                    template = Template.Floor;
                }

                if (template != null)
                {
                    tile.ApplyTemplate(template);
                }
                if (rooms.Any(x => x.Type == RoomType.Chasm) && template != Template.Chasm)
                {
                    Behavior.Apply(new BehaviorChasmSeam(tile, template == Template.Corridor ? new Color(155, 99, 74) : new Color(124, 88, 114)));
                }
                if (singleRoom?.Type == RoomType.Start)
                {
                    Behavior.Apply(new BehaviorLevelStart(tile, singleRoom.GetEdgeDirection()));
                }
                if (singleRoom?.Type == RoomType.End)
                {
                    Behavior.Apply(new BehaviorLevelEnd(tile, singleRoom.GetEdgeDirection()));
                    if (singleRoom.Interior.Center == pos)
                    {
                        var pointer = new Curio(Template.Pointer);
                        pointer.MoveTo(tile);
                        Behavior.Apply(new BehaviorEscapeTarget(pointer, singleRoom.Interior));
                    }
                }
            }
        }