Exemplo n.º 1
0
 public World(MainGame game)
 {
     _currentMap = null;
     Game = game;
     //_maps = new List<Map>();
     _player = new Player
     {
         Name = "Olaf the Viking",
         HitPoints = 40,
         HitPointsMax = 60,
         Luck = -100,
         LuckMax = 10,
         Strength = 18,
         Food = 10,
         FoodMax = 10,
     };
     Seed = (int)DateTime.Now.Ticks;
     _random = new Random(Seed);
     _soundManager = new SoundManager(Game);
     Game.Services.AddService(this);
 }
Exemplo n.º 2
0
 public void DoStepOn(Point point, Map startMap)
 {
     SteppedOn?.Invoke(point, startMap);
 }
Exemplo n.º 3
0
 private void OnTileStepOn(Point positionSteppedOn, Map startMap)
 {
     var mapConnection = startMap.Connections.FirstOrDefault(connection => connection.Start.Equals(positionSteppedOn));
     if (mapConnection != null)
     {
         _soundManager.PlaySound("Teleport_8000");
         if (mapConnection.EndMap != CurrentMap)
         {
             CurrentMap = mapConnection.EndMap;
         }
         _player.Position = mapConnection.End;
     }
 }
Exemplo n.º 4
0
        private void LoadMaps()
        {
            var soundThemeForest = "Bird";
            var soundThemeDungeon = "Dungeon";

            var floorDungeon = "DungeonFloor";
            var floorForest = "Grass";

            #region Forest Maps
            var mapForestNW = new Map(this, "Forest_NW", Constants.Graphics.Maps.MapWidth, Constants.Graphics.Maps.MapHeight, _random);
            mapForestNW.SoundTheme = soundThemeForest;
            mapForestNW.Fill(floorForest);
            mapForestNW.AddBorderTiles(MapBorder.North, "Mountain", 3, 80);
            mapForestNW.AddBorderTiles(MapBorder.West, "Mountain", 3, 70);
            mapForestNW.AddSubTiles(stem: "Tree", coverage: 15);
            mapForestNW.AddSubTiles(stem: "Rock", coverage: 5);

            var mapForestN = new Map(this, "Forest_N", Constants.Graphics.Maps.MapWidth, Constants.Graphics.Maps.MapHeight, _random);
            mapForestN.SoundTheme = soundThemeForest;
            mapForestN.Fill(floorForest);
            mapForestN.AddBorderTiles(MapBorder.North, "Mountain", 3, 70);
            mapForestN.AddSubTiles(stem: "Tree", coverage: 20);
            mapForestN.AddSubTiles(stem: "Rock", coverage: 5);

            var mapForestNE = new Map(this, "Forest_NE", Constants.Graphics.Maps.MapWidth, Constants.Graphics.Maps.MapHeight, _random);
            mapForestNE.SoundTheme = soundThemeForest;
            mapForestNE.Fill(floorForest);
            mapForestNE.AddBorderTiles(MapBorder.North, "Mountain", 3, 70);
            mapForestNE.AddBorderTiles(MapBorder.East, "Mountain", 3, 70);
            mapForestNE.AddSubTiles(stem: "Tree", coverage: 20);
            mapForestNE.AddSubTiles(stem: "Rock", coverage: 5);

            var mapForestW = new Map(this, "Forest_W", Constants.Graphics.Maps.MapWidth, Constants.Graphics.Maps.MapHeight, _random);
            mapForestW.SoundTheme = soundThemeForest;
            mapForestW.Fill(floorForest);
            mapForestW.AddBorderTiles(MapBorder.West, "Mountain", 3, 70);
            mapForestW.AddSubTiles(stem: "Tree", coverage: 20);
            mapForestW.AddSubTiles(stem: "Rock", coverage: 5);

            var mapForestC = new Map(this, "Forest_C", Constants.Graphics.Maps.MapWidth, Constants.Graphics.Maps.MapHeight, _random);
            mapForestC.SoundTheme = soundThemeForest;
            mapForestC.Fill(floorForest);
            mapForestC.AddSubTiles(stem: "Tree", coverage: 20);
            mapForestC.AddSubTiles(stem: "Rock", coverage: 5);

            var mapForestE = new Map(this, "Forest_E", Constants.Graphics.Maps.MapWidth, Constants.Graphics.Maps.MapHeight, _random);
            mapForestE.SoundTheme = soundThemeForest;
            mapForestE.Fill(floorForest);
            mapForestE.AddBorderTiles(MapBorder.East, "Mountain", 3, 70);
            mapForestE.AddSubTiles(stem: "Tree", coverage: 20);
            mapForestE.AddSubTiles(stem: "Rock", coverage: 5);

            var mapForestSW = new Map(this, "Forest_SW", Constants.Graphics.Maps.MapWidth, Constants.Graphics.Maps.MapHeight, _random);
            mapForestSW.SoundTheme = soundThemeForest;
            mapForestSW.Fill(floorForest);
            mapForestSW.AddBorderTiles(MapBorder.South, "Mountain", 3, 70);
            mapForestSW.AddBorderTiles(MapBorder.West, "Mountain", 3, 70);
            mapForestSW.AddSubTiles(stem: "Tree", coverage: 20);
            mapForestSW.AddSubTiles(stem: "Rock", coverage: 5);

            var mapForestS = new Map(this, "Forest_S", Constants.Graphics.Maps.MapWidth, Constants.Graphics.Maps.MapHeight, _random);
            mapForestS.SoundTheme = soundThemeForest;
            mapForestS.Fill(floorForest);
            mapForestS.AddBorderTiles(MapBorder.South, "Mountain", 3, 70);
            mapForestS.AddSubTiles(stem: "Tree", coverage: 20);
            mapForestS.AddSubTiles(stem: "Rock", coverage: 5);

            var mapForestSE = new Map(this, "Forest_SE", Constants.Graphics.Maps.MapWidth, Constants.Graphics.Maps.MapHeight, _random);
            mapForestSE.SoundTheme = "Bird";
            mapForestSE.Fill(floorForest);
            mapForestSE.AddBorderTiles(MapBorder.South, "Mountain", 3, 70);
            mapForestSE.AddBorderTiles(MapBorder.East, "Mountain", 3, 70);
            mapForestSE.AddSubTiles(stem: "Tree", coverage: 20);
            mapForestSE.AddSubTiles(stem: "Rock", coverage: 5);
            #endregion Forest Maps

            #region 10 meters Maps
            var map10mNW = new Map(this, "10 Meters NW", Constants.Graphics.Maps.MapWidth, Constants.Graphics.Maps.MapHeight, _random);
            map10mNW.SoundTheme = soundThemeDungeon;
            map10mNW.Fill(floorDungeon);
            map10mNW.AddBorderTiles(MapBorder.North, "Mountain", 3, 70);
            map10mNW.AddBorderTiles(MapBorder.West, "Mountain", 3, 70);
            map10mNW.AddSubTiles(stem: "Rock", coverage: 5);

            var map10mN = new Map(this, "10 Meters N", Constants.Graphics.Maps.MapWidth, Constants.Graphics.Maps.MapHeight, _random);
            map10mN.SoundTheme = soundThemeDungeon;
            map10mN.Fill(floorDungeon);
            map10mN.AddBorderTiles(MapBorder.North, "Mountain", 3, 70);
            map10mN.AddSubTiles(stem: "Rock", coverage: 5);

            var map10mNE = new Map(this, "10 Meters NE", Constants.Graphics.Maps.MapWidth, Constants.Graphics.Maps.MapHeight, _random);
            map10mNE.SoundTheme = soundThemeDungeon;
            map10mNE.Fill(floorDungeon);
            map10mNE.AddBorderTiles(MapBorder.North, "Mountain", 3, 70);
            map10mNE.AddBorderTiles(MapBorder.East, "Mountain", 3, 70);
            map10mNE.AddSubTiles(stem: "Rock", coverage: 5);

            var map10mW = new Map(this, "10 Meters W", Constants.Graphics.Maps.MapWidth, Constants.Graphics.Maps.MapHeight, _random);
            map10mW.SoundTheme = soundThemeDungeon;
            map10mW.Fill(floorDungeon);
            map10mW.AddBorderTiles(MapBorder.West, "Mountain", 3, 70);
            map10mW.AddSubTiles(stem: "Rock", coverage: 5);

            var map10mC = new Map(this, "10 Meters C", Constants.Graphics.Maps.MapWidth, Constants.Graphics.Maps.MapHeight, _random);
            map10mC.SoundTheme = soundThemeDungeon;
            map10mC.Fill(floorDungeon);
            map10mC.AddSubTiles(stem: "Rock", coverage: 5);

            var map10mE = new Map(this, "10 Meters E", Constants.Graphics.Maps.MapWidth, Constants.Graphics.Maps.MapHeight, _random);
            map10mE.SoundTheme = soundThemeDungeon;
            map10mE.Fill(floorDungeon);
            map10mE.AddBorderTiles(MapBorder.East, "Mountain", 3, 70);
            map10mE.AddSubTiles(stem: "Rock", coverage: 5);

            var map10mSW = new Map(this, "10 Meters SW", Constants.Graphics.Maps.MapWidth, Constants.Graphics.Maps.MapHeight, _random);
            map10mSW.SoundTheme = soundThemeDungeon;
            map10mSW.Fill(floorDungeon);
            map10mSW.AddBorderTiles(MapBorder.South, "Mountain", 3, 70);
            map10mSW.AddBorderTiles(MapBorder.West, "Mountain", 3, 70);
            map10mSW.AddSubTiles(stem: "Rock", coverage: 5);

            var map10mS = new Map(this, "10 Meters S", Constants.Graphics.Maps.MapWidth, Constants.Graphics.Maps.MapHeight, _random);
            map10mS.SoundTheme = soundThemeDungeon;
            map10mS.Fill(floorDungeon);
            map10mS.AddBorderTiles(MapBorder.South, "Mountain", 3, 70);
            map10mS.AddSubTiles(stem: "Rock", coverage: 5);

            var map10mSE = new Map(this, "10 Meters SE", Constants.Graphics.Maps.MapWidth, Constants.Graphics.Maps.MapHeight, _random);
            map10mSE.SoundTheme = soundThemeDungeon;
            map10mSE.Fill(floorDungeon);
            map10mSE.AddBorderTiles(MapBorder.South, "Mountain", 3, 70);
            map10mSE.AddBorderTiles(MapBorder.East, "Mountain", 3, 70);
            map10mSE.AddSubTiles(stem: "Rock", coverage: 5);

            #endregion 10 meters Maps

            #region 20 meters Maps
            #endregion 20 meters Maps

            #region 30 meters Maps
            #endregion 30 meters Maps

            _maps = new[] { mapForestNW, mapForestN, mapForestNE, mapForestW, mapForestC, mapForestE, mapForestSW, mapForestS, mapForestSE,
                    map10mN, map10mNE, map10mW, map10mC, map10mE, map10mSW, map10mS, map10mSE, }.ToDictionary(k => k.Name, v => v);

            //
            // Map Navigation
            //
            CreateBorderMapConnection(MapBorder.East, 30, mapForestNW, "Arrows_Right", mapForestN, "Arrows_Left");
            CreateBorderMapConnection(MapBorder.East, 30, mapForestN, "Arrows_Right", mapForestNE, "Arrows_Left");
            CreateBorderMapConnection(MapBorder.South, 30, mapForestNW, "Arrows_Down", mapForestW, "Arrows_Up");
            CreateBorderMapConnection(MapBorder.South, 30, mapForestN, "Arrows_Down", mapForestC, "Arrows_Up");
            CreateBorderMapConnection(MapBorder.South, 30, mapForestNE, "Arrows_Down", mapForestE, "Arrows_Up");
            CreateBorderMapConnection(MapBorder.East, 30, mapForestW, "Arrows_Right", mapForestC, "Arrows_Left");
            CreateBorderMapConnection(MapBorder.East, 30, mapForestC, "Arrows_Right", mapForestE, "Arrows_Left");
            CreateBorderMapConnection(MapBorder.South, 30, mapForestW, "Arrows_Down", mapForestSW, "Arrows_Up");
            CreateBorderMapConnection(MapBorder.South, 30, mapForestC, "Arrows_Down", mapForestS, "Arrows_Up");
            CreateBorderMapConnection(MapBorder.South, 30, mapForestE, "Arrows_Down", mapForestSE, "Arrows_Up");
            CreateBorderMapConnection(MapBorder.East, 30, mapForestSW, "Arrows_Right", mapForestS, "Arrows_Left");
            CreateBorderMapConnection(MapBorder.East, 30, mapForestS, "Arrows_Right", mapForestSE, "Arrows_Left");

            //
            // Manual Placing Map Connections
            //
            CreateMapConnection(mapForestNW, new Point(10, 10), "Stairs_01", map10mNW, new Point(10, 10), "Stairs_02");

            LoadItems();
        }
Exemplo n.º 5
0
        public void CreateMapConnection(Map startMap, Point startPosition, string startTileStem, Map endMap, Point endPosition, string endTileStem)
        {
            #region NullChecking
            if (startMap == null)
            {
                throw new ArgumentNullException(nameof(startMap));
            }
            if (string.IsNullOrEmpty(startTileStem))
            {
                throw new ArgumentNullException(nameof(startTileStem));
            }
            if (endMap == null)
            {
                throw new ArgumentNullException(nameof(endMap));
            }
            if (string.IsNullOrEmpty(endTileStem))
            {
                throw new ArgumentNullException(nameof(endTileStem));
            }
            #endregion NullChecking
            var startTile = Tile.GetRandomTile(startTileStem);
            var endTile = Tile.GetRandomTile(endTileStem);

            var tile1 = startMap.AddSubTile(startTile, startPosition);
            tile1.Position = startPosition;
            tile1.SteppedOn += OnTileStepOn;

            var tile2 = endMap.AddSubTile(endTile, endPosition, true);
            tile2.Position = endPosition;
            tile2.SteppedOn += OnTileStepOn;

            var mapConnectionStart = new MapConnection
            {
                End = endPosition,
                EndMap = endMap,
                Start = startPosition,
            };
            startMap.AddConnection(mapConnectionStart);
            var mapConnectionEnd = new MapConnection
            {
                End = startPosition,
                EndMap = startMap,
                Start = endPosition
            };
            endMap.AddConnection(mapConnectionEnd);
        }
Exemplo n.º 6
0
        /// <summary>
        /// creates random connection tiles at <see cref="mapBorder"/> in startMap, and on the opposite border of endMap 
        /// </summary>
        /// <param name="border"></param>
        /// <param name="thickness"></param>
        /// <param name="coverage"></param>
        /// <param name="startMap"></param>
        /// <param name="startPosition"></param>
        /// <param name="startTileStem"></param>
        /// <param name="endMap"></param>
        /// <param name="endTileStem"></param>
        /// TODO(philipp): no thickness needed for bordermapconnection tile thingies?
        public void CreateBorderMapConnection(MapBorder border, int coverage, Map startMap, string startTileStem, Map endMap, string endTileStem)
        {
            #region NullChecking
            if (startMap == null)
            {
                throw new ArgumentNullException(nameof(startMap));
            }
            if (string.IsNullOrEmpty(startTileStem))
            {
                throw new ArgumentNullException(nameof(startTileStem));
            }
            if (endMap == null)
            {
                throw new ArgumentNullException(nameof(endMap));
            }
            if (string.IsNullOrEmpty(endTileStem))
            {
                throw new ArgumentNullException(nameof(endTileStem));
            }
            #endregion NullChecking

            int startX = 0;
            int startY = 0;
            int endX = 0;
            int endY = 0;

            MapBorder oppositeMapBorder = MapBorder.None;

            switch (border)
            {
                case MapBorder.West:
                    startX = 0;
                    startY = 0;
                    endX = 1;
                    endY = startMap.Height;
                    oppositeMapBorder = MapBorder.East;
                    break;
                case MapBorder.North:
                    startX = 0;
                    startY = 0;
                    endX = startMap.Width;
                    endY = 1;
                    oppositeMapBorder = MapBorder.South;
                    break;
                case MapBorder.East:
                    startX = startMap.Width - 1;
                    startY = 0;
                    endX = startMap.Width;
                    endY = startMap.Height;
                    oppositeMapBorder = MapBorder.West;
                    break;
                case MapBorder.South:
                    startX = 0;
                    startY = startMap.Height - 1;
                    endX = startMap.Width;
                    endY = startMap.Height;
                    oppositeMapBorder = MapBorder.North;
                    break;
            }
            var rememberedTilePositions = new List<Point>();
            for (var y = startY; y < endY; ++y)
            {
                for (var x = startX; x < endX; ++x)
                {
                    if (_random.Next(0, 100) <= coverage)
                    {
                        var tileIndex = startMap.PointToIndex(x, y);
                        var tile = startMap.Tiles.ElementAt(tileIndex);
                        if (!tile.IsSolid)
                        {
                            //TODO(philipp): CLEAN UP THIS MESS!
                            var subTile = Tile.GetRandomTile(startTileStem);
                            subTile.Position = startMap.IndexToPoint(tileIndex);
                            rememberedTilePositions.Add(subTile.Position);
                            var connectionStartTile = startMap.AddSubTile(subTile, subTile.Position);
                            connectionStartTile.Position = subTile.Position;
                            connectionStartTile.SteppedOn += OnTileStepOn;
                        }
                    }
                }
            }
            var endTile = Tile.GetRandomTile(endTileStem);
            foreach (var rememberedTilePosition in rememberedTilePositions)
            {
                Point endPosition = Point.Zero;
                var startPosition = rememberedTilePosition;
                switch (oppositeMapBorder)
                {
                    case MapBorder.North:
                        endPosition = new Point(startPosition.X, 0);
                        break;
                    case MapBorder.West:
                        endPosition = new Point(0, startPosition.Y);
                        break;
                    case MapBorder.East:
                        endPosition = new Point(endMap.Width - 1, startPosition.Y);
                        break;
                    case MapBorder.South:
                        endPosition = new Point(startPosition.X, endMap.Height - 1);
                        break;
                }
                var connectionEndTile = endMap.AddSubTile(endTile, endPosition, true);
                connectionEndTile.Position = startPosition;
                connectionEndTile.SteppedOn += OnTileStepOn;

                var mapConnectionStart = new MapConnection
                {
                    End = endPosition,
                    EndMap = endMap,
                    Start = rememberedTilePosition,
                };
                startMap.AddConnection(mapConnectionStart);
                var mapConnectionEnd = new MapConnection
                {
                    End = rememberedTilePosition,
                    EndMap = startMap,
                    Start = endPosition
                };
                endMap.AddConnection(mapConnectionEnd);
            }
        }
Exemplo n.º 7
0
        public static Map FromDungeonGenerator3(World world, string name, int width, int height, uint seed, Random random)
        {
            var map = new Map(world, name, width, height, random);
            var dungeon = new DungeonGenerator3.MapBuilder(width, height);
            dungeon.Build_OneStartRoom();

            for (var x = 0; x < width; ++x)
            {
                for (var y = 0; y < height; ++y)
                {
                    var dungeonIndex = y * width + x;
                    var dungeonTile = dungeon._map[x, y];
                    if (dungeonTile == 1)
                    {
                        map.AddTile(Tile.GetRandomTile("DungeonWall"), new Point(x, y));
                    }
                    else
                    {
                        map.AddTile(Tile.GetRandomTile("DungeonFloor"), new Point(x, y));
                    }
                }
            }
            return map;
        }
Exemplo n.º 8
0
 public static Map FromDungeonGenerator2(World world, string name, int width, int height, uint seed, Random random)
 {
     var map = new Map(world, name, width, height, random);
     var dungeon = new DungeonGenerator2.Dungeon(new Random(), (foo) => { Console.WriteLine(foo); });
     dungeon.CreateDungeon(width, height, 100);
     for (var x = 0; x < width; ++x)
     {
         for (var y = 0; y < height; ++y)
         {
             var dungeonIndex = y * width + x;
             var dungeonTile = dungeon[dungeonIndex];
             if (dungeonTile == DungeonGenerator2.Tile.DirtWall || dungeonTile == DungeonGenerator2.Tile.StoneWall)
             {
                 map.AddTile(Tile.GetRandomTile("DungeonWall"), new Point(x, y));
             }
             else if (dungeonTile == DungeonGenerator2.Tile.Door)
             {
                 map.AddTile(Tile.GetRandomTile("Door_01"), new Point(x, y));
             }
             else if (dungeonTile == DungeonGenerator2.Tile.DirtFloor || dungeonTile == DungeonGenerator2.Tile.StoneFloor || dungeonTile == DungeonGenerator2.Tile.Corridor)
             {
                 map.AddTile(Tile.GetRandomTile("DungeonFloor"), new Point(x, y));
             }
         }
     }
     return map;
 }
Exemplo n.º 9
0
        public static Map FromDungeonGenerator(World world, string name, int width, int height, uint seed, Random random)
        {
            var map = new Map(world, name, width, height, random);
            var dungeonSettings = Dungeon.Generator.GeneratorParams.Default;
            dungeonSettings.RoomChance = 0.9f;

            //TODO(philipp): either find a better dungeon generator, or fix this shit here, that it works with our map sizes (142,32)
            var dungeon = Dungeon.Generator.Generator.Generate(width, height, seed);
            for (var x = 0; x < width; ++x)
            {
                for (var y = 0; y < height; ++y)
                {
                    if (x >= dungeon.Width || y >= dungeon.Height)
                    {
                        continue;
                    }

                    var dungeonTile = dungeon[x, y];
                    if (dungeonTile.MaterialType == Dungeon.Generator.MaterialType.Wall)
                    {
                        map.AddTile(Tile.GetRandomTile("DungeonWall"), new Point(x, y));
                    }
                    else if (dungeonTile.MaterialType == Dungeon.Generator.MaterialType.Floor)
                    {
                        map.AddTile(Tile.GetRandomTile("DungeonFloor"), new Point(x, y));
                    }
                }
            }
            return map;
        }